From a1558d5c7047a0215cc2068425d2e0c9fbdb4a8c Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Thu, 30 Sep 2021 13:56:20 -0700 Subject: [PATCH] test(cookies): add a test for SameSite=None cookies (#9242) --- tests/browsercontext-add-cookies.spec.ts | 36 ++++++++++++++++++++++++ tests/headful.spec.ts | 36 ++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/tests/browsercontext-add-cookies.spec.ts b/tests/browsercontext-add-cookies.spec.ts index 6b66485bb6..2d4ace9072 100644 --- a/tests/browsercontext-add-cookies.spec.ts +++ b/tests/browsercontext-add-cookies.spec.ts @@ -367,3 +367,39 @@ it('should(not) block third party cookies', async ({ context, page, server, brow expect(cookies).toEqual([]); } }); + +it('should not block third party SameSite=None cookies', async ({ contextFactory, httpsServer, browserName }) => { + it.skip(browserName === 'webkit', 'No third party cookies in WebKit'); + const context = await contextFactory({ + ignoreHTTPSErrors: true, + }); + const page = await context.newPage(); + + httpsServer.setRoute('/empty.html', (req, res) => { + res.writeHead(200, { + 'Content-Type': 'text/html' + }); + res.end(``); + }); + + httpsServer.setRoute('/grid.html', (req, res) => { + res.writeHead(200, { + 'Set-Cookie': ['a=b; Path=/; Max-Age=3600; SameSite=None; Secure'], + 'Content-Type': 'text/html' + }); + res.end(`Hello world + `); + }); + + const cookie = new Promise(f => { + httpsServer.setRoute('/json', (req, res) => { + f(req.headers.cookie); + res.end(); + }); + }); + + await page.goto(httpsServer.EMPTY_PAGE); + expect(await cookie).toBe('a=b'); +}); diff --git a/tests/headful.spec.ts b/tests/headful.spec.ts index f33a130f3d..9a04d98d34 100644 --- a/tests/headful.spec.ts +++ b/tests/headful.spec.ts @@ -107,6 +107,42 @@ it('should(not) block third party cookies', async ({ browserType, browserOptions await browser.close(); }); +it('should not block third party SameSite=None cookies', async ({ browserOptions, httpsServer, browserName, browserType }) => { + it.skip(browserName === 'webkit', 'No third party cookies in WebKit'); + const browser = await browserType.launch({ ...browserOptions, headless: false }); + const page = await browser.newPage({ + ignoreHTTPSErrors: true, + }); + + httpsServer.setRoute('/empty.html', (req, res) => { + res.writeHead(200, { + 'Content-Type': 'text/html' + }); + res.end(``); + }); + + httpsServer.setRoute('/grid.html', (req, res) => { + res.writeHead(200, { + 'Set-Cookie': ['a=b; Path=/; Max-Age=3600; SameSite=None; Secure'], + 'Content-Type': 'text/html' + }); + res.end(`Hello world + `); + }); + + const cookie = new Promise(f => { + httpsServer.setRoute('/json', (req, res) => { + f(req.headers.cookie); + res.end(); + }); + }); + + await page.goto(httpsServer.EMPTY_PAGE); + expect(await cookie).toBe('a=b'); +}); + it('should not override viewport size when passed null', async function({ browserType, browserOptions, server, browserName }) { it.fixme(browserName === 'webkit');