Bug 1694140 - [devtools] Stop using TargetFactory forTab in devtools browser mochitests r=nchevobbe

Depends on D105999

This patch is mostly a mechanical rewrite of:
```lang=javascript
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "inspector");
```
to
```lang=javascript
const toolbox = await gDevTools.showToolboxForTab(tab, { toolId: "inspector" });
```

The main changes are:
- if the target was actually used in the test, it is now retrieved from toolbox.target
- the arguments for showToolboxForTab are using an option argument, to avoid the occasional showToolbox("inspector", null, null, null, startTime, null, reason);

I suspect that any signature rewrite mistake would have been caught on try.
There a few less mechanical changes:
- devtools/client/framework/test/browser_toolbox_screenshot_tool.js the toolId "console" was omitted because this id doesn't match any tool (author probably meant "webconsole")
- a few tests were: 1/ first creating a target, 2/ looping on tool definitions to get supported tools 3/ opening the toolbox with each supported tool. To support this I extracted a helper called `getSupportedToolIds` which opens a temporary toolbox to list all supported tool ids
- all the tests under storage/ use a single helper to start the test, which can open toolboxes for both tab targets and other targets. This made it more complicated to refactor. We could also drop this part and just refactor each test when we actually modify forTab/showToolbox to only work with descriptors

All in all the goal of this stack is to pave the way to stop handling targets when using forTab/showToolbox, and behind the scenes stop replying on targets to cache open toolboxes. We don't aim to kill all the call sites, just get them to a smaller number so that the next refactors will be easier.

Differential Revision: https://phabricator.services.mozilla.com/D106000
This commit is contained in:
Julian Descottes 2021-02-25 12:58:14 +00:00
parent 5b183d1d77
commit 982c525960
112 changed files with 414 additions and 451 deletions

View File

@ -148,8 +148,9 @@ async function addTestTab(url) {
* @return a promise that is resolved once the panel is open.
*/
async function initAccessibilityPanel(tab = gBrowser.selectedTab) {
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "accessibility");
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "accessibility",
});
return toolbox.getCurrentPanel();
}
@ -802,10 +803,7 @@ function addA11yPanelTestsTask(tests, uri, msg, options) {
*/
async function closeTabToolboxAccessibility(tab = gBrowser.selectedTab) {
if (TargetFactory.isKnownTab(tab)) {
const target = await TargetFactory.forTab(tab);
if (target) {
await gDevTools.closeToolbox(target);
}
await gDevTools.closeToolboxForTab(tab);
}
await shutdownAccessibility(gBrowser.getBrowserForTab(tab));

View File

@ -95,10 +95,12 @@ function getWorkerContainers(doc) {
async function openNewTabAndApplicationPanel(url) {
const tab = await addTab(url);
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "application");
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "application",
});
const panel = toolbox.getCurrentPanel();
const target = toolbox.target;
return { panel, tab, target, toolbox };
}

View File

