popstate_event.html (1248B)
1 <!doctype html> 2 <title>Queue a task to fire popstate event</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <div id="log"></div> 6 <script> 7 t = async_test(); 8 window.onload = t.step_func(function () { 9 var states = []; 10 11 var timer = null; 12 13 history.pushState("a", "State a", "/a"); 14 history.pushState("b", "State b", "/b"); 15 16 history.back(); 17 window.onpopstate = t.step_func(function (e) { 18 assert_true(e.isTrusted, "isTrusted"); 19 assert_equals(e.target, window, "target"); 20 assert_equals(e.type, "popstate", "type"); 21 assert_true(e instanceof PopStateEvent, "is PopStateEvent"); 22 assert_false(e.bubbles, "bubbles"); 23 assert_false(e.cancelable, "cancelable"); 24 assert_not_equals(e.hasUAVisualTransition, undefined); 25 26 states.push(e.state); 27 28 if (states.length === 2) { 29 check_result(); 30 } else if (timer === null) { 31 timer = setTimeout(function() {check_result()}, 500); 32 } 33 }) 34 35 check_result = t.step_func(function() { 36 clearTimeout(timer); 37 try { 38 assert_array_equals(states, ["a", null]); 39 t.done(); 40 } finally { 41 location.hash = ""; 42 } 43 }); 44 45 setTimeout(function() {history.back()}, 0); 46 47 }); 48 </script>