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 } |
11 | 11 |
12 function lastPathComponent() | 12 function lastPathComponent() |
13 { | 13 { |
14 return window.location.href.split('/').pop(); | 14 return window.location.href.split('/').pop(); |
15 } | 15 } |
16 | 16 |
17 function runFirstStageOfTest() | 17 function runFirstStageOfTest() |
18 { | 18 { |
19 history.replaceState("FirstEntry", null, "?FirstEntry"); | 19 history.replaceState("FirstEntry", null, "?FirstEntry"); |
20 history.pushState("SecondEntry", null, "?SecondEntry"); | 20 history.pushState("SecondEntry", null, "?SecondEntry"); |
21 history.back(); | 21 history.back(); |
22 } | 22 } |
23 | 23 |
24 function runSecondStageOfTest() | |
25 { | |
26 alert("Last path component of location is " + lastPathComponent()); | |
27 } | |
28 | |
29 function runThirdStageOfTest() | |
30 { | |
31 alert("Final stage of test loaded"); | |
32 } | |
33 | |
34 function runTest() | 24 function runTest() |
35 { | 25 { |
36 if (!sessionStorage.stage) { | 26 if (!sessionStorage.stage) { |
37 // Location changes need to happen outside the onload handler to generat
e history entries. | 27 // Location changes need to happen outside the onload handler to generat
e history entries. |
38 setTimeout(runFirstStageOfTest, 0); | 28 setTimeout(runFirstStageOfTest, 0); |
39 } else if (sessionStorage.stage == 2) | 29 } else if (sessionStorage.stage == 2) |
40 runSecondStageOfTest(); | 30 alert("Last path component of location is " + lastPathComponent()); |
41 else if (sessionStorage.stage == 3) | |
42 runThirdStageOfTest(); | |
43 } | 31 } |
44 | 32 |
45 function statePopped() | 33 function continueTest(state) |
46 { | 34 { |
47 alert("State popped - " + event.state + " (type " + typeof event.state + ")"
); | 35 if (state == "FirstEntry") { |
48 if (event.state == "FirstEntry") { | |
49 history.replaceState("FirstEntryWillLaterBeReactivated", null, "?FirstEn
tryWillLaterBeReactivated"); | 36 history.replaceState("FirstEntryWillLaterBeReactivated", null, "?FirstEn
tryWillLaterBeReactivated"); |
50 history.forward(); | 37 history.forward(); |
51 } else if (event.state == "SecondEntry") { | 38 } else if (state == "SecondEntry") { |
52 history.replaceState("SecondEntryWillLaterBeReactivated", null, "?Second
EntryWillLaterBeReactivated"); | 39 history.replaceState("SecondEntryWillLaterBeReactivated", null, "?Second
EntryWillLaterBeReactivated"); |
53 window.location = "resources/navigate-back.html"; | 40 window.location = "resources/navigate-back.html"; |
54 } else if (event.state == "SecondEntryWillLaterBeReactivated") | 41 } else if (state == "SecondEntryWillLaterBeReactivated") |
55 history.back(); | 42 history.back(); |
56 else if (event.state == "FirstEntryWillLaterBeReactivated") { | 43 else if (state == "FirstEntryWillLaterBeReactivated") { |
57 alert("Test complete"); | 44 alert("Test complete"); |
58 sessionStorage.clear(); | 45 sessionStorage.clear(); |
59 if (window.testRunner) | 46 if (window.testRunner) |
60 testRunner.notifyDone(); | 47 testRunner.notifyDone(); |
61 } | 48 } |
62 } | 49 } |
63 | 50 |
| 51 window.onpopstate = function statePopped() |
| 52 { |
| 53 var state = event.state; |
| 54 alert("State popped - " + state + " (type " + typeof state + ")"); |
| 55 continueTest(state); |
| 56 } |
| 57 |
| 58 window.onpageshow = function pageShown() |
| 59 { |
| 60 if (sessionStorage.stage == 2) { |
| 61 var state = history.state; |
| 62 alert("Page shown - " + state + " (type " + typeof state + ")"); |
| 63 continueTest(state); |
| 64 } |
| 65 } |
| 66 |
64 </script> | 67 </script> |
65 <body onload="runTest();" onpopstate="statePopped();" onunload="/* disable page
cache */"> | 68 <body onload="runTest();" onunload="/* disable page cache */"> |
66 <pre> | 69 <pre> |
67 This test: | 70 This test: |
68 -Builds up a list of state object entries with fragment URLs. | 71 -Builds up a list of state object entries with fragment URLs. |
69 -Navigates through them to verify that the popstate event is fired. | 72 -Navigates through them to verify that the popstate event is fired. |
70 -Navigates away to a new document, with the old document being destroyed. | 73 -Navigates away to a new document, with the old document being destroyed. |
71 -Navigates back to the state object entries and verifies the popstate event is f
ired even on the new documents. | 74 -Navigates back to the state object entries and verifies the pageshow or popstat
e events are fired on the new documents. |
72 </pre><br> | 75 </pre><br> |
73 <pre id="logger"></pre> | 76 <pre id="logger"></pre> |
74 </body> | 77 </body> |
75 </html> | 78 </html> |
OLD | NEW |