browser/devtools/webconsole/test/browser_bug_871156_ctrlw_close_tab.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /*
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/publicdomain/zero/1.0/
     4  */
     6 // Check that Ctrl-W closes the Browser Console and that Ctrl-W closes the
     7 // current tab when using the Web Console - bug 871156.
     9 function test()
    10 {
    11   const TEST_URI = "data:text/html;charset=utf8,<title>bug871156</title>\n" +
    12                    "<p>hello world";
    13   let firstTab = gBrowser.selectedTab;
    14   Services.prefs.setBoolPref("browser.tabs.animate", false);
    16   addTab(TEST_URI);
    17   browser.addEventListener("load", function onLoad() {
    18     browser.removeEventListener("load", onLoad, true);
    19     openConsole(null, consoleOpened);
    20   }, true);
    22   function consoleOpened(hud)
    23   {
    24     ok(hud, "Web Console opened");
    26     let tabClosed = promise.defer();
    27     let toolboxDestroyed = promise.defer();
    28     let tabSelected = promise.defer();
    30     let pageWindow = firstTab.linkedBrowser.contentWindow;
    31     let toolbox = gDevTools.getToolbox(hud.target);
    33     gBrowser.tabContainer.addEventListener("TabClose", function onTabClose() {
    34       gBrowser.tabContainer.removeEventListener("TabClose", onTabClose);
    35       info("tab closed");
    36       tabClosed.resolve(null);
    37     });
    39     gBrowser.tabContainer.addEventListener("TabSelect", function onTabSelect() {
    40       gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect);
    41       if (gBrowser.selectedTab == firstTab) {
    42         info("tab selected");
    43         tabSelected.resolve(null);
    44       }
    45     });
    47     toolbox.once("destroyed", () => {
    48       info("toolbox destroyed");
    49       toolboxDestroyed.resolve(null);
    50     });
    52     promise.all([tabClosed.promise, toolboxDestroyed.promise, tabSelected.promise ]).then(() => {
    53       info("promise.all resolved");
    54       waitForFocus(testBrowserConsole, pageWindow, true);
    55     });
    57     // Get out of the web console initialization.
    58     executeSoon(() => {
    59       EventUtils.synthesizeKey("w", { accelKey: true });
    60     });
    61   }
    63   function testBrowserConsole()
    64   {
    65     info("test the Browser Console");
    67     HUDService.toggleBrowserConsole().then((hud) => {
    68       ok(hud, "Browser Console opened");
    70       Services.obs.addObserver(function onDestroy() {
    71         Services.obs.removeObserver(onDestroy, "web-console-destroyed");
    72         ok(true, "the Browser Console closed");
    74         Services.prefs.clearUserPref("browser.tabs.animate");
    75         waitForFocus(finish, content, true);
    76       }, "web-console-destroyed", false);
    78       waitForFocus(() => {
    79         EventUtils.synthesizeKey("w", { accelKey: true }, hud.iframeWindow);
    80       }, hud.iframeWindow);
    81     });
    82   }
    83 }

mercurial