Store what is actually set

This commit is contained in:
Yury Semikhatsky 2024-05-24 17:26:15 -07:00
parent b1a2d99fd4
commit ca3bae707d
5 changed files with 13 additions and 7 deletions

View file

@ -267,7 +267,11 @@ 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,
// Cookies without SameSite attribute are treated as Lax by the spec,
// so we provide the value explicitly to not depend on the underlying
// network library defaults.
sameSite: c.sameSite ?? 'Lax',
})) as Protocol.Playwright.SetCookieParam[];
await this._browser._browserSession.send('Playwright.setCookies', { cookies: cc, browserContextId: this._browserContextId });
}

View file

@ -71,7 +71,7 @@ const test = baseTest.extend<BrowserTestTestFixtures, BrowserTestWorkerFixtures>
if (browserName === 'chromium')
await run('Lax');
else if (browserName === 'webkit')
await run('None');
await run('Lax');
else if (browserName === 'firefox' && channel === 'firefox-beta')
await run(browserMajorVersion >= 103 && browserMajorVersion < 110 ? 'Lax' : 'None');
else if (browserName === 'firefox' && channel !== 'firefox-beta')

View file

@ -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, browserName, 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,
}]);
});

View file

@ -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,7 @@ 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');
expect(serverRequest.headers.cookie).toBe(browserName === 'webkit' ? undefined : 'name=value');
}
}
});

View file

@ -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