Bug 1554542 - Fix browser.urlbar.doubleClickSelectsAll handling. r=mak a=jcristau
authorDão Gottwald <dao@mozilla.com>
Mon, 27 May 2019 09:00:00 +0000
changeset 536529 466ee338b43b6ab11c7a4b35da2ca28539faf77f
parent 536528 89da9d90490a421de0dc706a17000fbfbb580455
child 536530 e5154e181cb3f210c0d90f68ce3a80ff947c1a65
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, jcristau
bugs1554542
milestone68.0
Bug 1554542 - Fix browser.urlbar.doubleClickSelectsAll handling. r=mak a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D32669
browser/components/urlbar/UrlbarInput.jsm
browser/components/urlbar/tests/browser/browser.ini
browser/components/urlbar/tests/browser/browser_doubleClickSelectsAll.js
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -1317,17 +1317,19 @@ class UrlbarInput {
     }
   }
 
   _on_mouseover(event) {
     this._updateUrlTooltip();
   }
 
   _on_mousedown(event) {
-    if (event.originalTarget == this.inputField &&
+    if ((event.target == this.inputField ||
+         // Can be removed after bug 1513337:
+         event.originalTarget.classList.contains("anonymous-div")) &&
         event.button == 0 &&
         event.detail == 2 &&
         UrlbarPrefs.get("doubleClickSelectsAll")) {
       this.editor.selectAll();
       event.preventDefault();
       return;
     }
 
--- a/browser/components/urlbar/tests/browser/browser.ini
+++ b/browser/components/urlbar/tests/browser/browser.ini
@@ -37,16 +37,17 @@ skip-if = os != "mac" # Mac only feature
 [browser_autoFill_undo.js]
 [browser_canonizeURL.js]
 support-files =
   searchSuggestionEngine.xml
   searchSuggestionEngine.sjs
 [browser_caret_navigation.js]
 [browser_customizeMode.js]
 [browser_deleteAllText.js]
+[browser_doubleClickSelectsAll.js]
 [browser_downArrowKeySearch.js]
 [browser_dragdropURL.js]
 [browser_dropmarker.js]
 [browser_ime_composition.js]
 [browser_keepStateAcrossTabSwitches.js]
 [browser_keywordBookmarklets.js]
 [browser_keyword_override.js]
 [browser_keywordSearch.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/urlbar/tests/browser/browser_doubleClickSelectsAll.js
@@ -0,0 +1,28 @@
+/* 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/. */
+
+function doubleClick(target) {
+  let promise = BrowserTestUtils.waitForEvent(target, "dblclick");
+  EventUtils.synthesizeMouseAtCenter(target, { clickCount: 1 }, target.ownerGlobal);
+  EventUtils.synthesizeMouseAtCenter(target, { clickCount: 2 }, target.ownerGlobal);
+  return promise;
+}
+
+add_task(async function() {
+  await SpecialPowers.pushPrefEnv({set: [
+    ["browser.urlbar.clickSelectsAll", false],
+    ["browser.urlbar.doubleClickSelectsAll", true],
+  ]});
+
+  let url = "about:mozilla";
+  let win = await BrowserTestUtils.openNewBrowserWindow();
+  let tab = await BrowserTestUtils.openNewForegroundTab({ gBrowser: win.gBrowser, url });
+
+  await doubleClick(win.gURLBar.inputField);
+  is(win.gURLBar.selectionStart, 0, "Selection should start at the beginning of the urlbar value");
+  is(win.gURLBar.selectionEnd, url.length, "Selection should end at the end of the urlbar value");
+
+  win.close();
+});
+