Skip to content

Commit bb81ef0

Browse files
authored
test(firefox): cover background cache revalidation and cached module body (#44050)
1 parent e17f097 commit bb81ef0

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎tests/library/browsercontext-network-event.spec.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,28 @@ it('NE-127 should reject response.finished if context closes', async ({ page, se
164164
const error = await finishPromise;
165165
expect(error.message).toContain('closed');
166166
});
167+
168+
it('NE-144 should not wait for navigation after background cache revalidation', {
169+
annotation: { type: 'issue', description: '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/microsoft/playwright/issues/43995' },
170+
}, async ({ context, server }) => {
171+
server.setRoute('/swr.html', (req, res) => {
172+
const headers = {
173+
'Content-Type': 'text/html',
174+
'Cache-Control': 's-maxage=900, stale-while-revalidate=31535100',
175+
'ETag': '"v1"',
176+
};
177+
if (req.headers['if-none-match'] === '"v1"') {
178+
res.writeHead(304, headers);
179+
res.end();
180+
return;
181+
}
182+
res.writeHead(200, headers);
183+
res.end('<h1>Hello</h1>');
184+
});
185+
const page1 = await context.newPage();
186+
await page1.goto(server.PREFIX + '/swr.html');
187+
const page2 = await context.newPage();
188+
await page2.goto(server.PREFIX + '/swr.html');
189+
await page2.waitForTimeout(1000);
190+
await expect(page2.locator('h1')).toHaveText('Hello');
191+
});

‎tests/page/page-network-response.spec.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,29 @@ it('NE-051 should return body for image with evicted body', {
392392
expect(body.toString('base64')).toBe(imageBase64);
393393
});
394394

395+
it('NE-145 should return source for a module script loaded from cache', {
396+
annotation: { type: 'issue', description: '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/microsoft/playwright/issues/43991' },
397+
}, async ({ page, server }) => {
398+
const source = Array.from({ length: 400 }, (_, i) => `export function f${i}() { return ${i}; }`).join('\n');
399+
server.setRoute('/module.js', (req, res) => {
400+
res.writeHead(200, { 'Content-Type': 'text/javascript', 'Cache-Control': 'max-age=3600' });
401+
res.end(source);
402+
});
403+
server.setRoute('/module.html', (req, res) => {
404+
res.setHeader('Content-Type', 'text/html');
405+
res.end('<script type="module" src="/module.js"></script>');
406+
});
407+
// Firefox stores module bytecode in the HTTP cache after several loads.
408+
for (let i = 0; i < 5; ++i) {
409+
const [response] = await Promise.all([
410+
page.waitForResponse('**/module.js'),
411+
page.goto(server.PREFIX + '/module.html'),
412+
]);
413+
expect((await response.body()).toString()).toBe(source);
414+
await page.waitForTimeout(500);
415+
}
416+
});
417+
395418
it('NE-052 should bypass disk cache when page interception is enabled', async ({ page, server }) => {
396419
it.info().annotations.push({ type: 'issue', description: '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/microsoft/playwright/issues/30000' });
397420
await page.goto(server.PREFIX + '/frames/one-frame.html');

‎tests/registry.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4021,6 +4021,8 @@ subsystem, add a row to the Subsystems table. Then update this file:
40214021
| `NE-141` | `library/ignorehttpserrors.spec.ts` | should fail with WebSocket if not ignored |
40224022
| `NE-142` | `library/ignorehttpserrors.spec.ts` | serviceWorker should intercept document request |
40234023
| `NE-143` | `page/page-event-network.spec.ts` | should resolve responses after a same-process navigation |
4024+
| `NE-144` | `library/browsercontext-network-event.spec.ts` | should not wait for navigation after background cache revalidation |
4025+
| `NE-145` | `page/page-network-response.spec.ts` | should return source for a module script loaded from cache |
40244026

40254027
### OO — OOPIF
40264028

0 commit comments

Comments
 (0)