Bug 1525245 - Stabilize cookiePolicy/cookiePermission for live documents - part 8 - Tests for ServiceWorkers and cookie settings changing, r=Ehsan
☠☠ backed out by 66a4a5cb3fc7 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 27 Feb 2019 19:57:09 +0000
changeset 461521 d02e3f436390ec69c44c3bd09ab1fe81489701a4
parent 461520 10afd61b758223b1a60541935817dc77ff033d30
child 461522 38e802661b143173e5f1a3606a28faab480b089d
push id79173
push useramarchesini@mozilla.com
push dateWed, 27 Feb 2019 20:36:38 +0000
treeherderautoland@009e7457b990 [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],
       ]});