test_triggeringprincipal_window_open.html (2710B)
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> 10 11 <script type="text/javascript"> 12 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:) 17 */ 18 19 const TRIGGERING_PRINCIPAL_URI = 20 "http://mochi.test:8888/tests/docshell/test/navigation/test_triggeringprincipal_window_open.html"; 21 22 SimpleTest.waitForExplicitFinish(); 23 24 const NUM_TESTS = 2; 25 var test_counter = 0; 26 27 function checkFinish() { 28 test_counter++; 29 if (test_counter === NUM_TESTS) { 30 SimpleTest.finish(); 31 } 32 } 33 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; 41 42 is(httpTriggeringPrincipal.split("?")[0], TRIGGERING_PRINCIPAL_URI, 43 "TriggeringPrincipal for window.open(http:) should be the principal of the document"); 44 45 is(httpWin.document.referrer.split("?")[0], TRIGGERING_PRINCIPAL_URI, 46 "Referrer for window.open(http:) should be the principal of the document"); 47 48 is(httpLoadingPrincipal, null, 49 "LoadingPrincipal for window.open(http:) should be null"); 50 51 httpWin.close(); 52 checkFinish(); 53 }; 54 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; 62 63 is(jsTriggeringPrincipal.split("?")[0], TRIGGERING_PRINCIPAL_URI, 64 "TriggeringPrincipal for window.open(javascript:) should be the principal of the document"); 65 66 is(jsWin.document.referrer, "", 67 "Referrer for window.open(javascript:) should be empty"); 68 69 is(jsLoadingPrincipal, null, 70 "LoadingPrincipal for window.open(javascript:) should be null"); 71 72 jsWin.close(); 73 checkFinish(); 74 }; 75 76 </script> 77 </pre> 78 </body> 79 </html>