Skip to content

Commit 4a8cc9f

Browse files
Speculative deflake of pointerevent test
pointerevent_iframe-touch-action-none_touch.html could timeout. An explanation for the timeout is that it was only waiting on the subframe to load, and it was possible to start the injection of synthetic events before the subframe has had a chance to add event listeners. If the child frame fails to catch the events, it won't send the results back to the parent and a timeout results. Added loadFrameAndExecuteScript to a support file for standardization of handling subframes with script. Cleaned up implementation to make better use of shared code. The tes Bug: 40770210 Change-Id: I5fe6983190810fde072cb3968419aa3f26af4d48 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7901957 Reviewed-by: Mustaq Ahmed <mustaq@chromium.org> Commit-Queue: Kevin Ellis <kevers@chromium.org> Cr-Commit-Position: refs/heads/main@{#1643870}
1 parent 7affece commit 4a8cc9f

3 files changed

Lines changed: 25 additions & 25 deletions

File tree

pointerevents/pointerevent_iframe-touch-action-none_touch.html

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,14 @@ <h2 id="pointerTypeDescription"></h2>
2525
<script>
2626
'use strict';
2727

28-
function loadFrame() {
29-
return new Promise(resolve => {
30-
const frame = document.getElementById('target');
31-
frame.onload = resolve;
32-
frame.src = 'resources/iframe-touch-action-none-subframe.html';
33-
});
34-
}
35-
36-
function messageReceived() {
37-
return new Promise(resolve => {
38-
window.addEventListener('message', (event) => {
39-
if (event.source != target.contentWindow) {
40-
return;
41-
}
42-
if (event.data && event.data.type == "subframe-event") {
43-
resolve(event.data.eventType);
44-
}
45-
});
46-
});
47-
}
48-
4928
promise_test(async t => {
5029
const target = document.getElementById("target");
51-
await loadFrame();
30+
await loadFrameAndExcecuteScript(
31+
document.getElementById('target'),
32+
'resources/iframe-touch-action-none-subframe.html');
5233

53-
const messagePromise = messageReceived();
34+
const messagePromise =
35+
getMessageData('subframe-event', frames[0]);
5436

5537
await new test_driver.Actions()
5638
.addPointer("pointer1", "touch")
@@ -60,8 +42,8 @@ <h2 id="pointerTypeDescription"></h2>
6042
.pointerUp()
6143
.send();
6244

63-
const eventType = await messagePromise;
64-
assert_equals(eventType, 'pointercancel');
45+
const result = await messagePromise;
46+
assert_equals(result.eventType, 'pointercancel');
6547
}, 'touch iframe received pointercancel');
6648
</script>
6749
</html>

pointerevents/pointerevent_support.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,22 @@ function getEvent(event_type, target, test) {
499499
});
500500
}
501501

502+
// Returns a promise that resolves when a child frame posts a subframe-ready
503+
// message back to the parent and style rules have been applied. When the child
504+
// frame needs to execute script, such as setting up listeners, it is
505+
// insufficient to wait for the frame to be loaded, as the load event is
506+
// received once the child frame's document has been parsed, which is before
507+
// script execution or style update.
508+
function loadFrameAndExcecuteScript(frame, src) {
509+
return new Promise(async resolve => {
510+
const ready = getMessageData('subframe-ready', frame.contentWindow);
511+
frame.src = src;
512+
await ready;
513+
// Ensure that the child frame has been properly styled.
514+
requestAnimationFrame(() => requestAnimationFrame(resolve));
515+
});
516+
}
517+
502518
// Returns a |Promise| that gets resolved with |event.data| when |window|
503519
// receives from |source| a "message" event whose |event.data.type| matches the
504520
// string |message_data_type|.

pointerevents/resources/iframe-touch-action-none-subframe.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@
2222
eventType,
2323
handler);
2424
});
25+
26+
parent.postMessage({ type: 'subframe-ready' }, '*');
2527
</script>
2628
</html>

0 commit comments

Comments
 (0)