blob: df4d94f09aef1d569be608546941d1e6b7c874ae [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 assert_equals(childFrameData.target, 'iframe_div');
Hongbo Song13817e22021-12-14 22:42:1142 verifyClickEvent(childFrameData, null, false, 104, 'mousedown');
Nicolás Peña Moreno80e94e62019-12-19 18:23:1043 assert_less_than(childFrameData.processingStart, childFrameData.clickDone,
44 "The entry's processing start should be before than the child frame's clickDone.");
Nicolas Penaa2e7e012018-11-29 16:01:5245 }
46
Nicolás Peña Moreno0432a102020-01-27 17:01:4947 promise_test(async t => {
Stephen McGruer67f7dd22020-04-16 13:24:5848 assert_implements(window.PerformanceEventTiming, "Event Timing is not supported");
Nicolás Peña Moreno0a345192020-08-10 21:07:5449 // Wait for load event so we can interact with the iframe.
50 await new Promise(resolve => {
51 window.addEventListener('load', resolve);
52 });
Nicolas Penaa2e7e012018-11-29 16:01:5253 clickTimeMin = performance.now();
Hongbo Song13817e22021-12-14 22:42:1154 let observedPointerDown = false;
Nicolás Peña Moreno80e94e62019-12-19 18:23:1055 const observerPromise = new Promise(resolve => {
56 new PerformanceObserver(t.step_func(entries => {
Hongbo Song13817e22021-12-14 22:42:1157 const pointerDowns = entries.getEntriesByName('pointerdown');
58 // Ignore the callback if there were no pointerdown entries.
59 if (pointerDowns.length === 0)
Nicolás Peña Moreno1843d2c2020-04-28 15:59:2060 return;
61
Hongbo Song13817e22021-12-14 22:42:1162 assert_false(observedPointerDown,
Nicolás Peña Moreno80e94e62019-12-19 18:23:1063 "Observer of main frames should only capture main-frame event-timing entries");
Hongbo Song13817e22021-12-14 22:42:1164 validateEntries(pointerDowns);
65 observedPointerDown = true;
Nicolás Peña Moreno80e94e62019-12-19 18:23:1066 resolve();
67 })).observe({type: 'event'});
68 });
Nicolás Peña Moreno0a345192020-08-10 21:07:5469 clickAndBlockMain('button').then(() => {
70 clickDone = performance.now();
71 });
Nicolás Peña Moreno80e94e62019-12-19 18:23:1072 const childFrameEntriesPromise = new Promise(resolve => {
Nicolas Penaa2e7e012018-11-29 16:01:5273 window.addEventListener("message", (event) => {
Sean Fengf2d01052021-02-09 19:00:4774 // testdriver-complete is a webdriver internal event
75 if (event.data.type != "testdriver-complete") {
76 t.step(() => {
77 validateChildFrameEntries(event.data);
78 });
79 resolve();
80 }
Nicolas Penaa2e7e012018-11-29 16:01:5281 }, false);
82 });
Nicolás Peña Moreno80e94e62019-12-19 18:23:1083 // Tap on the iframe, with an offset of 10 to target the div inside it.
84 const actions = new test_driver.Actions()
Emilio Cobos Álvareza90e2752021-03-10 15:20:2985 .pointerMove(10, 10, { origin: document.getElementById("iframe") })
Nicolás Peña Moreno80e94e62019-12-19 18:23:1086 .pointerDown()
Emilio Cobos Álvareza90e2752021-03-10 15:20:2987 .pointerUp();
Nicolás Peña Moreno80e94e62019-12-19 18:23:1088 actions.send();
Nicolás Peña Moreno0a345192020-08-10 21:07:5489 return Promise.all([observerPromise, childFrameEntriesPromise]);
Nicolas Penaa2e7e012018-11-29 16:01:5290 }, "Event Timing: entries should only be observable by its own frame.");
91
92</script>
93</body>
94</html>