browser/base/content/test/general/browser_urlbarAutoFillTrimURLs.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 // This test ensures that autoFilled values are not trimmed, unless the user
michael@0 6 // selects from the autocomplete popup.
michael@0 7
michael@0 8 function test() {
michael@0 9 waitForExplicitFinish();
michael@0 10
michael@0 11 const PREF_TRIMURL = "browser.urlbar.trimURLs";
michael@0 12 const PREF_AUTOFILL = "browser.urlbar.autoFill";
michael@0 13
michael@0 14 registerCleanupFunction(function () {
michael@0 15 Services.prefs.clearUserPref(PREF_TRIMURL);
michael@0 16 Services.prefs.clearUserPref(PREF_AUTOFILL);
michael@0 17 gURLBar.handleRevert();
michael@0 18 });
michael@0 19 Services.prefs.setBoolPref(PREF_TRIMURL, true);
michael@0 20 Services.prefs.setBoolPref(PREF_AUTOFILL, true);
michael@0 21
michael@0 22 // Adding a tab would hit switch-to-tab, so it's safer to just add a visit.
michael@0 23 let callback = {
michael@0 24 handleError: function () {},
michael@0 25 handleResult: function () {},
michael@0 26 handleCompletion: continue_test
michael@0 27 };
michael@0 28 let history = Cc["@mozilla.org/browser/history;1"]
michael@0 29 .getService(Ci.mozIAsyncHistory);
michael@0 30 history.updatePlaces({ uri: NetUtil.newURI("http://www.autofilltrimurl.com/")
michael@0 31 , visits: [ { transitionType: Ci.nsINavHistoryService.TRANSITION_TYPED
michael@0 32 , visitDate: Date.now() * 1000
michael@0 33 } ]
michael@0 34 }, callback);
michael@0 35 }
michael@0 36
michael@0 37 function continue_test() {
michael@0 38 function test_autoFill(aTyped, aExpected, aCallback) {
michael@0 39 gURLBar.inputField.value = aTyped.substr(0, aTyped.length - 1);
michael@0 40 gURLBar.focus();
michael@0 41 gURLBar.selectionStart = aTyped.length - 1;
michael@0 42 gURLBar.selectionEnd = aTyped.length - 1;
michael@0 43
michael@0 44 EventUtils.synthesizeKey(aTyped.substr(-1), {});
michael@0 45 waitForSearchComplete(function () {
michael@0 46 is(gURLBar.value, aExpected, "trim was applied correctly");
michael@0 47 aCallback();
michael@0 48 });
michael@0 49 }
michael@0 50
michael@0 51 test_autoFill("http://", "http://", function () {
michael@0 52 test_autoFill("http://a", "http://autofilltrimurl.com/", function () {
michael@0 53 test_autoFill("http://www.autofilltrimurl.com", "http://www.autofilltrimurl.com/", function () {
michael@0 54 // Now ensure selecting from the popup correctly trims.
michael@0 55 is(gURLBar.controller.matchCount, 1, "Found the expected number of matches");
michael@0 56 EventUtils.synthesizeKey("VK_DOWN", {});
michael@0 57 is(gURLBar.value, "www.autofilltrimurl.com", "trim was applied correctly");
michael@0 58 gURLBar.closePopup();
michael@0 59 waitForClearHistory(finish);
michael@0 60 });
michael@0 61 });
michael@0 62 });
michael@0 63 }
michael@0 64
michael@0 65 function waitForClearHistory(aCallback) {
michael@0 66 Services.obs.addObserver(function observeCH(aSubject, aTopic, aData) {
michael@0 67 Services.obs.removeObserver(observeCH, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
michael@0 68 aCallback();
michael@0 69 }, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false);
michael@0 70 PlacesUtils.bhistory.removeAllPages();
michael@0 71 }
michael@0 72
michael@0 73 let gOnSearchComplete = null;
michael@0 74 function waitForSearchComplete(aCallback) {
michael@0 75 info("Waiting for onSearchComplete");
michael@0 76 if (!gOnSearchComplete) {
michael@0 77 gOnSearchComplete = gURLBar.onSearchComplete;
michael@0 78 registerCleanupFunction(() => {
michael@0 79 gURLBar.onSearchComplete = gOnSearchComplete;
michael@0 80 });
michael@0 81 }
michael@0 82 gURLBar.onSearchComplete = function () {
michael@0 83 ok(gURLBar.popupOpen, "The autocomplete popup is correctly open");
michael@0 84 gOnSearchComplete.apply(gURLBar);
michael@0 85 aCallback();
michael@0 86 }
michael@0 87 }

mercurial