Bug 975707 - Links in Console load in Console's view on double-click, breaking Console till reopen; r=msucan
authorSami Jaktholm <sjakthol@outlook.com>
Tue, 25 Feb 2014 13:44:36 +0200
changeset 170868 70f928fe9ecf274d026b25946dcea07acbc281cf
parent 170867 989f56e2fca980b0518bf136a0a07ed63ab1ad02
child 170869 5bc4fa17cd79ca9994b37d1b7a04c1557f984649
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersmsucan
bugs975707
milestone30.0a1
Bug 975707 - Links in Console load in Console's view on double-click, breaking Console till reopen; r=msucan
browser/devtools/webconsole/test/browser.ini
browser/devtools/webconsole/test/browser_webconsole_dont_navigate_on_doubleclick.js
browser/devtools/webconsole/webconsole.js
--- a/browser/devtools/webconsole/test/browser.ini
+++ b/browser/devtools/webconsole/test/browser.ini
@@ -229,16 +229,17 @@ run-if = os == "mac"
 [browser_webconsole_cached_autocomplete.js]
 [browser_webconsole_change_font_size.js]
 [browser_webconsole_chrome.js]
 [browser_webconsole_closure_inspection.js]
 [browser_webconsole_completion.js]
 [browser_webconsole_console_extras.js]
 [browser_webconsole_console_logging_api.js]
 [browser_webconsole_count.js]
+[browser_webconsole_dont_navigate_on_doubleclick.js]
 [browser_webconsole_execution_scope.js]
 [browser_webconsole_for_of.js]
 [browser_webconsole_history.js]
 [browser_webconsole_input_field_focus_on_panel_select.js]
 [browser_webconsole_js_input_expansion.js]
 [browser_webconsole_jsterm.js]
 [browser_webconsole_live_filtering_of_message_types.js]
 [browser_webconsole_live_filtering_on_search_strings.js]
new file mode 100644
--- /dev/null
+++ b/browser/devtools/webconsole/test/browser_webconsole_dont_navigate_on_doubleclick.js
@@ -0,0 +1,43 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Tests that if a link in console is double clicked, the console frame doesn't
+// navigate to that destination (bug 975707).
+
+function test() {
+  Task.spawn(runner).then(finishTest);
+
+  function* runner() {
+    const TEST_PAGE_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html" + "?_uniq=" + Date.now();
+
+    const {tab} = yield loadTab("data:text/html;charset=utf8,<p>hello</p>");
+    const hud = yield openConsole(tab);
+
+    content.location = TEST_PAGE_URI;
+
+    let messages = yield waitForMessages({
+      webconsole: hud,
+      messages: [{
+        name: "Network request message",
+        url: TEST_PAGE_URI,
+        category: CATEGORY_NETWORK
+      }]
+    });
+
+    let networkEventMessage = messages[0].matched.values().next().value;
+    let urlNode = networkEventMessage.querySelector(".url");
+
+    let deferred = promise.defer();
+    urlNode.addEventListener("click", function onClick(aEvent) {
+      urlNode.removeEventListener("click", onClick);
+      ok(aEvent.defaultPrevented, "The default action was prevented.");
+
+      deferred.resolve();
+    });
+
+    EventUtils.synthesizeMouseAtCenter(urlNode, {clickCount: 2}, hud.iframeWindow);
+
+    yield deferred.promise;
+  }
+}
--- a/browser/devtools/webconsole/webconsole.js
+++ b/browser/devtools/webconsole/webconsole.js
@@ -2671,23 +2671,23 @@ WebConsoleFrame.prototype = {
       this._startX = aEvent.clientX;
       this._startY = aEvent.clientY;
     }, false);
 
     aNode.addEventListener("click", (aEvent) => {
       let mousedown = this._mousedown;
       this._mousedown = false;
 
+      aEvent.preventDefault();
+
       // Do not allow middle/right-click or 2+ clicks.
       if (aEvent.detail != 1 || aEvent.button != 0) {
         return;
       }
 
-      aEvent.preventDefault();
-
       // If this event started with a mousedown event and it ends at a different
       // location, we consider this text selection.
       if (mousedown &&
           (this._startX != aEvent.clientX) &&
           (this._startY != aEvent.clientY))
       {
         this._startX = this._startY = undefined;
         return;