@ -10,8 +10,7 @@ add_task(async function() {
const dbg = await initDebugger("doc-strict.html");
const { hud } = await getDebuggerSplitConsole(dbg);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = gDevTools.getToolbox(target);
const toolbox = await gDevTools.getToolboxForTab(gBrowser.selectedTab);
await addBreakpoint(dbg, "doc-strict.html", 15);
setInputValue(hud, "strict()");

View File

@ -11,8 +11,8 @@ const TEST_PAGE_URL = URL_ROOT + "page_dom_nodes.html";
add_task(async function() {
info("Test DOM panel node highlight started");
const { panel } = await addTestTab(TEST_PAGE_URL);
const toolbox = gDevTools.getToolbox(panel.currentTarget);
const { panel, tab } = await addTestTab(TEST_PAGE_URL);
const toolbox = await gDevTools.getToolboxForTab(tab);
const highlighter = toolbox.getHighlighter();
const tests = [

View File

@ -11,8 +11,8 @@ const TEST_PAGE_URL = URL_ROOT + "page_dom_nodes.html";
add_task(async function() {
info("Test DOM panel node highlight started");
const { panel } = await addTestTab(TEST_PAGE_URL);
const toolbox = gDevTools.getToolbox(panel.currentTarget);
const { panel, tab } = await addTestTab(TEST_PAGE_URL);
const toolbox = await gDevTools.getToolboxForTab(tab);
const node = getRowByIndex(panel, 2);
// Loading the inspector panel at first, to make it possible to listen for

View File

@ -64,8 +64,8 @@ async function addTestTab(url) {
* @return a promise that is resolved once the web console is open.
*/
async function initDOMPanel(tab) {
const target = await TargetFactory.forTab(tab || gBrowser.selectedTab);
const toolbox = await gDevTools.showToolbox(target, "dom");
tab = tab || gBrowser.selectedTab;
const toolbox = await gDevTools.showToolboxForTab(tab, { toolId: "dom" });
const panel = toolbox.getCurrentPanel();
return panel;
}

View File

@ -32,40 +32,41 @@ async function runTests(aTab) {
const collectedEvents = [];
const target = await TargetFactory.forTab(aTab);
gDevTools.showToolbox(target, toolDefinition.id).then(function(toolbox) {
const panel = toolbox.getPanel(toolDefinition.id);
ok(panel, "Tool open");
gDevTools
.showToolboxForTab(aTab, { toolId: toolDefinition.id })
.then(function(toolbox) {
const panel = toolbox.getPanel(toolDefinition.id);
ok(panel, "Tool open");
gDevTools.once("toolbox-destroy", (toolbox, iframe) => {
collectedEvents.push("toolbox-destroy");
});
gDevTools.once("toolbox-destroy", (toolbox, iframe) => {
collectedEvents.push("toolbox-destroy");
});
gDevTools.once(toolDefinition.id + "-destroy", (toolbox, iframe) => {
collectedEvents.push("gDevTools-" + toolDefinition.id + "-destroy");
});
gDevTools.once(toolDefinition.id + "-destroy", (toolbox, iframe) => {
collectedEvents.push("gDevTools-" + toolDefinition.id + "-destroy");
});
toolbox.once("destroy", () => {
collectedEvents.push("destroy");
});
toolbox.once("destroy", () => {
collectedEvents.push("destroy");
});
toolbox.once(toolDefinition.id + "-destroy", () => {
collectedEvents.push("toolbox-" + toolDefinition.id + "-destroy");
});
toolbox.once(toolDefinition.id + "-destroy", () => {
collectedEvents.push("toolbox-" + toolDefinition.id + "-destroy");
});
toolbox.destroy().then(function() {
is(
collectedEvents.join(":"),
"toolbox-destroy:destroy:gDevTools-testTool-destroy:toolbox-testTool-destroy",
"Found the right amount of collected events."
);
toolbox.destroy().then(function() {
is(
collectedEvents.join(":"),
"toolbox-destroy:destroy:gDevTools-testTool-destroy:toolbox-testTool-destroy",
"Found the right amount of collected events."
);
gDevTools.unregisterTool(toolDefinition.id);
gBrowser.removeCurrentTab();
gDevTools.unregisterTool(toolDefinition.id);
gBrowser.removeCurrentTab();
executeSoon(function() {
finish();
executeSoon(function() {
finish();
});
});
});
});
}

View File

@ -8,8 +8,9 @@
add_task(async function() {
let tab = await addTab(URL_ROOT + "doc_viewsource.html");
let target = await TargetFactory.forTab(tab);
let toolbox = await gDevTools.showToolbox(target, "styleeditor");
let toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "styleeditor",
});
let panel = toolbox.getPanel("styleeditor");
is(panel.UI.editors.length, 1, "correct number of editors opened");
@ -24,6 +25,6 @@ add_task(async function() {
);
await toolbox.destroy();
tab = target = toolbox = panel = null;
tab = toolbox = panel = null;
gBrowser.removeCurrentTab();
});

View File

@ -21,8 +21,7 @@ function getZoomValue() {
add_task(async function() {
info("Create a test tab and open the toolbox");
const tab = await addTab(URL);
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "webconsole");
const toolbox = await gDevTools.showToolboxForTab(tab, "webconsole");
const { RIGHT, BOTTOM } = Toolbox.HostType;
for (const type of [RIGHT, BOTTOM, RIGHT]) {

View File

@ -18,8 +18,7 @@ const L10N = new LocalizationHelper(
add_task(async function() {
info("Create a test tab and open the toolbox");
const tab = await addTab(URL);
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "webconsole");
const toolbox = await gDevTools.showToolboxForTab(tab, "webconsole");
const shortcut = L10N.getStr("toolbox.toggleHost.key");

View File

@ -12,8 +12,9 @@ const MenuItem = require("devtools/client/framework/menu-item");
add_task(async function() {
info("Create a test tab and open the toolbox");
const tab = await addTab(URL);
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "webconsole");
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "webconsole",
});
// This test will involve localized strings, make sure the necessary FTL file is
// available in the toolbox top window.

View File

@ -3,24 +3,25 @@
// Tests devtools API
var toolbox, target;
var toolbox;
function test() {
addTab("about:blank").then(async function(aTab) {
target = await TargetFactory.forTab(gBrowser.selectedTab);
loadWebConsole(aTab).then(function() {
addTab("about:blank").then(async function() {
loadWebConsole().then(function() {
console.log("loaded");
});
});
}
function loadWebConsole(aTab) {
function loadWebConsole() {
ok(gDevTools, "gDevTools exists");
return gDevTools.showToolbox(target, "webconsole").then(function(aToolbox) {
toolbox = aToolbox;
checkToolLoading();
});
const tab = gBrowser.selectedTab;
return gDevTools
.showToolboxForTab(tab, { toolId: "webconsole" })
.then(function(aToolbox) {
toolbox = aToolbox;
checkToolLoading();
});
}
function checkToolLoading() {
@ -53,12 +54,17 @@ function selectAndCheckById(id) {
function testToggle() {
toolbox.once("destroyed", async () => {
// Cannot reuse a target after it's destroyed.
target = await TargetFactory.forTab(gBrowser.selectedTab);
gDevTools.showToolbox(target, "styleeditor").then(function(aToolbox) {
toolbox = aToolbox;
is(toolbox.currentToolId, "styleeditor", "The style editor is selected");
finishUp();
});
gDevTools
.showToolboxForTab(gBrowser.selectedTab, { toolId: "styleeditor" })
.then(function(aToolbox) {
toolbox = aToolbox;
is(
toolbox.currentToolId,
"styleeditor",
"The style editor is selected"
);
finishUp();
});
});
toolbox.destroy();
@ -67,7 +73,6 @@ function testToggle() {
function finishUp() {
toolbox.destroy().then(function() {
toolbox = null;
target = null;
gBrowser.removeCurrentTab();
finish();
});

View File

@ -15,8 +15,8 @@ const EXAMPLE_NET_URI =
add_task(async function() {
const tab = await addTab(EXAMPLE_COM_URI);
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target);
const toolbox = await gDevTools.showToolboxForTab(tab);
const target = toolbox.target;
const client = target.client;
info("Retrieve the initial list of tab descriptors");

View File

@ -7,14 +7,11 @@ add_task(async function() {
const { Toolbox } = require("devtools/client/framework/toolbox");
const tab = await addTab(TEST_URL);
const target = await TargetFactory.forTab(tab);
const options = { doc: document };
const toolbox = await gDevTools.showToolbox(
target,
null,
Toolbox.HostType.BROWSERTOOLBOX,
options
);
const toolbox = await gDevTools.showToolboxForTab(tab, {
hostType: Toolbox.HostType.BROWSERTOOLBOX,
hostOptions: options,
});
is(toolbox.topWindow, window, "Toolbox is included in browser.xhtml");
const iframe = document.querySelector(

View File

@ -22,8 +22,9 @@ add_task(async function() {
});
async function checkConflictWithContentPageMenu(tab) {
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "inspector");
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "inspector",
});
info("Check that the content page context menu works as expected");
const contextMenu = document.getElementById("contentAreaContextMenu");

View File

@ -8,8 +8,7 @@ var toolbox;
function test() {
addTab(TEST_URL).then(async tab => {
const target = await TargetFactory.forTab(tab);
gDevTools.showToolbox(target).then(testRegister);
gDevTools.showToolboxForTab(tab).then(testRegister);
});
}

View File

@ -10,8 +10,7 @@ const URL = "data:text/html;charset=utf8,test for getPanelWhenReady";
add_task(async function() {
const tab = await addTab(URL);
const target = await TargetFactory.forTab(tab);
toolbox = await gDevTools.showToolbox(target);
toolbox = await gDevTools.showToolboxForTab(tab);
const debuggerPanelPromise = toolbox.getPanelWhenReady("jsdebugger");
await toolbox.selectTool("jsdebugger");

View File

@ -15,12 +15,10 @@ function test() {
const TOOL_ID_2 = "webconsole";
await addTab(URL);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
toolbox = await gDevTools.showToolbox(
target,
TOOL_ID_1,
Toolbox.HostType.BOTTOM
);
toolbox = await gDevTools.showToolboxForTab(gBrowser.selectedTab, {
toolId: TOOL_ID_1,
hostType: Toolbox.HostType.BOTTOM,
});
// select tool 2
await toolbox.selectTool(TOOL_ID_2);

View File

@ -5,7 +5,7 @@
var { Toolbox } = require("devtools/client/framework/toolbox");
var { LEFT, RIGHT, BOTTOM, WINDOW } = Toolbox.HostType;
var toolbox, target;
var toolbox;
const URL =
"data:text/html;charset=utf8,test for opening toolbox in different hosts";
@ -13,13 +13,12 @@ const URL =
add_task(async function runTest() {
info("Create a test tab and open the toolbox");
const tab = await addTab(URL);
target = await TargetFactory.forTab(tab);
toolbox = await gDevTools.showToolbox(target, "webconsole");
toolbox = await gDevTools.showToolboxForTab(tab, { toolId: "webconsole" });
await runHostTests(gBrowser);
await toolbox.destroy();
toolbox = target = null;
toolbox = null;
gBrowser.removeCurrentTab();
});
@ -47,13 +46,12 @@ async function runHostTestsFromSeparateWindow(options) {
browser.selectedTab = BrowserTestUtils.addTab(browser, URL);
const tab = browser.selectedTab;
target = await TargetFactory.forTab(tab);
toolbox = await gDevTools.showToolbox(target, "webconsole");
toolbox = await gDevTools.showToolboxForTab(tab, { toolId: "webconsole" });
await runHostTests(browser);
await toolbox.destroy();
toolbox = target = null;
toolbox = null;
await BrowserTestUtils.closeWindow(win);
}
@ -131,8 +129,7 @@ async function testToolSelect() {
async function testDestroy(browser) {
await toolbox.destroy();
target = await TargetFactory.forTab(browser.selectedTab);
toolbox = await gDevTools.showToolbox(target);
toolbox = await gDevTools.showToolboxForTab(browser.selectedTab);
}
function testRememberHost() {

View File

@ -17,8 +17,7 @@ add_task(async function() {
const tab = await addTab(URL);
const panel = gBrowser.getPanel();
const { clientHeight: panelHeight, clientWidth: panelWidth } = panel;
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target);
const toolbox = await gDevTools.showToolboxForTab(tab);
is(
panel.clientHeight,
@ -69,8 +68,7 @@ add_task(async function() {
const tab = await addTab(URL);
const panel = gBrowser.getPanel();
const { clientHeight: panelHeight, clientWidth: panelWidth } = panel;
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target);
const toolbox = await gDevTools.showToolboxForTab(tab);
is(
panel.clientHeight,

View File

@ -15,8 +15,9 @@ add_task(async function() {
info("Create a test tab and open the toolbox");
const tab = await addTab(URL);
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "webconsole");
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "webconsole",
});
await changeToolboxHost(toolbox);
await checkResults();

View File

@ -22,8 +22,7 @@ add_task(async function() {
"and unregistering tools";
registerNewTool();
const tab = await addTab(URL);
const target = await TargetFactory.forTab(tab);
toolbox = await gDevTools.showToolbox(target);
toolbox = await gDevTools.showToolboxForTab(tab);
doc = toolbox.doc;
await registerNewPerToolboxTool();

View File

@ -22,8 +22,7 @@ registerCleanupFunction(() => {
add_task(async function test() {
const tab = await addTab(TEST_URL);
const target = await TargetFactory.forTab(tab);
let toolbox = await gDevTools.showToolbox(target);
let toolbox = await gDevTools.showToolboxForTab(tab);
const optionsPanelWin = await selectOptionsPanel(toolbox);
await testToggleToolboxButtons(toolbox, optionsPanelWin);
toolbox = await testPrefsAreRespectedWhenReopeningToolbox();
@ -51,7 +50,7 @@ async function testToggleToolboxButtons(toolbox, optionsPanelWin) {
// Filter out all the buttons which are not supported on the current target.
// (DevTools Fission Preferences etc...)
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const target = toolbox.target;
const toolbarButtons = toolbox.toolbarButtons.filter(tool =>
tool.isTargetSupported(target)
);
@ -142,12 +141,10 @@ async function testToggleToolboxButtons(toolbox, optionsPanelWin) {
}
async function testPrefsAreRespectedWhenReopeningToolbox() {
const target = await TargetFactory.forTab(gBrowser.selectedTab);
info("Closing toolbox to test after reopening");
await gDevTools.closeToolbox(target);
await gDevTools.closeToolboxForTab(gBrowser.selectedTab);
const tabTarget = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = await gDevTools.showToolbox(tabTarget);
const toolbox = await gDevTools.showToolboxForTab(gBrowser.selectedTab);
const optionsPanelWin = await selectOptionsPanel(toolbox);
info("Toolbox has been reopened. Checking UI state.");

View File

@ -29,16 +29,19 @@ add_task(async function() {
await setDisableCacheCheckboxChecked(tabs[0], true);
// Open toolbox in tab 2 and ensure the cache is then disabled.
tabs[2].toolbox = await gDevTools.showToolbox(tabs[2].target, "options");
tabs[2].toolbox = await gDevTools.showToolboxForTab(tabs[2].tab, {
toolId: "options",
});
await checkCacheEnabled(tabs[2], false);
// Close toolbox in tab 2 and ensure the cache is enabled again
await tabs[2].toolbox.destroy();
tabs[2].target = await TargetFactory.forTab(tabs[2].tab);
await checkCacheEnabled(tabs[2], true);
// Open toolbox in tab 2 and ensure the cache is then disabled.
tabs[2].toolbox = await gDevTools.showToolbox(tabs[2].target, "options");
tabs[2].toolbox = await gDevTools.showToolboxForTab(tabs[2].tab, {
toolId: "options",
});
await checkCacheEnabled(tabs[2], false);
// Check the checkbox in tab 2 and ensure cache is enabled for all tabs.

View File

@ -7,11 +7,10 @@ const TEST_URI = URL_ROOT + "browser_toolbox_options_disable_js.html";
add_task(async function() {
const tab = await addTab(TEST_URI);
const target = await TargetFactory.forTab(tab);
// Start on the options panel from where we will toggle the disabling javascript
// option.
const toolbox = await gDevTools.showToolbox(target, "options");
const toolbox = await gDevTools.showToolboxForTab(tab, { toolId: "options" });
await testJSEnabled();
await testJSEnabledIframe();

View File

@ -17,10 +17,9 @@ add_task(async function() {
await pushPref(FRAME_BUTTON_PREF, false);
const tab = await addTab(TEST_URL);
const target = await TargetFactory.forTab(tab);
info("Open the toolbox on the Options panel");
const toolbox = await gDevTools.showToolbox(target, "options");
const toolbox = await gDevTools.showToolboxForTab(tab, { toolId: "options" });
const doc = toolbox.doc;
const optionsPanel = toolbox.getCurrentPanel();

View File

@ -19,8 +19,7 @@ add_task(async function() {
async function openToolboxOptionsInNewTab() {
const tab = await addTab(URL);
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target);
const toolbox = await gDevTools.showToolboxForTab(tab);
const doc = toolbox.doc;
const panel = await toolbox.selectTool("options");
const { id } = panel.panelDoc.querySelector(

View File

@ -10,9 +10,8 @@ var toolbox, tab1, tab2;
function test() {
addTab(TEST_URL).then(async tab => {
tab2 = BrowserTestUtils.addTab(gBrowser);
const target = await TargetFactory.forTab(tab);
gDevTools
.showToolbox(target)
.showToolboxForTab(tab)
.then(testBottomHost, console.error)
.catch(console.error);
});

View File

@ -5,13 +5,16 @@ const TEST_URL = "data:text/html,test for toolbox being ready";
add_task(async function() {
const tab = await addTab(TEST_URL);
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "webconsole");
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "webconsole",
});
ok(toolbox.isReady, "toolbox isReady is set");
ok(toolbox.threadFront, "toolbox has a thread front");
const toolbox2 = await gDevTools.showToolbox(toolbox.target, toolbox.toolId);
const toolbox2 = await gDevTools.showToolboxForTab(tab, {
toolId: toolbox.toolId,
});
is(toolbox2, toolbox, "same toolbox");
await toolbox.destroy();

View File

@ -27,10 +27,9 @@ add_task(async function() {
await pushPref("devtools.command-button-screenshot.enabled", true);
await addTab(TEST_URL);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
info("Open the toolbox");
const toolbox = await gDevTools.showToolbox(target, "console");
const toolbox = await gDevTools.showToolboxForTab(gBrowser.selectedTab);
const onScreenshotDownloaded = waitUntilScreenshot();
toolbox.doc.querySelector("#command-button-screenshot").click();

View File

@ -26,21 +26,21 @@ const testToolDefinition = {
add_task(async function() {
gDevTools.registerTool(testToolDefinition);
let tab = await addTab("about:blank");
let target = await TargetFactory.forTab(tab);
let toolbox = await gDevTools.showToolbox(target, testToolDefinition.id);
let toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: testToolDefinition.id,
});
is(toolbox.currentToolId, "testTool", "test-tool was selected");
await toolbox.destroy();
// Make the previously selected tool unavailable.
testToolDefinition.isTargetSupported = () => false;
target = await TargetFactory.forTab(tab);
toolbox = await gDevTools.showToolbox(target);
toolbox = await gDevTools.showToolboxForTab(tab);
is(toolbox.currentToolId, "webconsole", "web console was selected");
await toolbox.destroy();
gDevTools.unregisterTool(testToolDefinition.id);
tab = toolbox = target = null;
tab = toolbox = null;
gBrowser.removeCurrentTab();
});

View File

@ -59,7 +59,8 @@ add_task(async function automaticallyBindTexbox() {
},
});
const toolbox = await openNewTabAndToolbox(URL, "inspector");
const tab = await addTab(URL);
const toolbox = await openToolboxForTab(tab, "inspector");
const onLazyToolReady = toolbox.once(lazyToolId + "-ready");
toolbox.selectTool(lazyToolId);
@ -67,7 +68,7 @@ add_task(async function automaticallyBindTexbox() {
await waitUntil(() => toolbox.currentToolId == lazyToolId);
ok(!isPanelReady(toolbox, lazyToolId), "lazyTool should not be ready yet");
await gDevTools.showToolbox(toolbox.target, lazyToolId);
await gDevTools.showToolboxForTab(tab, { toolId: lazyToolId });
ok(
isPanelReady(toolbox, lazyToolId),
"lazyTool should not ready after showToolbox"

View File

@ -14,8 +14,7 @@ const URL = "data:text/html;charset=utf8,test split console key delegation";
add_task(async function() {
const tab = await addTab(URL);
const target = await TargetFactory.forTab(tab);
gToolbox = await gDevTools.showToolbox(target, "jsdebugger");
gToolbox = await gDevTools.showToolboxForTab(tab, { toolId: "jsdebugger" });
panelWin = gToolbox.getPanel("jsdebugger").panelWin;
await gToolbox.openSplitConsole();

View File

@ -14,18 +14,14 @@ const L10N = new LocalizationHelper(
add_task(async function() {
const tab = await addTab("about:blank");
const target = await TargetFactory.forTab(tab);
const toolIDs = gDevTools
.getToolDefinitionArray()
.filter(def => def.isTargetSupported(target) && def.id !== "options")
.map(def => def.id);
const toolbox = await gDevTools.showToolbox(
target,
toolIDs[0],
Toolbox.HostType.BOTTOM
const toolIDs = (await getSupportedToolIds(tab)).filter(
id => id != "options"
);
const toolbox = await gDevTools.showToolboxForTab(tab, {
hostType: Toolbox.HostType.BOTTOM,
toolId: toolIDs[0],
});
const nextShortcut = L10N.getStr("toolbox.nextTool.key");
const prevShortcut = L10N.getStr("toolbox.previousTool.key");

View File

@ -70,8 +70,9 @@ add_task(async function() {
ok(!snapshot.parent, "No events have been logged for the main process");
const tab = await addTab(URL);
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "inspector");
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "inspector",
});
await toolbox.openSplitConsole();
await toolbox.closeSplitConsole();

View File

@ -48,8 +48,7 @@ add_task(async function() {
async function openAndCloseToolbox(toolId, host) {
const tab = await addTab(URL);
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, toolId);
const toolbox = await gDevTools.showToolboxForTab(tab, { toolId });
await toolbox.switchHost(host);
await toolbox.destroy();

View File

@ -101,7 +101,6 @@ add_task(async function() {
ok(!snapshot.parent, "No events have been logged for the main process");
const tab = await addTab(URL);
const target = await TargetFactory.forTab(tab);
// Set up some cached messages for the web console.
await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
@ -113,14 +112,14 @@ add_task(async function() {
});
// Open the toolbox
await gDevTools.showToolbox(target, "inspector");
await gDevTools.showToolboxForTab(tab, { toolId: "inspector" });
// Switch between a few tools
await gDevTools.showToolbox(target, "jsdebugger");
await gDevTools.showToolbox(target, "styleeditor");
await gDevTools.showToolbox(target, "netmonitor");
await gDevTools.showToolbox(target, "storage");
await gDevTools.showToolbox(target, "netmonitor");
await gDevTools.showToolboxForTab(tab, { toolId: "jsdebugger" });
await gDevTools.showToolboxForTab(tab, { toolId: "styleeditor" });
await gDevTools.showToolboxForTab(tab, { toolId: "netmonitor" });
await gDevTools.showToolboxForTab(tab, { toolId: "storage" });
await gDevTools.showToolboxForTab(tab, { toolId: "netmonitor" });
await checkResults();
});

View File

@ -87,17 +87,16 @@ add_task(async function() {
ok(!snapshot.parent, "No events have been logged for the main process");
const tab = await addTab(URL);
const target = await TargetFactory.forTab(tab);
// Open the toolbox
await gDevTools.showToolbox(target, "inspector");
await gDevTools.showToolboxForTab(tab, { toolId: "inspector" });
// Switch between a few tools
await gDevTools.showToolbox(target, "jsdebugger");
await gDevTools.showToolbox(target, "styleeditor");
await gDevTools.showToolbox(target, "netmonitor");
await gDevTools.showToolbox(target, "storage");
await gDevTools.showToolbox(target, "netmonitor");
await gDevTools.showToolboxForTab(tab, { toolId: "jsdebugger" });
await gDevTools.showToolboxForTab(tab, { toolId: "styleeditor" });
await gDevTools.showToolboxForTab(tab, { toolId: "netmonitor" });
await gDevTools.showToolboxForTab(tab, { toolId: "storage" });
await gDevTools.showToolboxForTab(tab, { toolId: "netmonitor" });
await checkResults();
});

View File

@ -13,8 +13,7 @@ var toolbox;
add_task(async function themeRegistration() {
const tab = await addTab("data:text/html,test");
const target = await TargetFactory.forTab(tab);
toolbox = await gDevTools.showToolbox(target, "options");
toolbox = await gDevTools.showToolboxForTab(tab, { toolId: "options" });
const themeId = await new Promise(resolve => {
gDevTools.once("theme-registered", registeredThemeId => {

View File

@ -32,8 +32,7 @@ add_task(async function() {
async function testToggle(key, modifiers) {
const tab = await addTab(URL + " ; key : '" + key + "'");
const target = await TargetFactory.forTab(tab);
await gDevTools.showToolbox(target);
await gDevTools.showToolboxForTab(tab);
await testToggleDockedToolbox(tab, key, modifiers);
await testToggleDetachedToolbox(tab, key, modifiers);
@ -42,7 +41,7 @@ async function testToggle(key, modifiers) {
}
async function testToggleDockedToolbox(tab, key, modifiers) {
const toolbox = await getToolboxForTab(tab);
const toolbox = await gDevTools.getToolboxForTab(tab);
isnot(
toolbox.hostType,
@ -64,7 +63,7 @@ async function testToggleDockedToolbox(tab, key, modifiers) {
}
async function testToggleDetachedToolbox(tab, key, modifiers) {
const toolbox = await getToolboxForTab(tab);
const toolbox = await gDevTools.getToolboxForTab(tab);
info("change the toolbox hostType to WINDOW");
@ -106,11 +105,6 @@ async function testToggleDetachedToolbox(tab, key, modifiers) {
ok(true, "Toolbox destroyed");
}
async function getToolboxForTab(tab) {
const target = await TargetFactory.forTab(tab);
return gDevTools.getToolbox(target);
}
function cleanup() {
Services.prefs.setCharPref("devtools.toolbox.host", Toolbox.HostType.BOTTOM);
gBrowser.removeCurrentTab();

View File

@ -5,36 +5,27 @@
requestLongerTimeout(5);
function performChecks(target) {
return (async function() {
const toolIds = gDevTools
.getToolDefinitionArray()
.filter(def => def.isTargetSupported(target))
.map(def => def.id);
async function performChecks(tab) {
let toolbox;
const toolIds = await getSupportedToolIds(tab);
for (const toolId of toolIds) {
info("About to open " + toolId);
toolbox = await gDevTools.showToolboxForTab(tab, { toolId });
ok(toolbox, "toolbox exists for " + toolId);
is(toolbox.currentToolId, toolId, "currentToolId should be " + toolId);
let toolbox;
for (let index = 0; index < toolIds.length; index++) {
const toolId = toolIds[index];
const panel = toolbox.getCurrentPanel();
ok(panel.isReady, toolId + " panel should be ready");
}
info("About to open " + index + "/" + toolId);
toolbox = await gDevTools.showToolbox(target, toolId);
ok(toolbox, "toolbox exists for " + toolId);
is(toolbox.currentToolId, toolId, "currentToolId should be " + toolId);
const panel = toolbox.getCurrentPanel();
ok(panel.isReady, toolId + " panel should be ready");
}
await toolbox.destroy();
})();
await toolbox.destroy();
}
function test() {
(async function() {
toggleAllTools(true);
const tab = await addTab("about:blank");
const target = await TargetFactory.forTab(tab);
await performChecks(target);
await performChecks(tab);
gBrowser.removeCurrentTab();
toggleAllTools(false);
finish();

View File

@ -34,19 +34,16 @@ requestLongerTimeout(2);
* which leads to the tools failing if they don't destroy their fronts.
*/
function runTools(target) {
function runTools(tab) {
return (async function() {
const toolIds = gDevTools
.getToolDefinitionArray()
.filter(def => def.isTargetSupported(target))
.map(def => def.id);
let toolbox;
for (let index = 0; index < toolIds.length; index++) {
const toolId = toolIds[index];
info("About to open " + index + "/" + toolId);
toolbox = await gDevTools.showToolbox(target, toolId, "window");
const toolIds = await getSupportedToolIds(tab);
for (const toolId of toolIds) {
info("About to open " + toolId);
toolbox = await gDevTools.showToolboxForTab(tab, {
toolId,
hostType: "window",
});
ok(toolbox, "toolbox exists for " + toolId);
is(toolbox.currentToolId, toolId, "currentToolId should be " + toolId);
@ -54,7 +51,11 @@ function runTools(target) {
ok(panel.isReady, toolId + " panel should be ready");
}
const client = toolbox.target.client;
await toolbox.destroy();
// We need to check the client after the toolbox destruction.
return client;
})();
}
@ -63,9 +64,7 @@ function test() {
toggleAllTools(true);
const tab = await addTab("about:blank");
const target = await TargetFactory.forTab(tab);
const { client } = target;
await runTools(target);
const client = await runTools(tab);
const rootFronts = [...client.mainRoot.fronts.values()];

View File

@ -13,14 +13,11 @@ const TEST_URL = `data:text/html,<!DOCTYPE html>
const TOOL_ID = "test-toolbox-tool";
var toolbox;
var target;
function test() {
addTab(TEST_URL).then(async tab => {
target = await TargetFactory.forTab(tab);
gDevTools
.showToolbox(target)
.showToolboxForTab(tab)
.then(toolboxRegister)
.then(testToolRegistered);
});
@ -99,7 +96,7 @@ function testToolRegistered() {
// Test that the tool is built once selected and then test its unregistering.
info("select per-toolbox tool in the opened toolbox.");
gDevTools
.showToolbox(target, TOOL_ID)
.showToolboxForTab(gBrowser.selectedTab, { toolId: TOOL_ID })
.then(waitForToolInstanceBuild)
.then(testUnregister);
}

View File

@ -32,22 +32,16 @@ var reloadsSent = 0;
add_task(async function() {
await addTab(TEST_URL);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
info("Getting the entire list of tools supported in this tab");
const toolIDs = gDevTools
.getToolDefinitionArray()
.filter(def => def.isTargetSupported(target))
.map(def => def.id);
const tab = gBrowser.selectedTab;
const toolIDs = await getSupportedToolIds(tab);
info(
"Display the toolbox, docked at the bottom, with the first tool selected"
);
const toolbox = await gDevTools.showToolbox(
target,
toolIDs[0],
Toolbox.HostType.BOTTOM
);
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: toolIDs[0],
hostType: Toolbox.HostType.BOTTOM,
});
info(
"Listen to page reloads to check that they are indeed sent by the toolbox"

View File

@ -13,10 +13,12 @@ const L10N = new LocalizationHelper(
// header value: no-cache.
add_task(async function() {
await addTab(TEST_URL);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const tab = gBrowser.selectedTab;
info("Open the toolbox with the inspector selected");
const toolbox = await gDevTools.showToolbox(target, "inspector");
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "inspector",
});
await testReload("toolbox.reload.key", toolbox, "max-age=0");
await testReload("toolbox.reload2.key", toolbox, "max-age=0");

View File

@ -35,10 +35,13 @@ async function test() {
}
}
}
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const tab = gBrowser.selectedTab;
idIndex = 0;
gDevTools
.showToolbox(target, toolIDs[0], Toolbox.HostType.WINDOW)
.showToolboxForTab(tab, {
toolId: toolIDs[0],
hostType: Toolbox.HostType.WINDOW,
})
.then(testShortcuts);
});
}

View File

@ -21,9 +21,9 @@ function test() {
let panel;
addTab(URL_1).then(async function() {
let target = await TargetFactory.forTab(gBrowser.selectedTab);
const tab = gBrowser.selectedTab;
gDevTools
.showToolbox(target, null, Toolbox.HostType.BOTTOM)
.showToolboxForTab(tab, { hostType: Toolbox.HostType.BOTTOM })
.then(function(aToolbox) {
toolbox = aToolbox;
})
@ -76,13 +76,10 @@ function test() {
toolbox
.destroy()
.then(async function() {
// After destroying the toolbox, a fresh target is required.
target = await TargetFactory.forTab(gBrowser.selectedTab);
return gDevTools.showToolbox(
target,
null,
Toolbox.HostType.WINDOW
);
// After destroying the toolbox, open a new one.
return gDevTools.showToolboxForTab(tab, {
hostType: Toolbox.HostType.WINDOW,
});
})
.then(function(aToolbox) {
toolbox = aToolbox;

View File

@ -21,12 +21,10 @@ add_task(async function() {
Services.prefs.setBoolPref("devtools.command-button-frames.enabled", true);
await addTab(URL);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
let toolbox = await gDevTools.showToolbox(
target,
null,
Toolbox.HostType.BOTTOM
);
const tab = gBrowser.selectedTab;
let toolbox = await gDevTools.showToolboxForTab(tab, {
hostType: Toolbox.HostType.BOTTOM,
});
await toolbox.switchHost(Toolbox.HostType.WINDOW);
// Wait for title change event *after* switch host, in order to listen

View File

@ -17,12 +17,10 @@ add_task(async function() {
// This test assume that zoom value will be default value. i.e. x1.0.
Services.prefs.setCharPref("devtools.toolbox.zoomValue", "1.0");
await addTab("about:blank");
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = await gDevTools.showToolbox(
target,
"styleeditor",
Toolbox.HostType.BOTTOM
);
const toolbox = await gDevTools.showToolboxForTab(gBrowser.selectedTab, {
toolId: "styleeditor",
hostType: Toolbox.HostType.BOTTOM,
});
info("testing zoom keys");

View File

@ -20,12 +20,11 @@ add_task(async function() {
info("Load iframe page for checking the frame menu with x1.4 zoom.");
await addTab(TEST_URL);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = await gDevTools.showToolbox(
target,
"inspector",
Toolbox.HostType.WINDOW
);
const tab = gBrowser.selectedTab;
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "inspector",
hostType: Toolbox.HostType.WINDOW,
});
const inspector = toolbox.getCurrentPanel();
const hostWindow = toolbox.win.parent;
const originWidth = hostWindow.outerWidth;

View File

@ -36,10 +36,11 @@ var tabs = [
async function initTab(tabX, startToolbox) {
tabX.tab = await addTab(TEST_URI);
tabX.target = await TargetFactory.forTab(tabX.tab);
if (startToolbox) {
tabX.toolbox = await gDevTools.showToolbox(tabX.target, "options");
tabX.toolbox = await gDevTools.showToolboxForTab(tabX.tab, {
toolId: "options",
});
}
}
@ -119,7 +120,7 @@ function reloadTab(tabX) {
}
async function destroyTab(tabX) {
const toolbox = gDevTools.getToolbox(tabX.target);
const toolbox = await gDevTools.getToolboxForTab(tabX.tab);
let onceDestroyed = promise.resolve();
if (toolbox) {

View File

@ -47,8 +47,7 @@ const openAnimationInspector = async function() {
* @return {Promise} that resolves when the toolbox has closed.
*/
const closeAnimationInspector = async function() {
const target = await TargetFactory.forTab(gBrowser.selectedTab);
return gDevTools.closeToolbox(target);
return gDevTools.closeToolboxForTab(gBrowser.selectedTab);
};
/**

View File

@ -8,9 +8,7 @@ const TEST_URI = URL_ROOT + "doc_markup_view-original-source.html";
// Test that event handler links go to the right debugger source when the
// event handler is source mapped.
add_task(async function() {
const { inspector, toolbox } = await openInspectorForURL(TEST_URI);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const { inspector, tab, toolbox } = await openInspectorForURL(TEST_URI);
const nodeFront = await getNodeFront("#foo", inspector);
const container = getContainerForNodeFront(nodeFront, inspector);
@ -35,7 +33,7 @@ add_task(async function() {
);
EventUtils.synthesizeMouse(debuggerIcon, 2, 2, {}, debuggerIcon.ownerGlobal);
await gDevTools.showToolbox(target, "jsdebugger");
await gDevTools.showToolboxForTab(tab, { toolId: "jsdebugger" });
const dbg = toolbox.getPanel("jsdebugger");
let source;

View File

@ -24,9 +24,7 @@ const TEST_URI = "data:text/html;charset=utf-8," + DOCUMENT_SRC;
add_task(async function() {
// Test that event handler links go to the right debugger source when it
// came from an eval().
const { inspector, toolbox } = await openInspectorForURL(TEST_URI);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const { inspector, tab, toolbox } = await openInspectorForURL(TEST_URI);
const nodeFront = await getNodeFront("#foo", inspector);
const container = getContainerForNodeFront(nodeFront, inspector);
@ -50,7 +48,7 @@ add_task(async function() {
);
EventUtils.synthesizeMouse(debuggerIcon, 2, 2, {}, debuggerIcon.ownerGlobal);
await gDevTools.showToolbox(target, "jsdebugger");
await gDevTools.showToolboxForTab(tab, { toolId: "jsdebugger" });
const dbg = toolbox.getPanel("jsdebugger");
let source;

View File

@ -73,7 +73,6 @@ add_task(async function() {
);
}
const target = await TargetFactory.forTab(tab);
await gDevTools.closeToolbox(target);
await gDevTools.closeToolboxForTab(tab);
gBrowser.removeCurrentTab();
});

View File

@ -32,8 +32,7 @@ add_task(async function() {
await selectNode("#testid", inspector);
await basicTest(view, name, result);
const target = await TargetFactory.forTab(tab);
await gDevTools.closeToolbox(target);
await gDevTools.closeToolboxForTab(tab);
gBrowser.removeCurrentTab();
}
});

View File

@ -15,14 +15,15 @@ const TEST_URI = `
`;
add_task(async function() {
await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
const tab = await addTab(
"data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI)
);
info("Check that the flexbox highlighter can be displayed.");
await checkFlexboxHighlighter();
info("Close the toolbox before reloading the tab.");
const target = await TargetFactory.forTab(gBrowser.selectedTab);
await gDevTools.closeToolbox(target);
await gDevTools.closeToolboxForTab(tab);
await refreshTab();

View File

@ -26,8 +26,7 @@ add_task(async function() {
await checkGridHighlighter();
info("Close the toolbox before reloading the tab");
const target = await TargetFactory.forTab(gBrowser.selectedTab);
await gDevTools.closeToolbox(target);
await gDevTools.closeToolboxForTab(gBrowser.selectedTab);
await refreshTab();

View File

@ -15,8 +15,9 @@ add_task(async function() {
await addTab("data:text/html;charset=utf-8,test inspector destroy");
info("Open the toolbox on the debugger panel");
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = await gDevTools.showToolbox(target, "jsdebugger");
const toolbox = await gDevTools.showToolboxForTab(gBrowser.selectedTab, {
toolId: "jsdebugger",
});
info("Switch to the inspector panel and immediately end the test");
const onInspectorSelected = toolbox.once("inspector-selected");

View File

@ -60,15 +60,16 @@ const DOCUMENT_SRC =
const TEST_URI = "data:text/html;charset=utf-8," + DOCUMENT_SRC;
add_task(async function() {
const { inspector, toolbox, testActor } = await openInspectorForURL(TEST_URI);
const { inspector, toolbox, testActor, tab } = await openInspectorForURL(
TEST_URI
);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
await gDevTools.showToolbox(target, "jsdebugger");
await gDevTools.showToolboxForTab(tab, { toolId: "jsdebugger" });
const dbg = await createDebuggerContext(toolbox);
await waitForPaused(dbg);
await gDevTools.showToolbox(target, "inspector");
await gDevTools.showToolboxForTab(tab, { toolId: "inspector" });
// Needed to get this test to pass consistently :(
await waitForTime(1000);

View File

@ -33,10 +33,10 @@ add_task(async function() {
});
async function testToolboxInitialization(testActor, tab) {
const target = await TargetFactory.forTab(tab);
info("Opening inspector with gDevTools.");
const toolbox = await gDevTools.showToolbox(target, "inspector");
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "inspector",
});
const inspector = toolbox.getCurrentPanel();
ok(true, "Inspector started, and notification received.");
@ -58,7 +58,8 @@ async function testToolboxInitialization(testActor, tab) {
await toolbox.destroy();
ok(true, "'destroyed' notification received.");
ok(!gDevTools.getToolbox(target), "Toolbox destroyed.");
const toolboxForTab = await gDevTools.getToolboxForTab(tab);
ok(!toolboxForTab, "Toolbox destroyed.");
}
async function testContextMenuInitialization(testActor) {

View File

@ -15,8 +15,6 @@ add_task(async function() {
});
async function testToolboxInitialization(tab, inspector, toolbox) {
const target = await TargetFactory.forTab(tab);
ok(true, "Inspector started, and notification received.");
ok(inspector, "Inspector instance is accessible.");
ok(inspector.isReady, "Inspector instance is ready.");
@ -42,7 +40,8 @@ async function testToolboxInitialization(tab, inspector, toolbox) {
await toolbox.destroy();
ok(true, "'destroyed' notification received.");
ok(!gDevTools.getToolbox(target), "Toolbox destroyed.");
const toolboxForTab = await gDevTools.getToolboxForTab(tab);
ok(!toolboxForTab, "Toolbox destroyed.");
}
async function testMarkupView(selector, inspector) {

View File

@ -73,8 +73,7 @@ add_task(async function() {
async function openToolbox(tab) {
info("Opening webconsole.");
const target = await TargetFactory.forTab(tab);
return gDevTools.showToolbox(target, "webconsole");
return gDevTools.showToolboxForTab(tab, { toolId: "webconsole" });
}
async function startPickerAndAssertSwitchToInspector(toolbox) {

View File

@ -31,8 +31,7 @@ Services.prefs.setBoolPref("devtools.memory.enabled", true);
*/
this.openMemoryPanel = async function(tab) {
info("Opening memory panel.");
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "memory");
const toolbox = await gDevTools.showToolboxForTab(tab, { toolId: "memory" });
info("Memory panel shown successfully.");
const panel = toolbox.getCurrentPanel();
return { tab, panel };
@ -43,8 +42,7 @@ this.openMemoryPanel = async function(tab) {
*/
this.closeMemoryPanel = async function(tab) {
info("Closing memory panel.");
const target = await TargetFactory.forTab(tab);
const toolbox = gDevTools.getToolbox(target);
const toolbox = await gDevTools.getToolboxForTab(tab);
await toolbox.destroy();
info("Closed memory panel successfully.");
};

View File

@ -18,8 +18,9 @@ add_task(async function() {
await pushPref("devtools.netmonitor.har.defaultFileName", "test_filename");
const tab = await addTab(SIMPLE_URL);
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "inspector");
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "inspector",
});
tab.linkedBrowser.reload();

View File

@ -322,9 +322,9 @@ function initNetMonitor(
const tab = await addTab(url);
info("Net tab added successfully: " + url);
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "netmonitor");
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "netmonitor",
});
info("Network monitor pane shown successfully.");
const monitor = toolbox.getCurrentPanel();

View File

@ -467,14 +467,14 @@ async function withDevToolsPanel(callback) {
});
const { gDevTools } = require("devtools/client/framework/devtools");
const { TargetFactory } = require("devtools/client/framework/target");
info("Create a new about:blank tab.");
const tab = BrowserTestUtils.addTab(gBrowser, "about:blank");
info("Begin to open the DevTools and the performance-new panel.");
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "performance");
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "performance",
});
const { document } = toolbox.getCurrentPanel().panelWin;

View File

@ -5,7 +5,6 @@
/* globals dump */
const { gDevTools } = require("devtools/client/framework/devtools");
const { TargetFactory } = require("devtools/client/framework/target");
const {
addTab,
removeTab,
@ -28,12 +27,11 @@ exports.initPanelInNewTab = async function({ tool, url, win }, options = {}) {
exports.initPanelInTab = async function({ tool, tab }) {
dump(`Initializing a ${tool} panel.\n`);
const target = await TargetFactory.forTab(tab);
// Open a toolbox and wait for the connection to the performance actors
// to be opened. This is necessary because of the WebConsole's
// `profile` and `profileEnd` methods.
const toolbox = await gDevTools.showToolbox(target, tool);
const toolbox = await gDevTools.showToolboxForTab(tab, { toolId: tool });
const target = toolbox.target;
// ensure that the performance front is ready
await target.getFront("performance");

View File

@ -59,8 +59,9 @@ addRDMTask(
);
async function openNetworkMonitor(tab) {
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "netmonitor");
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "netmonitor",
});
const monitor = toolbox.getCurrentPanel();
return monitor;
}

View File

@ -62,10 +62,9 @@ addRDMTask(
ok(!snapshot.parent, "No events have been logged for the main process");
const tab = await addTab(URL);
const target = await TargetFactory.forTab(tab);
await openCloseRDM(tab);
await gDevTools.showToolbox(target, "inspector");
await gDevTools.showToolboxForTab(tab, { toolId: "inspector" });
await openCloseRDM(tab);
await checkResults();
},

View File

@ -27,8 +27,8 @@ const checkServerConnectionCount = async function(browser, expected, msg) {
};
const checkToolbox = async function(tab, location) {
const target = await TargetFactory.forTab(tab);
ok(!!gDevTools.getToolbox(target), `Toolbox exists ${location}`);
const toolbox = await gDevTools.getToolboxForTab(tab);
ok(!!toolbox, `Toolbox exists ${location}`);
};
addRDMTask(

View File

@ -8,8 +8,8 @@
const TEST_URL = "http://example.com/";
const checkToolbox = async function(tab, location) {
const target = await TargetFactory.forTab(tab);
ok(!!gDevTools.getToolbox(target), `Toolbox exists ${location}`);
const toolbox = await gDevTools.getToolboxForTab(tab);
ok(!!toolbox, `Toolbox exists ${location}`);
};
addRDMTask(

View File

@ -11,8 +11,10 @@ add_task(async function() {
await addTab(TEST_URI);
startTelemetry();
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = await gDevTools.showToolbox(target, "inspector");
const tab = gBrowser.selectedTab;
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "inspector",
});
info("testing the eyedropper button");
await testButton(toolbox);

View File

@ -18,8 +18,10 @@ add_task(async function() {
await pushPref("devtools.command-button-paintflashing.enabled", true);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = await gDevTools.showToolbox(target, "inspector");
const tab = gBrowser.selectedTab;
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "inspector",
});
info("inspector opened");
info("testing the paintflashing button");

View File

@ -43,8 +43,10 @@ add_task(async function() {
await addTab(TEST_URI);
startTelemetry();
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = await gDevTools.showToolbox(target, "inspector");
const tab = gBrowser.selectedTab;
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "inspector",
});
info("inspector opened");
info("testing the responsivedesign button");

View File

@ -114,8 +114,10 @@ add_task(async function() {
await addTab(TEST_URI);
startTelemetry();
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = await gDevTools.showToolbox(target, "inspector");
const tab = gBrowser.selectedTab;
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "inspector",
});
info("inspector opened");
await testSidebar(toolbox);

View File

@ -4,8 +4,8 @@
"use strict";
add_task(async function() {
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = await gDevTools.showToolbox(target);
const tab = gBrowser.selectedTab;
const toolbox = await gDevTools.showToolboxForTab(tab);
const doc = toolbox.doc;
const root = doc.documentElement;

View File

@ -134,8 +134,9 @@ const createHost = async function(
async function openAndCloseToolbox(nbOfTimes, usageTime, toolId) {
for (let i = 0; i < nbOfTimes; i++) {
info("Opening toolbox " + (i + 1));
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = await gDevTools.showToolbox(target, toolId);
const tab = gBrowser.selectedTab;
const toolbox = await gDevTools.showToolboxForTab(tab, { toolId });
// We use a timeout to check the toolbox's active time
await new Promise(resolve => setTimeout(resolve, usageTime));

View File

@ -455,8 +455,8 @@ var refreshTab = async function(tab = gBrowser.selectedTab) {
* @return a promise that resolves when the page has fully loaded.
*/
async function navigateTo(uri, { isErrorPage = false } = {}) {
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = gDevTools.getToolbox(target);
const toolbox = await gDevTools.getToolboxForTab(gBrowser.selectedTab);
const target = toolbox.target;
// If we're switching origins, we need to wait for the 'switched-target'
// event to make sure everything is ready.
@ -567,8 +567,8 @@ var openInspectorForURL = async function(url, hostType) {
};
async function getActiveInspector() {
const target = await TargetFactory.forTab(gBrowser.selectedTab);
return gDevTools.getToolbox(target).getPanel("inspector");
const toolbox = await gDevTools.getToolboxForTab(gBrowser.selectedTab);
return toolbox.getPanel("inspector");
}
/**
@ -810,10 +810,9 @@ var openToolboxForTab = async function(tab, toolId, hostType) {
info("Opening the toolbox");
let toolbox;
const target = await TargetFactory.forTab(tab);
// Check if the toolbox is already loaded.
toolbox = gDevTools.getToolbox(target);
toolbox = await gDevTools.getToolboxForTab(tab);
if (toolbox) {
if (!toolId || (toolId && toolbox.getPanel(toolId))) {
info("Toolbox is already opened");
@ -822,7 +821,7 @@ var openToolboxForTab = async function(tab, toolId, hostType) {
}
// If not, load it now.
toolbox = await gDevTools.showToolbox(target, toolId, hostType);
toolbox = await gDevTools.showToolboxForTab(tab, { toolId, hostType });
// Make sure that the toolbox frame is focused.
await new Promise(resolve => waitForFocus(resolve, toolbox.win));
@ -853,10 +852,7 @@ var openNewTabAndToolbox = async function(url, toolId, hostType) {
*/
var closeTabAndToolbox = async function(tab = gBrowser.selectedTab) {
if (TargetFactory.isKnownTab(tab)) {
const target = await TargetFactory.forTab(tab);
if (target) {
await gDevTools.closeToolbox(target);
}
await gDevTools.closeToolboxForTab(tab);
}
await removeTab(tab);
@ -875,6 +871,38 @@ var closeToolboxAndTab = async function(toolbox) {
await removeTab(gBrowser.selectedTab);
};
/**
* Retrieve all tool ids compatible with a target created for the provided tab.
*
* @param {XULTab} tab
* The tab for which we want to get the list of supported toolIds
* @return {Array<String>} array of tool ids
*/
async function getSupportedToolIds(tab) {
info("Getting the entire list of tools supported in this tab");
let shouldDestroyToolbox = false;
// Get the toolbox for this tab, or create one if needed.
let toolbox = await gDevTools.getToolboxForTab(tab);
if (!toolbox) {
toolbox = await gDevTools.showToolboxForTab(tab);
shouldDestroyToolbox = true;
}
const toolIds = gDevTools
.getToolDefinitionArray()
.filter(def => def.isTargetSupported(toolbox.target))
.map(def => def.id);
if (shouldDestroyToolbox) {
// Only close the toolbox if it was explicitly created here.
await toolbox.destroy();
}
return toolIds;
}
/**
* Waits until a predicate returns true.
*
@ -1003,8 +1031,7 @@ function lookupPath(obj, path) {
}
var closeToolbox = async function() {
const target = await TargetFactory.forTab(gBrowser.selectedTab);
await gDevTools.closeToolbox(target);
await gDevTools.closeToolboxForTab(gBrowser.selectedTab);
};
/**

View File

@ -19,8 +19,7 @@ add_task(async function() {
// On enumerating cache storages, CacheStorage::Keys would throw a
// DOM security exception. We'd like to verify storage panel still work in
// this case.
const target = await TargetFactory.forTab(win.gBrowser.selectedTab);
await openStoragePanel(null, target);
await openStoragePanel({ tab: win.gBrowser.selectedTab });
const cacheItemId = ["Cache", "http://test2.example.org"];

View File

@ -15,8 +15,7 @@ add_task(async function() {
await runTests();
info("Close Toolbox");
const target = await TargetFactory.forTab(gBrowser.selectedTab);
await gDevTools.closeToolbox(target);
await gDevTools.closeToolboxForTab(gBrowser.selectedTab);
});
async function runTests() {

View File

@ -15,8 +15,7 @@ add_task(async function() {
await runTests();
info("Close Toolbox");
const target = await TargetFactory.forTab(gBrowser.selectedTab);
await gDevTools.closeToolbox(target);
await gDevTools.closeToolboxForTab(gBrowser.selectedTab);
info("Set a toolbox height of 1000px");
await pushPref("devtools.toolbox.footer.height", 1000);

View File

@ -54,7 +54,10 @@ async function setupExtensionDebuggingToolbox(id, options = {}) {
let toolbox;
let storage;
if (openToolbox) {
const res = await openStoragePanel(null, target, Toolbox.HostType.WINDOW);
const res = await openStoragePanel({
target,
hostType: Toolbox.HostType.WINDOW,
});
({ toolbox, storage } = res);
}
@ -190,9 +193,12 @@ add_task(
await extension.awaitMessage("storage-local-onChanged");
info("Open the addon toolbox storage panel");
const { target } = await setupExtensionDebuggingToolbox(extension.id, {
openToolbox: true,
});
const { target, toolbox } = await setupExtensionDebuggingToolbox(
extension.id,
{
openToolbox: true,
}
);
await selectTreeItem(["extensionStorage", host]);
@ -238,7 +244,7 @@ add_task(
}
info("Shut down the test");
await gDevTools.closeToolbox(target);
await toolbox.destroy();
await extension.unload();
await target.destroy();
}

View File

@ -142,17 +142,16 @@ async function openTabAndSetupStorage(url, options = {}) {
/**
* Open the toolbox, with the storage tool visible.
*
* @param cb {Function} Optional callback, if you don't want to use the returned
* promise
* @param tab {XULTab} Optional, the tab for the toolbox; defaults to selected tab
* @param target {Object} Optional, the target for the toolbox; defaults to a tab target
* @param hostType {Toolbox.HostType} Optional, type of host that will host the toolbox
*
* @return {Promise} a promise that resolves when the storage inspector is ready
*/
var openStoragePanel = async function(cb, target, hostType) {
var openStoragePanel = async function({ tab, target, hostType } = {}) {
info("Opening the storage inspector");
if (!target) {
target = await TargetFactory.forTab(gBrowser.selectedTab);
target = await TargetFactory.forTab(tab || gBrowser.selectedTab);
}
let storage, toolbox;
@ -168,9 +167,6 @@ var openStoragePanel = async function(cb, target, hostType) {
gUI = storage.UI;
gToolbox = toolbox;
info("Toolbox and storage already open");
if (cb) {
return cb(storage, toolbox);
}
return {
toolbox: toolbox,
@ -192,10 +188,6 @@ var openStoragePanel = async function(cb, target, hostType) {
await waitForToolboxFrameFocus(toolbox);
if (cb) {
return cb(storage, toolbox);
}
return {
toolbox: toolbox,
storage: storage,

View File

@ -18,8 +18,9 @@ add_task(async function() {
// in the tab, we might have pending updates in the netmonitor which won't be
// awaited for by showToolbox)
const tab = await addTab(EMPTY_TEST_URL);
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "netmonitor");
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "netmonitor",
});
const monitor = toolbox.getPanel("netmonitor");
const { store, windowRequire } = monitor.panelWin;
const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");

View File

@ -12,12 +12,14 @@ add_task(async function() {
// opened *while* the page is still loading. The Style Editor should not
// signal that it is loaded until the accompanying content page is loaded.
const tabAdded = addTab(TESTCASE_URI);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const styleEditorLoaded = gDevTools.showToolbox(target, "styleeditor");
const tab = gBrowser.selectedTab;
const styleEditorLoaded = gDevTools.showToolboxForTab(tab, {
toolId: "styleeditor",
});
await Promise.all([tabAdded, styleEditorLoaded]);
const toolbox = gDevTools.getToolbox(target);
const toolbox = await gDevTools.getToolboxForTab(tab);
const panel = toolbox.getPanel("styleeditor");
const { panelWindow, UI: ui } = panel;

View File

@ -19,8 +19,7 @@ const expectedText = `
`;
async function closeAndReopenToolbox() {
const target = await TargetFactory.forTab(gBrowser.selectedTab);
await gDevTools.closeToolbox(target);
await gDevTools.closeToolboxForTab(gBrowser.selectedTab);
const { ui: newui } = await openStyleEditor();
return newui;
}

View File

@ -11,9 +11,9 @@ const TEST_URL = TEST_BASE + "doc_xulpage.xhtml";
add_task(async function() {
const tab = await addTab(TEST_URL);
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "styleeditor");
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "styleeditor",
});
const panel = toolbox.getCurrentPanel();
ok(

View File

@ -71,8 +71,9 @@ var openStyleEditor = async function(tab) {
if (!tab) {
tab = gBrowser.selectedTab;
}
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, "styleeditor");
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "styleeditor",
});
const panel = toolbox.getPanel("styleeditor");
const ui = panel.UI;

View File

@ -13,8 +13,7 @@ add_task(async function() {
let hud = await openNewTabAndConsole(TEST_URI);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = gDevTools.getToolbox(target);
const toolbox = await gDevTools.getToolboxForTab(gBrowser.selectedTab);
const tabClosed = once(gBrowser.tabContainer, "TabClose");
tabClosed.then(() => info("tab closed"));

View File

@ -36,8 +36,7 @@ add_task(async function() {
const hud = await openNewTabAndConsole(TEST_URI);
const { jsterm } = hud;
const { autocompletePopup } = jsterm;
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = gDevTools.getToolbox(target);
const toolbox = await gDevTools.getToolboxForTab(gBrowser.selectedTab);
let tooltip = await setInputValueForGetterConfirmDialog(
toolbox,

View File

@ -22,8 +22,7 @@ const TEST_URI = `data:text/html;charset=utf-8,
add_task(async function() {
const hud = await openNewTabAndConsole(TEST_URI);
const { jsterm } = hud;
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = gDevTools.getToolbox(target);
const toolbox = await gDevTools.getToolboxForTab(gBrowser.selectedTab);
let tooltip = await setInputValueForGetterConfirmDialog(
toolbox,

View File

@ -41,8 +41,7 @@ add_task(async function() {
const hud = await openNewTabAndConsole(TEST_URI);
const { jsterm } = hud;
const { autocompletePopup } = jsterm;
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = gDevTools.getToolbox(target);
const toolbox = await gDevTools.getToolboxForTab(gBrowser.selectedTab);
let tooltip = await setInputValueForGetterConfirmDialog(
toolbox,

View File

@ -28,8 +28,7 @@ const MDN_URL =
add_task(async function() {
const hud = await openNewTabAndConsole(TEST_URI);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = gDevTools.getToolbox(target);
const toolbox = await gDevTools.getToolboxForTab(gBrowser.selectedTab);
const tooltip = await setInputValueForGetterConfirmDialog(
toolbox,

View File

@ -18,8 +18,7 @@ add_task(async function() {
const { jsterm } = hud;
const { autocompletePopup: popup } = jsterm;
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = gDevTools.getToolbox(target);
const toolbox = await gDevTools.getToolboxForTab(gBrowser.selectedTab);
const jstermComplete = value => setInputValueForAutocompletion(hud, value);

View File

@ -24,8 +24,7 @@ add_task(async function() {
execute(hud, pauseExpression);
// wait for the debugger to be opened and paused.
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = gDevTools.getToolbox(target);
const toolbox = await gDevTools.getToolboxForTab(gBrowser.selectedTab);
await waitFor(() => toolbox.getPanel("jsdebugger"));
const dbg = createDebuggerContext(toolbox);

View File

@ -11,8 +11,7 @@ add_task(async function() {
const hud = await openNewTabAndConsole(TEST_URI);
const { jsterm } = hud;
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = gDevTools.getToolbox(target);
const toolbox = await gDevTools.getToolboxForTab(gBrowser.selectedTab);
// Open context menu and wait until it's visible
const element = jsterm.node.querySelector(".CodeMirror-wrap");

View File

@ -21,8 +21,7 @@ function pauseInDebugger(param) {
add_task(async function() {
const hud = await openNewTabAndConsole(TEST_URI);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = gDevTools.getToolbox(target);
const toolbox = await gDevTools.getToolboxForTab(gBrowser.selectedTab);
setInputValue(hud, "x");
await waitForEagerEvaluationResult(hud, `"global"`);

View File

@ -27,8 +27,8 @@ add_task(async function() {
info(
"Close toolboxes in tabs located in different windows, one of them not focused"
);
await closeToolboxForTab(tab1);
await closeToolboxForTab(tab2);
await gDevTools.closeToolboxForTab(tab1);
await gDevTools.closeToolboxForTab(tab2);
info("Close the second window");
win2.close();
@ -38,8 +38,3 @@ add_task(async function() {
ok(true, "No error was triggered during the test");
});
async function closeToolboxForTab(tab) {
const target = await TargetFactory.forTab(tab);
return gDevTools.closeToolbox(target);
}

View File

@ -12,8 +12,7 @@ const TEST_URI =
// console is opened first.
add_task(async function() {
const hud = await openNewTabAndConsole(TEST_URI);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = gDevTools.getToolbox(target);
const toolbox = await gDevTools.getToolboxForTab(gBrowser.selectedTab);
let messageNode = await waitFor(() => findMessage(hud, "BAR"));
await clickFirstStackElement(hud, messageNode, true);

Some files were not shown because too many files have changed in this diff Show More