Bug 1578108 - add addons actor back; r=ochameau
authoryulia <ystartsev@mozilla.com>
Mon, 02 Sep 2019 15:33:29 +0000
changeset 491219 b0c4546217586995ba6875770173638901118581
parent 491218 51cdbae0ac647598c2b27506b6ae27063d84eb43
child 491220 9cc29b004e7ededa5abffb89e6b0d8300e9c80bf
push id94265
push userystartsev@mozilla.com
push dateMon, 02 Sep 2019 15:34:20 +0000
treeherderautoland@b0c454621758 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1578108
milestone70.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 1578108 - add addons actor back; r=ochameau Differential Revision: https://phabricator.services.mozilla.com/D44375
devtools/server/actors/addon/addons.js
devtools/server/actors/addon/moz.build
devtools/server/actors/utils/actor-registry.js
devtools/server/tests/unit/test_addons_actor.js
devtools/server/tests/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/devtools/server/actors/addon/addons.js
@@ -0,0 +1,40 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { AddonManager } = require("resource://gre/modules/AddonManager.jsm");
+const protocol = require("devtools/shared/protocol");
+const { FileUtils } = require("resource://gre/modules/FileUtils.jsm");
+const { addonsSpec } = require("devtools/shared/specs/addon/addons");
+
+// This actor is not used by DevTools, but is relied on externally by
+// webext-run and the Firefox VS-Code plugin. see bug #1578108
+const AddonsActor = protocol.ActorClassWithSpec(addonsSpec, {
+  initialize: function(conn) {
+    protocol.Actor.prototype.initialize.call(this, conn);
+  },
+
+  async installTemporaryAddon(addonPath) {
+    let addonFile;
+    let addon;
+    try {
+      addonFile = new FileUtils.File(addonPath);
+      addon = await AddonManager.installTemporaryAddon(addonFile);
+    } catch (error) {
+      throw new Error(`Could not install add-on at '${addonPath}': ${error}`);
+    }
+
+    // TODO: once the add-on actor has been refactored to use
+    // protocol.js, we could return it directly.
+    // return new AddonTargetActor(this.conn, addon);
+
+    // Return a pseudo add-on object that a calling client can work
+    // with. Provide a flag that the client can use to detect when it
+    // gets upgraded to a real actor object.
+    return { id: addon.id, actor: false };
+  },
+});
+
+exports.AddonsActor = AddonsActor;
--- a/devtools/server/actors/addon/moz.build
+++ b/devtools/server/actors/addon/moz.build
@@ -1,9 +1,10 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 DevToolsModules(
+    'addons.js',
     'webextension-inspected-window.js',
 )
--- a/devtools/server/actors/utils/actor-registry.js
+++ b/devtools/server/actors/utils/actor-registry.js
@@ -127,16 +127,21 @@ const ActorRegistry = {
       constructor: "PreferenceActor",
       type: { global: true },
     });
     this.registerModule("devtools/server/actors/actor-registry", {
       prefix: "actorRegistry",
       constructor: "ActorRegistryActor",
       type: { global: true },
     });
+    this.registerModule("devtools/server/actors/addon/addons", {
+      prefix: "addons",
+      constructor: "AddonsActor",
+      type: { global: true },
+    });
     this.registerModule("devtools/server/actors/device", {
       prefix: "device",
       constructor: "DeviceActor",
       type: { global: true },
     });
     this.registerModule("devtools/server/actors/heap-snapshot-file", {
       prefix: "heapSnapshotFile",
       constructor: "HeapSnapshotFileActor",
new file mode 100644
--- /dev/null
+++ b/devtools/server/tests/unit/test_addons_actor.js
@@ -0,0 +1,52 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+/* eslint-disable no-shadow */
+
+"use strict";
+
+startupAddonsManager();
+
+async function connect() {
+  DebuggerServer.init();
+  DebuggerServer.registerAllActors();
+
+  const client = new DebuggerClient(DebuggerServer.connectPipe());
+  await client.connect();
+
+  const addons = await client.mainRoot.getFront("addons");
+  return [client, addons];
+}
+
+add_task(async function testSuccessfulInstall() {
+  const [client, addons] = await connect();
+
+  const allowMissing = false;
+  const usePlatformSeparator = true;
+  const addonPath = getFilePath(
+    "addons/web-extension",
+    allowMissing,
+    usePlatformSeparator
+  );
+  const installedAddon = await addons.installTemporaryAddon(addonPath);
+  equal(installedAddon.id, "test-addons-actor@mozilla.org");
+  // The returned object is currently not a proper actor.
+  equal(installedAddon.actor, false);
+
+  const addonList = await client.mainRoot.listAddons();
+  ok(addonList && addonList.map(a => a.name), "Received list of add-ons");
+  const addon = addonList.find(a => a.id === installedAddon.id);
+  ok(addon, "Test add-on appeared in root install list");
+
+  await close(client);
+});
+
+add_task(async function testNonExistantPath() {
+  const [client, addons] = await connect();
+
+  await Assert.rejects(
+    addons.installTemporaryAddon("some-non-existant-path"),
+    /Could not install add-on.*Component returned failure/
+  );
+
+  await close(client);
+});
--- a/devtools/server/tests/unit/xpcshell.ini
+++ b/devtools/server/tests/unit/xpcshell.ini
@@ -31,16 +31,17 @@ support-files =
   setBreakpoint-on-line-with-no-offsets-in-gcd-script.js
   addons/web-extension/manifest.json
   addons/web-extension-upgrade/manifest.json
   addons/web-extension2/manifest.json
 
 [test_addon_events.js]
 skip-if = (os == 'win' && bits == 32) #Bug 1543156
 [test_addon_reload.js]
+[test_addons_actor.js]
 [test_animation_name.js]
 [test_animation_type.js]
 [test_actor-registry-actor.js]
 [test_nesting-01.js]
 [test_nesting-02.js]
 [test_nesting-03.js]
 [test_forwardingprefix.js]
 [test_getyoungestframe.js]