Skip to content

Commit

Permalink
test: add third party cookies test
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman committed May 4, 2020
1 parent c62cb78 commit 2ea79d8
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 5 deletions.
2 changes: 1 addition & 1 deletion browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"name": "webkit",
"revision": "1213"
"revision": "1216"
}
]
}
2 changes: 1 addition & 1 deletion packages/playwright-webkit/browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"browsers": [
{
"name": "webkit",
"revision": "1213"
"revision": "1216"
}
]
}
2 changes: 1 addition & 1 deletion packages/playwright/browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"name": "webkit",
"revision": "1213"
"revision": "1216"
}
]
}
34 changes: 33 additions & 1 deletion test/cookies.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

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

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

expect(await page.frames()[1].evaluate('document.cookie')).toBe('frame-cookie=value');
});
it('should(not) block third party cookies', async({context, page, server}) => {
await page.goto(server.EMPTY_PAGE);
await page.evaluate(src => {
let fulfill;
const promise = new Promise(x => fulfill = x);
const iframe = document.createElement('iframe');
document.body.appendChild(iframe);
iframe.onload = fulfill;
iframe.src = src;
return promise;
}, server.CROSS_PROCESS_PREFIX + '/grid.html');
await page.frames()[1].evaluate(`document.cookie = 'username=John Doe'`);
await page.waitForTimeout(2000);
const allowsThirdParty = CHROMIUM || FFOX;
const cookies = await context.cookies(server.CROSS_PROCESS_PREFIX + '/grid.html');
if (allowsThirdParty) {
expect(cookies).toEqual([
{
"domain": "127.0.0.1",
"expires": -1,
"httpOnly": false,
"name": "username",
"path": "/",
"sameSite": "None",
"secure": false,
"value": "John Doe"
}
]);
} else {
expect(cookies).toEqual([]);
}
});
});

describe('BrowserContext.clearCookies', function() {
Expand Down
34 changes: 33 additions & 1 deletion test/defaultbrowsercontext.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

const utils = require('./utils');
const {makeUserDataDir, removeUserDataDir} = utils;
const {FFOX, CHROMIUM, WEBKIT} = utils.testOptions(browserType);
const {FFOX, MAC, CHROMIUM, WEBKIT} = utils.testOptions(browserType);

describe('launchPersistentContext()', function() {
beforeEach(async state => {
Expand Down Expand Up @@ -83,4 +83,36 @@ describe('launchPersistentContext()', function() {
expect(await page.context().cookies([])).toEqual([]);
expect(await page.evaluate('document.cookie')).toBe('');
});
it('should(not) block third party cookies', async({browserContext, page, server}) => {
await page.goto(server.EMPTY_PAGE);
await page.evaluate(src => {
let fulfill;
const promise = new Promise(x => fulfill = x);
const iframe = document.createElement('iframe');
document.body.appendChild(iframe);
iframe.onload = fulfill;
iframe.src = src;
return promise;
}, server.CROSS_PROCESS_PREFIX + '/grid.html');
await page.frames()[1].evaluate(`document.cookie = 'username=John Doe'`);
await page.waitForTimeout(2000);
const allowsThirdParty = CHROMIUM || FFOX;
const cookies = await browserContext.cookies(server.CROSS_PROCESS_PREFIX + '/grid.html');
if (allowsThirdParty) {
expect(cookies).toEqual([
{
"domain": "127.0.0.1",
"expires": -1,
"httpOnly": false,
"name": "username",
"path": "/",
"sameSite": "None",
"secure": false,
"value": "John Doe"
}
]);
} else {
expect(cookies).toEqual([]);
}
});
});

0 comments on commit 2ea79d8

Please sign in to comment.