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.pushState("StateStringData", "New title"); | 18 history.pushState("StateStringData", "New title"); |
19 log("History length is " + history.length); | 19 log("History length is " + history.length); |
20 history.back(); | 20 history.back(); |
21 } | 21 } |
22 | 22 |
23 var beganTest = false; | |
24 | |
25 function statePopped() | 23 function statePopped() |
26 { | 24 { |
27 // The first time popstate fires, it's because the page has finished loading
. | |
28 // Only then can we begin the test. | |
29 if (!beganTest) { | |
30 beganTest = true; | |
31 runTest(); | |
32 return; | |
33 } | |
34 | |
35 log("State popped - " + event.state + " (type " + typeof event.state + ")"); | 25 log("State popped - " + event.state + " (type " + typeof event.state + ")"); |
36 if (event.state == null) { | 26 if (event.state == null) { |
37 document.body.onpopstate = statePopped; | 27 document.body.onpopstate = statePopped; |
38 history.forward(); | 28 history.forward(); |
39 } else if (window.testRunner) | 29 } else if (window.testRunner) |
40 testRunner.notifyDone(); | 30 testRunner.notifyDone(); |
41 } | 31 } |
42 | 32 |
43 </script> | 33 </script> |
44 <body onpopstate="statePopped();"> | 34 <body onload="runTest();" onpopstate="statePopped();"> |
45 <pre> | 35 <pre> |
46 This test does the following: | 36 This test does the following: |
47 -Uses body.onpopstate to add a popstate handler (both by using the inline attrib
ute and a script-assigned attribute) | 37 -Uses body.onpopstate to add a popstate handler (both by using the inline attrib
ute and a script-assigned attribute) |
48 -Makes a call to pushState() | 38 -Makes a call to pushState() |
49 -Makes sure the history length is correct | 39 -Makes sure the history length is correct |
50 -Goes back, and makes sure the popstate event is correct | 40 -Goes back, and makes sure the popstate event is correct |
51 -Goes forward, and makes sure the popstate event is correct | 41 -Goes forward, and makes sure the popstate event is correct |
52 </pre><br> | 42 </pre><br> |
53 <pre id="logger"></pre> | 43 <pre id="logger"></pre> |
54 </body> | 44 </body> |
55 </html> | 45 </html> |
OLD | NEW |