Bug 1345573 - Part 2: Remove old tests for permissions syncing, and add test for new logic, r=baku
authorMichael Layzell <michael@thelayzells.com>
Thu, 09 Mar 2017 15:58:38 -0500
changeset 399179 63e7bf43da6505b9789b714495bebca9fc1c05da
parent 399178 035042b8b4aabb0f6f427a0eb9d12a160dbc6f5a
child 399180 2686c6ee997dce91e573d7b0e1555859e33810e6
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1345573
milestone55.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 1345573 - Part 2: Remove old tests for permissions syncing, and add test for new logic, r=baku MozReview-Commit-ID: A2vYqdCpeu6
extensions/cookie/test/browser.ini
extensions/cookie/test/browser_permmgr_sync.js
extensions/cookie/test/moz.build
extensions/cookie/test/unit_ipc/test_child.js
extensions/cookie/test/unit_ipc/test_parent.js
extensions/cookie/test/unit_ipc/xpcshell.ini
--- a/extensions/cookie/test/browser.ini
+++ b/extensions/cookie/test/browser.ini
@@ -1,3 +1,5 @@
 [DEFAULT]
 
 [browser_test_favicon.js]
+[browser_permmgr_sync.js]
+skip-if = !e10s # This tests e10s specific behavior
new file mode 100644
--- /dev/null
+++ b/extensions/cookie/test/browser_permmgr_sync.js
@@ -0,0 +1,149 @@
+function addPerm(aURI, aName) {
+  Services.perms.add(Services.io.newURI(aURI), aName, Services.perms.ALLOW_ACTION);
+}
+
+function hasPerm(aURI, aName) {
+  return Services.perms.testPermission(Services.io.newURI(aURI), aName)
+    == Services.perms.ALLOW_ACTION;
+}
+
+add_task(function* () {
+  // Make sure that we get a new process for the tab which we create. This is
+  // important, becuase we wanto to assert information about the initial state
+  // of the local permissions cache.
+  //
+  // We use the same approach here as was used in the e10s-multi localStorage
+  // tests (dom/tests/browser/browser_localStorage_e10s.js (bug )). This ensures
+  // that our tab has its own process.
+  //
+  // Bug 1345990 tracks implementing a better tool for ensuring this.
+  let keepAliveCount = 0;
+  try {
+    keepAliveCount = SpecialPowers.getIntPref("dom.ipc.keepProcessesAlive.web");
+  } catch (ex) {
+    // Then zero is correct.
+  }
+  let safeProcessCount = keepAliveCount + 2;
+  info("dom.ipc.keepProcessesAlive.web is " + keepAliveCount + ", boosting " +
+       "process count temporarily to " + safeProcessCount);
+  yield SpecialPowers.pushPrefEnv({
+    set: [
+      ["dom.ipc.processCount", safeProcessCount],
+      ["dom.ipc.processCount.web", safeProcessCount]
+    ]
+  });
+
+  addPerm("http://example.com", "perm1");
+  addPerm("http://foo.bar.example.com", "perm2");
+  addPerm("about:home", "perm3");
+  addPerm("https://example.com", "perm4");
+
+  yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" }, function* (aBrowser) {
+    yield ContentTask.spawn(aBrowser, null, function* () {
+      // Before the load http URIs shouldn't have been sent down yet
+      is(Services.perms.testPermission(Services.io.newURI("http://example.com"),
+                                       "perm1"),
+         Services.perms.UNKNOWN_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"),
+                                       "perm2"),
+         Services.perms.UNKNOWN_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("about:home"),
+                                       "perm3"),
+         Services.perms.ALLOW_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("https://example.com"),
+                                       "perm4"),
+         Services.perms.UNKNOWN_ACTION);
+
+      // Perform a load of example.com
+      yield new Promise(resolve => {
+        let iframe = content.document.createElement('iframe');
+        iframe.setAttribute('src', 'http://example.com');
+        iframe.onload = resolve;
+        content.document.body.appendChild(iframe);
+      });
+
+      // After the load finishes, we should know about example.com, but not foo.bar.example.com
+      is(Services.perms.testPermission(Services.io.newURI("http://example.com"),
+                                       "perm1"),
+         Services.perms.ALLOW_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"),
+                                       "perm2"),
+         Services.perms.UNKNOWN_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("about:home"),
+                                       "perm3"),
+         Services.perms.ALLOW_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("https://example.com"),
+                                       "perm4"),
+         Services.perms.UNKNOWN_ACTION);
+    });
+
+    addPerm("http://example.com", "newperm1");
+    addPerm("http://foo.bar.example.com", "newperm2");
+    addPerm("about:home", "newperm3");
+    addPerm("https://example.com", "newperm4");
+
+    yield ContentTask.spawn(aBrowser, null, function* () {
+      // The new permissions should be avaliable, but only for
+      // http://example.com, and about:home
+      is(Services.perms.testPermission(Services.io.newURI("http://example.com"),
+                                       "perm1"),
+         Services.perms.ALLOW_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("http://example.com"),
+                                       "newperm1"),
+         Services.perms.ALLOW_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"),
+                                       "perm2"),
+         Services.perms.UNKNOWN_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"),
+                                       "newperm2"),
+         Services.perms.UNKNOWN_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("about:home"),
+                                       "perm3"),
+         Services.perms.ALLOW_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("about:home"),
+                                       "newperm3"),
+         Services.perms.ALLOW_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("https://example.com"),
+                                       "perm4"),
+         Services.perms.UNKNOWN_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("https://example.com"),
+                                       "newperm4"),
+         Services.perms.UNKNOWN_ACTION);
+
+      // Loading a subdomain now, on https
+      yield new Promise(resolve => {
+        let iframe = content.document.createElement('iframe');
+        iframe.setAttribute('src', 'https://sub1.test1.example.com');
+        iframe.onload = resolve;
+        content.document.body.appendChild(iframe);
+      });
+
+      // Now that the https subdomain has loaded, we want to make sure that the
+      // permissions are also avaliable for its parent domain, https://example.com!
+      is(Services.perms.testPermission(Services.io.newURI("http://example.com"),
+                                       "perm1"),
+         Services.perms.ALLOW_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("http://example.com"),
+                                       "newperm1"),
+         Services.perms.ALLOW_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"),
+                                       "perm2"),
+         Services.perms.UNKNOWN_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("http://foo.bar.example.com"),
+                                       "newperm2"),
+         Services.perms.UNKNOWN_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("about:home"),
+                                       "perm3"),
+         Services.perms.ALLOW_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("about:home"),
+                                       "newperm3"),
+         Services.perms.ALLOW_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("https://example.com"),
+                                       "perm4"),
+         Services.perms.ALLOW_ACTION);
+      is(Services.perms.testPermission(Services.io.newURI("https://example.com"),
+                                       "newperm4"),
+         Services.perms.ALLOW_ACTION);
+    });
+  });
+});
--- a/extensions/cookie/test/moz.build
+++ b/extensions/cookie/test/moz.build
@@ -1,15 +1,14 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 XPCSHELL_TESTS_MANIFESTS += [
     'unit/xpcshell.ini',
-    'unit_ipc/xpcshell.ini',
 ]
 
 MOCHITEST_MANIFESTS += ['mochitest.ini']
 
 BROWSER_CHROME_MANIFESTS += ['browser.ini']
 
