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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alexandre Poirot 2018-11-27 11:23:20 +00:00
Родитель 31a22e9610
Коммит a4a14bea9f
5 изменённых файлов: 38 добавлений и 38 удалений

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

@ -89,9 +89,8 @@ var connect = async function() {
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});

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

@ -37,13 +37,12 @@ async function test_connect_addon(oopMode) {
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,
});

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

@ -98,16 +98,15 @@ async function attachAddon(addonId) {
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,
});
@ -116,18 +115,14 @@ async function attachAddon(addonId) {
}
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.

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

@ -34,17 +34,10 @@ function promiseWebExtensionStartup() {
});
}
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;
}
@ -74,10 +67,10 @@ add_task(async function testReloadExitedAddon() {
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(),
]);
@ -88,11 +81,11 @@ add_task(async function testReloadExitedAddon() {
// 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");
@ -107,13 +100,13 @@ add_task(async function testReloadExitedAddon() {
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);
});

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

@ -215,6 +215,20 @@ const RootFront = protocol.FrontClassWithSpec(rootSpec, {
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.
*