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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dão Gottwald 2018-10-26 09:52:23 +00:00
parent ab99750db5
commit 5a62defc27
4 changed files with 26 additions and 14 deletions

View File

@ -33,14 +33,8 @@ add_task(async function checkCtrlWorks() {
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;
}

View File

@ -5,6 +5,11 @@
// 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',
@ -27,7 +32,12 @@ add_task(async function injectJSON() {
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");

View File

@ -109,8 +109,9 @@ add_task(async function test_webnavigation_urlbar_typed_transitions() {
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");

View File

@ -230,7 +230,16 @@ class UrlbarInput {
* @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 {
@ -240,8 +249,6 @@ class UrlbarInput {
val = this.window.losslessDecodeURI(uri);
}
this.value = val;
this.controller.resultSelected(event, result);
}
// Getters and Setters below.