Skip to content

Commit

Permalink
test: worker interception for existing workers (#32494)
Browse files Browse the repository at this point in the history
Failing test for #32355
  • Loading branch information
yury-s authored Sep 6, 2024
1 parent 11441c0 commit df2bc2d
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions tests/page/interception.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ it('should work with glob', async () => {
expect(globToRegex('$^+.\\*()|\\?\\{\\}\\[\\]')).toEqual(/^\$\^\+\.\*\(\)\|\?\{\}\[\]$/);
});

it('should intercept network activity from worker', async function({ page, server, isAndroid, browserName, browserMajorVersion }) {
it.skip(browserName === 'firefox' && browserMajorVersion < 114, 'https://github.com/microsoft/playwright/issues/21760');
it('should intercept network activity from worker', async function({ page, server, isAndroid }) {
it.skip(isAndroid);

await page.goto(server.EMPTY_PAGE);
Expand All @@ -122,6 +121,35 @@ it('should intercept network activity from worker', async function({ page, serve
expect(msg.text()).toBe('intercepted');
});

it('should intercept worker requests when enabled after worker creation', {
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/32355' }
}, async function({ page, server, isAndroid, browserName }) {
it.skip(isAndroid);
it.fixme(browserName === 'chromium');

await page.goto(server.EMPTY_PAGE);
server.setRoute('/data_for_worker', (req, res) => res.end('failed to intercept'));
const url = server.PREFIX + '/data_for_worker';
await page.evaluate(url => {
(window as any).w = new Worker(URL.createObjectURL(new Blob([`
onmessage = function(e) {
fetch("${url}").then(response => response.text()).then(console.log);
};
`], { type: 'application/javascript' })));
}, url);
await page.route(url, route => {
route.fulfill({
status: 200,
body: 'intercepted',
}).catch(e => null);
});
const [msg] = await Promise.all([
page.waitForEvent('console'),
page.evaluate(() => (window as any).w.postMessage(''))
]);
expect(msg.text()).toBe('intercepted');
});

it('should intercept network activity from worker 2', async function({ page, server, isAndroid }) {
it.skip(isAndroid);

Expand Down

0 comments on commit df2bc2d

Please sign in to comment.