Bug 1273537, r=gijs a=lizzard
authorTimothy Guan-tin Chien <timdream@gmail.com>
Tue, 21 Mar 2017 11:46:29 +0100
changeset 379151 eb0f2eeda19bad353e90c1efbfd480af0c63b70b
parent 379150 a0b80d99c2fe2d007c95820cbdbb8568ce8ee437
child 379152 728b0e0b8dea97cd709204df088f3fc01276a6f7
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgijs, lizzard
bugs1273537
milestone53.0
Bug 1273537, r=gijs a=lizzard
browser/base/content/browser.js
browser/base/content/test/urlbar/browser_bug304198.js
browser/base/content/test/urlbar/browser_canonizeURL.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2474,18 +2474,23 @@ function URLBarSetURI(aURI) {
       } catch (ex) {
         value = "about:blank";
       }
     }
 
     valid = !isBlankPageURL(uri.spec);
   }
 
+  let isDifferentValidValue = valid && value != gURLBar.value;
   gURLBar.value = value;
   gURLBar.valueIsTyped = !valid;
+  if (isDifferentValidValue) {
+    gURLBar.selectionStart = gURLBar.selectionEnd = 0;
+  }
+
   SetPageProxyState(valid ? "valid" : "invalid");
 }
 
 function losslessDecodeURI(aURI) {
   let scheme = aURI.scheme;
   if (scheme == "moz-action")
     throw new Error("losslessDecodeURI should never get a moz-action URI");
 
--- a/browser/base/content/test/urlbar/browser_bug304198.js
+++ b/browser/base/content/test/urlbar/browser_bug304198.js
@@ -44,16 +44,19 @@ add_task(function* () {
   function urlbarBackspace() {
     return new Promise((resolve, reject) => {
       gBrowser.selectedBrowser.focus();
       gURLBar.addEventListener("input", function() {
         gURLBar.removeEventListener("input", arguments.callee);
         resolve();
       });
       gURLBar.focus();
+      if (gURLBar.selectionStart == gURLBar.selectionEnd) {
+        gURLBar.selectionStart = gURLBar.selectionEnd = gURLBar.textValue.length;
+      }
       EventUtils.synthesizeKey("VK_BACK_SPACE", {});
     });
   }
 
   function* prepareDeletedURLTab() {
     yield BrowserTestUtils.switchTab(gBrowser, deletedURLTab);
     is(gURLBar.textValue, testURL, "gURLBar.textValue should be testURL after initial switch to deletedURLTab");
 
--- a/browser/base/content/test/urlbar/browser_canonizeURL.js
+++ b/browser/base/content/test/urlbar/browser_canonizeURL.js
@@ -24,16 +24,18 @@ add_task(function*() {
   registerCleanupFunction(() => {
     Preferences.set("browser.urlbar.autoFill", autoFill);
   });
 
   for (let [inputValue, expectedURL, options] of testcases) {
     let promiseLoad = waitForDocLoadAndStopIt(expectedURL);
     gURLBar.focus();
     if (Object.keys(options).length > 0) {
+      gURLBar.selectionStart = gURLBar.selectionEnd =
+        gURLBar.inputField.value.length;
       gURLBar.inputField.value = inputValue.slice(0, -1);
       EventUtils.synthesizeKey(inputValue.slice(-1), {});
     } else {
       gURLBar.textValue = inputValue;
     }
     EventUtils.synthesizeKey("VK_RETURN", options);
     yield promiseLoad;
   }