Skip to content

Commit

Permalink
fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Sep 26, 2024
1 parent 74af249 commit 4aa36f9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
8 changes: 8 additions & 0 deletions tests/config/browserTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import type { TestInfo } from '@playwright/test';
export type BrowserTestWorkerFixtures = PageWorkerFixtures & {
browserVersion: string;
defaultSameSiteCookieValue: string;
sameSiteStoredValueForNone: string;
allowsThirdParty: boolean;
browserMajorVersion: number;
browserType: BrowserType;
Expand Down Expand Up @@ -86,6 +87,13 @@ const test = baseTest.extend<BrowserTestTestFixtures, BrowserTestWorkerFixtures>
throw new Error('unknown browser - ' + browserName);
}, { scope: 'worker' }],

sameSiteStoredValueForNone: [async ({ browserName, isMac }, run) => {
if (browserName === 'webkit' && isMac && parseInt(os.release(), 10) >= 24)
await run('Lax');
else
await run('None');
}, { scope: 'worker' }],

browserMajorVersion: [async ({ browserVersion }, run) => {
await run(Number(browserVersion.split('.')[0]));
}, { scope: 'worker' }],
Expand Down
8 changes: 4 additions & 4 deletions tests/library/browsercontext-cookies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ it('should get multiple cookies', async ({ context, page, server, defaultSameSit
]));
});

it('should get cookies from multiple urls', async ({ context, browserName, isWindows, platform }) => {
it('should get cookies from multiple urls', async ({ context, browserName, isWindows, sameSiteStoredValueForNone }) => {
await context.addCookies([{
url: 'https://foo.com',
name: 'doggo',
Expand Down Expand Up @@ -178,7 +178,7 @@ it('should get cookies from multiple urls', async ({ context, browserName, isWin
expires: -1,
httpOnly: false,
secure: true,
sameSite: (browserName === 'webkit' && platform === 'darwin' && parseInt(os.release(), 10) >= 24) ? 'Lax' : 'None',
sameSite: sameSiteStoredValueForNone,
}]));
});

Expand Down Expand Up @@ -274,7 +274,7 @@ it('should return secure cookies based on HTTP(S) protocol', async ({ context, b
}]);
});

it('should add cookies with an expiration', async ({ context, browserName, platform }) => {
it('should add cookies with an expiration', async ({ context, sameSiteStoredValueForNone }) => {
const expires = Math.floor((Date.now() / 1000)) + 3600;
await context.addCookies([{
url: 'https://foo.com',
Expand All @@ -293,7 +293,7 @@ it('should add cookies with an expiration', async ({ context, browserName, platf
expires,
httpOnly: false,
secure: true,
sameSite: (browserName === 'webkit' && platform === 'darwin' && parseInt(os.release(), 10) >= 24) ? 'Lax' : 'None',
sameSite: sameSiteStoredValueForNone,
}]);
{
// Rollover to 5-digit year
Expand Down
13 changes: 6 additions & 7 deletions tests/library/browsercontext-fetch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import os from 'os';
import type { LookupAddress } from 'dns';
import formidable from 'formidable';
import fs from 'fs';
Expand Down Expand Up @@ -1246,7 +1245,7 @@ it('should work with connectOverCDP', async ({ browserName, browserType, server
}
});

it('should support SameSite cookie attribute over https', async ({ contextFactory, httpsServer, browserName, isWindows, platform }) => {
it('should support SameSite cookie attribute over https', async ({ contextFactory, httpsServer, browserName, isWindows, sameSiteStoredValueForNone }) => {
// Cookies with SameSite=None must also specify the Secure attribute. WebKit navigation
// to HTTP url will fail if the response contains a cookie with Secure attribute, so
// we do HTTPS navigation.
Expand All @@ -1262,8 +1261,8 @@ it('should support SameSite cookie attribute over https', async ({ contextFactor
const [cookie] = await page.context().cookies();
if (browserName === 'webkit' && isWindows)
expect(cookie.sameSite).toBe('None');
else if (browserName === 'webkit' && platform === 'darwin' && value === 'None')
expect(cookie.sameSite).toBe('Lax');
else if (value === 'None')
expect(cookie.sameSite).toBe(sameSiteStoredValueForNone);
else
expect(cookie.sameSite).toBe(value);
});
Expand Down Expand Up @@ -1293,7 +1292,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, isLinux, isMac }) => {
it('should support set-cookie with SameSite and without Secure attribute over HTTP', async ({ page, server, browserName, isWindows, isLinux, sameSiteStoredValueForNone }) => {
for (const value of ['None', 'Lax', 'Strict']) {
await it.step(`SameSite=${value}`, async () => {
server.setRoute('/empty.html', (req, res) => {
Expand All @@ -1308,8 +1307,8 @@ it('should support set-cookie with SameSite and without Secure attribute over HT
expect(cookie).toBeFalsy();
else if (browserName === 'webkit' && isWindows)
expect(cookie.sameSite).toBe('None');
else if (browserName === 'webkit' && isMac && parseInt(os.release(), 10) >= 24 && value === 'None')
expect(cookie.sameSite).toBe('Lax');
else if (value === 'None')
expect(cookie.sameSite).toBe(sameSiteStoredValueForNone);
else
expect(cookie.sameSite).toBe(value);
});
Expand Down

0 comments on commit 4aa36f9

Please sign in to comment.