| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <meta charset=utf-8 /> |
| 4 | <title>Event Timing: buffer long-latency events before onload</title> |
| Sergio Villar Senin | 7287608 | 2019-03-22 17:18:58 | [diff] [blame] | 5 | <meta name="timeout" content="long"> |
| Nicolas Pena | 4052654 | 2018-12-12 20:53:51 | [diff] [blame] | 6 | <button id='button'>Generate a 'click' event</button> |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 7 | <script src=/resources/testharness.js></script> |
| 8 | <script src=/resources/testharnessreport.js></script> |
| 9 | <script src=/resources/testdriver.js></script> |
| 10 | <script src=/resources/testdriver-vendor.js></script> |
| 11 | |
| 12 | <script src=resources/event-timing-support.js></script> |
| 13 | |
| 14 | <script> |
| 15 | /* Timeline: |
| 16 | Onload |
| 17 | PerformanceObserver is registered |
| 18 | Click 1 |
| 19 | Click 2 |
| 20 | PerformanceObserver should observe only one firstInput entry. |
| 21 | (Dispatch and Process Click 2 - not buffered) |
| 22 | */ |
| 23 | async_test(function(t) { |
| 24 | let numFirstInputObserved = 0; |
| 25 | let numEventsObserved = 0; |
| 26 | new PerformanceObserver(t.step_func((entryList, obs) => { |
| Nicolas Pena | 4052654 | 2018-12-12 20:53:51 | [diff] [blame] | 27 | const observedEntries = entryList.getEntries().filter( |
| 28 | entry => entry.name === 'mousedown'); |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 29 | numEventsObserved += observedEntries.filter(entry => |
| 30 | entry.entryType == 'event').length; |
| 31 | numFirstInputObserved += observedEntries.filter(entry => |
| 32 | entry.entryType == 'firstInput').length; |
| 33 | if (numEventsObserved >= 2) { |
| 34 | assert_equals(performance.getEntriesByType('event').length, 0, |
| 35 | "There should be no buffered event entries."); |
| Nicolas Pena | d59c66c | 2018-12-05 15:33:57 | [diff] [blame] | 36 | assert_equals(performance.getEntriesByType('firstInput').length, 1, |
| 37 | "There should be a buffered firstInput entry."); |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 38 | // There should be 2 event entries and one firstInput entry. |
| 39 | assert_equals(numEventsObserved, 2, |
| 40 | "There should be 2 observed event entries."); |
| 41 | assert_equals(numFirstInputObserved, 1, |
| 42 | "There should be only 1 observed firstInput entry."); |
| 43 | t.done(); |
| 44 | } |
| 45 | })).observe({ entryTypes: ['event', 'firstInput'] }); |
| 46 | on_event(window, 'load', () => { |
| Nicolas Pena | d59c66c | 2018-12-05 15:33:57 | [diff] [blame] | 47 | clickAndBlockMain('button').then(() => { |
| 48 | clickAndBlockMain('button'); |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 49 | }); |
| 50 | }); |
| 51 | }, |
| 52 | "Event Timing: check firstInput after onload, observer, click, click." |
| 53 | ); |
| 54 | </script> |
| 55 | </html> |