Bug 1525245 - Stabilize cookiePolicy/cookiePermission for live documents - part 8 - Tests for ServiceWorkers and cookie settings changing, r=Ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 08 Mar 2019 09:02:30 +0000
changeset 463105 d778cbd509c36457d865516a07143831ba49d46e
parent 463104 5f8af0d132c83eb796ef9c1b796be648608efb38
child 463106 89c5023dd68eff8871e748be6167895760a725af
push id35666
push usershindli@mozilla.com
push dateFri, 08 Mar 2019 13:49:21 +0000
treeherdermozilla-central@3cddc7cd4da5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1525245
milestone67.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 1525245 - Stabilize cookiePolicy/cookiePermission for live documents - part 8 - Tests for ServiceWorkers and cookie settings changing, r=Ehsan Differential Revision: https://phabricator.services.mozilla.com/D18956
netwerk/cookie/test/browser/browser.ini
netwerk/cookie/test/browser/browser_serviceWorker.js
netwerk/cookie/test/browser/file_empty.js
netwerk/cookie/test/browser/head.js
--- a/netwerk/cookie/test/browser/browser.ini
+++ b/netwerk/cookie/test/browser/browser.ini
@@ -1,10 +1,12 @@
 [DEFAULT]
 support-files =
   file_empty.html
+  file_empty.js
   head.js
 
 [browser_broadcastChannel.js]
 [browser_indexedDB.js]
 [browser_originattributes.js]
 [browser_storage.js]
+[browser_serviceWorker.js]
 [browser_sharedWorker.js]
new file mode 100644
--- /dev/null
+++ b/netwerk/cookie/test/browser/browser_serviceWorker.js
@@ -0,0 +1,24 @@
+CookiePolicyHelper.runTest("ServiceWorker", {
+  prefs: [
+    ["dom.serviceWorkers.exemptFromPerDomainMax", true],
+    ["dom.ipc.processCount", 1],
+    ["dom.serviceWorkers.enabled", true],
+    ["dom.serviceWorkers.testing.enabled", true],
+  ],
+
+  cookieJarAccessAllowed: async _ => {
+    await content.navigator.serviceWorker.register("file_empty.js").then(
+      reg => { ok(true, "ServiceWorker can be used!"); return reg; },
+      _ => { ok(false, "ServiceWorker cannot be used! " + _); }).then(
+      reg => reg.unregister(),
+      _ => { ok(false, "unregister failed"); }).
+      catch(e => ok(false, "Promise rejected: " + e));
+  },
+
+  cookieJarAccessDenied: async _ => {
+    await content.navigator.serviceWorker.register("file_empty.js").then(
+      _ => { ok(false, "ServiceWorker cannot be used!"); },
+      _ => { ok(true, "ServiceWorker cannot be used!"); }).
+      catch(e => ok(false, "Promise rejected: " + e));
+  },
+});
new file mode 100644
--- /dev/null
+++ b/netwerk/cookie/test/browser/file_empty.js
@@ -0,0 +1,1 @@
+/* nothing here */
--- a/netwerk/cookie/test/browser/head.js
+++ b/netwerk/cookie/test/browser/head.js
@@ -19,66 +19,74 @@ const TEST_TOP_PAGE = TEST_DOMAIN + TEST
 // page.
 this.CookiePolicyHelper = {
   runTest(testName, config) {
     // Testing allowed to blocked by cookie behavior
     this._createTest(testName,
                      config.cookieJarAccessAllowed,
                      config.cookieJarAccessDenied,
                      config.cleanup,
+                     config.prefs,
                      {
                        fromBehavior: BEHAVIOR_ACCEPT,
                        toBehavior: BEHAVIOR_REJECT,
                        fromPermission: PERM_DEFAULT,
                        toPermission: PERM_DEFAULT,
                      });
 
     // Testing blocked to allowed by cookie behavior
     this._createTest(testName,
                      config.cookieJarAccessDenied,
                      config.cookieJarAccessAllowed,
                      config.cleanup,
+                     config.prefs,
                      {
                        fromBehavior: BEHAVIOR_REJECT,
                        toBehavior: BEHAVIOR_ACCEPT,
                        fromPermission: PERM_DEFAULT,
                        toPermission: PERM_DEFAULT,
                      });
 
     // Testing allowed to blocked by cookie permission
     this._createTest(testName,
                      config.cookieJarAccessAllowed,
                      config.cookieJarAccessDenied,
                      config.cleanup,
+                     config.prefs,
                      {
                        fromBehavior: BEHAVIOR_REJECT,
                        toBehavior: BEHAVIOR_REJECT,
                        fromPermission: PERM_ALLOW,
                        toPermission: PERM_DEFAULT,
                      });
 
     // Testing blocked to allowed by cookie permission
     this._createTest(testName,
                      config.cookieJarAccessDenied,
                      config.cookieJarAccessAllowed,
                      config.cleanup,
+                     config.prefs,
                      {
                        fromBehavior: BEHAVIOR_ACCEPT,
                        toBehavior: BEHAVIOR_ACCEPT,
                        fromPermission: PERM_DENY,
                        toPermission: PERM_DEFAULT,
                      });
   },
 
-  _createTest(testName, goodCb, badCb, cleanupCb, config) {
+  _createTest(testName, goodCb, badCb, cleanupCb, prefs, config) {
     add_task(async _ => {
       info("Starting " + testName + ": " + config.toSource());
 
       await SpecialPowers.flushPrefEnv();
 
+      if (prefs) {
+        await SpecialPowers.pushPrefEnv({"set": prefs });
+      }
+
       let uri = Services.io.newURI(TEST_DOMAIN);
 
       // Let's set the first cookie pref.
       Services.perms.add(uri, "cookie", config.fromPermission);
       await SpecialPowers.pushPrefEnv({"set": [
         ["network.cookie.cookieBehavior", config.fromBehavior],
       ]});