Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
test: link preload interception (#16908)
Yury Semikhatsky077b8a928960
diff --git a/tests/assets/preload.html b/tests/assets/preload.htmlnew file mode 100644index 0000000000..dc10ff6d69--- /dev/null+++ b/tests/assets/preload.html@@ -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>diff --git a/tests/page/page-request-continue.spec.ts b/tests/page/page-request-continue.spec.tsindex 3373ea2551..6befd3986c 100644--- a/tests/page/page-request-continue.spec.ts+++ b/tests/page/page-request-continue.spec.ts@@ -349,3 +349,27 @@ it('should delete the origin header', async ({ page, server, isAndroid, browserNexpect(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)');+});diff --git a/tests/page/page-request-fulfill.spec.ts b/tests/page/page-request-fulfill.spec.tsindex abcdb3ffe9..1c594fac29 100644--- a/tests/page/page-request-fulfill.spec.ts+++ b/tests/page/page-request-fulfill.spec.ts@@ -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)');+});+