| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <body> | |
| 4 <script src="../../js/resources/js-test-pre.js"></script> | |
| 5 <div id="description"></div> | |
| 6 <pre id="console"></pre> | |
| 7 <script> | |
| 8 description('Tests that popstate events fire for all history traversals (includi
ng navigation to fragments), not just when going back to a state object created
via pushState.'); | |
| 9 | |
| 10 onload = function() | |
| 11 { | |
| 12 setTimeout(step, 0); | |
| 13 } | |
| 14 | |
| 15 var currentStep = 0; | |
| 16 var popstateFireCount = 0; | |
| 17 | |
| 18 function step() | |
| 19 { | |
| 20 switch (currentStep) { | |
| 21 case 0: | |
| 22 debug('setting hash to #state1'); | |
| 23 location.hash = '#state1'; | |
| 24 break; | |
| 25 case 1: | |
| 26 debug('setting hash to #state2'); | |
| 27 location.hash = '#state2'; | |
| 28 break; | |
| 29 case 2: | |
| 30 debug('going back'); | |
| 31 history.back(); | |
| 32 break; | |
| 33 case 3: | |
| 34 debug('going back'); | |
| 35 history.back(); | |
| 36 break; | |
| 37 case 4: | |
| 38 // The 5 expected popstate events are when: | |
| 39 // 1. The page loads | |
| 40 // 2. Navigating to #state1 | |
| 41 // 3. Navigating to #state2 | |
| 42 // 4. Going back to #state1 | |
| 43 // 5. Going back to the initial page state | |
| 44 shouldBe('popstateFireCount', '5'); | |
| 45 finishJSTest(); | |
| 46 return; | |
| 47 default: | |
| 48 testFailed('unexpected state: ' + currentStep); | |
| 49 break; | |
| 50 } | |
| 51 | |
| 52 currentStep++; | |
| 53 | |
| 54 setTimeout(step, 0); | |
| 55 } | |
| 56 | |
| 57 onpopstate = function(event) | |
| 58 { | |
| 59 debug('popstate fired with state ' + event.state); | |
| 60 popstateFireCount++; | |
| 61 } | |
| 62 var jsTestIsAsync = true; | |
| 63 </script> | |
| 64 <script src="../../js/resources/js-test-post.js"></script> | |
| 65 </html> | |
| OLD | NEW |