| 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 testRunner.clearBackForwardList(); | 6 testRunner.clearBackForwardList(); |
| 7 testRunner.dumpAsText(); | 7 testRunner.dumpAsText(); |
| 8 testRunner.waitUntilDone(); | 8 testRunner.waitUntilDone(); |
| 9 } | 9 } |
| 10 | 10 |
| 11 function log(txt) | 11 function log(txt) |
| 12 { | 12 { |
| 13 document.getElementById("logger").innerText += txt + "\n"; | 13 document.getElementById("logger").innerText += txt + "\n"; |
| 14 } | 14 } |
| 15 | 15 |
| 16 function runTest() | 16 function runTest() |
| 17 { | 17 { |
| 18 history.replaceState("OriginalHistoryItem", "Replaced title"); | 18 history.replaceState("OriginalHistoryItem", "Replaced title"); |
| 19 log("History length is " + history.length); | 19 log("History length is " + history.length); |
| 20 history.pushState("NewHistoryItem", "Pushed title"); | 20 history.pushState("NewHistoryItem", "Pushed title"); |
| 21 log("History length is " + history.length); | 21 log("History length is " + history.length); |
| 22 history.back(); | 22 history.back(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 var beganTest = false; | |
| 26 | |
| 27 onpopstate = function(event) | 25 onpopstate = function(event) |
| 28 { | 26 { |
| 29 // The first time popstate fires, it's because the page has finished loading
. | |
| 30 // Only then can we begin the test. | |
| 31 if (!beganTest) { | |
| 32 beganTest = true; | |
| 33 runTest(); | |
| 34 return; | |
| 35 } | |
| 36 | |
| 37 log("State popped - " + event.state + " (type " + typeof event.state + ")"); | 27 log("State popped - " + event.state + " (type " + typeof event.state + ")"); |
| 38 if (event.state == "OriginalHistoryItem") | 28 if (event.state == "OriginalHistoryItem") |
| 39 history.forward(); | 29 history.forward(); |
| 40 else if (window.testRunner) | 30 else if (window.testRunner) |
| 41 testRunner.notifyDone(); | 31 testRunner.notifyDone(); |
| 42 } | 32 } |
| 43 | 33 |
| 44 </script> | 34 </script> |
| 45 <body> | 35 <body onload="runTest();"> |
| 46 <pre> | 36 <pre> |
| 47 This test does the following: | 37 This test does the following: |
| 48 -Makes a call to replaceState() | 38 -Makes a call to replaceState() |
| 49 -Makes sure the history length is correct | 39 -Makes sure the history length is correct |
| 50 -Makes a call to pushState() | 40 -Makes a call to pushState() |
| 51 -Makes sure the history length is correct | 41 -Makes sure the history length is correct |
| 52 -Goes back, and makes sure the popstate event is correct | 42 -Goes back, and makes sure the popstate event is correct |
| 53 -Goes forward, and makes sure the popstate event is correct | 43 -Goes forward, and makes sure the popstate event is correct |
| 54 </pre><br> | 44 </pre><br> |
| 55 <pre id="logger"></pre> | 45 <pre id="logger"></pre> |
| 56 </body> | 46 </body> |
| 57 </html> | 47 </html> |
| OLD | NEW |