Bug 1501624 - Add a method for setting the value from a result and migrate urlbar tests away from setting textValue. r=Standard8
authorDão Gottwald <dao@mozilla.com>
Fri, 26 Oct 2018 09:52:23 +0000
changeset 443125 5866c7a7e9066aa7451bf056cd82ca0683093bff
parent 443124 d0c4e1db970ef48154e77ae540f8bc71b1431ed1
child 443126 aa01df6dc4db602fff7b15b8179fa936a5141700
push id71804
push userdgottwald@mozilla.com
push dateFri, 26 Oct 2018 11:43:36 +0000
treeherderautoland@5866c7a7e906 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1501624
milestone65.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 1501624 - Add a method for setting the value from a result and migrate urlbar tests away from setting textValue. r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D9764
browser/base/content/test/urlbar/browser_canonizeURL.js
browser/base/content/test/urlbar/browser_urlbarDecode.js
browser/components/extensions/test/browser/browser_ext_webNavigation_urlbar_transitions.js
browser/components/urlbar/UrlbarInput.jsm
--- a/browser/base/content/test/urlbar/browser_canonizeURL.js
+++ b/browser/base/content/test/urlbar/browser_canonizeURL.js
@@ -28,24 +28,18 @@ add_task(async function checkCtrlWorks()
   await SpecialPowers.pushPrefEnv({set: [
     ["browser.urlbar.autoFill", false],
     ["browser.urlbar.ctrlCanonizesURLs", true],
   ]});
 
   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.sendString(inputValue.slice(-1));
-    } else {
-      gURLBar.textValue = inputValue;
-    }
+    gURLBar.inputField.value = inputValue.slice(0, -1);
+    EventUtils.sendString(inputValue.slice(-1));
     EventUtils.synthesizeKey("KEY_Enter", options);
     await promiseLoad;
   }
 });
 
 add_task(async function checkPrefTurnsOffCanonize() {
   // Add a dummy search engine to avoid hitting the network.
   let engine = await SearchTestUtils.promiseNewSearchEngine(
--- a/browser/base/content/test/urlbar/browser_urlbarDecode.js
+++ b/browser/base/content/test/urlbar/browser_urlbarDecode.js
@@ -1,15 +1,20 @@
 "use strict";
 
 // This test makes sure (1) you can't break the urlbar by typing particular JSON
 // or JS fragments into it, (2) urlbar.textValue shows URLs unescaped, and (3)
 // the urlbar also shows the URLs embedded in action URIs unescaped.  See bug
 // 1233672.
 
+XPCOMUtils.defineLazyModuleGetters(this, {
+  UrlbarMatch: "resource:///modules/UrlbarMatch.jsm",
+  UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
+});
+
 add_task(async function injectJSON() {
   let inputStrs = [
     'http://example.com/ ", "url": "bar',
     "http://example.com/\\",
     'http://example.com/"',
     'http://example.com/","url":"evil.com',
     "http://mozilla.org/\\u0020",
     'http://www.mozilla.org/","url":1e6,"some-key":"foo',
@@ -22,17 +27,22 @@ add_task(async function injectJSON() {
   gURLBar.value = "";
   gURLBar.handleRevert();
   gURLBar.blur();
 });
 
 add_task(function losslessDecode() {
   let urlNoScheme = "example.com/\u30a2\u30a4\u30a6\u30a8\u30aa";
   let url = "http://" + urlNoScheme;
-  gURLBar.textValue = url;
+  if (Services.prefs.getBoolPref("browser.urlbar.quantumbar", true)) {
+    const result = new UrlbarMatch(UrlbarUtils.MATCH_TYPE.TAB_SWITCH, {url});
+    gURLBar.setValueFromResult(result);
+  } else {
+    gURLBar.textValue = url;
+  }
   // Since this is directly setting textValue, it is expected to be trimmed.
   Assert.equal(gURLBar.inputField.value, urlNoScheme,
                "The string displayed in the textbox should not be escaped");
   gURLBar.value = "";
   gURLBar.handleRevert();
   gURLBar.blur();
 });
 
--- a/browser/components/extensions/test/browser/browser_ext_webNavigation_urlbar_transitions.js
+++ b/browser/components/extensions/test/browser/browser_ext_webNavigation_urlbar_transitions.js
@@ -104,18 +104,19 @@ add_task(async function test_webnavigati
   });
 
   await extension.startup();
   await SimpleTest.promiseFocus(window);
 
   await extension.awaitMessage("ready");
 
   gURLBar.focus();
-  gURLBar.textValue = "http://example.com/?q=typed";
-
+  const inputValue = "http://example.com/?q=typed";
+  gURLBar.inputField.value = inputValue.slice(0, -1);
+  EventUtils.sendString(inputValue.slice(-1));
   EventUtils.synthesizeKey("VK_RETURN", {altKey: true});
 
   await extension.awaitFinish("webNavigation.from_address_bar.typed");
 
   await extension.unload();
   info("extension unloaded");
 });
 
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -225,28 +225,35 @@ class UrlbarInput {
 
   /**
    * Called by the view when a result is selected.
    *
    * @param {Event} event The event that selected the result.
    * @param {UrlbarMatch} result The result that was selected.
    */
   resultSelected(event, result) {
-    // Set the input value to the target url.
+    this.setValueFromResult(result);
+    this.controller.resultSelected(event, result);
+  }
+
+  /**
+   * Called by the view when moving through results with the keyboard.
+   *
+   * @param {UrlbarMatch} result The result that was selected.
+   */
+  setValueFromResult(result) {
     let val = result.url;
     let uri;
     try {
       uri = Services.io.newURI(val);
     } catch (ex) {}
     if (uri) {
       val = this.window.losslessDecodeURI(uri);
     }
     this.value = val;
-
-    this.controller.resultSelected(event, result);
   }
 
   // Getters and Setters below.
 
   get focused() {
     return this.textbox.getAttribute("focused") == "true";
   }