tor-browser

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

browser_webconsole_split_escape_key.js (2813B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const TEST_URI =
      7  "data:text/html;charset=utf-8,<!DOCTYPE html><p>Web Console test for splitting";
      8 
      9 add_task(async function () {
     10  info(
     11    "Test various cases where the escape key should hide the split console."
     12  );
     13 
     14  const toolbox = await openNewTabAndToolbox(TEST_URI, "inspector");
     15 
     16  info("Send ESCAPE key and wait for the split console to be displayed");
     17 
     18  const onSplitConsoleReady = toolbox.once("webconsole-ready");
     19  toolbox.win.focus();
     20  EventUtils.sendKey("ESCAPE", toolbox.win);
     21  await onSplitConsoleReady;
     22 
     23  const hud = toolbox.getPanel("webconsole").hud;
     24  const jsterm = hud.jsterm;
     25  ok(toolbox.splitConsole, "Split console is created.");
     26 
     27  info(
     28    "Wait for the autocomplete to show suggestions for `document.location.`"
     29  );
     30  const popup = jsterm.autocompletePopup;
     31  const onPopupShown = popup.once("popup-opened");
     32  jsterm.focus();
     33  EventUtils.sendString("document.location.");
     34  await onPopupShown;
     35 
     36  info(
     37    "Send ESCAPE key and check that it only hides the autocomplete suggestions"
     38  );
     39 
     40  const onPopupClosed = popup.once("popup-closed");
     41  EventUtils.sendKey("ESCAPE", toolbox.win);
     42  await onPopupClosed;
     43 
     44  ok(!popup.isOpen, "Auto complete popup is hidden.");
     45  ok(
     46    toolbox.splitConsole,
     47    "Split console is open after hiding the autocomplete popup."
     48  );
     49 
     50  info("Send ESCAPE key again and check that now closes the splitconsole");
     51  const onSplitConsoleEvent = toolbox.once("split-console");
     52  EventUtils.sendKey("ESCAPE", toolbox.win);
     53  await onSplitConsoleEvent;
     54 
     55  ok(!toolbox.splitConsole, "Split console is hidden.");
     56 
     57  info("Test if Split console Shortcut stops working when it's disabled.");
     58 
     59  info("Setting the Pref to false and sending ESCAPE key.");
     60  await pushPref("devtools.toolbox.splitconsole.enabled", false);
     61  // pushPref doesn't trigger _prefChanged of toolbox-options.js, so we invoke the toolbox setting update manually
     62  toolbox.updateIsSplitConsoleEnabled();
     63  const onSplitConsole = toolbox.once("split-console");
     64  const onTimeout = wait(1000).then(() => "TIMEOUT");
     65  EventUtils.sendKey("ESCAPE", toolbox.win);
     66  const raceResult = await Promise.race([onSplitConsole, onTimeout]);
     67  is(raceResult, "TIMEOUT", "split-console wasn't emitted");
     68 
     69  ok(!toolbox.splitConsole, "Split console didn't get Triggered.");
     70 
     71  info("Setting the Pref to true and sending ESCAPE key again.");
     72  await pushPref("devtools.toolbox.splitconsole.enabled", true);
     73  toolbox.updateIsSplitConsoleEnabled();
     74  const onSplitConsoleReadyAgain = toolbox.once("split-console");
     75  EventUtils.sendKey("ESCAPE", toolbox.win);
     76  await onSplitConsoleReadyAgain;
     77 
     78  ok(toolbox.splitConsole, "Split console Shortcut is working again.");
     79 });