test: link preload interception (#16908)
This commit is contained in:
parent
71f061ea9a
commit
077b8a9289
5
tests/assets/preload.html
Normal file
5
tests/assets/preload.html
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<script>
|
||||
let preloadedStyles = false;
|
||||
</script>
|
||||
<link rel="preload" href="./one-style.css" as="style" onload="window.preloadedStyles=true;this.onload=null;this.rel='stylesheet'" />
|
||||
<div>hello, world!</div>
|
||||
|
|
@ -349,3 +349,27 @@ it('should delete the origin header', async ({ page, server, isAndroid, browserN
|
|||
expect(interceptedRequest.headers()['origin']).toEqual(undefined);
|
||||
expect(serverRequest.headers.origin).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should continue preload link requests', async ({ page, server, browserName }) => {
|
||||
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/16745' });
|
||||
it.fixme(browserName === 'webkit', 'Preload requests are aborted in WebKit when interception is enabled');
|
||||
let intercepted = false;
|
||||
await page.route('**/one-style.css', route => {
|
||||
intercepted = true;
|
||||
route.continue({
|
||||
headers: {
|
||||
...route.request().headers(),
|
||||
'custom': 'value'
|
||||
}
|
||||
});
|
||||
});
|
||||
const [serverRequest] = await Promise.all([
|
||||
server.waitForRequest('/one-style.css'),
|
||||
page.goto(server.PREFIX + '/preload.html')
|
||||
]);
|
||||
expect(serverRequest.headers['custom']).toBe('value');
|
||||
await page.waitForFunction(() => (window as any).preloadedStyles);
|
||||
expect(intercepted).toBe(true);
|
||||
const color = await page.evaluate(() => window.getComputedStyle(document.body).backgroundColor);
|
||||
expect(color).toBe('rgb(255, 192, 203)');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -353,3 +353,31 @@ function findResponse(har: har.HARFile, url: string): har.Response {
|
|||
expect(entry, originalUrl).toBeTruthy();
|
||||
return entry?.response;
|
||||
}
|
||||
|
||||
it('should fulfill preload link requests', async ({ page, server, browserName }) => {
|
||||
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/16745' });
|
||||
it.fixme(browserName === 'webkit', 'Preload requests are aborted in WebKit when interception is enabled');
|
||||
let intercepted = false;
|
||||
await page.route('**/one-style.css', route => {
|
||||
intercepted = true;
|
||||
route.fulfill({
|
||||
status: 200,
|
||||
headers: {
|
||||
'content-type': 'text/css; charset=utf-8',
|
||||
'cache-control': 'no-cache, no-store',
|
||||
'custom': 'value'
|
||||
},
|
||||
body: 'body { background-color: green; }'
|
||||
});
|
||||
});
|
||||
const [response] = await Promise.all([
|
||||
page.waitForResponse('**/one-style.css'),
|
||||
page.goto(server.PREFIX + '/preload.html')
|
||||
]);
|
||||
expect(await response.headerValue('custom')).toBe('value');
|
||||
await page.waitForFunction(() => (window as any).preloadedStyles);
|
||||
expect(intercepted).toBe(true);
|
||||
const color = await page.evaluate(() => window.getComputedStyle(document.body).backgroundColor);
|
||||
expect(color).toBe('rgb(0, 128, 0)');
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue