From cc51d13c363d7d184c867733b527a6c767a6dccd Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 12 Jul 2023 17:40:53 -0700 Subject: [PATCH] test: request cookie order is same as in set-cookie (#24194) --- tests/library/browsercontext-fetch.spec.ts | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/library/browsercontext-fetch.spec.ts b/tests/library/browsercontext-fetch.spec.ts index fa38270a58..8d31c6b6f5 100644 --- a/tests/library/browsercontext-fetch.spec.ts +++ b/tests/library/browsercontext-fetch.spec.ts @@ -218,6 +218,33 @@ it('should add cookies from Set-Cookie header', async ({ context, page, server } expect((await page.evaluate(() => document.cookie)).split(';').map(s => s.trim()).sort()).toEqual(['foo=bar', 'session=value']); }); +it('should preserve cookie order from Set-Cookie header', async ({ context, page, server, browserName, isLinux }) => { + it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/23390' }); + it.fixme(browserName === 'webkit' && isLinux); + server.setRoute('/setcookie.html', (req, res) => { + res.setHeader('Set-Cookie', ['cookie.0=foo', 'cookie.1=bar']); + res.end(); + }); + await page.request.get(server.PREFIX + '/setcookie.html'); + const cookies = await context.cookies(); + expect(cookies.map(c => ({ name: c.name, value: c.value }))).toEqual([ + { + name: 'cookie.0', + value: 'foo' + }, + { + name: 'cookie.1', + value: 'bar' + }, + ]); + await page.goto(server.EMPTY_PAGE); + expect(await page.evaluate(() => document.cookie)).toEqual('cookie.0=foo; cookie.1=bar'); + const requestPromise = server.waitForRequest('/empty.html'); + await page.request.get(server.EMPTY_PAGE); + const request = await requestPromise; + expect(request.headers.cookie).toEqual('cookie.0=foo; cookie.1=bar'); +}); + it('should support cookie with empty value', async ({ context, page, server }) => { server.setRoute('/setcookie.html', (req, res) => { res.setHeader('Set-Cookie', ['first=']);