Bug 1446686: Part 4 - Disable non-restartless extensions by default, with a pref to enable for xpcshell tests. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Sat, 17 Mar 2018 18:09:42 -0700
changeset 769609 d705afafda3a3cfa0710c10561f72eea679918bc
parent 769608 1bcc8b18bf3e2b473e7d5d7a39db897656cf2a74
push id103186
push usermaglione.k@gmail.com
push dateMon, 19 Mar 2018 21:29:22 +0000
reviewersaswan
bugs1446686
milestone61.0a1
Bug 1446686: Part 4 - Disable non-restartless extensions by default, with a pref to enable for xpcshell tests. r?aswan MozReview-Commit-ID: u8WkUEMig9
services/sync/tests/unit/test_addons_store.js
toolkit/mozapps/extensions/internal/XPIInstall.jsm
toolkit/mozapps/extensions/test/addons/test_install1/install.rdf
toolkit/mozapps/extensions/test/addons/test_install3/install.rdf
toolkit/mozapps/extensions/test/addons/webextension_2/install.rdf
toolkit/mozapps/extensions/test/xpcshell/head_addons.js
--- a/services/sync/tests/unit/test_addons_store.js
+++ b/services/sync/tests/unit/test_addons_store.js
@@ -341,17 +341,17 @@ add_task(async function test_get_all_ids
   let ids = await store.getAllIDs();
 
   Assert.equal("object", typeof(ids));
   Assert.equal(3, Object.keys(ids).length);
   Assert.ok(addon1.syncGUID in ids);
   Assert.ok(addon2.syncGUID in ids);
   Assert.ok(addon3.syncGUID in ids);
 
-  addon1.install.cancel();
+  await uninstallAddon(addon1, reconciler);
   await uninstallAddon(addon2, reconciler);
   await uninstallAddon(addon3, reconciler);
 });
 
 add_task(async function test_change_item_id() {
   _("Ensures that changeItemID() works properly.");
 
   let addon = await installAddon("test_bootstrap1_1", reconciler);
--- a/toolkit/mozapps/extensions/internal/XPIInstall.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIInstall.jsm
@@ -55,16 +55,18 @@ XPCOMUtils.defineLazyServiceGetter(this,
                                    Ci.nsIRDFService);
 
 
 ChromeUtils.defineModuleGetter(this, "XPIInternal",
                                "resource://gre/modules/addons/XPIProvider.jsm");
 ChromeUtils.defineModuleGetter(this, "XPIProvider",
                                "resource://gre/modules/addons/XPIProvider.jsm");
 
+const PREF_ALLOW_NON_RESTARTLESS      = "extensions.legacy.non-restartless.enabled";
+
 /* globals AddonInternal, BOOTSTRAP_REASONS, KEY_APP_SYSTEM_ADDONS, KEY_APP_SYSTEM_DEFAULTS, KEY_APP_TEMPORARY, TEMPORARY_ADDON_SUFFIX, SIGNED_TYPES, TOOLKIT_ID, XPIDatabase, XPIStates, getExternalType, isTheme, isUsableAddon, isWebExtension, mustSign, recordAddonTelemetry */
 const XPI_INTERNAL_SYMBOLS = [
   "AddonInternal",
   "BOOTSTRAP_REASONS",
   "KEY_APP_SYSTEM_ADDONS",
   "KEY_APP_SYSTEM_DEFAULTS",
   "KEY_APP_TEMPORARY",
   "SIGNED_TYPES",
@@ -546,16 +548,18 @@ async function loadManifestFromRDF(aUri,
     throw new Error("No version in install manifest");
 
   addon.strictCompatibility = !(addon.type in COMPATIBLE_BY_DEFAULT_TYPES) ||
                               getRDFProperty(ds, root, "strictCompatibility") == "true";
 
   // Only read these properties for extensions.
   if (addon.type == "extension") {
     addon.bootstrap = getRDFProperty(ds, root, "bootstrap") == "true";
+    if (!addon.bootstrap && !Services.prefs.getBoolPref(PREF_ALLOW_NON_RESTARTLESS, false))
+        throw new Error(`Non-restartless extensions no longer supported`);
 
     addon.hasEmbeddedWebExtension = getRDFProperty(ds, root, "hasEmbeddedWebExtension") == "true";
 
     if (addon.optionsType &&
         addon.optionsType != AddonManager.OPTIONS_INLINE_BROWSER &&
         addon.optionsType != AddonManager.OPTIONS_TYPE_TAB) {
       throw new Error("Install manifest specifies unknown optionsType: " + addon.optionsType);
     }
--- a/toolkit/mozapps/extensions/test/addons/test_install1/install.rdf
+++ b/toolkit/mozapps/extensions/test/addons/test_install1/install.rdf
@@ -2,16 +2,17 @@
 
 <!-- An extension that is compatible with the XPCShell test suite -->
 <RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:em="http://www.mozilla.org/2004/em-rdf#">
 
   <Description about="urn:mozilla:install-manifest">
     <em:id>addon1@tests.mozilla.org</em:id>
     <em:version>1.0</em:version>
+    <em:bootstrap>true</em:bootstrap>
 
     <!-- Front End MetaData -->
     <em:name>Test 1</em:name>
     <em:description>Test Description</em:description>
 
     <em:targetApplication>
       <Description>
         <em:id>xpcshell@tests.mozilla.org</em:id>
--- a/toolkit/mozapps/extensions/test/addons/test_install3/install.rdf
+++ b/toolkit/mozapps/extensions/test/addons/test_install3/install.rdf
@@ -3,16 +3,17 @@
 <!-- An extension that is incompatible with the XPCShell test suite until
      a compatibility update check is performed -->
 <RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:em="http://www.mozilla.org/2004/em-rdf#">
 
   <Description about="urn:mozilla:install-manifest">
     <em:id>addon3@tests.mozilla.org</em:id>
     <em:version>1.0</em:version>
+    <em:bootstrap>true</em:bootstrap>
 
     <!-- Front End MetaData -->
     <em:name>Real Test 4</em:name>
     <em:description>Test Description</em:description>
 
     <em:updateURL>http://localhost:4444/data/test_install.rdf</em:updateURL>
 
     <em:targetApplication>
--- a/toolkit/mozapps/extensions/test/addons/webextension_2/install.rdf
+++ b/toolkit/mozapps/extensions/test/addons/webextension_2/install.rdf
@@ -1,16 +1,17 @@
 <?xml version="1.0"?>
 
 <RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:em="http://www.mozilla.org/2004/em-rdf#">
 
   <Description about="urn:mozilla:install-manifest">
     <em:id>first-webextension2@tests.mozilla.org</em:id>
     <em:version>2.0</em:version>
+    <em:bootstrap>true</em:bootstrap>
 
     <em:targetApplication>
       <Description>
         <em:id>xpcshell@tests.mozilla.org</em:id>
         <em:minVersion>1</em:minVersion>
         <em:maxVersion>1</em:maxVersion>
       </Description>
     </em:targetApplication>
--- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
@@ -63,16 +63,102 @@ ChromeUtils.defineModuleGetter(this, "Mo
                                "resource://testing-common/MockRegistrar.jsm");
 ChromeUtils.defineModuleGetter(this, "MockRegistry",
                                "resource://testing-common/MockRegistry.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "aomStartup",
                                    "@mozilla.org/addons/addon-manager-startup;1",
                                    "amIAddonManagerStartup");
 
+// Whitelist existing tests that still use non-restartless extensions.
+const LEGACY_NON_RESTARTLESS_TESTS = new Set([
+  "test_AddonRepository.js",
+  "test_AddonRepository_cache.js",
+  "test_XPIStates.js",
+  "test_backgroundupdate.js",
+  "test_bad_json.js",
+  "test_badschema.js",
+  "test_blocklist_metadata_filters.js",
+  "test_blocklist_prefs.js",
+  "test_blocklist_regexp.js",
+  "test_blocklistchange.js",
+  "test_bug299716.js",
+  "test_bug299716_2.js",
+  "test_bug324121.js",
+  "test_bug335238.js",
+  "test_bug384052.js",
+  "test_bug393285.js",
+  "test_bug394300.js",
+  "test_bug397778.js",
+  "test_bug406118.js",
+  "test_bug425657.js",
+  "test_bug449027.js",
+  "test_bug455906.js",
+  "test_bug470377_1.js",
+  "test_bug470377_1_strictcompat.js",
+  "test_bug470377_2.js",
+  "test_bug470377_3.js",
+  "test_bug470377_3_strictcompat.js",
+  "test_bug470377_4.js",
+  "test_bug559800.js",
+  "test_bug564030.js",
+  "test_bug566626.js",
+  "test_bug569138.js",
+  "test_bug576735.js",
+  "test_bug595573.js",
+  "test_bug655254.js",
+  "test_bug659772.js",
+  "test_bug753900.js",
+  "test_cacheflush.js",
+  "test_checkcompatibility.js",
+  "test_compatoverrides.js",
+  "test_corrupt.js",
+  "test_corrupt_strictcompat.js",
+  "test_dataDirectory.js",
+  "test_disable.js",
+  "test_distribution.js",
+  "test_error.js",
+  "test_filepointer.js",
+  "test_install.js",
+  "test_install_strictcompat.js",
+  "test_invalid_install_rdf.js",
+  "test_isDebuggable.js",
+  "test_locale.js",
+  "test_locked.js",
+  "test_locked2.js",
+  "test_locked_strictcompat.js",
+  "test_manifest.js",
+  "test_migrate_state_prefs.js",
+  "test_nodisable_hidden.js",
+  "test_onPropertyChanged_appDisabled.js",
+  "test_proxies.js",
+  "test_safemode.js",
+  "test_sideloads.js",
+  "test_signed_verify.js",
+  "test_softblocked.js",
+  "test_sourceURI.js",
+  "test_startup.js",
+  "test_strictcompatibility.js",
+  "test_syncGUID.js",
+  "test_targetPlatforms.js",
+  "test_temporary.js",
+  "test_undouninstall.js",
+  "test_uninstall.js",
+  "test_updateCancel.js",
+  "test_update_compatmode.js",
+  "test_update_strictcompat.js",
+  "test_update_webextensions.js",
+  "test_upgrade.js",
+  "test_upgrade_strictcompat.js",
+]);
+
+if (LEGACY_NON_RESTARTLESS_TESTS.has(_TEST_FILE[0].replace(/.*\//, ""))) {
+  Services.prefs.setBoolPref("extensions.legacy.non-restartless.enabled", true);
+}
+
 const {
   awaitPromise,
   createAppInfo,
   createInstallRDF,
   createTempWebExtensionFile,
   createUpdateRDF,
   getFileForAddon,
   manuallyUninstall,