|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 const TEST_VALUE = "example.com/\xF7?\xF7"; |
|
5 const START_VALUE = "example.com/%C3%B7?%C3%B7"; |
|
6 |
|
7 function test() { |
|
8 waitForExplicitFinish(); |
|
9 runNextTest(); |
|
10 } |
|
11 |
|
12 function locationBarEnter(aEvent, aClosure) { |
|
13 executeSoon(function() { |
|
14 gURLBar.focus(); |
|
15 EventUtils.synthesizeKey("VK_RETURN", aEvent); |
|
16 addPageShowListener(aClosure); |
|
17 }); |
|
18 } |
|
19 |
|
20 function runNextTest() { |
|
21 let test = gTests.shift(); |
|
22 if (!test) { |
|
23 finish(); |
|
24 return; |
|
25 } |
|
26 |
|
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); |
|
32 |
|
33 // Clean up |
|
34 while (gBrowser.tabs.length > 1) |
|
35 gBrowser.removeTab(gBrowser.selectedTab) |
|
36 runNextTest(); |
|
37 }); |
|
38 }); |
|
39 } |
|
40 |
|
41 let gTests = [ |
|
42 { desc: "Simple return keypress", |
|
43 event: {}, |
|
44 check: checkCurrent |
|
45 }, |
|
46 |
|
47 { desc: "Alt+Return keypress", |
|
48 event: { altKey: true }, |
|
49 check: checkNewTab, |
|
50 }, |
|
51 ] |
|
52 |
|
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 } |
|
57 |
|
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 } |
|
62 |
|
63 function addPageShowListener(aFunc) { |
|
64 gBrowser.selectedBrowser.addEventListener("pageshow", function loadListener() { |
|
65 gBrowser.selectedBrowser.removeEventListener("pageshow", loadListener, false); |
|
66 aFunc(); |
|
67 }); |
|
68 } |
|
69 |