| <html> | |
| <head> | |
| <script> | |
| if (window.testRunner) { | |
| if (!sessionStorage.stage) | |
| testRunner.clearBackForwardList(); | |
| testRunner.dumpAsText(); | |
| testRunner.waitUntilDone(); | |
| } | |
| function lastPathComponent() | |
| { | |
| return window.location.href.split('/').pop(); | |
| } | |
| function runFirstStageOfTest() | |
| { | |
| history.replaceState("FirstEntry", null, "?FirstEntry"); | |
| history.pushState("SecondEntry", null, "?SecondEntry"); | |
| history.back(); | |
| } | |
| function runSecondStageOfTest() | |
| { | |
| alert("Last path component of location is " + lastPathComponent()); | |
| } | |
| function runThirdStageOfTest() | |
| { | |
| alert("Final stage of test loaded"); | |
| } | |
| function runTest() | |
| { | |
| if (!sessionStorage.stage) { | |
| // Location changes need to happen outside the onload handler to generate history entries. | |
| setTimeout(runFirstStageOfTest, 0); | |
| } else if (sessionStorage.stage == 2) | |
| runSecondStageOfTest(); | |
| else if (sessionStorage.stage == 3) | |
| runThirdStageOfTest(); | |
| } | |
| var beganTest = false; | |
| function statePopped() | |
| { | |
| // The first time popstate fires, it's because the page has finished loading. | |
| // Only then can we begin the test. | |
| if (!beganTest) { | |
| beganTest = true; | |
| runTest(); | |
| // Continue with the handler if we've already began the test. | |
| if (!sessionStorage.stage) | |
| return; | |
| } | |
| alert("State popped - " + event.state + " (type " + typeof event.state + ")"); | |
| if (event.state == "FirstEntry") { | |
| history.replaceState("FirstEntryWillLaterBeReactivated", null, "?FirstEntryWillLaterBeReactivated"); | |
| history.forward(); | |
| } else if (event.state == "SecondEntry") { | |
| history.replaceState("SecondEntryWillLaterBeReactivated", null, "?SecondEntryWillLaterBeReactivated"); | |
| window.location = "resources/navigate-back.html"; | |
| } else if (event.state == "SecondEntryWillLaterBeReactivated") | |
| history.back(); | |
| else if (event.state == "FirstEntryWillLaterBeReactivated") { | |
| alert("Test complete"); | |
| sessionStorage.clear(); | |
| if (window.testRunner) | |
| testRunner.notifyDone(); | |
| } | |
| } | |
| </script> | |
| <body onpopstate="statePopped();" onunload="/* disable page cache */"> | |
| <pre> | |
| This test: | |
| -Builds up a list of state object entries with fragment URLs. | |
| -Navigates through them to verify that the popstate event is fired. | |
| -Navigates away to a new document, with the old document being destroyed. | |
| -Navigates back to the state object entries and verifies the popstate event is fired even on the new documents. | |
| </pre><br> | |
| <pre id="logger"></pre> | |
| </body> | |
| </html> |