Bug 1571018 - Allow dragging in the Urlbar after selectAll and vice versa. r=adw, a=RyanVM
authorharry <htwyford@mozilla.com>
Tue, 06 Aug 2019 17:36:36 +0000
changeset 545229 e04819022cb11281277c013c6041edc88d6e6fdc
parent 545228 d1e960d52ee7b4826d39d6abed4382611eaf1be5
child 545230 3749ea604ad9274259291efdc86eddd4a8b8192b
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw, RyanVM
bugs1571018
milestone69.0
Bug 1571018 - Allow dragging in the Urlbar after selectAll and vice versa. r=adw, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D40508
browser/components/urlbar/UrlbarInput.jsm
browser/components/urlbar/tests/browser/browser_urlbar_selection.js
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -1474,16 +1474,21 @@ class UrlbarInput {
     // a command causing a focus change. For example opening preferences from
     // the oneoff settings button, or from a contextual tip button.
     // For now we detect that case by discarding the event on command, but we
     // may want to figure out a more robust way to detect abandonment.
     this.controller.engagementEvent.record(event, {
       numChars: this._lastSearchString.length,
     });
 
+    // Clear selection unless we are switching application windows.
+    if (this.document.activeElement != this.inputField) {
+      this.selectionStart = this.selectionEnd = 0;
+    }
+
     // In certain cases, like holding an override key and confirming an entry,
     // we don't key a keyup event for the override key, thus we make this
     // additional cleanup on blur.
     this._clearActionOverride();
     this.formatValue();
 
     // The extension input sessions depends more on blur than on the fact we
     // actually cancel a running query, so we do it here.
--- a/browser/components/urlbar/tests/browser/browser_urlbar_selection.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbar_selection.js
@@ -227,9 +227,74 @@ add_task(async function dragSelect() {
   // Drags from an artibrary offset of 30 to test for bug 1562145: that the
   // selection does not start at the beginning.
   await drag(gURLBar.inputField, 30, 0, 60, 0);
   Assert.greater(
     gURLBar.selectionStart,
     0,
     "Selection should not start at the beginning of the string."
   );
+
+  gURLBar.blur();
 });
+
+/**
+ * Testing for bug 1571018: that the entire Urlbar isn't selected when the
+ * Urlbar is dragged following a selectsAll event then a blur.
+ */
+add_task(async function dragAfterSelectAll() {
+  gURLBar.value = exampleSearch.repeat(10);
+  await click(gURLBar.inputField);
+  Assert.equal(
+    gURLBar.selectionStart,
+    0,
+    "The entire search term should be selected."
+  );
+  Assert.equal(
+    gURLBar.selectionEnd,
+    exampleSearch.repeat(10).length,
+    "The entire search term should be selected."
+  );
+
+  gURLBar.blur();
+
+  // The offset of 30 is arbitrary.
+  await drag(gURLBar.inputField, 30, 0, 60, 0);
+
+  Assert.notEqual(
+    gURLBar.selectionStart,
+    0,
+    "Only part of the search term should be selected."
+  );
+  Assert.notEqual(
+    gURLBar.selectionEnd,
+    exampleSearch.repeat(10).length,
+    "Only part of the search term should be selected."
+  );
+});
+
+/**
+ * Testing for bug 1571018: that the entire Urlbar is selected when the Urlbar
+ * is refocused following a partial text selection then a blur.
+ */
+add_task(async function selectAllAfterDrag() {
+  gURLBar.value = exampleSearch;
+
+  gURLBar.selectionStart = 3;
+  gURLBar.selectionEnd = 7;
+
+  gURLBar.blur();
+
+  await click(gURLBar.inputField);
+
+  Assert.equal(
+    gURLBar.selectionStart,
+    0,
+    "The entire search term should be selected."
+  );
+  Assert.equal(
+    gURLBar.selectionEnd,
+    exampleSearch.length,
+    "The entire search term should be selected."
+  );
+
+  gURLBar.blur();
+});