Bug 1508660 - introduce getCachedFront; r=ochameau

Depends on D12439

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
yulia 2018-12-17 13:23:29 +00:00
parent 0913e97c35
commit 26f279b0fb
4 changed files with 47 additions and 2 deletions

View File

@ -593,10 +593,17 @@ function createHighlightButton(highlighterName, id) {
return highlighter.show({});
},
isChecked(toolbox) {
if (!toolbox.inspector) {
// if the inspector doesn't exist, then the highlighter has not yet been connected
// to the front end.
const inspectorFront = toolbox.target.getCachedFront("inspector");
if (!inspectorFront) {
// initialize the inspector front asyncronously. There is a potential for buggy
// behavior here, but we need to change how the buttons get data (have them
// consume data from reducers rather than writing our own version) in order to
// fix this properly.
return false;
}
const highlighter = toolbox.inspector.getKnownHighlighter(highlighterName);
const highlighter = inspectorFront.getKnownHighlighter(highlighterName);
return highlighter && highlighter.isShown();
},
};

View File

@ -398,11 +398,24 @@ Target.prototype = {
return front;
}
front = getFront(this.client, typeName, this.form);
this.fronts.set(typeName, front);
// replace the placeholder with the instance of the front once it has loaded
front = await front;
this.emit(typeName, front);
this.fronts.set(typeName, front);
return front;
},
getCachedFront(typeName) {
// do not wait for async fronts;
const front = this.fronts.get(typeName);
// ensure that the front is a front, and not async front
if (front && front.actorID) {
return front;
}
return null;
},
get client() {
return this._client;
},

View File

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

View File

@ -0,0 +1,24 @@
/* 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("Cached front when getFront has not been called");
let getCachedFront = target.getCachedFront("accessibility");
ok(!getCachedFront, "no front exists");
info("Cached front when getFront has been called but has not finished");
const asyncFront = target.getFront("accessibility");
getCachedFront = target.getCachedFront("accessibility");
ok(!getCachedFront, "no front exists");
info("Cached front when getFront has been called and has finished");
const front = await asyncFront;
getCachedFront = target.getCachedFront("accessibility");
is(getCachedFront, front, "front is the same as async front");
});