Bug 1554542 - Fix browser.urlbar.doubleClickSelectsAll handling. r=mak
authorDão Gottwald <dao@mozilla.com>
Mon, 27 May 2019 09:00:00 +0000
changeset 475697 cab022901ff73cabd94dea46418167cf118055ad
parent 475696 8b110b9889c34d70465d2a2b98b1747ae03f3c3f
child 475698 0427669077f6e32b724033a4702fb38b73a5e613
push id86417
push userdgottwald@mozilla.com
push dateMon, 27 May 2019 09:08:27 +0000
treeherderautoland@cab022901ff7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1554542
milestone69.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 1554542 - Fix browser.urlbar.doubleClickSelectsAll handling. r=mak 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();
+});
+