Bug 1311508 - Store the hasEmbeddedWebExtension flag in the bootstrappedAddons pref. r=kmag
authorLuca Greco <lgreco@mozilla.com>
Fri, 21 Oct 2016 05:19:29 +0200
changeset 364268 426d6b4448a7da82db5b00cd48ea0571ec0e60fe
parent 364245 08efaee1d568cea9e70c86a7eca49c3c53553ed8
child 364269 5c11e677e0b472167b2c2c2095c8b899a62a1ade
push id1369
push userjlorenzo@mozilla.com
push dateMon, 27 Feb 2017 14:59:41 +0000
treeherdermozilla-release@d75a1dba431f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1311508
milestone52.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 1311508 - Store the hasEmbeddedWebExtension flag in the bootstrappedAddons pref. r=kmag MozReview-Commit-ID: 7hK78VTY7nO
toolkit/mozapps/extensions/internal/XPIProvider.jsm
toolkit/mozapps/extensions/test/xpcshell/test_webextension_embedded.js
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -4768,29 +4768,32 @@ this.XPIProvider = {
    * @param  aType
    *         The type for the add-on
    * @param  aMultiprocessCompatible
    *         Boolean indicating whether the add-on is compatible with electrolysis.
    * @param  aRunInSafeMode
    *         Boolean indicating whether the add-on can run in safe mode.
    * @param  aDependencies
    *         An array of add-on IDs on which this add-on depends.
+   * @param  hasEmbeddedWebExtension
+   *         Boolean indicating whether the add-on has an embedded webextension.
    * @return a JavaScript scope
    */
   loadBootstrapScope: function(aId, aFile, aVersion, aType,
                                aMultiprocessCompatible, aRunInSafeMode,
-                               aDependencies) {
+                               aDependencies, hasEmbeddedWebExtension) {
     // Mark the add-on as active for the crash reporter before loading
     this.bootstrappedAddons[aId] = {
       version: aVersion,
       type: aType,
       descriptor: aFile.persistentDescriptor,
       multiprocessCompatible: aMultiprocessCompatible,
       runInSafeMode: aRunInSafeMode,
       dependencies: aDependencies,
+      hasEmbeddedWebExtension,
     };
     this.persistBootstrappedAddons();
     this.addAddonsToCrashReporter();
 
     this.activeAddons.set(aId, {
       debugGlobal: null,
       safeWrapper: null,
       bootstrapScope: null,
@@ -4937,17 +4940,18 @@ this.XPIProvider = {
     }
 
     try {
       // Load the scope if it hasn't already been loaded
       let activeAddon = this.activeAddons.get(aAddon.id);
       if (!activeAddon) {
         this.loadBootstrapScope(aAddon.id, aFile, aAddon.version, aAddon.type,
                                 aAddon.multiprocessCompatible || false,
-                                runInSafeMode, aAddon.dependencies);
+                                runInSafeMode, aAddon.dependencies,
+                                aAddon.hasEmbeddedWebExtension || false);
         activeAddon = this.activeAddons.get(aAddon.id);
       }
 
       if (aMethod == "startup" || aMethod == "shutdown") {
         if (!aExtraParams) {
           aExtraParams = {};
         }
         aExtraParams["instanceID"] = this.activeAddons.get(aAddon.id).instanceID;
@@ -5157,16 +5161,17 @@ this.XPIProvider = {
         else {
           this.bootstrappedAddons[aAddon.id] = {
             version: aAddon.version,
             type: aAddon.type,
             descriptor: aAddon._sourceBundle.persistentDescriptor,
             multiprocessCompatible: aAddon.multiprocessCompatible,
             runInSafeMode: canRunInSafeMode(aAddon),
             dependencies: aAddon.dependencies,
+            hasEmbeddedWebExtension: aAddon.hasEmbeddedWebExtension,
           };
           this.persistBootstrappedAddons();
         }
       }
     }
 
     // Sync with XPIStates.
     let xpiState = XPIStates.getAddon(aAddon.location, aAddon.id);
--- a/toolkit/mozapps/extensions/test/xpcshell/test_webextension_embedded.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_webextension_embedded.js
@@ -50,16 +50,87 @@ const BOOTSTRAP = String.raw`
 
 const EMBEDDED_WEBEXT_MANIFEST = JSON.stringify({
   name: "embedded webextension addon",
   manifest_version: 2,
   version: "1.0",
 });
 
 /**
+ *  This test case checks that an hasEmbeddedWebExtension addon property
+ *  is persisted and restored correctly across restarts.
+ */
+add_task(function* has_embedded_webextension_persisted() {
+  const ID = "embedded-webextension-addon-persist@tests.mozilla.org";
+
+  const xpiFile = createTempXPIFile({
+    id: ID,
+    name: "Test Add-on",
+    version: "1.0",
+    bootstrap: true,
+    hasEmbeddedWebExtension: true,
+    targetApplications: [{
+      id: "xpcshell@tests.mozilla.org",
+      minVersion: "1",
+      maxVersion: "1.9.2"
+    }]
+  }, {
+    "bootstrap.js": BOOTSTRAP,
+    "webextension/manifest.json": EMBEDDED_WEBEXT_MANIFEST,
+  });
+
+  yield promiseInstallFile(xpiFile);
+
+  let addon = yield promiseAddonByID(ID);
+
+  notEqual(addon, null, "Got an addon object as expected");
+  equal(addon.version, "1.0", "Got the expected version");
+  equal(addon.hasEmbeddedWebExtension, true,
+        "Got the expected hasEmbeddedWebExtension value");
+
+  // Check that the addon has been installed and started.
+  BootstrapMonitor.checkAddonInstalled(ID, "1.0");
+  BootstrapMonitor.checkAddonStarted(ID, "1.0");
+
+  let startupInfo = BootstrapMonitor.started.get(ID);
+  ok(("webExtension" in startupInfo.data),
+     "Got an webExtension property in the startup bootstrap method params");
+  ok(("startup" in startupInfo.data.webExtension),
+     "Got the expected 'startup' property in the webExtension object");
+
+  // After restarting the manager, the add-on should still have the
+  // hasEmbeddedWebExtension property as expected.
+  yield promiseRestartManager();
+
+  let persisted = JSON.parse(Services.prefs.getCharPref("extensions.bootstrappedAddons"));
+  ok(ID in persisted, "Hybrid add-on persisted to bootstrappedAddons.");
+  equal(persisted[ID].hasEmbeddedWebExtension, true,
+        "hasEmbeddedWebExtension flag persisted to bootstrappedAddons.");
+
+  // Check that the addon has been installed and started.
+  BootstrapMonitor.checkAddonInstalled(ID, "1.0");
+  BootstrapMonitor.checkAddonStarted(ID, "1.0");
+
+  addon = yield promiseAddonByID(ID);
+  notEqual(addon, null, "Got an addon object as expected");
+  equal(addon.hasEmbeddedWebExtension, true, "Got the expected hasEmbeddedWebExtension value");
+
+  // Check that the addon has been installed and started.
+  let newStartupInfo = BootstrapMonitor.started.get(ID);
+  ok(("webExtension" in newStartupInfo.data),
+     "Got an webExtension property in the startup bootstrap method params");
+  ok(("startup" in newStartupInfo.data.webExtension),
+     "Got the expected 'startup' property in the webExtension object");
+
+  let waitUninstall = promiseAddonEvent("onUninstalled");
+  addon.uninstall();
+  yield waitUninstall;
+});
+
+/**
  *  This test case checks that an addon with hasEmbeddedWebExtension set to true
  *  in its install.rdf gets the expected `embeddedWebExtension` object in the
  *  parameters of its bootstrap methods.
  */
 add_task(function* run_embedded_webext_bootstrap() {
   const ID = "embedded-webextension-addon2@tests.mozilla.org";
 
   const xpiFile = createTempXPIFile({