Bug 1694506 - [puppeteer] chore: skip non-standard cookie asserts on Firefox (sync #6994) r=remote-protocol-reviewers,whimboo

Depends on D108099

Synchronize the upstream change merged at https://github.com/puppeteer/puppeteer/pull/6994

Differential Revision: https://phabricator.services.mozilla.com/D108859
This commit is contained in:
Julian Descottes 2021-03-18 15:02:13 +00:00
parent 3eac4f3ce3
commit 408f997797
3 changed files with 82 additions and 49 deletions

View File

@ -15,6 +15,7 @@
*/
import expect from 'expect';
import {
expectCookieEquals,
getTestState,
setupTestBrowserHooks,
setupTestPageAndContextHooks,
@ -29,7 +30,7 @@ describe('Cookie specs', () => {
it('should return no cookies in pristine browser context', async () => {
const { page, server } = getTestState();
await page.goto(server.EMPTY_PAGE);
expect(await page.cookies()).toEqual([]);
expectCookieEquals(await page.cookies(), []);
});
it('should get a cookie', async () => {
const { page, server } = getTestState();
@ -37,7 +38,8 @@ describe('Cookie specs', () => {
await page.evaluate(() => {
document.cookie = 'username=John Doe';
});
expect(await page.cookies()).toEqual([
expectCookieEquals(await page.cookies(), [
{
name: 'username',
value: 'John Doe',
@ -96,7 +98,7 @@ describe('Cookie specs', () => {
});
const cookies = await page.cookies();
cookies.sort((a, b) => a.name.localeCompare(b.name));
expect(cookies).toEqual([
expectCookieEquals(cookies, [
{
name: 'password',
value: '1234',
@ -148,7 +150,7 @@ describe('Cookie specs', () => {
);
const cookies = await page.cookies('https://foo.com', 'https://baz.com');
cookies.sort((a, b) => a.name.localeCompare(b.name));
expect(cookies).toEqual([
expectCookieEquals(cookies, [
{
name: 'birdo',
value: 'tweets',
@ -229,12 +231,13 @@ describe('Cookie specs', () => {
value: 'bar',
}
);
expect(
expectCookieEquals(
await page.evaluate(() => {
const cookies = document.cookie.split(';');
return cookies.map((cookie) => cookie.trim()).sort();
})
).toEqual(['foo=bar', 'password=123456']);
}),
['foo=bar', 'password=123456']
);
});
it('should have |expires| set to |-1| for session cookies', async () => {
const { page, server } = getTestState();
@ -257,22 +260,25 @@ describe('Cookie specs', () => {
value: '123456',
});
const cookies = await page.cookies();
expect(cookies.sort((a, b) => a.name.localeCompare(b.name))).toEqual([
{
name: 'password',
value: '123456',
domain: 'localhost',
path: '/',
sameParty: false,
expires: -1,
size: 14,
httpOnly: false,
secure: false,
session: true,
sourcePort: 80,
sourceScheme: 'NonSecure',
},
]);
expectCookieEquals(
cookies.sort((a, b) => a.name.localeCompare(b.name)),
[
{
name: 'password',
value: '123456',
domain: 'localhost',
path: '/',
sameParty: false,
expires: -1,
size: 14,
httpOnly: false,
secure: false,
session: true,
sourcePort: 80,
sourceScheme: 'NonSecure',
},
]
);
});
it('should set a cookie with a path', async () => {
const { page, server } = getTestState();
@ -283,7 +289,7 @@ describe('Cookie specs', () => {
value: 'GRID',
path: '/grid.html',
});
expect(await page.cookies()).toEqual([
expectCookieEquals(await page.cookies(), [
{
name: 'gridcookie',
value: 'GRID',
@ -301,7 +307,7 @@ describe('Cookie specs', () => {
]);
expect(await page.evaluate('document.cookie')).toBe('gridcookie=GRID');
await page.goto(server.EMPTY_PAGE);
expect(await page.cookies()).toEqual([]);
expectCookieEquals(await page.cookies(), []);
expect(await page.evaluate('document.cookie')).toBe('');
await page.goto(server.PREFIX + '/grid.html');
expect(await page.evaluate('document.cookie')).toBe('gridcookie=GRID');
@ -390,8 +396,8 @@ describe('Cookie specs', () => {
value: 'best',
});
expect(await page.evaluate('document.cookie')).toBe('');
expect(await page.cookies()).toEqual([]);
expect(await page.cookies('https://www.example.com')).toEqual([
expectCookieEquals(await page.cookies(), []);
expectCookieEquals(await page.cookies('https://www.example.com'), [
{
name: 'example-cookie',
value: 'best',
@ -432,7 +438,7 @@ describe('Cookie specs', () => {
);
expect(await page.frames()[1].evaluate('document.cookie')).toBe('');
expect(await page.cookies()).toEqual([
expectCookieEquals(await page.cookies(), [
{
name: 'localhost-cookie',
value: 'best',
@ -449,7 +455,7 @@ describe('Cookie specs', () => {
},
]);
expect(await page.cookies(server.CROSS_PROCESS_PREFIX)).toEqual([
expectCookieEquals(await page.cookies(server.CROSS_PROCESS_PREFIX), [
{
name: '127-cookie',
value: 'worst',
@ -503,23 +509,26 @@ describe('Cookie specs', () => {
expect(await page.frames()[1].evaluate('document.cookie')).toBe(
'127-same-site-cookie=best'
);
expect(await page.cookies(httpsServer.CROSS_PROCESS_PREFIX)).toEqual([
{
name: '127-same-site-cookie',
value: 'best',
domain: '127.0.0.1',
path: '/',
sameParty: false,
expires: -1,
size: 24,
httpOnly: false,
sameSite: 'None',
secure: true,
session: true,
sourcePort: 443,
sourceScheme: 'Secure',
},
]);
expectCookieEquals(
await page.cookies(httpsServer.CROSS_PROCESS_PREFIX),
[
{
name: '127-same-site-cookie',
value: 'best',
domain: '127.0.0.1',
path: '/',
sameParty: false,
expires: -1,
size: 24,
httpOnly: false,
sameSite: 'None',
secure: true,
session: true,
sourcePort: 443,
sourceScheme: 'Secure',
},
]
);
} finally {
await page.close();
await browser.close();

View File

@ -15,6 +15,7 @@
*/
import expect from 'expect';
import {
expectCookieEquals,
getTestState,
setupTestBrowserHooks,
setupTestPageAndContextHooks,
@ -31,7 +32,7 @@ describe('DefaultBrowserContext', function () {
await page.evaluate(() => {
document.cookie = 'username=John Doe';
});
expect(await page.cookies()).toEqual([
expectCookieEquals(await page.cookies(), [
{
name: 'username',
value: 'John Doe',
@ -59,7 +60,7 @@ describe('DefaultBrowserContext', function () {
expect(await page.evaluate(() => document.cookie)).toBe(
'username=John Doe'
);
expect(await page.cookies()).toEqual([
expectCookieEquals(await page.cookies(), [
{
name: 'username',
value: 'John Doe',
@ -93,7 +94,7 @@ describe('DefaultBrowserContext', function () {
expect(await page.evaluate('document.cookie')).toBe('cookie1=1; cookie2=2');
await page.deleteCookie({ name: 'cookie2' });
expect(await page.evaluate('document.cookie')).toBe('cookie1=1');
expect(await page.cookies()).toEqual([
expectCookieEquals(await page.cookies(), [
{
name: 'cookie1',
value: '1',

View File

@ -28,6 +28,7 @@ import { Page } from '../lib/cjs/puppeteer/common/Page.js';
import { PuppeteerNode } from '../lib/cjs/puppeteer/node/Puppeteer.js';
import utils from './utils.js';
import rimraf from 'rimraf';
import expect from 'expect';
import { trackCoverage } from './coverage-utils.js';
@ -277,3 +278,25 @@ export const mochaHooks = {
sinon.restore();
},
};
export const expectCookieEquals = (cookies, expectedCookies) => {
const { isChrome } = getTestState();
if (!isChrome) {
// Only keep standard properties when testing on a browser other than Chrome.
expectedCookies = expectedCookies.map((cookie) => {
return {
domain: cookie.domain,
expires: cookie.expires,
httpOnly: cookie.httpOnly,
name: cookie.name,
path: cookie.path,
secure: cookie.secure,
session: cookie.session,
size: cookie.size,
value: cookie.value,
};
});
}
expect(cookies).toEqual(expectedCookies);
};