| Nicolás Peña Moreno | cd2c04e | 2019-05-09 23:24:54 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <meta charset=utf-8 /> |
| 4 | <div id='div' onclick='delay()'>Click me</div> |
| 5 | <div id='div2'>No, click me!</div> |
| 6 | <script src=/resources/testharness.js></script> |
| 7 | <script src=/resources/testharnessreport.js></script> |
| 8 | <script src=/resources/testdriver.js></script> |
| 9 | <script src=/resources/testdriver-vendor.js></script> |
| 10 | |
| Nicolás Peña Moreno | aa9d7f5 | 2019-05-14 22:20:06 | [diff] [blame] | 11 | <script src=resources/event-timing-test-utils.js></script> |
| Nicolás Peña Moreno | cd2c04e | 2019-05-09 23:24:54 | [diff] [blame] | 12 | <script> |
| 13 | let delayCalled = false; |
| 14 | let beforeClick; |
| 15 | function delay() { |
| 16 | const end = performance.now() + 150; |
| 17 | while(performance.now() < end) {} |
| 18 | delayCalled = true; |
| 19 | } |
| 20 | async_test(function(t) { |
| Nicolás Peña Moreno | 32a1ff6 | 2019-07-19 14:38:27 | [diff] [blame] | 21 | if (!window.PerformanceEventTiming) |
| 22 | assert_unreached("PerformanceEventTiming is not supported"); |
| 23 | |
| Nicolás Peña Moreno | cd2c04e | 2019-05-09 23:24:54 | [diff] [blame] | 24 | const observer = new PerformanceObserver(t.step_func_done((entryList) => { |
| Nicolás Peña Moreno | aa9d7f5 | 2019-05-14 22:20:06 | [diff] [blame] | 25 | const entries = entryList.getEntries().filter(e => e.name === 'mousedown'); |
| Nicolás Peña Moreno | cd2c04e | 2019-05-09 23:24:54 | [diff] [blame] | 26 | // There must only be one click entry: from the clickAndBlockMain() call. |
| 27 | assert_equals(entries.length, 1); |
| 28 | const entry = entries[0]; |
| 29 | // This ensures that the entry is exposing timing from the second click, i.e. |
| 30 | // the one from the clickAndBlockMain() call. |
| 31 | assert_greater_than_equal(entry.processingStart, beforeClick); |
| Nicolás Peña Moreno | aa9d7f5 | 2019-05-14 22:20:06 | [diff] [blame] | 32 | // Check that the first input entry was also from the second click. |
| Nicolás Peña Moreno | f1a492a | 2019-07-04 15:09:30 | [diff] [blame] | 33 | const firstInput = performance.getEntriesByType('first-input'); |
| Nicolás Peña Moreno | aa9d7f5 | 2019-05-14 22:20:06 | [diff] [blame] | 34 | assert_equals(firstInput.length, 1); |
| 35 | assert_greater_than_equal(firstInput[0].processingStart, beforeClick); |
| Nicolás Peña Moreno | cd2c04e | 2019-05-09 23:24:54 | [diff] [blame] | 36 | })); |
| Nicolás Peña Moreno | aa9d7f5 | 2019-05-14 22:20:06 | [diff] [blame] | 37 | observer.observe({entryTypes: ['event']}); |
| Nicolás Peña Moreno | cd2c04e | 2019-05-09 23:24:54 | [diff] [blame] | 38 | document.getElementById('div').click(); |
| 39 | // Take the timestamp after the programmatic click but before the next click. |
| 40 | beforeClick = performance.now(); |
| 41 | // After the programmatic click, use another input to know when entries have been |
| 42 | // dispatched to the PerformanceObserver callback. |
| 43 | clickAndBlockMain('div2'); |
| 44 | }, "Event Timing: events from programmatic click are not observed"); |
| 45 | </script> |
| 46 | </html> |