Bug 1578108 - add addons actor back; r=ochameau

Differential Revision: https://phabricator.services.mozilla.com/D44375

--HG--
extra : moz-landing-system : lando
This commit is contained in:
yulia 2019-09-02 15:33:29 +00:00
Родитель a83d028749
Коммит 329cb69c2c
5 изменённых файлов: 99 добавлений и 0 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -5,5 +5,6 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
DevToolsModules(
'addons.js',
'webextension-inspected-window.js',
)

Просмотреть файл

@ -132,6 +132,11 @@ const 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",

Просмотреть файл

@ -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);
});

Просмотреть файл

@ -36,6 +36,7 @@ support-files =
[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]