Skip to content

Commit

Permalink
Fix timeout in update-and-send-events-replacment.html
Browse files Browse the repository at this point in the history
The handling of iframe load events is finicky as indicated in the open
WHATWG issue:

whatwg/html#490

This patch switches the wait mechanism to one that is well behaved
across browsers.  The new process arms the listener before inserting the
iframe into the document.

Bug: 1059963
Change-Id: I372d4fdae3b270699aedf2c5a4de4429e62f42a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2096782
Reviewed-by: Yi Gu <[email protected]>
Commit-Queue: Kevin Ellis <[email protected]>
Cr-Commit-Position: refs/heads/master@{#748853}
  • Loading branch information
Kevin Ellis authored and chromium-wpt-export-bot committed Mar 10, 2020
1 parent afb12c9 commit ecc8ad0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
16 changes: 3 additions & 13 deletions web-animations/interfaces/DocumentOrShadowRoot/getAnimations.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@

const gKeyFrames = { 'marginLeft': ['100px', '200px'] };

async function insert_frame_and_await_load(test, iframe, document) {
const eventWatcher = new EventWatcher(test, iframe, ['load']);
const event_promise = eventWatcher.wait_for('load');

document.body.appendChild(iframe);
test.add_cleanup(() => { document.body.removeChild(iframe); });

await event_promise;
}

test(t => {
assert_equals(document.getAnimations().length, 0,
'getAnimations returns an empty sequence for a document ' +
Expand Down Expand Up @@ -78,7 +68,7 @@

promise_test(async t => {
const iframe = document.createElement('iframe');
insert_frame_and_await_load(t, iframe, document)
insertFrameAndAwaitLoad(t, iframe, document)

const div = createDiv(t, iframe.contentDocument)
const effect = new KeyframeEffect(div, null, 100 * MS_PER_SEC);
Expand All @@ -98,8 +88,8 @@
const iframe1 = document.createElement('iframe');
const iframe2 = document.createElement('iframe');

insert_frame_and_await_load(t, iframe1, document);
insert_frame_and_await_load(t, iframe2, document);
insertFrameAndAwaitLoad(t, iframe1, document);
insertFrameAndAwaitLoad(t, iframe2, document);

const div_frame1 = createDiv(t, iframe1.contentDocument)
const div_main_frame = createDiv(t)
Expand Down
10 changes: 10 additions & 0 deletions web-animations/testcommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ function waitForNextFrame() {
});
}

async function insertFrameAndAwaitLoad(test, iframe, document) {
const eventWatcher = new EventWatcher(test, iframe, ['load']);
const event_promise = eventWatcher.wait_for('load');

document.body.appendChild(iframe);
test.add_cleanup(() => { document.body.removeChild(iframe); });

await event_promise;
}

// Returns 'matrix()' or 'matrix3d()' function string generated from an array.
function createMatrixFromArray(array) {
return (array.length == 16 ? 'matrix3d' : 'matrix') + `(${array.join()})`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -988,18 +988,16 @@
}, 'Queues all remove events before running them');

promise_test(async t => {
const outerIframe = createElement(t, 'iframe');
const outerIframe = document.createElement('iframe');
insertFrameAndAwaitLoad(t, outerIframe, document);
outerIframe.width = 10;
outerIframe.height = 10;

await new Promise(resolve => outerIframe.addEventListener('load', resolve));

const innerIframe = createElement(t, 'iframe', outerIframe.contentDocument);
const innerIframe = document.createElement('iframe');
insertFrameAndAwaitLoad(t, innerIframe, outerIframe.contentDocument);
innerIframe.width = 10;
innerIframe.height = 10;

await new Promise(resolve => innerIframe.addEventListener('load', resolve));

const div = createDiv(t, innerIframe.contentDocument);

const animA = div.animate({ opacity: 1 }, { duration: 1, fill: 'forwards' });
Expand Down

0 comments on commit ecc8ad0

Please sign in to comment.