Bug 1465063 - Add tests for get/getAll w/o firstPartyDomain r=rpl
authorRob Wu <rob@robwu.nl>
Fri, 08 Jun 2018 13:36:36 +0200
changeset 478708 dccf43cba794a6934858ff0e2e0a3ece92b1f443
parent 478707 b3e5e1651b4929af121a87e73f1c48d7ee5ecc04
child 478709 8d32de5379894ef395bde70ecfa0f62e2b47a71a
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrpl
bugs1465063
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1465063 - Add tests for get/getAll w/o firstPartyDomain r=rpl The test coverage for cookies.get was incomplete, as scenarios with empty, null and undefined firstPartyDomain were not checked. There is a distinction between "empty" and "w/o firstPartyDomain". MozReview-Commit-ID: 1l54nUOCneK
toolkit/components/extensions/test/mochitest/test_ext_cookies_first_party.html
--- a/toolkit/components/extensions/test/mochitest/test_ext_cookies_first_party.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_cookies_first_party.html
@@ -9,16 +9,19 @@
 
 async function background() {
   const url = "http://ext-cookie-first-party.mochi.test/";
   const firstPartyDomain = "ext-cookie-first-party.mochi.test";
   const expectedError = "First-Party Isolation is enabled, but the required 'firstPartyDomain' attribute was not set.";
 
   const assertExpectedCookies = (expected, cookies, message) => {
     let matches = (cookie, expected) => {
+      if (!cookie || !expected) {
+        return cookie === expected; // true if both are null.
+      }
       for (let key of Object.keys(expected)) {
         if (cookie[key] !== expected[key]) {
           return false;
         }
       }
       return true;
     };
     browser.test.assertEq(expected.length, cookies.length, `Got expected number of cookies - ${message}`);
@@ -35,37 +38,64 @@ async function background() {
   // Test when FPI is disabled.
   const test_fpi_disabled = async () => {
     let cookie, cookies;
 
     // set
     cookie = await browser.cookies.set({url, name: "foo1", value: "bar1"});
     assertExpectedCookies([
       {name: "foo1", value: "bar1", firstPartyDomain: ""},
-    ], [cookie], "set: FPI off, w/o firstPartyDomain, non-FP cookie");
+    ], [cookie], "set: FPI off, w/ empty firstPartyDomain, non-FP cookie");
     cookie = await browser.cookies.set({url, name: "foo2", value: "bar2", firstPartyDomain});
     assertExpectedCookies([
       {name: "foo2", value: "bar2", firstPartyDomain},
     ], [cookie], "set: FPI off, w/ firstPartyDomain, FP cookie");
 
     // get
+    // When FPI is disabled, missing key/null/undefined is equivalent to "".
     cookie = await browser.cookies.get({url, name: "foo1"});
     assertExpectedCookies([
       {name: "foo1", value: "bar1", firstPartyDomain: ""},
     ], [cookie], "get: FPI off, w/o firstPartyDomain, non-FP cookie");
+    cookie = await browser.cookies.get({url, name: "foo1", firstPartyDomain: ""});
+    assertExpectedCookies([
+      {name: "foo1", value: "bar1", firstPartyDomain: ""},
+    ], [cookie], "get: FPI off, w/ empty firstPartyDomain, non-FP cookie");
+    cookie = await browser.cookies.get({url, name: "foo1", firstPartyDomain: null});
+    assertExpectedCookies([
+      {name: "foo1", value: "bar1", firstPartyDomain: ""},
+    ], [cookie], "get: FPI off, w/ null firstPartyDomain, non-FP cookie");
+    cookie = await browser.cookies.get({url, name: "foo1", firstPartyDomain: undefined});
+    assertExpectedCookies([
+      {name: "foo1", value: "bar1", firstPartyDomain: ""},
+    ], [cookie], "get: FPI off, w/ undefined firstPartyDomain, non-FP cookie");
+
     cookie = await browser.cookies.get({url, name: "foo2", firstPartyDomain});
     assertExpectedCookies([
       {name: "foo2", value: "bar2", firstPartyDomain},
     ], [cookie], "get: FPI off, w/ firstPartyDomain, FP cookie");
+    // There is no match for non-FP cookies with name "foo2".
+    cookie = await browser.cookies.get({url, name: "foo2"});
+    assertExpectedCookies([null], [cookie], "get: FPI off, w/o firstPartyDomain, no cookie");
+    cookie = await browser.cookies.get({url, name: "foo2", firstPartyDomain: ""});
+    assertExpectedCookies([null], [cookie], "get: FPI off, w/ empty firstPartyDomain, no cookie");
+    cookie = await browser.cookies.get({url, name: "foo2", firstPartyDomain: null});
+    assertExpectedCookies([null], [cookie], "get: FPI off, w/ null firstPartyDomain, no cookie");
+    cookie = await browser.cookies.get({url, name: "foo2", firstPartyDomain: undefined});
+    assertExpectedCookies([null], [cookie], "get: FPI off, w/ undefined firstPartyDomain, no cookie");
 
     // getAll
     cookies = await browser.cookies.getAll({});
     assertExpectedCookies([
       {name: "foo1", value: "bar1", firstPartyDomain: ""},
     ], cookies, "getAll: FPI off, w/o firstPartyDomain, non-FP cookies");
+    cookies = await browser.cookies.getAll({firstPartyDomain: ""});
+    assertExpectedCookies([
+      {name: "foo1", value: "bar1", firstPartyDomain: ""},
+    ], cookies, "getAll: FPI off, w/ empty firstPartyDomain, non-FP cookies");
     cookies = await browser.cookies.getAll({firstPartyDomain: null});
     assertExpectedCookies([
       {name: "foo1", value: "bar1", firstPartyDomain: ""},
       {name: "foo2", value: "bar2", firstPartyDomain},
     ], cookies, "getAll: FPI off, w/ null firstPartyDomain, all cookies");
     cookies = await browser.cookies.getAll({firstPartyDomain: undefined});
     assertExpectedCookies([
       {name: "foo1", value: "bar1", firstPartyDomain: ""},
@@ -75,17 +105,17 @@ async function background() {
     assertExpectedCookies([
       {name: "foo2", value: "bar2", firstPartyDomain},
     ], cookies, "getAll: FPI off, w/ firstPartyDomain, FP cookies");
 
     // remove
     cookie = await browser.cookies.remove({url, name: "foo1"});
     assertExpectedCookies([
       {url, name: "foo1", firstPartyDomain: ""},
-    ], [cookie], "remove: FPI off, w/o firstPartyDomain, non-FP cookie");
+    ], [cookie], "remove: FPI off, w/ empty firstPartyDomain, non-FP cookie");
     cookie = await browser.cookies.remove({url, name: "foo2", firstPartyDomain});
     assertExpectedCookies([
       {url, name: "foo2", firstPartyDomain},
     ], [cookie], "remove: FPI off, w/ firstPartyDomain, FP cookie");
 
     // Test if FP cookies set when FPI off can be accessed when FPI on.
     await browser.cookies.set({url, name: "foo1", value: "bar1"});
     await browser.cookies.set({url, name: "foo2", value: "bar2", firstPartyDomain});
@@ -107,36 +137,58 @@ async function background() {
       {name: "foo4", value: "bar4", firstPartyDomain},
     ], [cookie], "set: FPI on, w/ firstPartyDomain, FP cookie");
 
     // get
     await browser.test.assertRejects(
       browser.cookies.get({url, name: "foo3"}),
       expectedError,
       "get: FPI on, w/o firstPartyDomain, rejection");
+    await browser.test.assertRejects(
+      browser.cookies.get({url, name: "foo3", firstPartyDomain: null}),
+      expectedError,
+      "get: FPI on, w/ null firstPartyDomain, rejection");
+    await browser.test.assertRejects(
+      browser.cookies.get({url, name: "foo3", firstPartyDomain: undefined}),
+      expectedError,
+      "get: FPI on, w/ undefined firstPartyDomain, rejection");
+    cookie = await browser.cookies.get({url, name: "foo1", firstPartyDomain: ""});
+    assertExpectedCookies([
+      {name: "foo1", value: "bar1", firstPartyDomain: ""},
+    ], [cookie], "get: FPI on, w/ empty firstPartyDomain, non-FP cookie");
     cookie = await browser.cookies.get({url, name: "foo4", firstPartyDomain});
     assertExpectedCookies([
       {name: "foo4", value: "bar4", firstPartyDomain},
     ], [cookie], "get: FPI on, w/ firstPartyDomain, FP cookie");
     cookie = await browser.cookies.get({url, name: "foo2", firstPartyDomain});
     assertExpectedCookies([
       {name: "foo2", value: "bar2", firstPartyDomain},
     ], [cookie], "get: FPI on, w/ firstPartyDomain, FP cookie (set when FPI off)");
 
     // getAll
     await browser.test.assertRejects(
       browser.cookies.getAll({}),
       expectedError,
       "getAll: FPI on, w/o firstPartyDomain, rejection");
+    cookies = await browser.cookies.getAll({firstPartyDomain: ""});
+    assertExpectedCookies([
+      {name: "foo1", value: "bar1", firstPartyDomain: ""},
+    ], cookies, "getAll: FPI on, w/ empty firstPartyDomain, non-FP cookies");
     cookies = await browser.cookies.getAll({firstPartyDomain: null});
     assertExpectedCookies([
       {name: "foo1", value: "bar1", firstPartyDomain: ""},
       {name: "foo2", value: "bar2", firstPartyDomain},
       {name: "foo4", value: "bar4", firstPartyDomain},
     ], cookies, "getAll: FPI on, w/ null firstPartyDomain, all cookies");
+    cookies = await browser.cookies.getAll({firstPartyDomain: undefined});
+    assertExpectedCookies([
+      {name: "foo1", value: "bar1", firstPartyDomain: ""},
+      {name: "foo2", value: "bar2", firstPartyDomain},
+      {name: "foo4", value: "bar4", firstPartyDomain},
+    ], cookies, "getAll: FPI on, w/ undefined firstPartyDomain, all cookies");
     cookies = await browser.cookies.getAll({firstPartyDomain});
     assertExpectedCookies([
       {name: "foo2", value: "bar2", firstPartyDomain},
       {name: "foo4", value: "bar4", firstPartyDomain},
     ], cookies, "getAll: FPI on, w/ firstPartyDomain, FP cookies");
 
     // remove
     await browser.test.assertRejects(