Bug 871156 - Allow Ctrl+W to close the tab when the Web Console is focused. r=robcee, a=lsblakk
authorMihai Sucan <mihai.sucan@gmail.com>
Thu, 16 May 2013 15:35:53 +0300
changeset 142695 10738444bf15b09de4c85d6594f4b56aab4ad520
parent 142694 01fe1133726a5f9b9f46aa1abb71e0803e7a026c
child 142696 c43520eb66d0c3467b8fcbada030d218294502d1
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobcee, lsblakk
bugs871156
milestone23.0a2
Bug 871156 - Allow Ctrl+W to close the tab when the Web Console is focused. r=robcee, a=lsblakk
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;
         }