event-click-counts.html (1597B)
1 <!DOCTYPE html> 2 <html> 3 <meta charset=utf-8 /> 4 <title>Event Timing: eventCounts.</title> 5 <script src=/resources/testharness.js></script> 6 <script src=/resources/testharnessreport.js></script> 7 <script src=/resources/testdriver.js></script> 8 <script src=/resources/testdriver-vendor.js></script> 9 <div id='div'>Click me</div> 10 <button id='button'>Click me</button> 11 <script> 12 promise_test( t => { 13 assert_implements(window.EventCounts, "Event Counts isn't supported"); 14 function testClicks(expectedCount, resolve) { 15 const clickCount = performance.eventCounts.get('click'); 16 if (clickCount < expectedCount) { 17 t.step_timeout(function() { 18 testClicks(expectedCount, resolve); 19 }, 5); 20 return; 21 } 22 assert_equals(clickCount, expectedCount,'Incorrect click count.'); 23 assert_equals(performance.eventCounts.get('mousedown'), expectedCount, 'Incorrect mousedown count'); 24 assert_equals(performance.eventCounts.get('mouseup'), expectedCount, 'Incorrect mouseup count.'); 25 resolve(); 26 } 27 function promiseClicks(expectedCount) { 28 return new Promise(resolve => { 29 testClicks(expectedCount, resolve) 30 }); 31 } 32 33 return test_driver.click(document.getElementById('div')).then(() => { 34 return promiseClicks(1); 35 }).then(() => { 36 return test_driver.click(document.getElementById('button')); 37 }).then(() => { 38 return promiseClicks(2); 39 }).then(() => { 40 return test_driver.click(document.getElementById('div')); 41 }).then(() => { 42 return promiseClicks(3); 43 }); 44 }) 45 </script> 46 </html>