Bug 1649910 - Emit "switched-target" only after we fully attached to the new target. r=jdescottes

The previous code, emitting the event from Toolbox.onTargetAvailable,
wasn't waiting for the call to TargetList.startListening which is done
from TargetList.onTargetAvailable.

Differential Revision: https://phabricator.services.mozilla.com/D82664
This commit is contained in:
Alexandre Poirot 2020-07-08 22:57:36 +00:00
parent 14dea7d7a6
commit 6c430374e4
8 changed files with 11 additions and 9 deletions

View File

@ -31,7 +31,7 @@ add_task(async function() {
const onPropertiesFetched = waitForDispatch(panel, "FETCH_PROPERTIES");
// Also wait for the toolbox to switch to the new target, to avoid hanging requests when
// the test ends.
const onTargetSwitched = toolbox.once("switched-target");
const onTargetSwitched = toolbox.targetList.once("switched-target");
await toolbox.target.navigateTo({ url: CONTENT_PROCESS_URI });

View File

@ -39,7 +39,7 @@ async function navigateBetweenProcesses(enableTargetSwitching) {
const onToolboxDestroyed = toolbox.once("destroyed");
const onToolboxCreated = gDevTools.once("toolbox-created");
const onToolboxSwitchedToTarget = toolbox.once("switched-target");
const onToolboxSwitchedToTarget = toolbox.targetList.once("switched-target");
info("Navigate to a URL supporting remote process");
if (enableTargetSwitching) {

View File

@ -727,8 +727,6 @@ Toolbox.prototype = {
// expect the target to be attached.
await this._listFrames();
await this.initPerformance();
this.emit("switched-target", targetFront);
}
},

View File

@ -80,7 +80,7 @@ function getNodeNames(snapshot) {
}
async function navigateTo(uri, toolbox, tab) {
const onSwitched = once(toolbox, "switched-target");
const onSwitched = toolbox.targetList.once("switched-target");
const onLoaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
await BrowserTestUtils.loadURI(tab.linkedBrowser, uri);
await onLoaded;

View File

@ -409,7 +409,7 @@ async function navigateTo(uri, { isErrorPage = false } = {}) {
// Navigating from/to pages loaded in the parent process, like about:robots,
// also spawn new targets.
// (If target-switching pref is false, the toolbox will reboot)
const onTargetSwitched = toolbox.once("switched-target");
const onTargetSwitched = toolbox.targetList.once("switched-target");
// Otherwise, if we don't switch target, it is safe to wait for navigate event.
const onNavigate = target.once("navigate");

View File

@ -21,7 +21,7 @@ add_task(async function() {
info("Navigate to a page that runs in the child process");
const onEditorReady = ui.editors[0].getSourceEditor();
const onTargetSwitched = toolbox.once("switched-target");
const onTargetSwitched = toolbox.targetList.once("switched-target");
await navigateToAndWaitForStyleSheets(CONTENT_PROCESS_URI, ui);
// We also have to wait for the toolbox to complete the target switching
// in order to avoid pending requests during test teardown.

View File

@ -46,7 +46,7 @@ add_task(async function() {
// 1270234).
const promises = [hud.ui.once("messages-cleared")];
if (isTargetSwitchingEnabled()) {
promises.push(hud.toolbox.once("switched-target"));
promises.push(hud.targetList.once("switched-target"));
}
gBrowser.goBack();

View File

@ -33,7 +33,7 @@ loader.lazyRequireGetter(
true
);
class TargetList {
class TargetList extends EventEmitter {
/**
* This class helps managing, iterating over and listening for Targets.
*
@ -53,6 +53,8 @@ class TargetList {
* this may be replaced by a new one over time.
*/
constructor(rootFront, targetFront) {
super();
this.rootFront = rootFront;
// Once we have descriptor for all targets we create a toolbox for,
@ -506,6 +508,8 @@ class TargetList {
// Notify about this new target to creation listeners
await this._onTargetAvailable(newTarget, true);
this.emit("switched-target", newTarget);
}
isTargetRegistered(targetFront) {