Skip to content

Commit

Permalink
Adjust test to wait for first focus change like it waits for the second.
Browse files Browse the repository at this point in the history
This adjusts the test to wait for the first change in focus in a manner
similar to the way it waits for the second focus change (although only
for one frame rather than three).

My hope is that this change will fix the test being flaky in Chromium
CI.

Bug: 332068449
Change-Id: I80d0848378b10ddb4e7f45081d8c0f3a8c43e036
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5414837
Auto-Submit: David Baron <dbaron@chromium.org>
Reviewed-by: Di Zhang <dizhangg@chromium.org>
Commit-Queue: Di Zhang <dizhangg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1282127}
  • Loading branch information
dbaron authored and chromium-wpt-export-bot committed Apr 3, 2024
1 parent ba2770d commit fa48865
Showing 1 changed file with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,31 @@
const innerIFrame = outerIFrame.contentDocument.createElement("iframe");

window.onmessage = function() {
// We receive an message when the innerIFrame is ready and its input is focused.
// outerIframe is the ancestor of inner iframe, so the activeElement of
// it should be the inner iframe.
assert_equals(outerIFrame.contentDocument.activeElement, innerIFrame,
"The activeElement of the outer iframe should be the inner iframe");

// Now we focus the input in the top level
document.querySelector("input").focus();

// Wait for a bit to let whatever the code that might change the focus to run
window.requestAnimationFrame(function() {

// We receive an message when the innerIFrame is ready and its input is focused.
// outerIframe is the ancestor of inner iframe, so the activeElement of
// it should be the inner iframe.
assert_equals(outerIFrame.contentDocument.activeElement, innerIFrame,
"The activeElement of the outer iframe should be the inner iframe");

// Now we focus the input in the top level
document.querySelector("input").focus();

// Wait for a bit to let whatever the code that might change the focus to run
window.requestAnimationFrame(function() {
window.requestAnimationFrame(function() {
// Since inner iframe lost its focus, the activeElement of outer iframe
// should be cleared as well, hence <body> should be focused.
assert_equals(outerIFrame.contentDocument.activeElement, outerIFrame.contentDocument.body,
"The activeElement of the outer iframe should be reverted back to <body>");
assert_equals(document.activeElement, document.querySelector("input"),
"The activeElement of the top-level document should the input");
done();
})
window.requestAnimationFrame(function() {
// Since inner iframe lost its focus, the activeElement of outer iframe
// should be cleared as well, hence <body> should be focused.
assert_equals(outerIFrame.contentDocument.activeElement, outerIFrame.contentDocument.body,
"The activeElement of the outer iframe should be reverted back to <body>");
assert_equals(document.activeElement, document.querySelector("input"),
"The activeElement of the top-level document should the input");
done();
});
});
});
});
}
Expand Down

0 comments on commit fa48865

Please sign in to comment.