1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_bug_871156_ctrlw_close_tab.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.7 + */ 1.8 + 1.9 +// Check that Ctrl-W closes the Browser Console and that Ctrl-W closes the 1.10 +// current tab when using the Web Console - bug 871156. 1.11 + 1.12 +function test() 1.13 +{ 1.14 + const TEST_URI = "data:text/html;charset=utf8,<title>bug871156</title>\n" + 1.15 + "<p>hello world"; 1.16 + let firstTab = gBrowser.selectedTab; 1.17 + Services.prefs.setBoolPref("browser.tabs.animate", false); 1.18 + 1.19 + addTab(TEST_URI); 1.20 + browser.addEventListener("load", function onLoad() { 1.21 + browser.removeEventListener("load", onLoad, true); 1.22 + openConsole(null, consoleOpened); 1.23 + }, true); 1.24 + 1.25 + function consoleOpened(hud) 1.26 + { 1.27 + ok(hud, "Web Console opened"); 1.28 + 1.29 + let tabClosed = promise.defer(); 1.30 + let toolboxDestroyed = promise.defer(); 1.31 + let tabSelected = promise.defer(); 1.32 + 1.33 + let pageWindow = firstTab.linkedBrowser.contentWindow; 1.34 + let toolbox = gDevTools.getToolbox(hud.target); 1.35 + 1.36 + gBrowser.tabContainer.addEventListener("TabClose", function onTabClose() { 1.37 + gBrowser.tabContainer.removeEventListener("TabClose", onTabClose); 1.38 + info("tab closed"); 1.39 + tabClosed.resolve(null); 1.40 + }); 1.41 + 1.42 + gBrowser.tabContainer.addEventListener("TabSelect", function onTabSelect() { 1.43 + gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect); 1.44 + if (gBrowser.selectedTab == firstTab) { 1.45 + info("tab selected"); 1.46 + tabSelected.resolve(null); 1.47 + } 1.48 + }); 1.49 + 1.50 + toolbox.once("destroyed", () => { 1.51 + info("toolbox destroyed"); 1.52 + toolboxDestroyed.resolve(null); 1.53 + }); 1.54 + 1.55 + promise.all([tabClosed.promise, toolboxDestroyed.promise, tabSelected.promise ]).then(() => { 1.56 + info("promise.all resolved"); 1.57 + waitForFocus(testBrowserConsole, pageWindow, true); 1.58 + }); 1.59 + 1.60 + // Get out of the web console initialization. 1.61 + executeSoon(() => { 1.62 + EventUtils.synthesizeKey("w", { accelKey: true }); 1.63 + }); 1.64 + } 1.65 + 1.66 + function testBrowserConsole() 1.67 + { 1.68 + info("test the Browser Console"); 1.69 + 1.70 + HUDService.toggleBrowserConsole().then((hud) => { 1.71 + ok(hud, "Browser Console opened"); 1.72 + 1.73 + Services.obs.addObserver(function onDestroy() { 1.74 + Services.obs.removeObserver(onDestroy, "web-console-destroyed"); 1.75 + ok(true, "the Browser Console closed"); 1.76 + 1.77 + Services.prefs.clearUserPref("browser.tabs.animate"); 1.78 + waitForFocus(finish, content, true); 1.79 + }, "web-console-destroyed", false); 1.80 + 1.81 + waitForFocus(() => { 1.82 + EventUtils.synthesizeKey("w", { accelKey: true }, hud.iframeWindow); 1.83 + }, hud.iframeWindow); 1.84 + }); 1.85 + } 1.86 +}