Bug 1495386 - emit event when target scoped front is created; r=ochameau

this change only impacts the target front, and emits an event every time a target is
created. No listners yet.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
yulia 2018-11-09 09:03:54 +00:00
Родитель af6942ecbc
Коммит e938edd036
3 изменённых файлов: 38 добавлений и 0 удалений

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

@ -388,6 +388,16 @@ Target.prototype = {
return this._inspector;
},
// Run callback on every front of this type that currently exists, and on every
// instantiation of front type in the future.
onFront(typeName, callback) {
const front = this.fronts.get(typeName);
if (front) {
return callback(front);
}
return this.on(typeName, callback);
},
// Get a Front for a target-scoped actor.
// i.e. an actor served by RootActor.listTabs or RootActorActor.getTab requests
getFront(typeName) {
@ -397,6 +407,7 @@ Target.prototype = {
return front;
}
front = getFront(this.client, typeName, this.form);
this.emit(typeName, front);
this.fronts.set(typeName, front);
return front;
},

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

@ -77,6 +77,7 @@ skip-if = os == 'win' || debug # Bug 1282269, 1448084
[browser_source_map-late-script.js]
[browser_target_from_url.js]
[browser_target_events.js]
[browser_target_listeners.js]
[browser_target_remote.js]
[browser_target_support.js]
[browser_toolbox_custom_host.js]

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

@ -0,0 +1,26 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
add_task(async function() {
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
await target.attach();
info("Test applying onFront to a front that will be created");
const promise = new Promise(resolve => {
target.onFront("accessibility", resolve);
});
const getFrontFront = target.getFront("accessibility");
const onFrontFront = await promise;
is(getFrontFront, onFrontFront, "got the front instantiated in the future and it's the same");
info("Test applying onFront to an existing front");
await new Promise(resolve => {
target.onFront("accessibility", front => {
is(front, getFrontFront, "got the already instantiated front and it's the same");
resolve();
});
});
});