tor-browser

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

browser_webconsole_split_focus.js (1483B)


      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</p>";
      8 
      9 add_task(async function () {
     10  info(
     11    "Test that the split console input is focused and restores the focus properly."
     12  );
     13 
     14  const toolbox = await openNewTabAndToolbox(TEST_URI, "inspector");
     15  ok(!toolbox.splitConsole, "Split console is hidden by default");
     16 
     17  info("Focusing the search box before opening the split console");
     18  const inspector = toolbox.getPanel("inspector");
     19  inspector.searchBox.focus();
     20 
     21  let activeElement = getActiveElement(inspector.panelDoc);
     22  is(activeElement, inspector.searchBox, "Search box is focused");
     23 
     24  await toolbox.openSplitConsole();
     25 
     26  ok(toolbox.splitConsole, "Split console is now visible");
     27 
     28  const { hud } = toolbox.getPanel("webconsole");
     29  ok(isInputFocused(hud), "Split console input is focused by default");
     30 
     31  await toolbox.closeSplitConsole();
     32 
     33  info(
     34    "Making sure that the search box is refocused after closing the split console"
     35  );
     36  activeElement = getActiveElement(inspector.panelDoc);
     37  is(activeElement, inspector.searchBox, "Search box is focused");
     38 });
     39 
     40 function getActiveElement(doc) {
     41  let activeElement = doc.activeElement;
     42  while (activeElement && activeElement.contentDocument) {
     43    activeElement = activeElement.contentDocument.activeElement;
     44  }
     45  return activeElement;
     46 }