tor-browser

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

browser_console_webconsole_ctrlw_close_tab.js (1927B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Check that Ctrl-W closes the Browser Console and that Ctrl-W closes the
      5 // current tab when using the Web Console - bug 871156.
      6 
      7 "use strict";
      8 
      9 add_task(async function () {
     10  const TEST_URI =
     11    "data:text/html;charset=utf8,<!DOCTYPE html><title>bug871156</title>\n" +
     12    "<p>hello world";
     13  const firstTab = gBrowser.selectedTab;
     14 
     15  let hud = await openNewTabAndConsole(TEST_URI);
     16 
     17  const toolbox = gDevTools.getToolboxForTab(gBrowser.selectedTab);
     18 
     19  const tabClosed = once(gBrowser.tabContainer, "TabClose");
     20  tabClosed.then(() => info("tab closed"));
     21 
     22  const tabSelected = new Promise(resolve => {
     23    gBrowser.tabContainer.addEventListener(
     24      "TabSelect",
     25      function () {
     26        if (gBrowser.selectedTab == firstTab) {
     27          info("tab selected");
     28          resolve(null);
     29        }
     30      },
     31      { once: true }
     32    );
     33  });
     34 
     35  const toolboxDestroyed = toolbox.once("destroyed", () => {
     36    info("toolbox destroyed");
     37  });
     38 
     39  // Get out of the web console initialization.
     40  executeSoon(() => {
     41    EventUtils.synthesizeKey("w", { accelKey: true });
     42  });
     43 
     44  await Promise.all([tabClosed, toolboxDestroyed, tabSelected]);
     45  info("Promise.all resolved. start testing the Browser Console");
     46 
     47  hud = await BrowserConsoleManager.toggleBrowserConsole();
     48  ok(hud, "Browser Console opened");
     49 
     50  const onBrowserConsoleClosed = new Promise(resolve => {
     51    Services.obs.addObserver(function onDestroy() {
     52      Services.obs.removeObserver(onDestroy, "web-console-destroyed");
     53      resolve();
     54    }, "web-console-destroyed");
     55  });
     56 
     57  await waitForAllTargetsToBeAttached(hud.commands.targetCommand);
     58  waitForFocus(() => {
     59    EventUtils.synthesizeKey("w", { accelKey: true }, hud.iframeWindow);
     60  }, hud.iframeWindow);
     61 
     62  await onBrowserConsoleClosed;
     63  ok(true, "the Browser Console closed");
     64 });