OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script> | 3 <script> |
4 | 4 |
5 if (window.testRunner) { | 5 if (window.testRunner) { |
6 if (!sessionStorage.stage) | 6 if (!sessionStorage.stage) |
7 testRunner.clearBackForwardList(); | 7 testRunner.clearBackForwardList(); |
8 testRunner.dumpAsText(); | 8 testRunner.dumpAsText(); |
9 testRunner.waitUntilDone(); | 9 testRunner.waitUntilDone(); |
10 } | 10 } |
(...skipping 15 matching lines...) Expand all Loading... |
26 history.back(); | 26 history.back(); |
27 } | 27 } |
28 | 28 |
29 function runTest() | 29 function runTest() |
30 { | 30 { |
31 alert("LOADED"); | 31 alert("LOADED"); |
32 if (!sessionStorage.stage) | 32 if (!sessionStorage.stage) |
33 runFirstStageOfTest(); | 33 runFirstStageOfTest(); |
34 } | 34 } |
35 | 35 |
36 onpopstate = function() | 36 function continueTest(state) |
37 { | 37 { |
38 alert("State popped - " + event.state + " (type " + typeof event.state + ")"
); | |
39 | |
40 // FIXME: Once the popstate and hashchange events fire asynchronously, we | 38 // FIXME: Once the popstate and hashchange events fire asynchronously, we |
41 // can eliminate this setTimeout hack. The hashchange event currently runs | 39 // can eliminate this setTimeout hack. The hashchange event currently runs |
42 // synchronously following the popstate event, but the calls to | 40 // synchronously following the popstate event, but the calls to |
43 // replaceState cause the location to change immediately. That confuses | 41 // replaceState cause the location to change immediately. That confuses |
44 // our hashchange handler, which expects to see the "old" value of the | 42 // our hashchange handler, which expects to see the "old" value of the |
45 // location. | 43 // location. |
46 | 44 |
47 var state = event.state; | |
48 setTimeout(function() { | 45 setTimeout(function() { |
49 if (state == "FirstEntry") { | 46 if (state == "FirstEntry") { |
50 history.replaceState("FirstEntryWillLaterBeReactivated", null, "#Fir
stEntryWillLaterBeReactivated"); | 47 history.replaceState("FirstEntryWillLaterBeReactivated", null, "#Fir
stEntryWillLaterBeReactivated"); |
51 history.forward(); | 48 history.forward(); |
52 } else if (state == "SecondEntry") { | 49 } else if (state == "SecondEntry") { |
53 history.replaceState("SecondEntryWillLaterBeReactivated", null, "#Se
condEntryWillLaterBeReactivated"); | 50 history.replaceState("SecondEntryWillLaterBeReactivated", null, "#Se
condEntryWillLaterBeReactivated"); |
54 window.location = "resources/navigate-back.html"; | 51 window.location = "resources/navigate-back.html"; |
55 } else if (state == "SecondEntryWillLaterBeReactivated") | 52 } else if (state == "SecondEntryWillLaterBeReactivated") |
56 history.back(); | 53 history.back(); |
57 }, 0); | 54 }, 0); |
58 } | 55 } |
59 | 56 |
60 onhashchange = function(event) | 57 window.onpopstate = function statePopped() |
| 58 { |
| 59 var state = event.state; |
| 60 alert("State popped - " + state + " (type " + typeof state + ")"); |
| 61 continueTest(state); |
| 62 } |
| 63 |
| 64 window.onpageshow = function pageShown() |
| 65 { |
| 66 if (sessionStorage.stage == 2) { |
| 67 var state = history.state; |
| 68 alert("Page shown - " + state + " (type " + typeof state + ")"); |
| 69 continueTest(state); |
| 70 } |
| 71 } |
| 72 |
| 73 window.onhashchange = function hashChanged(event) |
61 { | 74 { |
62 alert("hashChanged - Last path component of location is " + lastPathComponent
(event.newURL)); | 75 alert("hashChanged - Last path component of location is " + lastPathComponent
(event.newURL)); |
63 if (hashOf(event.newURL) == "#FirstEntryWillLaterBeReactivated") { | 76 if (hashOf(event.newURL) == "#FirstEntryWillLaterBeReactivated") { |
64 alert("Test complete"); | 77 alert("Test complete"); |
65 sessionStorage.clear(); | 78 sessionStorage.clear(); |
66 if (window.testRunner) | 79 if (window.testRunner) |
67 testRunner.notifyDone(); | 80 testRunner.notifyDone(); |
68 } | 81 } |
69 } | 82 } |
70 | 83 |
71 </script> | 84 </script> |
72 <body onload="runTest();" onunload="/* disable page cache */"> | 85 <body onload="runTest();" onunload="/* disable page cache */"> |
73 <pre> | 86 <pre> |
74 This test: | 87 This test: |
75 -Builds up a list of state object entries with fragment URLs. | 88 -Builds up a list of state object entries with fragment URLs. |
76 -Navigates through them to verify that the popstate and hashchanged events are f
ired. | 89 -Navigates through them to verify that the popstate and hashchanged events are f
ired. |
77 -Navigates away to a new document, with the old document being destroyed. | 90 -Navigates away to a new document, with the old document being destroyed. |
78 -Navigates back to the state object entries and verifies the popstate event is f
ired even on the new documents. | 91 -Navigates back to the state object entries and verifies the pageshow or popstat
e events are fired on the new documents. |
79 </pre> | 92 </pre> |
80 </body> | 93 </body> |
81 </html> | 94 </html> |
OLD | NEW |