Store what is actually set
This commit is contained in:
parent
b1a2d99fd4
commit
ca3bae707d
|
|
@ -267,7 +267,11 @@ export class WKBrowserContext extends BrowserContext {
|
||||||
const cc = network.rewriteCookies(cookies).map(c => ({
|
const cc = network.rewriteCookies(cookies).map(c => ({
|
||||||
...c,
|
...c,
|
||||||
session: c.expires === -1 || c.expires === undefined,
|
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[];
|
})) as Protocol.Playwright.SetCookieParam[];
|
||||||
await this._browser._browserSession.send('Playwright.setCookies', { cookies: cc, browserContextId: this._browserContextId });
|
await this._browser._browserSession.send('Playwright.setCookies', { cookies: cc, browserContextId: this._browserContextId });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ const test = baseTest.extend<BrowserTestTestFixtures, BrowserTestWorkerFixtures>
|
||||||
if (browserName === 'chromium')
|
if (browserName === 'chromium')
|
||||||
await run('Lax');
|
await run('Lax');
|
||||||
else if (browserName === 'webkit')
|
else if (browserName === 'webkit')
|
||||||
await run('None');
|
await run('Lax');
|
||||||
else if (browserName === 'firefox' && channel === 'firefox-beta')
|
else if (browserName === 'firefox' && channel === 'firefox-beta')
|
||||||
await run(browserMajorVersion >= 103 && browserMajorVersion < 110 ? 'Lax' : 'None');
|
await run(browserMajorVersion >= 103 && browserMajorVersion < 110 ? 'Lax' : 'None');
|
||||||
else if (browserName === 'firefox' && channel !== 'firefox-beta')
|
else if (browserName === 'firefox' && channel !== 'firefox-beta')
|
||||||
|
|
|
||||||
|
|
@ -224,7 +224,7 @@ it('should have |expires| set to |-1| for session cookies', async ({ context, se
|
||||||
expect(cookies[0].expires).toBe(-1);
|
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([{
|
await context.addCookies([{
|
||||||
url: server.EMPTY_PAGE,
|
url: server.EMPTY_PAGE,
|
||||||
name: 'defaults',
|
name: 'defaults',
|
||||||
|
|
@ -239,7 +239,7 @@ it('should set cookie with reasonable defaults', async ({ context, server, brows
|
||||||
expires: -1,
|
expires: -1,
|
||||||
httpOnly: false,
|
httpOnly: false,
|
||||||
secure: false,
|
secure: false,
|
||||||
sameSite: browserName === 'chromium' ? 'Lax' : 'None',
|
sameSite: defaultSameSiteCookieValue,
|
||||||
}]);
|
}]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -384,7 +384,7 @@ it('should support requestStorageAccess', async ({ page, server, channel, browse
|
||||||
server.waitForRequest('/title.html'),
|
server.waitForRequest('/title.html'),
|
||||||
frame.evaluate(() => fetch('/title.html'))
|
frame.evaluate(() => fetch('/title.html'))
|
||||||
]);
|
]);
|
||||||
if (!isMac && browserName === 'webkit')
|
if (isWindows && browserName === 'webkit')
|
||||||
expect(serverRequest.headers.cookie).toBe('name=value');
|
expect(serverRequest.headers.cookie).toBe('name=value');
|
||||||
else
|
else
|
||||||
expect(serverRequest.headers.cookie).toBeFalsy();
|
expect(serverRequest.headers.cookie).toBeFalsy();
|
||||||
|
|
@ -396,7 +396,7 @@ it('should support requestStorageAccess', async ({ page, server, channel, browse
|
||||||
server.waitForRequest('/title.html'),
|
server.waitForRequest('/title.html'),
|
||||||
frame.evaluate(() => fetch('/title.html'))
|
frame.evaluate(() => fetch('/title.html'))
|
||||||
]);
|
]);
|
||||||
expect(serverRequest.headers.cookie).toBe('name=value');
|
expect(serverRequest.headers.cookie).toBe(browserName === 'webkit' ? undefined : 'name=value');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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');
|
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']) {
|
for (const value of ['None', 'Lax', 'Strict']) {
|
||||||
await it.step(`SameSite=${value}`, async () => {
|
await it.step(`SameSite=${value}`, async () => {
|
||||||
server.setRoute('/empty.html', (req, res) => {
|
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();
|
const [cookie] = await page.context().cookies();
|
||||||
if (browserName === 'chromium' && value === 'None')
|
if (browserName === 'chromium' && value === 'None')
|
||||||
expect(cookie).toBeFalsy();
|
expect(cookie).toBeFalsy();
|
||||||
|
else if (browserName === 'webkit' && isLinux && value === 'None')
|
||||||
|
expect(cookie).toBeFalsy();
|
||||||
else if (browserName === 'webkit' && isWindows)
|
else if (browserName === 'webkit' && isWindows)
|
||||||
expect(cookie.sameSite).toBe('None');
|
expect(cookie.sameSite).toBe('None');
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue