tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_toolbox_split_console.js (2291B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Tests that these toolbox split console APIs work:
      7 //  * toolbox.useKeyWithSplitConsole()
      8 //  * toolbox.isSplitConsoleFocused
      9 
     10 let gToolbox = null;
     11 let panelWin = null;
     12 
     13 const URL = "data:text/html;charset=utf8,test split console key delegation";
     14 
     15 add_task(async function () {
     16  const tab = await addTab(URL);
     17  gToolbox = await gDevTools.showToolboxForTab(tab, { toolId: "jsdebugger" });
     18  panelWin = gToolbox.getPanel("jsdebugger").panelWin;
     19 
     20  await gToolbox.openSplitConsole();
     21  await testIsSplitConsoleFocused();
     22  await testUseKeyWithSplitConsole();
     23  await testUseKeyWithSplitConsoleWrongTool();
     24 
     25  await cleanup();
     26 });
     27 
     28 async function testIsSplitConsoleFocused() {
     29  await gToolbox.openSplitConsole();
     30  // The newly opened split console should have focus
     31  ok(gToolbox.isSplitConsoleFocused(), "Split console is focused");
     32  panelWin.focus();
     33  ok(!gToolbox.isSplitConsoleFocused(), "Split console is no longer focused");
     34 }
     35 
     36 // A key bound to the selected tool should trigger it's command
     37 function testUseKeyWithSplitConsole() {
     38  let commandCalled = false;
     39 
     40  info("useKeyWithSplitConsole on debugger while debugger is focused");
     41  gToolbox.useKeyWithSplitConsole(
     42    "F3",
     43    () => {
     44      commandCalled = true;
     45    },
     46    "jsdebugger"
     47  );
     48 
     49  info("synthesizeKey with the console focused");
     50  focusConsoleInput();
     51  synthesizeKeyShortcut("F3", panelWin);
     52 
     53  ok(commandCalled, "Shortcut key should trigger the command");
     54 }
     55 
     56 // A key bound to a *different* tool should not trigger it's command
     57 function testUseKeyWithSplitConsoleWrongTool() {
     58  let commandCalled = false;
     59 
     60  info("useKeyWithSplitConsole on inspector while debugger is focused");
     61  gToolbox.useKeyWithSplitConsole(
     62    "F4",
     63    () => {
     64      commandCalled = true;
     65    },
     66    "inspector"
     67  );
     68 
     69  info("synthesizeKey with the console focused");
     70  focusConsoleInput();
     71  synthesizeKeyShortcut("F4", panelWin);
     72 
     73  ok(!commandCalled, "Shortcut key shouldn't trigger the command");
     74 }
     75 
     76 async function cleanup() {
     77  await gToolbox.destroy();
     78  gBrowser.removeCurrentTab();
     79  gToolbox = panelWin = null;
     80 }
     81 
     82 function focusConsoleInput() {
     83  gToolbox.getPanel("webconsole").hud.jsterm.focus();
     84 }