From f93da4092521892307b150aaeeffa465a67a6bda Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 29 May 2024 17:20:38 -0700 Subject: [PATCH] feat(webkit): roll to r2014 (#31074) Closes https://github.com/microsoft/playwright/pull/31059 Closes https://github.com/microsoft/playwright/pull/31012 Reference https://github.com/microsoft/playwright-browsers/issues/795 --- packages/playwright-core/browsers.json | 2 +- packages/playwright-core/src/server/webkit/wkBrowser.ts | 4 +++- tests/config/browserTest.ts | 6 ++++-- tests/library/browsercontext-add-cookies.spec.ts | 6 +++--- tests/library/browsercontext-cookies.spec.ts | 7 +++++-- tests/library/browsercontext-fetch.spec.ts | 4 +++- tests/library/browsercontext-route.spec.ts | 4 ++-- 7 files changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/playwright-core/browsers.json b/packages/playwright-core/browsers.json index 26417b7054..25384e9345 100644 --- a/packages/playwright-core/browsers.json +++ b/packages/playwright-core/browsers.json @@ -27,7 +27,7 @@ }, { "name": "webkit", - "revision": "2013", + "revision": "2014", "installByDefault": true, "revisionOverrides": { "mac10.14": "1446", diff --git a/packages/playwright-core/src/server/webkit/wkBrowser.ts b/packages/playwright-core/src/server/webkit/wkBrowser.ts index 4b10dfd3fe..b65ca55c21 100644 --- a/packages/playwright-core/src/server/webkit/wkBrowser.ts +++ b/packages/playwright-core/src/server/webkit/wkBrowser.ts @@ -267,7 +267,9 @@ export class WKBrowserContext extends BrowserContext { const cc = network.rewriteCookies(cookies).map(c => ({ ...c, session: c.expires === -1 || c.expires === undefined, - expires: c.expires && c.expires !== -1 ? c.expires * 1000 : c.expires + expires: c.expires && c.expires !== -1 ? c.expires * 1000 : c.expires, + // TODO: make WebKit on linux work without eplicit sameSite. + sameSite: c.sameSite ?? (process.platform === 'linux' ? 'Lax' : undefined) })) as Protocol.Playwright.SetCookieParam[]; await this._browser._browserSession.send('Playwright.setCookies', { cookies: cc, browserContextId: this._browserContextId }); } diff --git a/tests/config/browserTest.ts b/tests/config/browserTest.ts index 02555d42eb..8b4fdc27b9 100644 --- a/tests/config/browserTest.ts +++ b/tests/config/browserTest.ts @@ -67,10 +67,12 @@ const test = baseTest.extend await run(false); }, { scope: 'worker' }], - defaultSameSiteCookieValue: [async ({ browserName, browserMajorVersion, channel }, run) => { + defaultSameSiteCookieValue: [async ({ browserName, browserMajorVersion, channel, isLinux }, run) => { if (browserName === 'chromium') await run('Lax'); - else if (browserName === 'webkit') + else if (browserName === 'webkit' && isLinux) + await run('Lax'); + else if (browserName === 'webkit' && !isLinux) await run('None'); else if (browserName === 'firefox' && channel === 'firefox-beta') await run(browserMajorVersion >= 103 && browserMajorVersion < 110 ? 'Lax' : 'None'); diff --git a/tests/library/browsercontext-add-cookies.spec.ts b/tests/library/browsercontext-add-cookies.spec.ts index bdfe14ef0a..f35ea8b327 100644 --- a/tests/library/browsercontext-add-cookies.spec.ts +++ b/tests/library/browsercontext-add-cookies.spec.ts @@ -24,7 +24,7 @@ it('should work @smoke', async ({ context, page, server }) => { await context.addCookies([{ url: server.EMPTY_PAGE, name: 'password', - value: '123456' + value: '123456', }]); expect(await page.evaluate(() => document.cookie)).toEqual('password=123456'); }); @@ -224,7 +224,7 @@ it('should have |expires| set to |-1| for session cookies', async ({ context, se expect(cookies[0].expires).toBe(-1); }); -it('should set cookie with reasonable defaults', async ({ context, server, browserName }) => { +it('should set cookie with reasonable defaults', async ({ context, server, defaultSameSiteCookieValue }) => { await context.addCookies([{ url: server.EMPTY_PAGE, name: 'defaults', @@ -239,7 +239,7 @@ it('should set cookie with reasonable defaults', async ({ context, server, brows expires: -1, httpOnly: false, secure: false, - sameSite: browserName === 'chromium' ? 'Lax' : 'None', + sameSite: defaultSameSiteCookieValue, }]); }); diff --git a/tests/library/browsercontext-cookies.spec.ts b/tests/library/browsercontext-cookies.spec.ts index a53f989886..df923ef3ff 100644 --- a/tests/library/browsercontext-cookies.spec.ts +++ b/tests/library/browsercontext-cookies.spec.ts @@ -384,7 +384,7 @@ it('should support requestStorageAccess', async ({ page, server, channel, browse server.waitForRequest('/title.html'), frame.evaluate(() => fetch('/title.html')) ]); - if (!isMac && browserName === 'webkit') + if (isWindows && browserName === 'webkit') expect(serverRequest.headers.cookie).toBe('name=value'); else expect(serverRequest.headers.cookie).toBeFalsy(); @@ -396,7 +396,10 @@ it('should support requestStorageAccess', async ({ page, server, channel, browse server.waitForRequest('/title.html'), frame.evaluate(() => fetch('/title.html')) ]); - expect(serverRequest.headers.cookie).toBe('name=value'); + if (isLinux && browserName === 'webkit') + expect(serverRequest.headers.cookie).toBe(undefined); + else + expect(serverRequest.headers.cookie).toBe('name=value'); } } }); diff --git a/tests/library/browsercontext-fetch.spec.ts b/tests/library/browsercontext-fetch.spec.ts index f4088359cf..99fd0265a3 100644 --- a/tests/library/browsercontext-fetch.spec.ts +++ b/tests/library/browsercontext-fetch.spec.ts @@ -1202,7 +1202,7 @@ it('fetch should not throw on long set-cookie value', async ({ context, server } expect(cookies.map(c => c.name)).toContain('bar'); }); -it('should support set-cookie with SameSite and without Secure attribute over HTTP', async ({ page, server, browserName, isWindows }) => { +it('should support set-cookie with SameSite and without Secure attribute over HTTP', async ({ page, server, browserName, isWindows, isLinux }) => { for (const value of ['None', 'Lax', 'Strict']) { await it.step(`SameSite=${value}`, async () => { server.setRoute('/empty.html', (req, res) => { @@ -1213,6 +1213,8 @@ it('should support set-cookie with SameSite and without Secure attribute over HT const [cookie] = await page.context().cookies(); if (browserName === 'chromium' && value === 'None') expect(cookie).toBeFalsy(); + else if (browserName === 'webkit' && isLinux && value === 'None') + expect(cookie).toBeFalsy(); else if (browserName === 'webkit' && isWindows) expect(cookie.sameSite).toBe('None'); else diff --git a/tests/library/browsercontext-route.spec.ts b/tests/library/browsercontext-route.spec.ts index a597cf1157..25d965c1b6 100644 --- a/tests/library/browsercontext-route.spec.ts +++ b/tests/library/browsercontext-route.spec.ts @@ -109,7 +109,7 @@ it('should fall back to context.route', async ({ browser, server }) => { await context.close(); }); -it('should support Set-Cookie header', async ({ contextFactory, server, browserName, defaultSameSiteCookieValue }) => { +it('should support Set-Cookie header', async ({ contextFactory, defaultSameSiteCookieValue }) => { const context = await contextFactory(); const page = await context.newPage(); await page.route('https://example.com/', (route, request) => { @@ -152,7 +152,7 @@ it('should ignore secure Set-Cookie header for insecure requests', async ({ cont expect(await context.cookies()).toEqual([]); }); -it('should use Set-Cookie header in future requests', async ({ contextFactory, server, browserName, defaultSameSiteCookieValue }) => { +it('should use Set-Cookie header in future requests', async ({ contextFactory, server, defaultSameSiteCookieValue }) => { const context = await contextFactory(); const page = await context.newPage();