Bug 1561122: Cleanup SpecialPowers.loadExtension after JSWindowActor migration. r=aswan
☠☠ backed out by f9bf5e4b0b4f ☠ ☠
authorKris Maglione <maglione.k@gmail.com>
Mon, 24 Jun 2019 16:48:51 -0700
changeset 540550 43211ebfe7384909dd95cb44196eea4359156d2a
parent 540549 c2d0956f41d82e76c682f829807e818863cd802a
child 540551 0b3e2164f1283b639782b41b7fd640986d3feca5
push id11529
push userarchaeopteryx@coole-files.de
push dateThu, 04 Jul 2019 15:22:33 +0000
treeherdermozilla-beta@ebb510a784b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1561122
milestone69.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 1561122: Cleanup SpecialPowers.loadExtension after JSWindowActor migration. r=aswan Differential Revision: https://phabricator.services.mozilla.com/D35731
testing/specialpowers/content/SpecialPowersAPI.jsm
testing/specialpowers/content/SpecialPowersAPIParent.jsm
--- a/testing/specialpowers/content/SpecialPowersAPI.jsm
+++ b/testing/specialpowers/content/SpecialPowersAPI.jsm
@@ -1568,69 +1568,57 @@ class SpecialPowersAPI extends JSWindowA
       });
     }
 
     // Note, this is not the addon is as used by the AddonManager etc,
     // this is just an identifier used for specialpowers messaging
     // between this content process and the chrome process.
     let id = this._nextExtensionID++;
 
-    let resolveStartup, resolveUnload, rejectStartup;
-    let startupPromise = new Promise((resolve, reject) => {
-      resolveStartup = resolve;
-      rejectStartup = reject;
-    });
-    let unloadPromise = new Promise(resolve => { resolveUnload = resolve; });
-
-    startupPromise.catch(() => {
-      this._extensionListeners.delete(listener);
-    });
 
     handler = Cu.waiveXrays(handler);
     ext = Cu.waiveXrays(ext);
 
     let sp = this;
     let state = "uninitialized";
     let extension = {
       get state() { return state; },
 
       startup() {
         state = "pending";
-        sp.sendAsyncMessage("SPStartupExtension", {id});
-        return startupPromise;
+        return sp.sendQuery("SPStartupExtension", {id}).then(
+          () => {
+            state = "running";
+          }, () => {
+            state = "failed";
+            sp._extensionListeners.delete(listener);
+            return Promise.reject("startup failed");
+          });
       },
 
       unload() {
         state = "unloading";
-        sp.sendAsyncMessage("SPUnloadExtension", {id});
-        return unloadPromise;
+        return sp.sendQuery("SPUnloadExtension", {id}).finally(() => {
+          sp._extensionListeners.delete(listener);
+          state = "unloaded";
+        });
       },
 
       sendMessage(...args) {
         sp.sendAsyncMessage("SPExtensionMessage", {id, args});
       },
     };
 
     this.sendAsyncMessage("SPLoadExtension", {ext, id});
 
     let listener = (msg) => {
       if (msg.data.id == id) {
-        if (msg.data.type == "extensionStarted") {
-          state = "running";
-          resolveStartup();
-        } else if (msg.data.type == "extensionSetId") {
+        if (msg.data.type == "extensionSetId") {
           extension.id = msg.data.args[0];
           extension.uuid = msg.data.args[1];
-        } else if (msg.data.type == "extensionFailed") {
-          state = "failed";
-          rejectStartup("startup failed");
-        } else if (msg.data.type == "extensionUnloaded") {
-          this._extensionListeners.delete(listener);
-          state = "unloaded";
-          resolveUnload();
         } else if (msg.data.type in handler) {
           handler[msg.data.type](...Cu.cloneInto(msg.data.args, this.contentWindow));
         } else {
           dump(`Unexpected: ${msg.data.type}\n`);
         }
       }
     };
 
--- a/testing/specialpowers/content/SpecialPowersAPIParent.jsm
+++ b/testing/specialpowers/content/SpecialPowersAPIParent.jsm
@@ -714,17 +714,17 @@ class SpecialPowersAPIParent extends JSW
           // is a MockExtension.
           this.sendAsyncMessage("SPExtensionMessage", {id, type: "extensionSetId", args: [ext.id, ext.uuid]});
         });
 
         // Make sure the extension passes the packaging checks when
         // they're run on a bare archive rather than a running instance,
         // as the add-on manager runs them.
         let extensionData = new ExtensionData(extension.rootURI);
-        extensionData.loadManifest().then(
+        return extensionData.loadManifest().then(
           () => {
             return extensionData.initAllLocales().then(() => {
               if (extensionData.errors.length) {
                 return Promise.reject("Extension contains packaging errors");
               }
               return undefined;
             });
           },
@@ -734,43 +734,37 @@ class SpecialPowersAPIParent extends JSW
             // case.
           }
         ).then(async () => {
           // browser tests do not call startup in ExtensionXPCShellUtils or MockExtension,
           // in that case we have an ID here and we need to set the override.
           if (extension.id) {
             await ExtensionTestCommon.setIncognitoOverride(extension);
           }
-          return extension.startup();
-        }).then(() => {
-          this.sendAsyncMessage("SPExtensionMessage", {id, type: "extensionStarted", args: []});
-        }).catch(e => {
-          dump(`Extension startup failed: ${e}\n${e.stack}`);
-          this.sendAsyncMessage("SPExtensionMessage", {id, type: "extensionFailed", args: []});
+          return extension.startup().then(() => {}, e => {
+            dump(`Extension startup failed: ${e}\n${e.stack}`);
+            throw e;
+          });
         });
-        return undefined;
       }
 
       case "SPExtensionMessage": {
         let id = aMessage.data.id;
         let extension = this._extensions.get(id);
         extension.testMessage(...aMessage.data.args);
         return undefined;
       }
 
       case "SPUnloadExtension": {
         let id = aMessage.data.id;
         let extension = this._extensions.get(id);
         this._extensions.delete(id);
-        let done = async () => {
-          await extension._uninstallPromise;
-          this.sendAsyncMessage("SPExtensionMessage", {id, type: "extensionUnloaded", args: []});
-        };
-        extension.shutdown().then(done, done);
-        return undefined;
+        return extension.shutdown().then(() => {
+          return extension._uninstallPromise;
+        });
       }
 
       case "Spawn": {
         let {browsingContext, task, args, caller} = aMessage.data;
 
         let spParent = browsingContext.currentWindowGlobal.getActor("SpecialPowers");
         return spParent.sendQuery("Spawn", {task, args, caller});
       }