browser/base/content/test/general/browser_urlbarEnter.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 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 const TEST_VALUE = "example.com/\xF7?\xF7";
     5 const START_VALUE = "example.com/%C3%B7?%C3%B7";
     7 function test() {
     8   waitForExplicitFinish();
     9   runNextTest();
    10 }
    12 function locationBarEnter(aEvent, aClosure) {
    13   executeSoon(function() {
    14     gURLBar.focus();
    15     EventUtils.synthesizeKey("VK_RETURN", aEvent);
    16     addPageShowListener(aClosure);
    17   });
    18 }
    20 function runNextTest() {
    21   let test = gTests.shift();
    22   if (!test) {
    23     finish();
    24     return;
    25   }
    27   info("Running test: " + test.desc);
    28   let tab = gBrowser.selectedTab = gBrowser.addTab(START_VALUE);
    29   addPageShowListener(function() {
    30     locationBarEnter(test.event, function() {
    31       test.check(tab);
    33       // Clean up
    34       while (gBrowser.tabs.length > 1)
    35         gBrowser.removeTab(gBrowser.selectedTab)
    36       runNextTest();
    37     });
    38   });
    39 }
    41 let gTests = [
    42   { desc: "Simple return keypress",
    43     event: {},
    44     check: checkCurrent
    45   },
    47   { desc: "Alt+Return keypress",
    48     event: { altKey: true },
    49     check: checkNewTab,
    50   },
    51 ]
    53 function checkCurrent(aTab) {
    54   is(gURLBar.value, TEST_VALUE, "Urlbar should preserve the value on return keypress");
    55   is(gBrowser.selectedTab, aTab, "New URL was loaded in the current tab");
    56 }
    58 function checkNewTab(aTab) {
    59   is(gURLBar.value, TEST_VALUE, "Urlbar should preserve the value on return keypress");
    60   isnot(gBrowser.selectedTab, aTab, "New URL was loaded in a new tab");
    61 }
    63 function addPageShowListener(aFunc) {
    64   gBrowser.selectedBrowser.addEventListener("pageshow", function loadListener() {
    65     gBrowser.selectedBrowser.removeEventListener("pageshow", loadListener, false);
    66     aFunc();
    67   });
    68 }

mercurial