no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / docshell / test / navigation / test_triggeringprincipal_window_open.html
blob439a125f9769a4946dfa1bb0f96da636cf1a8cc5
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="/tests/SimpleTest/SimpleTest.js"></script>
5 <script src="/tests/SimpleTest/EventUtils.js"></script>
6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
7 <script type="text/javascript" src="NavigationUtils.js"></script>
8 </head>
9 <body>
11 <script type="text/javascript">
13 /* We call window.open() using different URIs and make sure the triggeringPrincipal
14 * loadingPrincipal are correct.
15 * Test1: window.open(http:)
16 * Test2: window.open(javascript:)
19 const TRIGGERING_PRINCIPAL_URI =
20 "http://mochi.test:8888/tests/docshell/test/navigation/test_triggeringprincipal_window_open.html";
22 SimpleTest.waitForExplicitFinish();
24 const NUM_TESTS = 2;
25 var test_counter = 0;
27 function checkFinish() {
28 test_counter++;
29 if (test_counter === NUM_TESTS) {
30 SimpleTest.finish();
34 // ----------------------------------------------------------------------------
35 // Test 1: window.open(http:)
36 var httpWin = window.open("file_triggeringprincipal_window_open.html", "_blank", "width=10,height=10");
37 httpWin.onload = function() {
38 var httpChannel = SpecialPowers.wrap(httpWin).docShell.currentDocumentChannel;
39 var httpTriggeringPrincipal = httpChannel.loadInfo.triggeringPrincipal.asciiSpec;
40 var httpLoadingPrincipal = httpChannel.loadInfo.loadingPrincipal;
42 is(httpTriggeringPrincipal.split("?")[0], TRIGGERING_PRINCIPAL_URI,
43 "TriggeringPrincipal for window.open(http:) should be the principal of the document");
45 is(httpWin.document.referrer.split("?")[0], TRIGGERING_PRINCIPAL_URI,
46 "Referrer for window.open(http:) should be the principal of the document");
48 is(httpLoadingPrincipal, null,
49 "LoadingPrincipal for window.open(http:) should be null");
51 httpWin.close();
52 checkFinish();
55 // ----------------------------------------------------------------------------
56 // Test 2: window.open(javascript:)
57 var jsWin = window.open("javascript:'<html><body>js</body></html>';", "_blank", "width=10,height=10");
58 jsWin.onload = function() {
59 var jsChannel = SpecialPowers.wrap(jsWin).docShell.currentDocumentChannel;
60 var jsTriggeringPrincipal = jsChannel.loadInfo.triggeringPrincipal.asciiSpec;
61 var jsLoadingPrincipal = jsChannel.loadInfo.loadingPrincipal;
63 is(jsTriggeringPrincipal.split("?")[0], TRIGGERING_PRINCIPAL_URI,
64 "TriggeringPrincipal for window.open(javascript:) should be the principal of the document");
66 is(jsWin.document.referrer, "",
67 "Referrer for window.open(javascript:) should be empty");
69 is(jsLoadingPrincipal, null,
70 "LoadingPrincipal for window.open(javascript:) should be null");
72 jsWin.close();
73 checkFinish();
76 </script>
77 </pre>
78 </body>
79 </html>