Bug 1506546 - Implement RootFront.getAddon and use it to retrieve a single AddonTargetFront. r=yulia
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 27 Nov 2018 19:18:06 +0000
changeset 504789 da5ade7a2726215570a14dd717bdeb19ed2d47bb
parent 504788 e5fb062f20f85af04b876b05e5031ab3282d64bc
child 504790 abfeab4a1d650c8f275725b62a416d13b25e29dc
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyulia
bugs1506546
milestone65.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 1506546 - Implement RootFront.getAddon and use it to retrieve a single AddonTargetFront. r=yulia MozReview-Commit-ID: nWTkfbF9qb Depends on D12574 Differential Revision: https://phabricator.services.mozilla.com/D12575
devtools/client/framework/toolbox-process-window.js
devtools/server/tests/mochitest/test_webextension-addon-debugging-connect.html
devtools/server/tests/mochitest/webextension-helpers.js
devtools/server/tests/unit/test_addon_reload.js
devtools/shared/fronts/root.js
--- a/devtools/client/framework/toolbox-process-window.js
+++ b/devtools/client/framework/toolbox-process-window.js
@@ -84,19 +84,18 @@ var connect = async function() {
     webSocket,
   });
   gClient = new DebuggerClient(transport);
   appendStatusMessage("Start protocol client for connection");
   await gClient.connect();
 
   appendStatusMessage("Get root form for toolbox");
   if (addonID) {
-    const { addons } = await gClient.listAddons();
-    const addonTargetActor = addons.filter(addon => addon.id === addonID).pop();
-    await openToolbox({form: addonTargetActor, chrome: true});
+    const addonTargetFront = await gClient.mainRoot.getAddon({ id: addonID });
+    await openToolbox({activeTab: addonTargetFront, chrome: true});
   } else {
     const front = await gClient.mainRoot.getMainProcess();
     await openToolbox({activeTab: front, chrome: true});
   }
 };
 
 // Certain options should be toggled since we can assume chrome debugging here
 function setPrefDefaults() {
--- a/devtools/server/tests/mochitest/test_webextension-addon-debugging-connect.html
+++ b/devtools/server/tests/mochitest/test_webextension-addon-debugging-connect.html
@@ -32,23 +32,22 @@ async function test_connect_addon(oopMod
   await extension.awaitMessage("background page ready");
 
   // Connect a DebuggerClient.
   const transport = DebuggerServer.connectPipe();
   const client = new DebuggerClient(transport);
   await client.connect();
 
   // List addons and assertions on the expected addon actor.
-  const {addons} = await client.mainRoot.listAddons();
-  const addonTargetActor = addons.filter(actor => actor.id === extension.id).pop();
-  ok(addonTargetActor, "The expected webextension addon actor has been found");
+  const addonTargetFront = await client.mainRoot.getAddon({ id: extension.id });
+  ok(addonTargetFront, "The expected webextension addon actor has been found");
 
   // Connect to the target addon actor and wait for the updated list of frames.
   const addonTarget = await TargetFactory.forRemoteTab({
-    form: addonTargetActor,
+    activeTab: addonTargetFront,
     client,
     chrome: true,
   });
   is(addonTarget.form.isOOP, oopMode,
      "Got the expected oop mode in the webextension actor form");
   const frames = await waitForFramesUpdated(addonTarget);
   const backgroundPageFrame = frames.filter((frame) => {
     return frame.url && frame.url.endsWith("/_generated_background_page.html");
--- a/devtools/server/tests/mochitest/webextension-helpers.js
+++ b/devtools/server/tests/mochitest/webextension-helpers.js
@@ -93,46 +93,41 @@ function collectFrameUpdates({client}, m
 }
 
 async function attachAddon(addonId) {
   const transport = DebuggerServer.connectPipe();
   const client = new DebuggerClient(transport);
 
   await client.connect();
 
-  const {addons} = await client.mainRoot.listAddons();
-  const addonTargetActor = addons.filter(actor => actor.id === addonId).pop();
+  const addonTargetFront = await client.mainRoot.getAddon({ id: addonId });
 
-  if (!addonTargetActor) {
+  if (!addonTargetFront) {
     client.close();
     throw new Error(`No WebExtension Actor found for ${addonId}`);
   }
 
   const addonTarget = await TargetFactory.forRemoteTab({
-    form: addonTargetActor,
+    activeTab: addonTargetFront,
     client,
     chrome: true,
   });
 
   return addonTarget;
 }
 
 async function reloadAddon({client}, addonId) {
-  const {addons} = await client.mainRoot.listAddons();
-  const addonTargetActor = addons.filter(actor => actor.id === addonId).pop();
+  const addonTargetFront = await client.mainRoot.getAddon({ id: addonId });
 
-  if (!addonTargetActor) {
+  if (!addonTargetFront) {
     client.close();
     throw new Error(`No WebExtension Actor found for ${addonId}`);
   }
 
-  await client.request({
-    to: addonTargetActor.actor,
-    type: "reload",
-  });
+  await addonTargetFront.reload();
 }
 
 // Test helpers related to the AddonManager.
 
 function generateWebExtensionXPI(extDetails) {
   const addonFile = Extension.generateXPI(extDetails);
 
   flushJarCache(addonFile.path);
--- a/devtools/server/tests/unit/test_addon_reload.js
+++ b/devtools/server/tests/unit/test_addon_reload.js
@@ -29,27 +29,20 @@ function promiseWebExtensionStartup() {
       Management.off("ready", listener);
       resolve(extension);
     };
 
     Management.on("ready", listener);
   });
 }
 
-async function findAddonInRootList(client, addonId) {
-  const result = await client.listAddons();
-  const addonTargetActor = result.addons.filter(addon => addon.id === addonId)[0];
-  ok(addonTargetActor, `Found add-on actor for ${addonId}`);
-  return addonTargetActor;
-}
-
-async function reloadAddon(client, addonTargetActor) {
+async function reloadAddon(addonTargetFront) {
   // The add-on will be re-installed after a successful reload.
   const onInstalled = promiseAddonEvent("onInstalled");
-  await client.request({to: addonTargetActor.actor, type: "reload"});
+  await addonTargetFront.reload();
   await onInstalled;
 }
 
 function getSupportFile(path) {
   const allowMissing = false;
   return do_get_file(path, allowMissing);
 }
 
@@ -69,51 +62,51 @@ add_task(async function testReloadExited
 
   // Install a decoy add-on.
   const addonFile2 = getSupportFile("addons/web-extension2");
   const [installedAddon2] = await Promise.all([
     AddonManager.installTemporaryAddon(addonFile2),
     promiseWebExtensionStartup(),
   ]);
 
-  const addonTargetActor = await findAddonInRootList(client, installedAddon.id);
+  const addonTargetFront = await client.mainRoot.getAddon({ id: installedAddon.id });
 
   await Promise.all([
-    reloadAddon(client, addonTargetActor),
+    reloadAddon(addonTargetFront),
     promiseWebExtensionStartup(),
   ]);
 
   // Uninstall the decoy add-on, which should cause its actor to exit.
   const onUninstalled = promiseAddonEvent("onUninstalled");
   installedAddon2.uninstall();
   await onUninstalled;
 
   // Try to re-list all add-ons after a reload.
   // This was throwing an exception because of the exited actor.
-  const newAddonActor = await findAddonInRootList(client, installedAddon.id);
-  equal(newAddonActor.id, addonTargetActor.id);
+  const newAddonFront = await client.mainRoot.getAddon({ id: installedAddon.id });
+  equal(newAddonFront.id, addonTargetFront.id);
 
-  // The actor id should be the same after the reload
-  equal(newAddonActor.actor, addonTargetActor.actor);
+  // The fronts should be the same after the reload
+  equal(newAddonFront, addonTargetFront);
 
   const onAddonListChanged = client.mainRoot.once("addonListChanged");
 
   // Install an upgrade version of the first add-on.
   const addonUpgradeFile = getSupportFile("addons/web-extension-upgrade");
   const [upgradedAddon] = await Promise.all([
     AddonManager.installTemporaryAddon(addonUpgradeFile),
     promiseWebExtensionStartup(),
   ]);
 
   // Waiting for addonListChanged unsolicited event
   await onAddonListChanged;
 
   // re-list all add-ons after an upgrade.
-  const upgradedAddonActor = await findAddonInRootList(client, upgradedAddon.id);
-  equal(upgradedAddonActor.id, addonTargetActor.id);
-  // The actor id should be the same after the upgrade.
-  equal(upgradedAddonActor.actor, addonTargetActor.actor);
+  const upgradedAddonFront = await client.mainRoot.getAddon({ id: upgradedAddon.id });
+  equal(upgradedAddonFront.id, addonTargetFront.id);
+  // The fronts should be the same after the upgrade.
+  equal(upgradedAddonFront, addonTargetFront);
 
   // The addon metadata has been updated.
-  equal(upgradedAddonActor.name, "Test Addons Actor Upgrade");
+  equal(upgradedAddonFront.name, "Test Addons Actor Upgrade");
 
   await close(client);
 });
--- a/devtools/shared/fronts/root.js
+++ b/devtools/shared/fronts/root.js
@@ -211,16 +211,30 @@ const RootFront = protocol.FrontClassWit
     }
 
     return this._getTab(packet);
   }, {
     impl: "_getTab",
   }),
 
   /**
+   * Fetch the target front for a given add-on.
+   * This is just an helper on top of `listAddons` request.
+   *
+   * @param object filter
+   *        A dictionary object with following attribute:
+   *         - id: used to match the add-on to connect to.
+   */
+  async getAddon({ id }) {
+    const addons = await this.listAddons();
+    const addonTargetFront = addons.find(addon => addon.id === id);
+    return addonTargetFront;
+  },
+
+  /**
    * Test request that returns the object passed as first argument.
    *
    * `echo` is special as all the property of the given object have to be passed
    * on the packet object. That's not something that can be achieve by requester helper.
    */
 
   echo(packet) {
     packet.type = "echo";