Bug 1247497. Test for e10s-addons mechanism. r=krizsa draft
authorFelipe Gomes <felipc@gmail.com>
Tue, 26 Jul 2016 14:51:59 -0300
changeset 393010 1af0763c57b7f42a45c3df2db3330952fbf34d3d
parent 393009 90010610e2801c342acec238508b50ec446fa814
child 526454 79a450997fa747e8b5c2e2c1c045b59560f17925
push id24170
push userfelipc@gmail.com
push dateTue, 26 Jul 2016 17:52:35 +0000
reviewerskrizsa
bugs1247497
milestone50.0a1
Bug 1247497. Test for e10s-addons mechanism. r=krizsa MozReview-Commit-ID: 13uaHT4nz5y
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
@@ -44,16 +44,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];
 
@@ -71,16 +80,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();