tor-browser

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

browser_console_open_or_focus.js (1633B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Test that the "browser console" menu item opens or focuses (if already open)
      5 // the console window instead of toggling it open/close.
      6 
      7 "use strict";
      8 requestLongerTimeout(2);
      9 
     10 const TEST_MESSAGE = "testmessage";
     11 const { Tools } = require("resource://devtools/client/definitions.js");
     12 
     13 add_task(async function () {
     14  info("Get main browser window");
     15  const mainWindow = Services.wm.getMostRecentWindow(null);
     16 
     17  info("Open the Browser Console");
     18  await BrowserConsoleManager.openBrowserConsoleOrFocus();
     19 
     20  let hud = BrowserConsoleManager.getBrowserConsole();
     21  await waitFor(() => hud.ui.document.hasFocus());
     22  ok(true, "Focus is in the Browser Console");
     23 
     24  info("Emit a log message to display it in the Browser Console");
     25  console.log(TEST_MESSAGE);
     26  await waitFor(() => findConsoleAPIMessage(hud, TEST_MESSAGE));
     27 
     28  let currWindow = Services.wm.getMostRecentWindow(null);
     29  is(
     30    currWindow.document.documentURI,
     31    Tools.webConsole.url,
     32    "The Browser Console is open and has focus"
     33  );
     34 
     35  info("Focus the main browser window");
     36  mainWindow.focus();
     37 
     38  info("Focus the Browser Console window");
     39  await BrowserConsoleManager.openBrowserConsoleOrFocus();
     40  currWindow = Services.wm.getMostRecentWindow(null);
     41  is(
     42    currWindow.document.documentURI,
     43    Tools.webConsole.url,
     44    "The Browser Console is open and has focus"
     45  );
     46 
     47  info("Close the Browser Console");
     48  await safeCloseBrowserConsole();
     49 
     50  hud = BrowserConsoleManager.getBrowserConsole();
     51  ok(!hud, "Browser Console has been closed");
     52 });