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
chore(bidi): add support for setting partitioned cookies and update test expectations (#39101)
Holger Benld87043b114a7
diff --git a/packages/playwright-core/src/server/bidi/bidiBrowser.ts b/packages/playwright-core/src/server/bidi/bidiBrowser.tsindex f92d3e171b..071db4381b 100644--- a/packages/playwright-core/src/server/bidi/bidiBrowser.ts+++ b/packages/playwright-core/src/server/bidi/bidiBrowser.ts@@ -287,7 +287,7 @@ export class BidiBrowserContext extends BrowserContext {expiry: (c.expires === -1 || c.expires === undefined) ? undefined : Math.round(c.expires),};return this._browser._browserSession.send('storage.setCookie',- { cookie, partition: { type: 'storageKey', userContext: this._browserContextId } });+ { cookie, partition: { type: 'storageKey', userContext: this._browserContextId, sourceOrigin: c.partitionKey } });});await Promise.all(promises);}diff --git a/tests/bidi/expectations/moz-firefox-nightly-library.txt b/tests/bidi/expectations/moz-firefox-nightly-library.txtindex c4670bd364..6fe0666551 100644--- a/tests/bidi/expectations/moz-firefox-nightly-library.txt+++ b/tests/bidi/expectations/moz-firefox-nightly-library.txt@@ -8,13 +8,10 @@ library/browsercontext-basic.spec.ts › should emulate media in popup [fail]library/browsercontext-basic.spec.ts › should emulate navigator.onLine [fail]library/browsercontext-basic.spec.ts › should emulate offline event [fail]library/browsercontext-basic.spec.ts › should work with offline option [fail]-library/browsercontext-cookies-third-party.spec.ts › add 'Partitioned;' cookie via API [fail]library/browsercontext-cookies-third-party.spec.ts › same origin third party 'Partitioned;' cookie with different origin intermediate iframe [fail]library/browsercontext-cookies-third-party.spec.ts › save/load third party non-partitioned cookies [fail]+library/browsercontext-cookies-third-party.spec.ts › save/load third party 'Partitioned;' cookies [fail]library/browsercontext-cookies-third-party.spec.ts › should be able to send third party cookies via an iframe [fail]-library/browsercontext-cookies-third-party.spec.ts › third party 'Partitioned;' cookies [fail]-library/browsercontext-cookies-third-party.spec.ts › third party non-partitioned cookies [fail]-library/browsercontext-cookies-third-party.spec.ts › top level 'Partitioned;' cookie and same origin iframe [fail]library/browsercontext-cookies.spec.ts › should support requestStorageAccess [fail]library/browsercontext-credentials.spec.ts › should fail without credentials [timeout]library/browsercontext-credentials.spec.ts › should work with setHTTPCredentials [timeout]@@ -180,6 +177,7 @@ library/popup.spec.ts › should inherit viewport size from browser context [failibrary/popup.spec.ts › should not dispatch binding on a closed page [fail]library/popup.spec.ts › should not throw when click closes popup [timeout]library/role-utils.spec.ts › axe-core accessible-text [timeout]+library/role-utils.spec.ts › wpt accname #2 [timeout]library/screenshot.spec.ts › page screenshot › should work with device scale factor and scale:css [fail]library/screenshot.spec.ts › page screenshot › should work with device scale factor, clip and scale:css [fail]library/selector-generator.spec.ts › selector generator › should work in dynamic iframes without navigation [fail]@@ -221,6 +219,7 @@ library/video.spec.ts › screencast › should fail when recordVideo is set [falibrary/video.spec.ts › screencast › should expose video path [timeout]library/video.spec.ts › screencast › should expose video path blank page [timeout]library/video.spec.ts › screencast › should expose video path blank popup [timeout]+library/video.spec.ts › screencast › should not create video for internal pages [fail]library/video.spec.ts › screencast › should scale frames down to the requested size [timeout]library/video.spec.ts › screencast › should throw if browser dies [fail]library/video.spec.ts › screencast › should throw on browser close [fail]@@ -231,6 +230,7 @@ library/video.spec.ts › screencast › should work with old options [timeout]library/video.spec.ts › screencast › should work with relative path for recordVideo.dir [timeout]library/video.spec.ts › screencast › should work with video+trace [timeout]library/video.spec.ts › screencast › should work with weird screen resolution [timeout]+library/video.spec.ts › screencast › video.start should fail when recordVideo is set, but stop should work [fail]library/video.spec.ts › screencast › video.start/stop twice [timeout]library/video.spec.ts › should saveAs video [timeout]library/web-socket.spec.ts › should emit binary frame events [timeout]diff --git a/tests/library/browsercontext-cookies-third-party.spec.ts b/tests/library/browsercontext-cookies-third-party.spec.tsindex 8adab361e0..59800a9f91 100644--- a/tests/library/browsercontext-cookies-third-party.spec.ts+++ b/tests/library/browsercontext-cookies-third-party.spec.ts@@ -111,7 +111,7 @@ function expectPartitionKey(cookies: Cookie[], name: string, partitionKey: strinthrow new Error(`Cookie ${name} has partitionKey ${cookie.partitionKey} but expected ${partitionKey}.`);}-async function runNonPartitionedTest(page: Page, httpsServer: TestServer, browserName: string, isMac: boolean, isLinux: boolean, channel: string, urls: TestUrls) {+async function runNonPartitionedTest(page: Page, httpsServer: TestServer, browserName: string, isMac: boolean, isLinux: boolean, isBidi: boolean, channel: string, urls: TestUrls) {addCommonCookieHandlers(httpsServer, urls);httpsServer.setRoute('/set-cookie.html', (req, res) => {res.setHeader('Set-Cookie', `${req.headers.referer ? 'frame' : 'top-level'}=value; SameSite=None; Path=/; Secure;`);@@ -127,7 +127,7 @@ async function runNonPartitionedTest(page: Page, httpsServer: TestServer, browseconst frameBody = page.locator('iframe').contentFrame().locator('body');// WebKit does not support third-party cookies without a 'Partition' attribute.- if (browserName === 'webkit' && isMac)+ if ((browserName === 'webkit' && isMac) || (browserName === 'firefox' && isBidi))await expect(frameBody).toHaveText('Received cookie: undefined');elseawait expect(frameBody).toHaveText('Received cookie: top-level=value');@@ -135,15 +135,20 @@ async function runNonPartitionedTest(page: Page, httpsServer: TestServer, browse// Set cookie and do second navigation.await page.goto(urls.set_origin2_origin1);await page.goto(urls.read_origin2_origin1);- const expectedThirdParty = browserName === 'webkit' && isMac ?- 'Received cookie: undefined' : browserName === 'webkit' && (isLinux || channel === 'webkit-wsl') ?- 'Received cookie: top-level=value' :- 'Received cookie: frame=value; top-level=value';+ let expectedThirdParty = 'Received cookie: ';+ if (browserName === 'webkit' && isMac)+ expectedThirdParty += 'undefined';+ else if (browserName === 'webkit' && (isLinux || channel === 'webkit-wsl'))+ expectedThirdParty += 'top-level=value';+ else if (browserName === 'firefox' && isBidi)+ expectedThirdParty += 'frame=value';+ else+ expectedThirdParty += 'frame=value; top-level=value';await expect(frameBody).toHaveText(expectedThirdParty, { timeout: 1000 });// Check again the top-level cookie.await page.goto(urls.read_origin1);- const expectedTopLevel = browserName === 'webkit' && (isMac || isLinux || channel === 'webkit-wsl') ?+ const expectedTopLevel = (browserName === 'webkit' && (isMac || isLinux || channel === 'webkit-wsl')) || (browserName === 'firefox' && isBidi) ?'Received cookie: top-level=value' :'Received cookie: frame=value; top-level=value';expect(await page.locator('body').textContent()).toBe(expectedTopLevel);@@ -154,13 +159,13 @@ async function runNonPartitionedTest(page: Page, httpsServer: TestServer, browse};}-test(`third party non-partitioned cookies`, async ({ page, browserName, httpsServer, isMac, isLinux, urls, channel }) => {- await runNonPartitionedTest(page, httpsServer, browserName, isMac, isLinux, channel, urls);+test(`third party non-partitioned cookies`, async ({ page, browserName, httpsServer, isMac, isLinux, isBidi, urls, channel }) => {+ await runNonPartitionedTest(page, httpsServer, browserName, isMac, isLinux, isBidi, channel, urls);});-test(`save/load third party non-partitioned cookies`, async ({ page, browserName, httpsServer, isMac, isLinux, browser, urls, channel }) => {+test(`save/load third party non-partitioned cookies`, async ({ page, browserName, httpsServer, isMac, isLinux, isBidi, browser, urls, channel }) => {// Run the test to populate the cookies.- const { expectedTopLevel, expectedThirdParty } = await runNonPartitionedTest(page, httpsServer, browserName, isMac, isLinux, channel, urls);+ const { expectedTopLevel, expectedThirdParty } = await runNonPartitionedTest(page, httpsServer, browserName, isMac, isLinux, isBidi, channel, urls);async function checkCookies(page: Page) {// Check top-level cookie first.@@ -191,7 +196,7 @@ test(`save/load third party non-partitioned cookies`, async ({ page, browserName});});-async function runPartitionedTest(page: Page, httpsServer: TestServer, browserName: string, isMac: boolean, urls: TestUrls) {+async function runPartitionedTest(page: Page, httpsServer: TestServer, browserName: string, isMac: boolean, isBidi: boolean, urls: TestUrls) {addCommonCookieHandlers(httpsServer, urls);httpsServer.setRoute('/set-cookie.html', (req, res) => {res.setHeader('Set-Cookie', [@@ -208,9 +213,9 @@ async function runPartitionedTest(page: Page, httpsServer: TestServer, browserNaawait page.goto(urls.read_origin2_origin1);const frameBody = page.locator('iframe').contentFrame().locator('body');- // Firefox cookie partitioning is disabled in Firefox.+ // Firefox cookie partitioning is disabled in Firefox(Juggler).// TODO: reenable cookie partitioning?- if (browserName === 'firefox') {+ if (browserName === 'firefox' && !isBidi) {await expect(frameBody).toHaveText('Received cookie: top-level-non-partitioned=value; top-level-partitioned=value');return;}@@ -221,7 +226,7 @@ async function runPartitionedTest(page: Page, httpsServer: TestServer, browserNareturn;}- if (browserName === 'webkit') {+ if (browserName === 'webkit' || (browserName === 'firefox' && isBidi)) {// WebKit will only send 'Partitioned' third-party cookies exactly matching the partition.await expect(frameBody).toHaveText('Received cookie: undefined');} else {@@ -239,19 +244,21 @@ async function runPartitionedTest(page: Page, httpsServer: TestServer, browserNaawait page.goto(urls.read_origin2_origin1);if (browserName === 'webkit')await expect(frameBody).toHaveText('Received cookie: undefined');+ else if (browserName === 'firefox' && isBidi)+ await expect(frameBody).toHaveText('Received cookie: frame-non-partitioned=value; frame-partitioned=value');elseawait expect(frameBody).toHaveText('Received cookie: frame-non-partitioned=value; frame-partitioned=value; top-level-non-partitioned=value');}-test(`third party 'Partitioned;' cookies`, async ({ page, browserName, httpsServer, isMac, urls }) => {- await runPartitionedTest(page, httpsServer, browserName, isMac, urls);+test(`third party 'Partitioned;' cookies`, async ({ page, browserName, httpsServer, isMac, isBidi, urls }) => {+ await runPartitionedTest(page, httpsServer, browserName, isMac, isBidi, urls);});-test(`save/load third party 'Partitioned;' cookies`, async ({ page, browserName, httpsServer, isMac, browser, urls }) => {- test.fixme(browserName === 'firefox', 'Firefox cookie partitioning is disabled in Firefox.');+test(`save/load third party 'Partitioned;' cookies`, async ({ page, browserName, httpsServer, isMac, isBidi, browser, urls }) => {+ test.fixme(browserName === 'firefox' && !isBidi, 'Firefox cookie partitioning is disabled in Firefox(Juggler).');test.fixme(browserName === 'webkit' && !isMac, 'Linux and Windows WebKit builds do not partition third-party cookies at all.');- await runPartitionedTest(page, httpsServer, browserName, isMac, urls);+ await runPartitionedTest(page, httpsServer, browserName, isMac, isBidi, urls);async function checkCookies(page: Page) {{@@ -316,7 +323,7 @@ test(`save/load third party 'Partitioned;' cookies`, async ({ page, browserName,});});-test(`add 'Partitioned;' cookie via API`, async ({ page, context, browserName, httpsServer, isMac, urls }) => {+test(`add 'Partitioned;' cookie via API`, async ({ page, context, browserName, httpsServer, isMac, isBidi, urls }) => {addCommonCookieHandlers(httpsServer, urls);await context.addCookies([@@ -370,7 +377,7 @@ test(`add 'Partitioned;' cookie via API`, async ({ page, context, browserName, h{// Check top-level cookie first.await page.goto(urls.read_origin1);- const expectedTopLevel = browserName === 'webkit' || browserName === 'firefox' ?+ const expectedTopLevel = browserName === 'webkit' || (browserName === 'firefox' && !isBidi) ?'Received cookie: frame-non-partitioned=value; frame-partitioned=value; top-level-non-partitioned=value; top-level-partitioned=value' :'Received cookie: frame-non-partitioned=value; top-level-non-partitioned=value; top-level-partitioned=value';expect.soft(await page.locator('body').textContent()).toBe(expectedTopLevel);@@ -379,19 +386,28 @@ test(`add 'Partitioned;' cookie via API`, async ({ page, context, browserName, h// Check third-party cookie.await page.goto(urls.read_origin2_origin1);const frameBody = page.locator('iframe').contentFrame().locator('body');- const expectedThirdParty = browserName === 'webkit' && isMac ?- 'Received cookie: undefined' : browserName === 'chromium' ?- 'Received cookie: frame-non-partitioned=value; frame-partitioned=value; top-level-non-partitioned=value' :- // Firefox and WebKit on Linux/Windows do not partition third-party cookies.- 'Received cookie: frame-non-partitioned=value; frame-partitioned=value; top-level-non-partitioned=value; top-level-partitioned=value';+ let expectedThirdParty = 'Received cookie: ';+ if (browserName === 'webkit' && isMac)+ expectedThirdParty += 'undefined';+ else if (browserName === 'firefox' && isBidi)+ expectedThirdParty += 'frame-partitioned=value';+ else if (browserName === 'chromium')+ expectedThirdParty += 'frame-non-partitioned=value; frame-partitioned=value; top-level-non-partitioned=value';+ else+ // Firefox(Juggler) and WebKit on Linux/Windows do not partition third-party cookies.+ expectedThirdParty += 'frame-non-partitioned=value; frame-partitioned=value; top-level-non-partitioned=value; top-level-partitioned=value';await expect.soft(frameBody).toHaveText(expectedThirdParty, { timeout: 1000 });}{await page.goto(urls.read_origin1_origin2_origin1); // read-origin1-origin2-origin1.htmlconst frameBody = page.locator('iframe').contentFrame().locator('iframe').contentFrame().locator('body');- const expectedThirdParty = browserName === 'webkit' || browserName === 'firefox' ?- 'Received cookie: frame-non-partitioned=value; frame-partitioned=value; top-level-non-partitioned=value; top-level-partitioned=value' :- 'Received cookie: frame-non-partitioned=value; top-level-non-partitioned=value';+ let expectedThirdParty = 'Received cookie: ';+ if (browserName === 'webkit' || (browserName === 'firefox' && !isBidi))+ expectedThirdParty += 'frame-non-partitioned=value; frame-partitioned=value; top-level-non-partitioned=value; top-level-partitioned=value';+ else if (browserName === 'firefox' && isBidi)+ expectedThirdParty += 'undefined';+ else+ expectedThirdParty += 'frame-non-partitioned=value; top-level-non-partitioned=value';await expect.soft(frameBody).toHaveText(expectedThirdParty, { timeout: 1000 });}}@@ -400,7 +416,7 @@ test(`add 'Partitioned;' cookie via API`, async ({ page, context, browserName, h});-test(`same origin third party 'Partitioned;' cookie with different origin intermediate iframe`, async ({ page, httpsServer, browser, urls }) => {+test(`same origin third party 'Partitioned;' cookie with different origin intermediate iframe`, async ({ page, httpsServer, browser, isBidi, urls }) => {addCommonCookieHandlers(httpsServer, urls);httpsServer.setRoute('/set-cookie.html', (req, res) => {res.setHeader('Set-Cookie', [@@ -438,7 +454,7 @@ test(`same origin third party 'Partitioned;' cookie with different origin interm});});-test(`top level 'Partitioned;' cookie and same origin iframe`, async ({ page, browserName, httpsServer, browser, urls }) => {+test(`top level 'Partitioned;' cookie and same origin iframe`, async ({ page, browserName, httpsServer, browser, isBidi, urls }) => {addCommonCookieHandlers(httpsServer, urls);httpsServer.setRoute('/set-cookie.html', (req, res) => {res.setHeader('Set-Cookie', [@@ -469,9 +485,13 @@ test(`top level 'Partitioned;' cookie and same origin iframe`, async ({ page, br// main frame: origin1 -> iframe1: origin2 -> iframe2: origin1await page.goto(urls.read_origin1_origin2_origin1);const frameBody = page.locator('iframe').contentFrame().locator('iframe').contentFrame().locator('body');- const expectedThirdParty = browserName === 'chromium'- ? 'Received cookie: top-level-non-partitioned=value'- : 'Received cookie: top-level-non-partitioned=value; top-level=value';+ let expectedThirdParty = 'Received cookie: ';+ if (browserName === 'chromium')+ expectedThirdParty += 'top-level-non-partitioned=value';+ else if (browserName === 'firefox' && isBidi)+ expectedThirdParty += 'undefined';+ else+ expectedThirdParty += 'top-level-non-partitioned=value; top-level=value';await expect.soft(frameBody).toHaveText(expectedThirdParty, { timeout: 1000 });}}@@ -494,8 +514,9 @@ test(`top level 'Partitioned;' cookie and same origin iframe`, async ({ page, br});});-test('should be able to send third party cookies via an iframe', async ({ browser, httpsServer, browserName, isMac }) => {+test('should be able to send third party cookies via an iframe', async ({ browser, httpsServer, browserName, isMac, isBidi }) => {test.fixme(browserName === 'webkit' && isMac);+ test.skip(browserName === 'firefox' && isBidi, 'Firefox\'s Total Cookie Protection blocks this third-party cookie');test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/16937' });const context = await browser.newContext({