summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_console_webconsole_ctrlw_close_tab.js
blob: 4234f8427acc0ac8bdebf83816fc3683fb927583 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Check that Ctrl-W closes the Browser Console and that Ctrl-W closes the
// current tab when using the Web Console - bug 871156.

"use strict";

add_task(async function () {
  const TEST_URI =
    "data:text/html;charset=utf8,<!DOCTYPE html><title>bug871156</title>\n" +
    "<p>hello world";
  const firstTab = gBrowser.selectedTab;

  let hud = await openNewTabAndConsole(TEST_URI);

  const toolbox = gDevTools.getToolboxForTab(gBrowser.selectedTab);

  const tabClosed = once(gBrowser.tabContainer, "TabClose");
  tabClosed.then(() => info("tab closed"));

  const tabSelected = new Promise(resolve => {
    gBrowser.tabContainer.addEventListener(
      "TabSelect",
      function () {
        if (gBrowser.selectedTab == firstTab) {
          info("tab selected");
          resolve(null);
        }
      },
      { once: true }
    );
  });

  const toolboxDestroyed = toolbox.once("destroyed", () => {
    info("toolbox destroyed");
  });

  // Get out of the web console initialization.
  executeSoon(() => {
    EventUtils.synthesizeKey("w", { accelKey: true });
  });

  await Promise.all([tabClosed, toolboxDestroyed, tabSelected]);
  info("Promise.all resolved. start testing the Browser Console");

  hud = await BrowserConsoleManager.toggleBrowserConsole();
  ok(hud, "Browser Console opened");

  const onBrowserConsoleClosed = new Promise(resolve => {
    Services.obs.addObserver(function onDestroy() {
      Services.obs.removeObserver(onDestroy, "web-console-destroyed");
      resolve();
    }, "web-console-destroyed");
  });

  await waitForAllTargetsToBeAttached(hud.commands.targetCommand);
  waitForFocus(() => {
    EventUtils.synthesizeKey("w", { accelKey: true }, hud.iframeWindow);
  }, hud.iframeWindow);

  await onBrowserConsoleClosed;
  ok(true, "the Browser Console closed");
});