Bug 1493057 - Make sure test_ext_privacy.js doesn't depend on the default value of the network.cookie.cookieBehavior preference r=rpl
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 21 Sep 2018 15:12:10 +0000
changeset 437710 9a99305d2fcbbfed6ddaa56e214f6177873f1f5d
parent 437709 fd174216895b75204427c4ef83bcd1baf84f2e0b
child 437711 3ffe4318af3ad3033e22c80f1d4c8d1e8222a5f7
push id108133
push usercbrindusan@mozilla.com
push dateFri, 21 Sep 2018 17:33:11 +0000
treeherdermozilla-inbound@1879856ca1ab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrpl
bugs1493057
milestone64.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 1493057 - Make sure test_ext_privacy.js doesn't depend on the default value of the network.cookie.cookieBehavior preference r=rpl Differential Revision: https://phabricator.services.mozilla.com/D6456
toolkit/components/extensions/parent/ext-privacy.js
toolkit/components/extensions/schemas/privacy.json
toolkit/components/extensions/test/xpcshell/test_ext_privacy.js
--- a/toolkit/components/extensions/parent/ext-privacy.js
+++ b/toolkit/components/extensions/parent/ext-privacy.js
@@ -13,16 +13,17 @@ var {
 
 const cookieSvc = Ci.nsICookieService;
 
 const cookieBehaviorValues = new Map([
   ["allow_all", cookieSvc.BEHAVIOR_ACCEPT],
   ["reject_third_party", cookieSvc.BEHAVIOR_REJECT_FOREIGN],
   ["reject_all", cookieSvc.BEHAVIOR_REJECT],
   ["allow_visited", cookieSvc.BEHAVIOR_LIMIT_FOREIGN],
+  ["reject_trackers", cookieSvc.BEHAVIOR_REJECT_TRACKER],
 ]);
 
 const checkScope = scope => {
   if (scope && scope !== "regular") {
     throw new ExtensionError(
       `Firefox does not support the ${scope} settings scope.`);
   }
 };
--- a/toolkit/components/extensions/schemas/privacy.json
+++ b/toolkit/components/extensions/schemas/privacy.json
@@ -77,17 +77,18 @@
         "properties": {
           "behavior": {
             "type": "string",
             "optional": true,
             "enum": [
               "allow_all",
               "reject_all",
               "reject_third_party",
-              "allow_visited"
+              "allow_visited",
+              "reject_trackers"
             ],
             "description": "The type of cookies to allow."
           },
           "nonPersistentCookies": {
             "type": "boolean",
             "optional": true,
             "default": false,
             "description": "Whether to create all cookies as nonPersistent (i.e., session) cookies."
--- a/toolkit/components/extensions/test/xpcshell/test_ext_privacy.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_privacy.js
@@ -242,16 +242,40 @@ add_task(async function test_privacy_oth
       "privacy.firstparty.isolate": true,
     },
     "websites.cookieConfig": {
       "network.cookie.cookieBehavior": cookieSvc.BEHAVIOR_ACCEPT,
       "network.cookie.lifetimePolicy": cookieSvc.ACCEPT_NORMALLY,
     },
   };
 
+  let defaultPrefs = new Preferences({defaultBranch: true});
+  let defaultCookieBehavior = defaultPrefs.get("network.cookie.cookieBehavior");
+  let defaultBehavior;
+  switch (defaultCookieBehavior) {
+    case cookieSvc.BEHAVIOR_ACCEPT:
+      defaultBehavior = "allow_all";
+      break;
+    case cookieSvc.BEHAVIOR_REJECT_FOREIGN:
+      defaultBehavior = "reject_third_party";
+      break;
+    case cookieSvc.BEHAVIOR_REJECT:
+      defaultBehavior = "reject_all";
+      break;
+    case cookieSvc.BEHAVIOR_LIMIT_FOREIGN:
+      defaultBehavior = "allow_visited";
+      break;
+    case cookieSvc.BEHAVIOR_REJECT_TRACKER:
+      defaultBehavior = "reject_trackers";
+      break;
+    default:
+      ok(false, `Unexpected cookie behavior encountered: ${defaultCookieBehavior}`);
+      break;
+  }
+
   async function background() {
     browser.test.onMessage.addListener(async (msg, ...args) => {
       let data = args[0];
       // The second argument is the end of the api name,
       // e.g., "network.webRTCIPHandlingPolicy".
       let apiObj = args[1].split(".").reduce((o, i) => o[i], browser.privacy);
       let settingData;
       switch (msg) {
@@ -422,20 +446,20 @@ add_task(async function test_privacy_oth
     },
     {behavior: "reject_third_party", nonPersistentCookies: false},
   );
   // A missing behavior property should reset the pref.
   await testSetting(
     "websites.cookieConfig",
     {nonPersistentCookies: true},
     {
-      "network.cookie.cookieBehavior": cookieSvc.BEHAVIOR_ACCEPT,
+      "network.cookie.cookieBehavior": defaultCookieBehavior,
       "network.cookie.lifetimePolicy": cookieSvc.ACCEPT_SESSION,
     },
-    {behavior: "allow_all", nonPersistentCookies: true},
+    {behavior: defaultBehavior, nonPersistentCookies: true},
   );
   await testSetting(
     "websites.cookieConfig",
     {behavior: "reject_all"},
     {
       "network.cookie.cookieBehavior": cookieSvc.BEHAVIOR_REJECT,
       "network.cookie.lifetimePolicy": cookieSvc.ACCEPT_NORMALLY,
     },
@@ -458,30 +482,40 @@ add_task(async function test_privacy_oth
       "network.cookie.lifetimePolicy": cookieSvc.ACCEPT_NORMALLY,
     },
     {behavior: "allow_all", nonPersistentCookies: false},
   );
   await testSetting(
     "websites.cookieConfig",
     {nonPersistentCookies: true},
     {
-      "network.cookie.cookieBehavior": cookieSvc.BEHAVIOR_ACCEPT,
+      "network.cookie.cookieBehavior": defaultCookieBehavior,
       "network.cookie.lifetimePolicy": cookieSvc.ACCEPT_SESSION,
     },
-    {behavior: "allow_all", nonPersistentCookies: true},
+    {behavior: defaultBehavior, nonPersistentCookies: true},
   );
   await testSetting(
     "websites.cookieConfig",
     {nonPersistentCookies: false},
     {
-      "network.cookie.cookieBehavior": cookieSvc.BEHAVIOR_ACCEPT,
+      "network.cookie.cookieBehavior": defaultCookieBehavior,
       "network.cookie.lifetimePolicy": cookieSvc.ACCEPT_NORMALLY,
     },
-    {behavior: "allow_all", nonPersistentCookies: false},
+    {behavior: defaultBehavior, nonPersistentCookies: false},
   );
+  await testSetting(
+    "websites.cookieConfig",
+    {behavior: "reject_trackers"},
+    {
+      "network.cookie.cookieBehavior": cookieSvc.BEHAVIOR_REJECT_TRACKER,
+      "network.cookie.lifetimePolicy": cookieSvc.ACCEPT_NORMALLY,
+    },
+    {behavior: "reject_trackers", nonPersistentCookies: false},
+  );
+
 
   await extension.unload();
 
   await promiseShutdownManager();
 });
 
 add_task(async function test_exceptions() {
   async function background() {