Bug 970914 - Avoid confusion where if there's already a console client (attachConsole), we get the same WebConsoleClient instance and startListeners is not called. r=past
authorMihai Sucan <mihai.sucan@gmail.com>
Tue, 25 Feb 2014 18:47:51 +0200
changeset 171089 4572f97a634e0cc30eafc50c365c6f81331ae4eb
parent 171088 dff147791e987c96fbe9e5ab1c4e0235860f273d
child 171090 319fd4968916c4974401f532e0583eb90bed6a85
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewerspast
bugs970914
milestone30.0a1
Bug 970914 - Avoid confusion where if there's already a console client (attachConsole), we get the same WebConsoleClient instance and startListeners is not called. r=past
browser/devtools/webconsole/test/browser.ini
browser/devtools/webconsole/test/browser_webconsole_start_netmon_first.js
toolkit/devtools/client/dbg-client.jsm
--- a/browser/devtools/webconsole/test/browser.ini
+++ b/browser/devtools/webconsole/test/browser.ini
@@ -263,10 +263,11 @@ run-if = os == "mac"
 [browser_webconsole_autocomplete_popup_close_on_tab_switch.js]
 [browser_console_hide_jsterm_when_devtools_chrome_enabled_false.js]
 [browser_webconsole_output_01.js]
 [browser_webconsole_output_02.js]
 [browser_webconsole_output_03.js]
 [browser_webconsole_output_04.js]
 [browser_webconsole_output_events.js]
 [browser_console_variables_view_highlighter.js]
+[browser_webconsole_start_netmon_first.js]
 [browser_webconsole_console_trace_duplicates.js]
 [browser_webconsole_cd_iframe.js]
new file mode 100644
--- /dev/null
+++ b/browser/devtools/webconsole/test/browser_webconsole_start_netmon_first.js
@@ -0,0 +1,37 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// Check that the webconsole works if the network monitor is first opened, then
+// the user switches to the webconsole. See bug 970914.
+
+function test() {
+  Task.spawn(runner).then(finishTest);
+
+  function* runner() {
+    const {tab} = yield loadTab("data:text/html;charset=utf8,<p>hello");
+
+    const target = TargetFactory.forTab(tab);
+    const toolbox = yield gDevTools.showToolbox(target, "netmonitor");
+
+    const hud = yield openConsole(tab);
+
+    hud.jsterm.execute("console.log('foobar bug970914')");
+
+    yield waitForMessages({
+      webconsole: hud,
+      messages: [{
+        name: "console.log",
+        text: "foobar bug970914",
+        category: CATEGORY_WEBDEV,
+        severity: SEVERITY_LOG,
+      }],
+    });
+
+    let text = hud.outputNode.textContent;
+    isnot(text.indexOf("foobar bug970914"), -1, "console.log message confirmed");
+    ok(!/logging API|disabled by a script/i.test(text),
+       "no warning about disabled console API");
+  }
+}
+
--- a/toolkit/devtools/client/dbg-client.jsm
+++ b/toolkit/devtools/client/dbg-client.jsm
@@ -474,32 +474,31 @@ DebuggerClient.prototype = {
    * @param array aListeners
    *        The console listeners you want to start.
    * @param function aOnResponse
    *        Called with the response packet and a WebConsoleClient
    *        instance (which will be undefined on error).
    */
   attachConsole:
   function (aConsoleActor, aListeners, aOnResponse) {
-    if (this._consoleClients.has(aConsoleActor)) {
-      setTimeout(() => aOnResponse({}, this._consoleClients.get(aConsoleActor)), 0);
-      return;
-    }
-
     let packet = {
       to: aConsoleActor,
       type: "startListeners",
       listeners: aListeners,
     };
 
     this.request(packet, (aResponse) => {
       let consoleClient;
       if (!aResponse.error) {
-        consoleClient = new WebConsoleClient(this, aConsoleActor);
-        this._consoleClients.set(aConsoleActor, consoleClient);
+        if (this._consoleClients.has(aConsoleActor)) {
+          consoleClient = this._consoleClients.get(aConsoleActor);
+        } else {
+          consoleClient = new WebConsoleClient(this, aConsoleActor);
+          this._consoleClients.set(aConsoleActor, consoleClient);
+        }
       }
       aOnResponse(aResponse, consoleClient);
     });
   },
 
   /**
    * Attach to a global-scoped thread actor for chrome debugging.
    *