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();
19 return url
.substring(url
.lastIndexOf('#'));
22 function runFirstStageOfTest()
24 history
.replaceState("FirstEntry", null, "#FirstEntry");
25 history
.pushState("SecondEntry", null, "#SecondEntry");
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
45 setTimeout(function() {
46 if (state
== "FirstEntry") {
47 history
.replaceState("FirstEntryWillLaterBeReactivated", null, "#FirstEntryWillLaterBeReactivated");
49 } else if (state
== "SecondEntry") {
50 history
.replaceState("SecondEntryWillLaterBeReactivated", null, "#SecondEntryWillLaterBeReactivated");
51 window
.location
= "resources/navigate-back.html";
52 } else if (state
== "SecondEntryWillLaterBeReactivated")
57 window
.onpopstate
= function statePopped()
59 var state
= event
.state
;
60 alert("State popped - " + state
+ " (type " + typeof state
+ ")");
64 window
.onpageshow
= function pageShown()
66 if (sessionStorage
.stage
== 2) {
67 var state
= history
.state
;
68 alert("Page shown - " + state
+ " (type " + typeof 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();
85 <body onload=
"runTest();" onunload=
"/* disable page cache */">
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.