Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / loader / stateobjects / document-destroyed-navigate-back-with-fragment-scroll.html
blob0a533a812417a7e0766ea5f2d5cb58b9c30d646d
1 <html>
2 <head>
3 <script>
5 if (window.testRunner) {
6 if (!sessionStorage.stage)
7 testRunner.clearBackForwardList();
8 testRunner.dumpAsText();
9 testRunner.waitUntilDone();
12 function lastPathComponent(url)
14 return url.split('/').pop();
17 function hashOf(url)
19 return url.substring(url.lastIndexOf('#'));
22 function runFirstStageOfTest()
24 history.replaceState("FirstEntry", null, "#FirstEntry");
25 history.pushState("SecondEntry", null, "#SecondEntry");
26 history.back();
29 function runTest()
31 alert("LOADED");
32 if (!sessionStorage.stage)
33 runFirstStageOfTest();
36 function continueTest(state)
38 // FIXME: Once the popstate and hashchange events fire asynchronously, we
39 // can eliminate this setTimeout hack. The hashchange event currently runs
40 // synchronously following the popstate event, but the calls to
41 // replaceState cause the location to change immediately. That confuses
42 // our hashchange handler, which expects to see the "old" value of the
43 // location.
45 setTimeout(function() {
46 if (state == "FirstEntry") {
47 history.replaceState("FirstEntryWillLaterBeReactivated", null, "#FirstEntryWillLaterBeReactivated");
48 history.forward();
49 } else if (state == "SecondEntry") {
50 history.replaceState("SecondEntryWillLaterBeReactivated", null, "#SecondEntryWillLaterBeReactivated");
51 window.location = "resources/navigate-back.html";
52 } else if (state == "SecondEntryWillLaterBeReactivated")
53 history.back();
54 }, 0);
57 window.onpopstate = function statePopped()
59 var state = event.state;
60 alert("State popped - " + state + " (type " + typeof state + ")");
61 continueTest(state);
64 window.onpageshow = function pageShown()
66 if (sessionStorage.stage == 2) {
67 var state = history.state;
68 alert("Page shown - " + state + " (type " + typeof state + ")");
69 continueTest(state);
73 window.onhashchange = function hashChanged(event)
75 alert("hashChanged - Last path component of location is " + lastPathComponent(event.newURL));
76 if (hashOf(event.newURL) == "#FirstEntryWillLaterBeReactivated") {
77 alert("Test complete");
78 sessionStorage.clear();
79 if (window.testRunner)
80 testRunner.notifyDone();
84 </script>
85 <body onload="runTest();" onunload="/* disable page cache */">
86 <pre>
87 This test:
88 -Builds up a list of state object entries with fragment URLs.
89 -Navigates through them to verify that the popstate and hashchanged events are fired.
90 -Navigates away to a new document, with the old document being destroyed.
91 -Navigates back to the state object entries and verifies the pageshow or popstate events are fired on the new documents.
92 </pre>
93 </body>
94 </html>