Bug 1247497. Test for e10s-addons mechanism. r=krizsa a=sylvestre
authorFelipe Gomes <felipc@gmail.com>
Fri, 29 Jul 2016 13:48:39 -0300
changeset 340101 3ef9694e9341a2215f29dbc152f22f1bb8d95ae0
parent 340100 ed1ccacac3d82e261254e853f359e399f72bd424
child 340102 40e4aa52d1d00969771baf1d8e558f0ff5500f3c
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskrizsa, sylvestre
bugs1247497
milestone49.0a2
Bug 1247497. Test for e10s-addons mechanism. r=krizsa a=sylvestre MozReview-Commit-ID: HHn475ZMOl5
toolkit/mozapps/extensions/internal/E10SAddonsRollout.jsm
toolkit/mozapps/extensions/test/xpcshell/test_e10s_restartless.js
--- a/toolkit/mozapps/extensions/internal/E10SAddonsRollout.jsm
+++ b/toolkit/mozapps/extensions/internal/E10SAddonsRollout.jsm
@@ -40,16 +40,25 @@ const ADDONS = {
 
   "Emoji": { // Emoji Cheatsheet
     id: "jid1-Xo5SuA6qc1DFpw@jetpack", minVersion: "1.1.1",
   },
 
   "ASP": { // Awesome Screenshot Plus
     id: "jid0-GXjLLfbCoAx0LcltEdFrEkQdQPI@jetpack", minVersion: "3.0.10",
   },
+
+  // Add-ons used for testing
+  "test1": {
+    id: "bootstrap1@tests.mozilla.org", minVersion: "1.0",
+  },
+
+  "test2": {
+    id: "bootstrap2@tests.mozilla.org", minVersion: "1.0",
+  },
 };
 
 // NOTE: Do not modify sets or policies after they have already been
 // published to users. They must remain unchanged to provide valid data.
 const set1 = [ADDONS.Emoji,
               ADDONS.ASP,
               ADDONS.DYTV];
 
