mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 06:09:19 +00:00
Bug 1605362 - Network.getCookies() returns all cookies of current page and all of its sub frames as well. r=webdriver-reviewers,jdescottes
Added check in Network.getCookies() to skip duplicate cookies Also added tests. Created html files for running tests which set cookies - remote/cdp/test/browser/network/doc_get_cookies_page.html - remote/cdp/test/browser/network/doc_get_cookies_frame.html Added tests to /remote/cdp/test/browser/network/browser_getCookies.js Updated Puppeteer tests- - changed Page.setCookie should set secure same-site cookies from a frame spec to PASS Differential Revision: https://phabricator.services.mozilla.com/D122382
This commit is contained in:
parent
40c63c264c
commit
7b783556f9
@ -185,7 +185,9 @@ class Network extends Domain {
|
||||
*/
|
||||
async getCookies(options = {}) {
|
||||
// Bug 1605354 - Add support for options.urls
|
||||
const urls = [this.session.target.url];
|
||||
const urls = this.session.target.browsingContext
|
||||
.getAllBrowsingContextsInSubtree()
|
||||
.map(context => context.currentURI.spec);
|
||||
|
||||
const cookies = [];
|
||||
for (let url of urls) {
|
||||
@ -209,7 +211,20 @@ class Network extends Domain {
|
||||
continue;
|
||||
}
|
||||
|
||||
cookies.push(_buildCookie(cookie));
|
||||
const builtCookie = _buildCookie(cookie);
|
||||
const duplicateCookie = cookies.some(value => {
|
||||
return (
|
||||
value.name === builtCookie.name &&
|
||||
value.path === builtCookie.path &&
|
||||
value.domain === builtCookie.domain
|
||||
);
|
||||
});
|
||||
|
||||
if (duplicateCookie) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cookies.push(builtCookie);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,8 @@ support-files =
|
||||
head.js
|
||||
doc_empty.html
|
||||
doc_frameset.html
|
||||
doc_get_cookies_frame.html
|
||||
doc_get_cookies_page.html
|
||||
doc_networkEvents.html
|
||||
file_networkEvents.js
|
||||
file_framesetEvents.js
|
||||
|
@ -3,12 +3,13 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
const SJS_PATH = "/browser/remote/cdp/test/browser/network/sjs-cookies.sjs";
|
||||
|
||||
const DEFAULT_HOST = "http://example.org";
|
||||
const ALT_HOST = "http://example.net";
|
||||
const SECURE_HOST = "https://example.com";
|
||||
|
||||
const BASE_PATH = "/browser/remote/cdp/test/browser/network";
|
||||
const SJS_PATH = `${BASE_PATH}/sjs-cookies.sjs`;
|
||||
|
||||
const DEFAULT_URL = `${DEFAULT_HOST}${SJS_PATH}`;
|
||||
|
||||
add_task(async function noCookiesWhenNoneAreSet({ client }) {
|
||||
@ -68,6 +69,26 @@ add_task(async function allCookiesFromCurrentURL({ client }) {
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function allCookiesIncludingSubFrames({ client }) {
|
||||
const GET_COOKIES_PAGE_URL = `${DEFAULT_HOST}${BASE_PATH}/doc_get_cookies_page.html`;
|
||||
|
||||
const { Network } = client;
|
||||
await loadURL(GET_COOKIES_PAGE_URL);
|
||||
|
||||
const cookie_page = { name: "page", value: "mainpage", path: BASE_PATH };
|
||||
const cookie_frame = { name: "frame", value: "subframe", path: BASE_PATH };
|
||||
|
||||
try {
|
||||
const { cookies } = await Network.getCookies();
|
||||
cookies.sort((a, b) => a.name.localeCompare(b.name));
|
||||
is(cookies.length, 2, "All cookies have been found including subframe");
|
||||
assertCookie(cookies[0], cookie_frame);
|
||||
assertCookie(cookies[1], cookie_page);
|
||||
} finally {
|
||||
Services.cookies.removeAll();
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function secure({ client }) {
|
||||
const { Network } = client;
|
||||
await loadURL(`${SECURE_HOST}${SJS_PATH}?name=foo&value=bar&secure`);
|
||||
|
16
remote/cdp/test/browser/network/doc_get_cookies_frame.html
Normal file
16
remote/cdp/test/browser/network/doc_get_cookies_frame.html
Normal file
@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Sub Frame to get cookies</title>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="content">Example Sub Frame</div>
|
||||
<script type="text/javascript">
|
||||
document.cookie = "frame=subframe";
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
16
remote/cdp/test/browser/network/doc_get_cookies_page.html
Normal file
16
remote/cdp/test/browser/network/doc_get_cookies_page.html
Normal file
@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Page to get cookies</title>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<iframe src="doc_get_cookies_frame.html"></iframe>
|
||||
<script type="text/javascript">
|
||||
document.cookie = "page=mainpage";
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -234,7 +234,7 @@
|
||||
"FAIL"
|
||||
],
|
||||
"Cookie specs Page.setCookie should set secure same-site cookies from a frame (cookies.spec.ts)": [
|
||||
"FAIL"
|
||||
"PASS"
|
||||
],
|
||||
"Cookie specs Page.deleteCookie should work (cookies.spec.ts)": [
|
||||
"FAIL"
|
||||
|
Loading…
x
Reference in New Issue
Block a user