|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 waitForExplicitFinish(); |
|
6 |
|
7 nextTest(); |
|
8 } |
|
9 |
|
10 let urls = [ |
|
11 "javascript:'foopy';", |
|
12 "data:text/html,<body>hi" |
|
13 ]; |
|
14 |
|
15 function urlEnter(url) { |
|
16 gURLBar.value = url; |
|
17 gURLBar.focus(); |
|
18 EventUtils.synthesizeKey("VK_RETURN", {}); |
|
19 } |
|
20 |
|
21 function urlClick(url) { |
|
22 gURLBar.value = url; |
|
23 gURLBar.focus(); |
|
24 let goButton = document.getElementById("urlbar-go-button"); |
|
25 EventUtils.synthesizeMouseAtCenter(goButton, {}); |
|
26 } |
|
27 |
|
28 function nextTest() { |
|
29 let url = urls.shift(); |
|
30 if (url) { |
|
31 testURL(url, urlEnter, function () { |
|
32 testURL(url, urlClick, nextTest); |
|
33 }); |
|
34 } |
|
35 else |
|
36 finish(); |
|
37 } |
|
38 |
|
39 function testURL(url, loadFunc, endFunc) { |
|
40 let tab = gBrowser.selectedTab = gBrowser.addTab(); |
|
41 registerCleanupFunction(function () { |
|
42 gBrowser.removeTab(tab); |
|
43 }); |
|
44 addPageShowListener(function () { |
|
45 let pagePrincipal = gBrowser.contentPrincipal; |
|
46 loadFunc(url); |
|
47 |
|
48 addPageShowListener(function () { |
|
49 let fm = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager); |
|
50 is(fm.focusedElement, null, "should be no focused element"); |
|
51 is(fm.focusedWindow, gBrowser.contentWindow, "content window should be focused"); |
|
52 |
|
53 ok(!gBrowser.contentPrincipal.equals(pagePrincipal), |
|
54 "load of " + url + " by " + loadFunc.name + " should produce a page with a different principal"); |
|
55 endFunc(); |
|
56 }); |
|
57 }); |
|
58 } |
|
59 |
|
60 function addPageShowListener(func) { |
|
61 gBrowser.selectedBrowser.addEventListener("pageshow", function loadListener() { |
|
62 gBrowser.selectedBrowser.removeEventListener("pageshow", loadListener, false); |
|
63 func(); |
|
64 }); |
|
65 } |