@@ -66,16 +75,18 @@ const set2 = [ADDONS.Greasemonkey,
 // data with them, in order to understand how each set
 // is behaving in the wild.
 const RolloutPolicy = {
   "1a": { addons: set1, webextensions: true },
   "2a": { addons: set2, webextensions: true },
 
   "1b": { addons: set1, webextensions: false },
   "2b": { addons: set2, webextensions: false },
+
+  "xpcshell-test": { addons: [ADDONS.test1, ADDONS.test2], webextensions: false },
 };
 
 Object.defineProperty(this, "isAddonPartOfE10SRollout", {
   configurable: false,
   enumerable: false,
   writable: false,
   value: function isAddonPartOfE10SRollout(aAddon) {
     let blocklist = Preferences.get(PREF_E10S_ADDON_BLOCKLIST, "");
--- a/toolkit/mozapps/extensions/test/xpcshell/test_e10s_restartless.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_e10s_restartless.js
@@ -275,16 +275,134 @@ add_task(function*() {
   do_check_false(blocked);
 
   addon2 = yield promiseAddonByID(ID2);
   addon2.uninstall();
 
   restartManager();
 });
 
+// Check that the rollout policy sets work as expected
+add_task(function*(){
+  gAppInfo.browserTabsRemoteAutostart = true;
+  Services.prefs.setBoolPref("extensions.e10sBlocksEnabling", true);
+  Services.prefs.setCharPref("extensions.e10s.rollout.policy", "xpcshell-test");
+
+  // Both 'bootstrap1' and 'bootstrap2' addons are listed in the allowed policy
+  // set, so they should install and start normally.
+  yield check_normal();
+
+  // Check that the two add-ons can be installed together correctly as
+  // check_normal() only perform checks on bootstrap1.
+  let install1 = yield new Promise(resolve => AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_1"), resolve));
+  let install2 = yield new Promise(resolve => AddonManager.getInstallForFile(do_get_addon("test_bootstrap2_1"), resolve));
+  yield promiseCompleteAllInstalls([install1, install2]);
+
+  do_check_eq(install1.state, AddonManager.STATE_INSTALLED);
+  do_check_eq(install2.state, AddonManager.STATE_INSTALLED);
+  do_check_false(hasFlag(install1.addon.pendingOperations, AddonManager.PENDING_INSTALL));
+  do_check_false(hasFlag(install2.addon.pendingOperations, AddonManager.PENDING_INSTALL));
+
+  let addon = yield promiseAddonByID(ID);
+  let addon2 = yield promiseAddonByID(ID2);
+
+  do_check_neq(addon, null);
+  do_check_neq(addon2, null);
+
+  BootstrapMonitor.checkAddonInstalled(ID);
+  BootstrapMonitor.checkAddonStarted(ID);
+
+  BootstrapMonitor.checkAddonInstalled(ID2);
+  BootstrapMonitor.checkAddonStarted(ID2);
+
+  yield promiseRestartManager();
+
+  // After install and restart e10s should not be blocked.
+  let blocked = Services.prefs.getBoolPref("extensions.e10sBlockedByAddons");
+  do_check_false(blocked);
+
+  // Check that adding bootstrap2 to the blocklist will trigger a disable of e10s.
+  Services.prefs.setCharPref("extensions.e10s.rollout.blocklist", ID2);
+  blocked = Services.prefs.getBoolPref("extensions.e10sBlockedByAddons");
+  do_check_true(blocked);
+
+  yield promiseRestartManager();
+
+  // Check that after restarting, e10s continues to be blocked.
+  blocked = Services.prefs.getBoolPref("extensions.e10sBlockedByAddons");
+  do_check_true(blocked);
+
+  // Check that uninstalling bootstrap2 (which is in the blocklist) will
+  // cause e10s to be re-enabled.
+  addon2 = yield promiseAddonByID(ID2);
+  do_check_false(hasFlag(addon2.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_UNINSTALL));
+  addon2.uninstall();
+  BootstrapMonitor.checkAddonNotStarted(ID2);
+  BootstrapMonitor.checkAddonNotInstalled(ID2);
+
+  yield promiseRestartManager();
+
+  // After uninstall the blocklisted addon and restart we should not block.
+  blocked = Services.prefs.getBoolPref("extensions.e10sBlockedByAddons");
+  do_check_false(blocked);
+
+
+  // Let's perform similar checks again, now that bootstrap2 is in the blocklist.
+  // The bootstrap1 add-on should install and start correctly, but bootstrap2 should not.
+  addon = yield promiseAddonByID(ID);
+  addon.uninstall();
+  BootstrapMonitor.checkAddonNotStarted(ID);
+  BootstrapMonitor.checkAddonNotInstalled(ID);
+
+  yield promiseRestartManager();
+
+  install1 = yield new Promise(resolve => AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_1"), resolve));
+  install2 = yield new Promise(resolve => AddonManager.getInstallForFile(do_get_addon("test_bootstrap2_1"), resolve));
+  yield promiseCompleteAllInstalls([install1, install2]);
+
+  do_check_eq(install1.state, AddonManager.STATE_INSTALLED);
+  do_check_eq(install2.state, AddonManager.STATE_INSTALLED);
+  do_check_false(hasFlag(install1.addon.pendingOperations, AddonManager.PENDING_INSTALL));
+  do_check_true(hasFlag(install2.addon.pendingOperations, AddonManager.PENDING_INSTALL));
+
+  addon = yield promiseAddonByID(ID);
+  addon2 = yield promiseAddonByID(ID2);
+
+  do_check_neq(addon, null);
+  do_check_eq(addon2, null);
+
+  BootstrapMonitor.checkAddonInstalled(ID);
+  BootstrapMonitor.checkAddonStarted(ID);
+
+  BootstrapMonitor.checkAddonNotInstalled(ID2);
+  BootstrapMonitor.checkAddonNotStarted(ID2);
+
+  yield promiseRestartManager();
+
+  blocked = Services.prefs.getBoolPref("extensions.e10sBlockedByAddons");
+  do_check_true(blocked);
+
+  // Clean-up
+  addon = yield promiseAddonByID(ID);
+  addon2 = yield promiseAddonByID(ID2);
+
+  addon.uninstall();
+  BootstrapMonitor.checkAddonNotStarted(ID);
+  BootstrapMonitor.checkAddonNotInstalled(ID);
+
+  addon2.uninstall();
+  BootstrapMonitor.checkAddonNotStarted(ID2);
+  BootstrapMonitor.checkAddonNotInstalled(ID2);
+
+  Services.prefs.clearUserPref("extensions.e10s.rollout.policy");
+  Services.prefs.clearUserPref("extensions.e10s.rollout.blocklist");
+
+  yield promiseRestartManager();
+});
+
 // The hotfix is unaffected
 add_task(function*() {
   gAppInfo.browserTabsRemoteAutostart = true;
   Services.prefs.setBoolPref("extensions.e10sBlocksEnabling", true);
   Services.prefs.setCharPref("extensions.hotfix.id", ID);
   Services.prefs.setBoolPref("extensions.hotfix.cert.checkAttributes", false);
 
   yield check_normal();