Skip to content

Commit 08d7139

Browse files
authored
test: add third party cookies test (#2073)
1 parent c62cb78 commit 08d7139

File tree

5 files changed

+69
-5
lines changed

5 files changed

+69
-5
lines changed

browsers.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
{
1212
"name": "webkit",
13-
"revision": "1213"
13+
"revision": "1216"
1414
}
1515
]
1616
}

packages/playwright-webkit/browsers.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"browsers": [
33
{
44
"name": "webkit",
5-
"revision": "1213"
5+
"revision": "1216"
66
}
77
]
88
}

packages/playwright/browsers.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
{
1212
"name": "webkit",
13-
"revision": "1213"
13+
"revision": "1216"
1414
}
1515
]
1616
}

test/cookies.spec.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
const {FFOX, CHROMIUM, WEBKIT, MAC} = require('./utils').testOptions(browserType);
18+
const {FFOX, CHROMIUM, WEBKIT, MAC, LINUX} = require('./utils').testOptions(browserType);
1919

2020
describe('BrowserContext.cookies', function() {
2121
it('should return no cookies in pristine browser context', async({context, page, server}) => {
@@ -432,6 +432,38 @@ describe('BrowserContext.addCookies', function() {
432432

433433
expect(await page.frames()[1].evaluate('document.cookie')).toBe('frame-cookie=value');
434434
});
435+
it('should(not) block third party cookies', async({context, page, server}) => {
436+
await page.goto(server.EMPTY_PAGE);
437+
await page.evaluate(src => {
438+
let fulfill;
439+
const promise = new Promise(x => fulfill = x);
440+
const iframe = document.createElement('iframe');
441+
document.body.appendChild(iframe);
442+
iframe.onload = fulfill;
443+
iframe.src = src;
444+
return promise;
445+
}, server.CROSS_PROCESS_PREFIX + '/grid.html');
446+
await page.frames()[1].evaluate(`document.cookie = 'username=John Doe'`);
447+
await page.waitForTimeout(2000);
448+
const allowsThirdParty = CHROMIUM || FFOX;
449+
const cookies = await context.cookies(server.CROSS_PROCESS_PREFIX + '/grid.html');
450+
if (allowsThirdParty) {
451+
expect(cookies).toEqual([
452+
{
453+
"domain": "127.0.0.1",
454+
"expires": -1,
455+
"httpOnly": false,
456+
"name": "username",
457+
"path": "/",
458+
"sameSite": "None",
459+
"secure": false,
460+
"value": "John Doe"
461+
}
462+
]);
463+
} else {
464+
expect(cookies).toEqual([]);
465+
}
466+
});
435467
});
436468

437469
describe('BrowserContext.clearCookies', function() {

test/defaultbrowsercontext.spec.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
const utils = require('./utils');
1919
const {makeUserDataDir, removeUserDataDir} = utils;
20-
const {FFOX, CHROMIUM, WEBKIT} = utils.testOptions(browserType);
20+
const {FFOX, MAC, CHROMIUM, WEBKIT} = utils.testOptions(browserType);
2121

2222
describe('launchPersistentContext()', function() {
2323
beforeEach(async state => {
@@ -83,4 +83,36 @@ describe('launchPersistentContext()', function() {
8383
expect(await page.context().cookies([])).toEqual([]);
8484
expect(await page.evaluate('document.cookie')).toBe('');
8585
});
86+
it('should(not) block third party cookies', async({browserContext, page, server}) => {
87+
await page.goto(server.EMPTY_PAGE);
88+
await page.evaluate(src => {
89+
let fulfill;
90+
const promise = new Promise(x => fulfill = x);
91+
const iframe = document.createElement('iframe');
92+
document.body.appendChild(iframe);
93+
iframe.onload = fulfill;
94+
iframe.src = src;
95+
return promise;
96+
}, server.CROSS_PROCESS_PREFIX + '/grid.html');
97+
await page.frames()[1].evaluate(`document.cookie = 'username=John Doe'`);
98+
await page.waitForTimeout(2000);
99+
const allowsThirdParty = CHROMIUM || FFOX;
100+
const cookies = await browserContext.cookies(server.CROSS_PROCESS_PREFIX + '/grid.html');
101+
if (allowsThirdParty) {
102+
expect(cookies).toEqual([
103+
{
104+
"domain": "127.0.0.1",
105+
"expires": -1,
106+
"httpOnly": false,
107+
"name": "username",
108+
"path": "/",
109+
"sameSite": "None",
110+
"secure": false,
111+
"value": "John Doe"
112+
}
113+
]);
114+
} else {
115+
expect(cookies).toEqual([]);
116+
}
117+
});
86118
});

0 commit comments

Comments
 (0)