Bug 1470887 - Preserve exactly autofilled values in the urlbar, and don't call losslessDecodeURI on them. r=mak

Differential Revision: https://phabricator.services.mozilla.com/D2256

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Drew Willcoxon 2018-07-20 17:08:29 +00:00
Родитель a59b9489b5
Коммит 7f79160fea
4 изменённых файлов: 122 добавлений и 5 удалений

Просмотреть файл

@ -75,6 +75,7 @@ support-files =
urlbarAddonIframe.js
urlbarAddonIframeContentScript.js
[browser_urlbarAboutHomeLoading.js]
[browser_urlbarAutofillPreserveCase.js]
[browser_urlbarAutoFillTrimURLs.js]
[browser_urlbarCopying.js]
subsuite = clipboard

Просмотреть файл

@ -0,0 +1,74 @@
// This test makes sure that when the user starts typing origins and URLs, the
// case of the user's search string is preserved inside the origin part of the
// autofilled string.
"use strict";
add_task(async function init() {
await cleanUp();
});
add_task(async function origin() {
await PlacesTestUtils.addVisits([{
uri: "http://example.com/",
}]);
await promiseAutocompleteResultPopup("ExA");
await waitForAutocompleteResultAt(0);
Assert.equal(gURLBar.value, "ExAmple.com/");
await cleanUp();
});
add_task(async function originPort() {
await PlacesTestUtils.addVisits([{
uri: "http://example.com:8888/",
}]);
await promiseAutocompleteResultPopup("ExA");
await waitForAutocompleteResultAt(0);
Assert.equal(gURLBar.value, "ExAmple.com:8888/");
await cleanUp();
});
add_task(async function originScheme() {
await PlacesTestUtils.addVisits([{
uri: "http://example.com/",
}]);
await promiseAutocompleteResultPopup("http://ExA");
await waitForAutocompleteResultAt(0);
Assert.equal(gURLBar.value, "http://ExAmple.com/");
await cleanUp();
});
add_task(async function originPortScheme() {
await PlacesTestUtils.addVisits([{
uri: "http://example.com:8888/",
}]);
await promiseAutocompleteResultPopup("http://ExA");
await waitForAutocompleteResultAt(0);
Assert.equal(gURLBar.value, "http://ExAmple.com:8888/");
await cleanUp();
});
add_task(async function url() {
await PlacesTestUtils.addVisits([{
uri: "http://example.com/foo",
}]);
await promiseAutocompleteResultPopup("ExAmple.com/f");
Assert.equal(gURLBar.value, "ExAmple.com/foo");
await cleanUp();
});
add_task(async function urlPort() {
await PlacesTestUtils.addVisits([{
uri: "http://example.com:8888/foo",
}]);
await promiseAutocompleteResultPopup("ExAmple.com:8888/f");
Assert.equal(gURLBar.value, "ExAmple.com:8888/foo");
await cleanUp();
});
async function cleanUp() {
EventUtils.synthesizeKey("KEY_Escape");
await promisePopupHidden(gURLBar.popup);
await PlacesUtils.bookmarks.eraseEverything();
await PlacesUtils.history.clear();
}

Просмотреть файл

@ -81,6 +81,45 @@ add_task(async function portPartial() {
await cleanup();
});
// "EXaM" should match http://example.com/ and the case of the search string
// should be preserved in the autofilled value.
add_task(async function preserveCase() {
await PlacesTestUtils.addVisits([{
uri: "http://example.com/",
}]);
await check_autocomplete({
search: "EXaM",
autofilled: "EXaMple.com/",
completed: "http://example.com/",
matches: [{
value: "example.com/",
comment: "example.com",
style: ["autofill", "heuristic"],
}],
});
await cleanup();
});
// "EXaM" should match http://example.com:8888/, the port should be completed,
// and the case of the search string should be preserved in the autofilled
// value.
add_task(async function preserveCasePort() {
await PlacesTestUtils.addVisits([{
uri: "http://example.com:8888/",
}]);
await check_autocomplete({
search: "EXaM",
autofilled: "EXaMple.com:8888/",
completed: "http://example.com:8888/",
matches: [{
value: "example.com:8888/",
comment: "example.com:8888",
style: ["autofill", "heuristic"],
}],
});
await cleanup();
});
// "example.com:89" should *not* match http://example.com:8888/.
add_task(async function portNoMatch1() {
await PlacesTestUtils.addVisits([{

Просмотреть файл

@ -173,10 +173,10 @@
<body><![CDATA[
if (aReason == Ci.nsIAutoCompleteInput
.TEXTVALUE_REASON_COMPLETEDEFAULT) {
this._disableTrim = true;
this._textValueSetByCompleteDefault = true;
}
this.textValue = aValue;
this._disableTrim = false;
this._textValueSetByCompleteDefault = false;
]]></body>
</method>
@ -191,8 +191,10 @@
return this.value;
]]></getter>
<setter><![CDATA[
if (typeof this.onBeforeTextValueSet == "function")
if (typeof this.onBeforeTextValueSet == "function" &&
!this._textValueSetByCompleteDefault) {
val = this.onBeforeTextValueSet(val);
}
this.value = val;
@ -283,7 +285,7 @@
<!-- =================== PUBLIC MEMBERS =================== -->
<field name="valueIsTyped">false</field>
<field name="_disableTrim">false</field>
<field name="_textValueSetByCompleteDefault">false</field>
<property name="value">
<getter><![CDATA[
if (typeof this.onBeforeValueGet == "function") {
@ -299,7 +301,8 @@
if (typeof this.onBeforeValueSet == "function")
val = this.onBeforeValueSet(val);
if (typeof this.trimValue == "function" && !this._disableTrim)
if (typeof this.trimValue == "function" &&
!this._textValueSetByCompleteDefault)
val = this.trimValue(val);
this.valueIsTyped = false;