Files
firefox/devtools/client/framework/test/browser_toolbox_split_console.js
T
Julian Descottes bfb875751c 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
2021-02-25 18:02:52 +00:00

85 lines
2.2 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Tests that these toolbox split console APIs work:
// * toolbox.useKeyWithSplitConsole()
// * toolbox.isSplitConsoleFocused
let gToolbox = null;
let panelWin = null;
const URL = "data:text/html;charset=utf8,test split console key delegation";
add_task(async function() {
const tab = await addTab(URL);
gToolbox = await gDevTools.showToolboxForTab(tab, { toolId: "jsdebugger" });
panelWin = gToolbox.getPanel("jsdebugger").panelWin;
await gToolbox.openSplitConsole();
await testIsSplitConsoleFocused();
await testUseKeyWithSplitConsole();
await testUseKeyWithSplitConsoleWrongTool();
await cleanup();
});
async function testIsSplitConsoleFocused() {
await gToolbox.openSplitConsole();
// The newly opened split console should have focus
ok(gToolbox.isSplitConsoleFocused(), "Split console is focused");
panelWin.focus();
ok(!gToolbox.isSplitConsoleFocused(), "Split console is no longer focused");
}
// A key bound to the selected tool should trigger it's command
function testUseKeyWithSplitConsole() {
let commandCalled = false;
info("useKeyWithSplitConsole on debugger while debugger is focused");
gToolbox.useKeyWithSplitConsole(
"F3",
() => {
commandCalled = true;
},
"jsdebugger"
);
info("synthesizeKey with the console focused");
focusConsoleInput();
synthesizeKeyShortcut("F3", panelWin);
ok(commandCalled, "Shortcut key should trigger the command");
}
// A key bound to a *different* tool should not trigger it's command
function testUseKeyWithSplitConsoleWrongTool() {
let commandCalled = false;
info("useKeyWithSplitConsole on inspector while debugger is focused");
gToolbox.useKeyWithSplitConsole(
"F4",
() => {
commandCalled = true;
},
"inspector"
);
info("synthesizeKey with the console focused");
focusConsoleInput();
synthesizeKeyShortcut("F4", panelWin);
ok(!commandCalled, "Shortcut key shouldn't trigger the command");
}
async function cleanup() {
await gToolbox.destroy();
gBrowser.removeCurrentTab();
gToolbox = panelWin = null;
}
function focusConsoleInput() {
gToolbox.getPanel("webconsole").hud.jsterm.focus();
}