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.

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

mercurial