blob: dfbd2897ad4bb5bfd4edeb2cdc17afc438e37962 [file] [log] [blame]
Nicolas Penaa2e7e012018-11-29 16:01:521<!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 Senin72876082019-03-22 17:18:587 <meta name="timeout" content="long">
Nicolas Penaa2e7e012018-11-29 16:01:528</head>
9
10<body>
Nicolas Pena40526542018-12-12 20:53:5111<button id='button'>Generate a 'click' event</button>
Nicolas Penaa2e7e012018-11-29 16:01:5212<script src=/resources/testharness.js></script>
13<script src=/resources/testharnessreport.js></script>
14<script src=/resources/testdriver.js></script>
Nicolás Peña Moreno80e94e62019-12-19 18:23:1015<script src=/resources/testdriver-actions.js></script>
Nicolas Penaa2e7e012018-11-29 16:01:5216<script src=/resources/testdriver-vendor.js></script>
17
Nicolás Peña Morenofdb7ca22019-05-09 22:58:0018<script src=resources/event-timing-test-utils.js></script>
Nicolás Peña Moreno80e94e62019-12-19 18:23:1019<iframe id='iframe' src=resources/crossiframe-childframe.html></iframe>
Nicolas Penaa2e7e012018-11-29 16:01:5220<script>
21 let clickTimeMin;
Nicolás Peña Moreno80e94e62019-12-19 18:23:1022 let clickDone;
Nicolas Penaa2e7e012018-11-29 16:01:5223
Nicolás Peña Moreno80e94e62019-12-19 18:23:1024 function validateEntries(entries) {
25 assert_equals(entries.length, 1, "Only 1 entry should be received");
Nicolas Penaa2e7e012018-11-29 16:01:5226 const entry = entries[0];
Nicolás Peña Morenobc01db72020-04-18 00:14:0127 verifyClickEvent(entry, 'button', true);
Nicolas Penaa2e7e012018-11-29 16:01:5228
Nicolás Peña Moreno80e94e62019-12-19 18:23:1029 assert_less_than(entry.processingStart, clickDone,
30 "The entry's processing start should be before clickDone.");
Nicolas Penaa2e7e012018-11-29 16:01:5231 assert_greater_than(entry.startTime, clickTimeMin,
32 "The entry's start time should be later than clickTimeMin.");
Nicolas Penaa2e7e012018-11-29 16:01:5233 }
34
35 function validateChildFrameEntries(childFrameData) {
Nicolás Peña Moreno80e94e62019-12-19 18:23:1036 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 Morenobc01db72020-04-18 00:14:0141 verifyClickEvent(childFrameData, null);
42 assert_equals(childFrameData.target, 'iframe_div');
Nicolas Penaa2e7e012018-11-29 16:01:5243
Nicolás Peña Moreno80e94e62019-12-19 18:23:1044 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 Penaa2e7e012018-11-29 16:01:5247 "The entry's start time should be later than the child frame's \
48 clickTimeMin.");
Nicolas Penaa2e7e012018-11-29 16:01:5249 }
50
Nicolás Peña Moreno0432a102020-01-27 17:01:4951 promise_test(async t => {
Stephen McGruer67f7dd22020-04-16 13:24:5852 assert_implements(window.PerformanceEventTiming, "Event Timing is not supported");
Nicolas Penaa2e7e012018-11-29 16:01:5253 clickTimeMin = performance.now();
Nicolás Peña Moreno1843d2c2020-04-28 15:59:2054 let observedMouseDown = false;
Nicolás Peña Moreno80e94e62019-12-19 18:23:1055 const observerPromise = new Promise(resolve => {
56 new PerformanceObserver(t.step_func(entries => {
Nicolás Peña Moreno1843d2c2020-04-28 15:59:2057 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 Moreno80e94e62019-12-19 18:23:1063 "Observer of main frames should only capture main-frame event-timing entries");
Nicolás Peña Moreno1843d2c2020-04-28 15:59:2064 validateEntries(mouseDowns);
65 observedMouseDown = true;
Nicolás Peña Moreno80e94e62019-12-19 18:23:1066 resolve();
67 })).observe({type: 'event'});
68 });
69 await clickAndBlockMain('button');
70 clickDone = performance.now();
71 await observerPromise;
72 const childFrameEntriesPromise = new Promise(resolve => {
Nicolas Penaa2e7e012018-11-29 16:01:5273 window.addEventListener("message", (event) => {
74 resolve(event.data);
75 }, false);
76 });
Nicolás Peña Moreno80e94e62019-12-19 18:23:1077
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 Penaa2e7e012018-11-29 16:01:5290 });
Nicolas Penaa2e7e012018-11-29 16:01:5291 }, "Event Timing: entries should only be observable by its own frame.");
92
93</script>
94</body>
95</html>