chained-setTimeout.html (2039B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/resources/testdriver.js"></script> 7 <script src="/resources/testdriver-vendor.js"></script> 8 <script> 9 let chained_timeout_test = async_test("Chained setTimeout test"); 10 11 const max_call_depth = 3; 12 const delay_ms = 10; 13 14 function testInitialStates(depth) { 15 assert_true(1 <= depth && depth <= max_call_depth); 16 17 chained_timeout_test.step_timeout(() => { 18 let test_name = "Call-depth=" + depth + ": initial activation states are false"; 19 test(() => { 20 assert_false(navigator.userActivation.isActive); 21 assert_false(navigator.userActivation.hasBeenActive); 22 }, test_name); 23 24 if (depth < max_call_depth) 25 testInitialStates(depth+1); 26 else 27 test_driver.click(document.body); 28 }, delay_ms); 29 } 30 31 function testFinalStates(depth) { 32 assert_true(1 <= depth && depth <= max_call_depth); 33 34 chained_timeout_test.step_timeout(() => { 35 let test_name = "Call-depth=" + depth + ": after-click activation states are true"; 36 test(() => { 37 assert_true(navigator.userActivation.isActive); 38 assert_true(navigator.userActivation.hasBeenActive); 39 }, test_name); 40 41 if (depth < max_call_depth) 42 testFinalStates(depth+1); 43 else 44 chained_timeout_test.done(); 45 }, delay_ms) 46 } 47 48 function run() { 49 window.addEventListener("click", event => { 50 testFinalStates(1); 51 }); 52 53 testInitialStates(1); 54 } 55 </script> 56 </head> 57 <body onload="run()"> 58 <h1>User activation state in chained setTimeout calls</h1> 59 <p>Tests that user activation state is visible in arbitrary call depth of setTimeout.</p> 60 <ol id="instructions"> 61 <li>Click anywhere in the document. 62 </ol></body> 63 </html>