deleted file mode 100644
--- a/extensions/cookie/test/unit_ipc/test_child.js
+++ /dev/null
@@ -1,59 +0,0 @@
-var Ci = Components.interfaces;
-var Cc = Components.classes;
-var Cr = Components.results;
-
-var gIoService = Components.classes["@mozilla.org/network/io-service;1"]
-                           .getService(Components.interfaces.nsIIOService);
-
-function isParentProcess() {
-    let appInfo = Cc["@mozilla.org/xre/app-info;1"];
-    return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
-}
-
-function getPrincipalForURI(aURI) {
-  var uri =  gIoService.newURI(aURI);
-  var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"]
-              .getService(Ci.nsIScriptSecurityManager);
-  return ssm.createCodebasePrincipal(uri, {});
-}
-
-function run_test() {
-  if (!isParentProcess()) {
-    const Ci = Components.interfaces;
-    const Cc = Components.classes;
-
-    var mM = Cc["@mozilla.org/childprocessmessagemanager;1"].
-                         getService(Ci.nsISyncMessageSender);
-
-    var messageListener = {
-      receiveMessage: function(aMessage) {
-        switch(aMessage.name) {
-          case "TESTING:Stage2A":
-            // Permissions created after the child is present
-            do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.org"), "cookie1"), pm.ALLOW_ACTION);
-            do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.com"), "cookie2"), pm.DENY_ACTION);
-            do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.net"), "cookie3"), pm.ALLOW_ACTION);
-            do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://firefox.org"), "cookie1"), pm.ALLOW_ACTION);
-            do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://firefox.com"), "cookie2"), pm.DENY_ACTION);
-            do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://firefox.net"), "cookie3"), pm.ALLOW_ACTION);
-
-            mM.sendAsyncMessage("TESTING:Stage3");
-            break;
-
-        }
-        return true;
-      },
-    };
-
-    mM.addMessageListener("TESTING:Stage2A", messageListener);
-
-    // Permissions created before the child is present
-    var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
-    do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.org"), "cookie1"), pm.ALLOW_ACTION);
-    do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.com"), "cookie2"), pm.DENY_ACTION);
-    do_check_eq(pm.testPermissionFromPrincipal(getPrincipalForURI("http://mozilla.net"), "cookie3"), pm.ALLOW_ACTION);
-
-    mM.sendAsyncMessage("TESTING:Stage2");
-  }
-}
-
deleted file mode 100644
--- a/extensions/cookie/test/unit_ipc/test_parent.js
+++ /dev/null
@@ -1,59 +0,0 @@
-var Ci = Components.interfaces;
-var Cc = Components.classes;
-var Cr = Components.results;
-
-var gIoService = Components.classes["@mozilla.org/network/io-service;1"]
-                           .getService(Components.interfaces.nsIIOService);
-
-function isParentProcess() {
-    let appInfo = Cc["@mozilla.org/xre/app-info;1"];
-    return (!appInfo || appInfo.getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT);
-}
-
-function getPrincipalForURI(aURI) {
-  var uri = gIoService.newURI(aURI);
-  var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"]
-              .getService(Ci.nsIScriptSecurityManager);
-  return ssm.createCodebasePrincipal(uri, {});
-}
-
-function run_test() {
-  if (isParentProcess()) {
-    var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
-
-    // Permissions created before the child is present
-    pm.addFromPrincipal(getPrincipalForURI("http://mozilla.org"), "cookie1", pm.ALLOW_ACTION, pm.EXPIRE_NEVER, 0);
-    pm.addFromPrincipal(getPrincipalForURI("http://mozilla.com"), "cookie2", pm.DENY_ACTION, pm.EXPIRE_SESSION, 0);
-    pm.addFromPrincipal(getPrincipalForURI("http://mozilla.net"), "cookie3", pm.ALLOW_ACTION, pm.EXPIRE_TIME, Date.now() + 1000*60*60*24);
-
-    var mM = Cc["@mozilla.org/parentprocessmessagemanager;1"].
-             getService(Ci.nsIMessageBroadcaster);
-
-    var messageListener = {
-      receiveMessage: function(aMessage) {
-        switch(aMessage.name) {
-          case "TESTING:Stage2":
-            // Permissions created after the child is present
-            pm.addFromPrincipal(getPrincipalForURI("http://firefox.org"), "cookie1", pm.ALLOW_ACTION, pm.EXPIRE_NEVER, 0);
-            pm.addFromPrincipal(getPrincipalForURI("http://firefox.com"), "cookie2", pm.DENY_ACTION, pm.EXPIRE_SESSION, 0);
-            pm.addFromPrincipal(getPrincipalForURI("http://firefox.net"), "cookie3", pm.ALLOW_ACTION, pm.EXPIRE_TIME, Date.now() + 1000*60*60*24);
-            mM.broadcastAsyncMessage("TESTING:Stage2A");
-            break;
-
-          case "TESTING:Stage3":
-            do_test_finished();
-            break;
-        }
-        return true;
-      },
-    };
-
-    mM.addMessageListener("TESTING:Stage2", messageListener);
-    mM.addMessageListener("TESTING:Stage3", messageListener);
-
-    do_test_pending();
-    do_load_child_test_harness();
-    run_test_in_child("test_child.js");
-  }
-}
-
deleted file mode 100644
--- a/extensions/cookie/test/unit_ipc/xpcshell.ini
+++ /dev/null
@@ -1,6 +0,0 @@
-[DEFAULT]
-head = 
-skip-if = toolkit == 'android'
-
-[test_child.js]
-[test_parent.js]