| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | |
| 4 | <head> |
| 5 | <meta charset=utf-8 /> |
| 6 | <title>Event Timing: entries should be observable by its own frame.</title> |
| Sergio Villar Senin | 7287608 | 2019-03-22 17:18:58 | [diff] [blame] | 7 | <meta name="timeout" content="long"> |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 8 | </head> |
| 9 | |
| 10 | <body> |
| Nicolas Pena | 4052654 | 2018-12-12 20:53:51 | [diff] [blame] | 11 | <button id='button'>Generate a 'click' event</button> |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 12 | <script src=/resources/testharness.js></script> |
| 13 | <script src=/resources/testharnessreport.js></script> |
| 14 | <script src=/resources/testdriver.js></script> |
| Nicolás Peña Moreno | 80e94e6 | 2019-12-19 18:23:10 | [diff] [blame] | 15 | <script src=/resources/testdriver-actions.js></script> |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 16 | <script src=/resources/testdriver-vendor.js></script> |
| 17 | |
| Nicolás Peña Moreno | fdb7ca2 | 2019-05-09 22:58:00 | [diff] [blame] | 18 | <script src=resources/event-timing-test-utils.js></script> |
| Nicolás Peña Moreno | 80e94e6 | 2019-12-19 18:23:10 | [diff] [blame] | 19 | <iframe id='iframe' src=resources/crossiframe-childframe.html></iframe> |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 20 | <script> |
| 21 | let clickTimeMin; |
| Nicolás Peña Moreno | 80e94e6 | 2019-12-19 18:23:10 | [diff] [blame] | 22 | let clickDone; |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 23 | |
| Nicolás Peña Moreno | 80e94e6 | 2019-12-19 18:23:10 | [diff] [blame] | 24 | function validateEntries(entries) { |
| 25 | assert_equals(entries.length, 1, "Only 1 entry should be received"); |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 26 | const entry = entries[0]; |
| Nicolás Peña Moreno | bc01db7 | 2020-04-18 00:14:01 | [diff] [blame] | 27 | verifyClickEvent(entry, 'button', true); |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 28 | |
| Nicolás Peña Moreno | 80e94e6 | 2019-12-19 18:23:10 | [diff] [blame] | 29 | assert_less_than(entry.processingStart, clickDone, |
| 30 | "The entry's processing start should be before clickDone."); |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 31 | assert_greater_than(entry.startTime, clickTimeMin, |
| 32 | "The entry's start time should be later than clickTimeMin."); |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | function validateChildFrameEntries(childFrameData) { |
| Nicolás Peña Moreno | 80e94e6 | 2019-12-19 18:23:10 | [diff] [blame] | 36 | if (childFrameData === "failed") { |
| 37 | assert_unreached("Did not receive exactly one entry from child as expected"); |
| 38 | } |
| 39 | // |childFrameData| has properties with the same names as its |
| 40 | // PerformanceEventTiming counterpart. |
| Nicolás Peña Moreno | bc01db7 | 2020-04-18 00:14:01 | [diff] [blame] | 41 | verifyClickEvent(childFrameData, null); |
| 42 | assert_equals(childFrameData.target, 'iframe_div'); |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 43 | |
| Nicolás Peña Moreno | 80e94e6 | 2019-12-19 18:23:10 | [diff] [blame] | 44 | assert_less_than(childFrameData.processingStart, childFrameData.clickDone, |
| 45 | "The entry's processing start should be before than the child frame's clickDone."); |
| 46 | assert_greater_than(childFrameData.startTime, childFrameData.clickTimeMin, |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 47 | "The entry's start time should be later than the child frame's \ |
| 48 | clickTimeMin."); |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 49 | } |
| 50 | |
| Nicolás Peña Moreno | 0432a10 | 2020-01-27 17:01:49 | [diff] [blame] | 51 | promise_test(async t => { |
| Stephen McGruer | 67f7dd2 | 2020-04-16 13:24:58 | [diff] [blame] | 52 | assert_implements(window.PerformanceEventTiming, "Event Timing is not supported"); |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 53 | clickTimeMin = performance.now(); |
| Nicolás Peña Moreno | 1843d2c | 2020-04-28 15:59:20 | [diff] [blame] | 54 | let observedMouseDown = false; |
| Nicolás Peña Moreno | 80e94e6 | 2019-12-19 18:23:10 | [diff] [blame] | 55 | const observerPromise = new Promise(resolve => { |
| 56 | new PerformanceObserver(t.step_func(entries => { |
| Nicolás Peña Moreno | 1843d2c | 2020-04-28 15:59:20 | [diff] [blame] | 57 | const mouseDowns = entries.getEntriesByName('mousedown'); |
| 58 | // Ignore the callback if there were no mousedown entries. |
| 59 | if (mouseDowns.length === 0) |
| 60 | return; |
| 61 | |
| 62 | assert_false(observedMouseDown, |
| Nicolás Peña Moreno | 80e94e6 | 2019-12-19 18:23:10 | [diff] [blame] | 63 | "Observer of main frames should only capture main-frame event-timing entries"); |
| Nicolás Peña Moreno | 1843d2c | 2020-04-28 15:59:20 | [diff] [blame] | 64 | validateEntries(mouseDowns); |
| 65 | observedMouseDown = true; |
| Nicolás Peña Moreno | 80e94e6 | 2019-12-19 18:23:10 | [diff] [blame] | 66 | resolve(); |
| 67 | })).observe({type: 'event'}); |
| 68 | }); |
| 69 | await clickAndBlockMain('button'); |
| 70 | clickDone = performance.now(); |
| 71 | await observerPromise; |
| 72 | const childFrameEntriesPromise = new Promise(resolve => { |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 73 | window.addEventListener("message", (event) => { |
| 74 | resolve(event.data); |
| 75 | }, false); |
| 76 | }); |
| Nicolás Peña Moreno | 80e94e6 | 2019-12-19 18:23:10 | [diff] [blame] | 77 | |
| 78 | let iframe = document.getElementById('iframe'); |
| 79 | const iframeX = document.getElementById('iframe').offsetLeft; |
| 80 | const iframeY = document.getElementById('iframe').offsetTop; |
| 81 | // Tap on the iframe, with an offset of 10 to target the div inside it. |
| 82 | const actions = new test_driver.Actions() |
| 83 | .pointerMove(iframeX + 10, iframeY + 10) |
| 84 | .pointerDown() |
| 85 | .pointerUp() |
| 86 | actions.send(); |
| 87 | const childFrameData = await childFrameEntriesPromise; |
| 88 | t.step(() => { |
| 89 | validateChildFrameEntries(childFrameData); |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 90 | }); |
| Nicolas Pena | a2e7e01 | 2018-11-29 16:01:52 | [diff] [blame] | 91 | }, "Event Timing: entries should only be observable by its own frame."); |
| 92 | |
| 93 | </script> |
| 94 | </body> |
| 95 | </html> |