Bug 871156 - Allow Ctrl+W to close the tab when the Web Console is focused; r=robcee
authorMihai Sucan <mihai.sucan@gmail.com>
Thu, 16 May 2013 15:35:53 +0300
changeset 143733 1e2fd4d04d61b32b4d7c751743915db26566cdf5
parent 143732 1ad8dcecee7f630984b003faa1f6f1de1b26da8f
child 143734 7ac5779a426c1982572b751f13332ff5512350e1
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobcee
bugs871156
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 871156 - Allow Ctrl+W to close the tab when the Web Console is focused; r=robcee
browser/devtools/webconsole/HUDService.jsm
browser/devtools/webconsole/test/Makefile.in
browser/devtools/webconsole/test/browser_bug_871156_ctrlw_close_tab.js
browser/devtools/webconsole/webconsole.xul
toolkit/devtools/Console.jsm
--- a/browser/devtools/webconsole/HUDService.jsm
+++ b/browser/devtools/webconsole/HUDService.jsm
@@ -542,16 +542,20 @@ ViewHelpers.create({ constructor: Browse
       window.removeEventListener("unload", onClose);
       this.destroy();
     };
     window.addEventListener("unload", onClose);
 
     this._bc_init = this.$init().then((aReason) => {
       let title = this.ui.rootElement.getAttribute("browserConsoleTitle");
       this.ui.rootElement.setAttribute("title", title);
+
+      let cmd_close = this.ui.document.getElementById("cmd_close");
+      cmd_close.removeAttribute("disabled");
+
       return aReason;
     });
 
     return this._bc_init;
   },
 
   $destroy: WebConsole.prototype.destroy,
 
--- a/browser/devtools/webconsole/test/Makefile.in
+++ b/browser/devtools/webconsole/test/Makefile.in
@@ -124,16 +124,17 @@ MOCHITEST_BROWSER_FILES = \
 	browser_console_consolejsm_output.js \
 	browser_webconsole_bug_837351_securityerrors.js \
 	browser_bug_865871_variables_view_close_on_esc_key.js \
 	browser_bug_865288_repeat_different_objects.js \
 	browser_jsterm_inspect.js \
 	browser_bug_869003_inspect_cross_domain_object.js \
 	browser_bug_862916_console_dir_and_filter_off.js \
 	browser_console_native_getters.js \
+	browser_bug_871156_ctrlw_close_tab.js \
 	head.js \
 	$(NULL)
 
 ifeq ($(OS_ARCH), Darwin)
 MOCHITEST_BROWSER_FILES += \
 	browser_webconsole_bug_804845_ctrl_key_nav.js \
         $(NULL)
 endif
new file mode 100644
--- /dev/null
+++ b/browser/devtools/webconsole/test/browser_bug_871156_ctrlw_close_tab.js
@@ -0,0 +1,66 @@
+/*
+ * 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.
+
+function test()
+{
+  const TEST_URI = "data:text/html;charset=utf8,<title>bug871156</title>\n" +
+                   "<p>hello world";
+  addTab(TEST_URI);
+  browser.addEventListener("load", function onLoad() {
+    browser.removeEventListener("load", onLoad, true);
+    openConsole(null, consoleOpened);
+  }, true);
+
+  function consoleOpened(hud)
+  {
+    ok(hud, "Web Console opened");
+
+    let tabClosed = false, toolboxDestroyed = false;
+
+    gBrowser.tabContainer.addEventListener("TabClose", function onTabClose() {
+      gBrowser.tabContainer.removeEventListener("TabClose", onTabClose);
+
+      ok(true, "tab closed");
+
+      tabClosed = true;
+      if (toolboxDestroyed) {
+        testBrowserConsole();
+      }
+    });
+
+    let toolbox = gDevTools.getToolbox(hud.target);
+    toolbox.once("destroyed", () => {
+      ok(true, "toolbox destroyed");
+
+      toolboxDestroyed = true;
+      if (tabClosed) {
+        testBrowserConsole();
+      }
+    });
+
+    EventUtils.synthesizeKey("w", { accelKey: true }, hud.iframeWindow);
+  }
+
+  function testBrowserConsole()
+  {
+    info("test the Browser Console");
+
+    HUDConsoleUI.toggleBrowserConsole().then((hud) => {
+      ok(hud, "Browser Console opened");
+
+      Services.obs.addObserver(function onDestroy() {
+        Services.obs.removeObserver(onDestroy, "web-console-destroyed");
+        ok(true, "the Browser Console closed");
+
+        executeSoon(finishTest);
+      }, "web-console-destroyed", false);
+
+      EventUtils.synthesizeKey("w", { accelKey: true }, hud.iframeWindow);
+    });
+  }
+}
--- a/browser/devtools/webconsole/webconsole.xul
+++ b/browser/devtools/webconsole/webconsole.xul
@@ -32,17 +32,17 @@
               oncommandupdate="goUpdateConsoleCommands();">
     <command id="consoleCmd_openURL"
              oncommand="goDoCommand('consoleCmd_openURL');"/>
     <command id="consoleCmd_copyURL"
              oncommand="goDoCommand('consoleCmd_copyURL');"/>
     <command id="cmd_fullZoomEnlarge" oncommand="goDoCommand('cmd_fontSizeEnlarge');"/>
     <command id="cmd_fullZoomReduce" oncommand="goDoCommand('cmd_fontSizeReduce');"/>
     <command id="cmd_fullZoomReset" oncommand="goDoCommand('cmd_fontSizeReset');"/>
-    <command id="cmd_close" oncommand="goDoCommand('cmd_close');"/>
+    <command id="cmd_close" oncommand="goDoCommand('cmd_close');" disabled="true"/>
   </commandset>
   <keyset id="consoleKeys">
     <key id="key_fullZoomReduce"  key="&fullZoomReduceCmd.commandkey;" command="cmd_fullZoomReduce"  modifiers="accel"/>
     <key key="&fullZoomReduceCmd.commandkey2;"  command="cmd_fullZoomReduce" modifiers="accel"/>
     <key id="key_fullZoomEnlarge" key="&fullZoomEnlargeCmd.commandkey;" command="cmd_fullZoomEnlarge" modifiers="accel"/>
     <key key="&fullZoomEnlargeCmd.commandkey2;" command="cmd_fullZoomEnlarge" modifiers="accel"/>
     <key key="&fullZoomEnlargeCmd.commandkey3;" command="cmd_fullZoomEnlarge" modifiers="accel"/>
     <key id="key_fullZoomReset" key="&fullZoomResetCmd.commandkey;" command="cmd_fullZoomReset" modifiers="accel"/>
--- a/toolkit/devtools/Console.jsm
+++ b/toolkit/devtools/Console.jsm
@@ -182,17 +182,19 @@ function log(aThing) {
     else if (type == "Set") {
       let i = 0;
       reply += "Set\n";
       for (let value of aThing) {
         reply += logProperty('' + i, value);
         i++;
       }
     }
-    else if (type.match("Error$") || aThing.name == "NS_ERROR_FAILURE") {
+    else if (type.match("Error$") ||
+             (typeof aThing.name == "string" &&
+              aThing.name.match("NS_ERROR_"))) {
       reply += "  Message: " + aThing + "\n";
       if (aThing.stack) {
         reply += "  Stack:\n";
         var frame = aThing.stack;
         while (frame) {
           reply += "    " + frame + "\n";
           frame = frame.caller;
         }