Bug 1539071 - Wait for toolbox destroy to finish before reloading toolbox tab;r=daisuke

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Julian Descottes 2019-04-08 09:42:24 +00:00
parent 56fffce764
commit b6dc05b08d
6 changed files with 88 additions and 14 deletions

View File

@ -55,6 +55,7 @@ support-files =
!/devtools/client/shared/test/telemetry-test-helpers.js !/devtools/client/shared/test/telemetry-test-helpers.js
[browser_about-devtools-toolbox_load.js] [browser_about-devtools-toolbox_load.js]
[browser_about-devtools-toolbox_reload.js]
[browser_browser_toolbox.js] [browser_browser_toolbox.js]
skip-if = coverage # Bug 1387827 skip-if = coverage # Bug 1387827
[browser_browser_toolbox_debugger.js] [browser_browser_toolbox_debugger.js]

View File

@ -26,17 +26,3 @@ add_task(async function() {
ok(doc.querySelector(".js-error-page"), "Error page is rendered"); ok(doc.querySelector(".js-error-page"), "Error page is rendered");
} }
}); });
async function openAboutToolbox(params) {
info("opening about:devtools-toolbox");
const querystring = new URLSearchParams();
Object.keys(params).forEach(x => querystring.append(x, params[x]));
const tab = await addTab(`about:devtools-toolbox?${querystring}`);
const browser = tab.linkedBrowser;
return {
tab,
document: browser.contentDocument,
};
}

View File

@ -0,0 +1,54 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Test that about:devtools-toolbox is reloaded correctly when reusing the same debugger
* client instance.
*/
add_task(async function() {
const debuggerClient = await createLocalClient();
info("Preload a local DebuggerClient as this-firefox in the remoteClientManager");
const { remoteClientManager } =
require("devtools/client/shared/remote-debugging/remote-client-manager");
remoteClientManager.setClient("this-firefox", "this-firefox", debuggerClient);
registerCleanupFunction(() => {
remoteClientManager.removeAllClients();
});
info("Create a dummy target tab");
const targetTab = await addTab("data:text/html,somehtml");
const { tab } = await openAboutToolbox({
id: targetTab.linkedBrowser.outerWindowID,
remoteId: "this-firefox-this-firefox",
type: "tab",
});
info("Reload about:devtools-toolbox page");
const onToolboxReady = gDevTools.once("toolbox-ready");
tab.linkedBrowser.reload();
await onToolboxReady;
info("Check if about:devtools-toolbox was reloaded correctly");
const refreshedDoc = tab.linkedBrowser.contentDocument;
ok(refreshedDoc.querySelector(".debug-target-info"),
"about:devtools-toolbox header is correctly displayed");
await removeTab(tab);
await removeTab(targetTab);
});
async function createLocalClient() {
const { DebuggerClient } = require("devtools/shared/client/debugger-client");
const { DebuggerServer } = require("devtools/server/main");
DebuggerServer.init();
DebuggerServer.registerAllActors();
DebuggerServer.allowChromeProcess = true;
const debuggerClient = new DebuggerClient(DebuggerServer.connectPipe());
await debuggerClient.connect();
return debuggerClient;
}

View File

@ -389,3 +389,21 @@ function assertSelectedLocationInDebugger(debuggerPanel, line, column) {
is(location.line, line); is(location.line, line);
is(location.column, column); is(location.column, column);
} }
/**
* Open a new tab on about:devtools-toolbox with the provided params object used as
* queryString.
*/
async function openAboutToolbox(params) {
info("Open about:devtools-toolbox");
const querystring = new URLSearchParams();
Object.keys(params).forEach(x => querystring.append(x, params[x]));
const tab = await addTab(`about:devtools-toolbox?${querystring}`);
const browser = tab.linkedBrowser;
return {
tab,
document: browser.contentDocument,
};
}

View File

@ -108,6 +108,14 @@ async function initToolbox(url, host) {
target = await client.mainRoot.getTab({ tab }); target = await client.mainRoot.getTab({ tab });
} else { } else {
target = await targetFromURL(url); target = await targetFromURL(url);
const toolbox = gDevTools.getToolbox(target);
if (toolbox && toolbox.isDestroying()) {
// If a toolbox already exists for the target, wait for current toolbox destroy to
// be finished and retrieve a new valid target. The ongoing toolbox destroy will
// destroy the target, so it can not be reused.
await toolbox.destroy();
target = await targetFromURL(url);
}
} }
const options = { customIframe: host }; const options = { customIframe: host };
await gDevTools.showToolbox(target, tool, Toolbox.HostType.PAGE, options); await gDevTools.showToolbox(target, tool, Toolbox.HostType.PAGE, options);

View File

@ -2905,6 +2905,13 @@ Toolbox.prototype = {
} }
}, },
/**
* Public API to check is the current toolbox is currently being destroyed.
*/
isDestroying: function() {
return this._destroyer;
},
/** /**
* Remove all UI elements, detach from target and clear up * Remove all UI elements, detach from target and clear up
*/ */