historyframes.html (4448B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=602256 5 --> 6 <head> 7 <title>Test for Bug 602256</title> 8 </head> 9 <body onload="SimpleTest.executeSoon(run_test)"> 10 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=602256">Mozilla Bug 602256</a> 11 <div id="content"> 12 <iframe id="iframe" src="start_historyframe.html"></iframe> 13 </div> 14 <pre id="test"> 15 <script type="application/javascript"> 16 17 /** Test for Bug 602256 */ 18 19 var testWin = window.opener ? window.opener : window.parent; 20 21 var SimpleTest = testWin.SimpleTest; 22 function is() { testWin.is.apply(testWin, arguments); } 23 24 var gFrame = null; 25 26 var gState = null; 27 28 window.addEventListener("popstate", function(aEvent) { 29 gState = aEvent.state; 30 }); 31 32 function waitForLoad() { 33 function listener() { 34 gFrame.removeEventListener("load", listener); 35 SimpleTest.executeSoon(continue_test); 36 } 37 38 gFrame.addEventListener("load", listener); 39 } 40 41 function loadContent(aURL) { 42 waitForLoad(); 43 44 gFrame.src = aURL; 45 } 46 47 function getURL() { 48 return gFrame.contentDocument.documentURI; 49 } 50 51 function getContent() { 52 return gFrame.contentDocument.getElementById("text").textContent; 53 } 54 55 var BASE_URI = "http://mochi.test:8888/tests/dom/tests/mochitest/general/"; 56 var START = BASE_URI + "start_historyframe.html"; 57 var URL1 = BASE_URI + "url1_historyframe.html"; 58 var URL2 = BASE_URI + "url2_historyframe.html"; 59 60 function run_test() { 61 window.history.pushState("START", window.location); 62 63 gFrame = document.getElementById("iframe"); 64 65 continue_test(); 66 } 67 68 function* test_body() 69 { 70 yield* test_basic_inner_navigation(); 71 yield* test_state_navigation(); 72 } 73 74 var gTestContinuation = null; 75 76 function continue_test() { 77 if (!gTestContinuation) { 78 gTestContinuation = test_body(); 79 } 80 var ret = gTestContinuation.next(); 81 if (ret.done) { 82 testWin.done(); 83 } 84 } 85 86 var gTestContinuation = null; 87 function continueAsync() { 88 setTimeout(function() { gTestContinuation.next(); }) 89 } 90 91 function continueOnPopState() { 92 // Use continueAsync to avoid recursion within sync popstate listener. 93 window.addEventListener("popstate", continueAsync, { once: true }); 94 } 95 96 function* test_basic_inner_navigation() { 97 // Navigate the inner frame a few times 98 yield loadContent(URL1); 99 is(getURL(), URL1, "URL should be correct"); 100 is(getContent(), "Test1", "Page should be correct"); 101 102 yield loadContent(URL2); 103 104 is(getURL(), URL2, "URL should be correct"); 105 is(getContent(), "Test2", "Page should be correct"); 106 107 // Test that history is working 108 window.history.back(); 109 yield waitForLoad(); 110 is(getURL(), URL1, "URL should be correct"); 111 is(getContent(), "Test1", "Page should be correct"); 112 113 window.history.forward(); 114 yield waitForLoad(); 115 is(getURL(), URL2, "URL should be correct"); 116 is(getContent(), "Test2", "Page should be correct"); 117 } 118 119 function* test_state_navigation() { 120 window.history.pushState("STATE1", window.location); 121 122 is(getURL(), URL2, "URL should be correct"); 123 is(getContent(), "Test2", "Page should be correct"); 124 125 window.history.pushState("STATE2", window.location); 126 127 is(getURL(), URL2, "URL should be correct"); 128 is(getContent(), "Test2", "Page should be correct"); 129 130 window.history.back(); 131 continueOnPopState(); 132 yield; 133 134 is(gState, "STATE1", "State should be correct"); 135 is(getURL(), URL2, "URL should be correct"); 136 is(getContent(), "Test2", "Page should be correct"); 137 138 window.history.forward(); 139 continueOnPopState(); 140 yield; 141 142 is(gState, "STATE2", "State should be correct"); 143 is(getURL(), URL2, "URL should be correct"); 144 is(getContent(), "Test2", "Page should be correct"); 145 146 window.history.back(); 147 continueOnPopState(); 148 yield; 149 window.history.back(); 150 continueOnPopState(); 151 yield; 152 153 is(gState, "START", "State should be correct"); 154 is(getURL(), URL2, "URL should be correct"); 155 is(getContent(), "Test2", "Page should be correct"); 156 157 window.history.back(); 158 continueAsync(); 159 yield; 160 is(gState, "START", "State should be correct"); 161 yield waitForLoad(); 162 163 is(getURL(), URL1, "URL should be correct"); 164 is(getContent(), "Test1", "Page should be correct"); 165 166 window.history.back(); 167 continueAsync(); 168 yield; 169 is(gState, "START", "State should be correct after going back twice"); 170 yield waitForLoad(); 171 172 is(gState, "START", "State should be correct"); 173 is(getURL(), START, "URL should be correct"); 174 is(getContent(), "Start", "Page should be correct"); 175 } 176 </script> 177 </pre> 178 </body> 179 </html>