1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_urlbarEnter.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,69 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +const TEST_VALUE = "example.com/\xF7?\xF7"; 1.8 +const START_VALUE = "example.com/%C3%B7?%C3%B7"; 1.9 + 1.10 +function test() { 1.11 + waitForExplicitFinish(); 1.12 + runNextTest(); 1.13 +} 1.14 + 1.15 +function locationBarEnter(aEvent, aClosure) { 1.16 + executeSoon(function() { 1.17 + gURLBar.focus(); 1.18 + EventUtils.synthesizeKey("VK_RETURN", aEvent); 1.19 + addPageShowListener(aClosure); 1.20 + }); 1.21 +} 1.22 + 1.23 +function runNextTest() { 1.24 + let test = gTests.shift(); 1.25 + if (!test) { 1.26 + finish(); 1.27 + return; 1.28 + } 1.29 + 1.30 + info("Running test: " + test.desc); 1.31 + let tab = gBrowser.selectedTab = gBrowser.addTab(START_VALUE); 1.32 + addPageShowListener(function() { 1.33 + locationBarEnter(test.event, function() { 1.34 + test.check(tab); 1.35 + 1.36 + // Clean up 1.37 + while (gBrowser.tabs.length > 1) 1.38 + gBrowser.removeTab(gBrowser.selectedTab) 1.39 + runNextTest(); 1.40 + }); 1.41 + }); 1.42 +} 1.43 + 1.44 +let gTests = [ 1.45 + { desc: "Simple return keypress", 1.46 + event: {}, 1.47 + check: checkCurrent 1.48 + }, 1.49 + 1.50 + { desc: "Alt+Return keypress", 1.51 + event: { altKey: true }, 1.52 + check: checkNewTab, 1.53 + }, 1.54 +] 1.55 + 1.56 +function checkCurrent(aTab) { 1.57 + is(gURLBar.value, TEST_VALUE, "Urlbar should preserve the value on return keypress"); 1.58 + is(gBrowser.selectedTab, aTab, "New URL was loaded in the current tab"); 1.59 +} 1.60 + 1.61 +function checkNewTab(aTab) { 1.62 + is(gURLBar.value, TEST_VALUE, "Urlbar should preserve the value on return keypress"); 1.63 + isnot(gBrowser.selectedTab, aTab, "New URL was loaded in a new tab"); 1.64 +} 1.65 + 1.66 +function addPageShowListener(aFunc) { 1.67 + gBrowser.selectedBrowser.addEventListener("pageshow", function loadListener() { 1.68 + gBrowser.selectedBrowser.removeEventListener("pageshow", loadListener, false); 1.69 + aFunc(); 1.70 + }); 1.71 +} 1.72 +