mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 711503 - Don't trim url when inline autocomplete inserts text.
r=gavin
This commit is contained in:
parent
e25a415af3
commit
c1a836106d
@ -214,6 +214,7 @@ _BROWSER_FILES = \
|
||||
browser_tabfocus.js \
|
||||
browser_tabs_isActive.js \
|
||||
browser_tabs_owner.js \
|
||||
browser_urlbarAutoFillTrimURLs.js \
|
||||
browser_urlbarCopying.js \
|
||||
browser_urlbarEnter.js \
|
||||
browser_urlbarTrimURLs.js \
|
||||
|
85
browser/base/content/test/browser_urlbarAutoFillTrimURLs.js
Normal file
85
browser/base/content/test/browser_urlbarAutoFillTrimURLs.js
Normal file
@ -0,0 +1,85 @@
|
||||
/* This Source Code is subject to the terms of the Mozilla Public License
|
||||
* version 2.0 (the "License"). You can obtain a copy of the License at
|
||||
* http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// This test ensures that autoFilled values are not trimmed, unless the user
|
||||
// selects from the autocomplete popup.
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
const PREF_TRIMURL = "browser.urlbar.trimURLs";
|
||||
const PREF_AUTOFILL = "browser.urlbar.autoFill";
|
||||
|
||||
registerCleanupFunction(function () {
|
||||
Services.prefs.clearUserPref(PREF_TRIMURL);
|
||||
Services.prefs.clearUserPref(PREF_AUTOFILL);
|
||||
URLBarSetURI();
|
||||
});
|
||||
Services.prefs.setBoolPref(PREF_TRIMURL, true);
|
||||
Services.prefs.setBoolPref(PREF_AUTOFILL, true);
|
||||
|
||||
// Adding a tab would hit switch-to-tab, so it's safer to just add a visit.
|
||||
let callback = {
|
||||
handleError: function () {},
|
||||
handleResult: function () {},
|
||||
handleCompletion: continue_test
|
||||
};
|
||||
let history = Cc["@mozilla.org/browser/history;1"]
|
||||
.getService(Ci.mozIAsyncHistory);
|
||||
history.updatePlaces({ uri: NetUtil.newURI("http://www.autofilltrimurl.com/")
|
||||
, visits: [ { transitionType: Ci.nsINavHistoryService.TRANSITION_TYPED
|
||||
, visitDate: Date.now() * 1000
|
||||
} ]
|
||||
}, callback);
|
||||
}
|
||||
|
||||
function continue_test() {
|
||||
function test_autoFill(aTyped, aExpected, aCallback) {
|
||||
gURLBar.inputField.value = aTyped.substr(0, aTyped.length - 1);
|
||||
gURLBar.focus();
|
||||
gURLBar.selectionStart = aTyped.length - 1;
|
||||
gURLBar.selectionEnd = aTyped.length - 1;
|
||||
|
||||
EventUtils.synthesizeKey(aTyped.substr(-1), {});
|
||||
is(gURLBar.value, aExpected, "trim was applied correctly");
|
||||
|
||||
aCallback();
|
||||
}
|
||||
|
||||
test_autoFill("http://", "http://", function () {
|
||||
test_autoFill("http://a", "http://autofilltrimurl.com/", function () {
|
||||
test_autoFill("http://www.autofilltrimurl.com", "http://www.autofilltrimurl.com/", function () {
|
||||
// Now ensure selecting from the popup correctly trims.
|
||||
waitForSearchComplete(function () {
|
||||
EventUtils.synthesizeKey("VK_DOWN", {});
|
||||
is(gURLBar.value, "www.autofilltrimurl.com", "trim was applied correctly");
|
||||
gURLBar.closePopup();
|
||||
waitForClearHistory(finish);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function waitForClearHistory(aCallback) {
|
||||
Services.obs.addObserver(function observeCH(aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(observeCH, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
|
||||
aCallback();
|
||||
}, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false);
|
||||
PlacesUtils.bhistory.removeAllPages();
|
||||
}
|
||||
|
||||
function waitForSearchComplete(aCallback) {
|
||||
info("Waiting for onSearchComplete");
|
||||
let onSearchComplete = gURLBar.onSearchComplete;
|
||||
registerCleanupFunction(function () {
|
||||
gURLBar.onSearchComplete = onSearchComplete;
|
||||
});
|
||||
gURLBar.onSearchComplete = function () {
|
||||
ok(gURLBar.popupOpen, "The autocomplete popup is correctly open");
|
||||
is(gURLBar.controller.matchCount, 1, "Found the expected number of matches")
|
||||
onSearchComplete.apply(gURLBar);
|
||||
aCallback();
|
||||
}
|
||||
}
|
@ -667,7 +667,13 @@
|
||||
try {
|
||||
val = losslessDecodeURI(makeURI(val));
|
||||
} catch (ex) { }
|
||||
|
||||
// Trim popup selected values, but never trim results coming from
|
||||
// autofill.
|
||||
if (this.popup.selectedIndex == -1)
|
||||
this._disableTrim = true;
|
||||
this.value = val;
|
||||
this._disableTrim = false;
|
||||
|
||||
// Completing a result should simulate the user typing the result, so
|
||||
// fire an input event.
|
||||
|
@ -195,7 +195,13 @@
|
||||
<setter><![CDATA[
|
||||
// Completing a result should simulate the user typing the result,
|
||||
// so fire an input event.
|
||||
// Trim popup selected values, but never trim results coming from
|
||||
// autofill.
|
||||
if (this.popup.selectedIndex == -1)
|
||||
this._disableTrim = true;
|
||||
this.value = val;
|
||||
this._disableTrim = false;
|
||||
|
||||
var evt = document.createEvent("UIEvents");
|
||||
evt.initUIEvent("input", true, false, window, 0);
|
||||
this.mIgnoreInput = true;
|
||||
@ -266,6 +272,7 @@
|
||||
<!-- =================== PUBLIC MEMBERS =================== -->
|
||||
|
||||
<field name="valueIsTyped">false</field>
|
||||
<field name="_disableTrim">false</field>
|
||||
<property name="value">
|
||||
<getter><![CDATA[
|
||||
if (typeof this.onBeforeValueGet == "function") {
|
||||
@ -281,7 +288,7 @@
|
||||
if (typeof this.onBeforeValueSet == "function")
|
||||
val = this.onBeforeValueSet(val);
|
||||
|
||||
if (typeof this.trimValue == "function")
|
||||
if (typeof this.trimValue == "function" && !this._disableTrim)
|
||||
val = this.trimValue(val);
|
||||
|
||||
this.valueIsTyped = false;
|
||||
|
Loading…
Reference in New Issue
Block a user