test_triggeringprincipal_location_seturi.html (3309B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script src="/tests/SimpleTest/SimpleTest.js"></script> 5 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 6 </head> 7 <body> 8 9 <script type="text/javascript"> 10 11 SimpleTest.waitForExplicitFinish(); 12 13 const SAME_ORIGIN_URI = "http://mochi.test:8888/tests/docshell/test/dummy_page.html"; 14 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 15 const CROSS_ORIGIN_URI = "http://example.com/tests/docshell/test/dummy_page.html"; 16 const NUMBER_OF_TESTS = 3; 17 let testCounter = 0; 18 19 function checkFinish() { 20 testCounter++; 21 if (testCounter < NUMBER_OF_TESTS) { 22 return; 23 } 24 SimpleTest.finish(); 25 } 26 27 // ---- test 1 ---- 28 29 let myFrame1 = document.createElement("iframe"); 30 myFrame1.src = SAME_ORIGIN_URI; 31 myFrame1.addEventListener("load", checkLoadFrame1); 32 document.documentElement.appendChild(myFrame1); 33 34 function checkLoadFrame1() { 35 myFrame1.removeEventListener("load", checkLoadFrame1); 36 // window.location.href is no longer cross-origin accessible in gecko. 37 is(SpecialPowers.wrap(myFrame1.contentWindow).location.href, SAME_ORIGIN_URI, 38 "initial same origin dummy loaded into frame1"); 39 40 SpecialPowers.wrap(myFrame1.contentWindow).location.hash = "#bar"; 41 is(SpecialPowers.wrap(myFrame1.contentWindow).location.href, SAME_ORIGIN_URI + "#bar", 42 "initial same origin dummy#bar loaded into iframe1"); 43 44 myFrame1.addEventListener("load", checkNavFrame1); 45 myFrame1.src = CROSS_ORIGIN_URI; 46 } 47 48 async function checkNavFrame1() { 49 myFrame1.removeEventListener("load", checkNavFrame1); 50 is(await SpecialPowers.spawn(myFrame1, [], () => this.content.location.href), 51 CROSS_ORIGIN_URI, 52 "cross origin dummy loaded into frame1"); 53 54 myFrame1.addEventListener("load", checkBackNavFrame1); 55 myFrame1.src = SAME_ORIGIN_URI + "#bar"; 56 } 57 58 async function checkBackNavFrame1() { 59 myFrame1.removeEventListener("load", checkBackNavFrame1); 60 is(await SpecialPowers.spawn(myFrame1, [], () => this.content.location.href), 61 SAME_ORIGIN_URI + "#bar", 62 "navagiating back to same origin dummy for frame1"); 63 checkFinish(); 64 } 65 66 // ---- test 2 ---- 67 68 let myFrame2 = document.createElement("iframe"); 69 myFrame2.src = "about:blank"; 70 myFrame2.addEventListener("load", checkLoadFrame2); 71 document.documentElement.appendChild(myFrame2); 72 73 function checkLoadFrame2() { 74 myFrame2.removeEventListener("load", checkLoadFrame2); 75 is(SpecialPowers.wrap(myFrame2.contentWindow).location.href, "about:blank", 76 "initial about:blank frame loaded"); 77 78 myFrame2.contentWindow.location.hash = "#foo"; 79 is(SpecialPowers.wrap(myFrame2.contentWindow).location.href, "about:blank#foo", 80 "about:blank#foo frame loaded"); 81 82 myFrame2.addEventListener("load", checkHistoryFrame2); 83 myFrame2.src = "about:blank"; 84 } 85 86 function checkHistoryFrame2() { 87 myFrame2.removeEventListener("load", checkHistoryFrame2); 88 is(SpecialPowers.wrap(myFrame2.contentWindow).location.href, "about:blank", 89 "about:blank frame loaded again"); 90 checkFinish(); 91 } 92 93 // ---- test 3 ---- 94 95 let myFrame3 = document.createElement("frame"); 96 document.documentElement.appendChild(myFrame3); 97 myFrame3.contentWindow.location.hash = "#foo"; 98 99 is(myFrame3.contentWindow.location.href, "about:blank#foo", 100 "created history entry with about:blank#foo"); 101 checkFinish(); 102 103 </script> 104 </body> 105 </html>