Skip to content

Commit

Permalink
Fix a flaky html/dom/render-blocking WPT
Browse files Browse the repository at this point in the history
This patch fixes a flaky WPT in html/dom/render-blocking/ that:
- LoadObserver used to check whether `target instanceof EventTarget`,
  which doesn't work if `target` is in a subframe. This patch changes
  it to check whether it has `addEventListener` method.
- The autofocus target used to be declared directly with markup, and
  as a result, it may be autofocused before `DOMContentLoaded` event,
  then the event listener added after DCL can't trigger. So this patch
  changes the element to be dynamically inserted after DCL.
- The last promise test is supposed to be run after the font finishes
  loading, so this test adds a missing await for that

Fixed: 1313014
Change-Id: Ia55667a1876f76eb0bb4f91543f2c1e9f2f4a8c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3575243
Reviewed-by: Joey Arhar <jarhar@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#990135}
  • Loading branch information
xiaochengh authored and Chromium LUCI CQ committed Apr 7, 2022
1 parent 1ef905e commit 5367959
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
Expand Up @@ -51,10 +51,18 @@
});
}

autofocusTest = rejectIfEventsFired(
preloadObserver.load,
iframe.contentDocument.getElementById('autofocus-target'),
'focus');
// The autofocus target must be created and inserted after subframe DCL so
// that we can add the event listener here before the subframe flushes
// autofocus candidates.
function createAutofocusTest(document) {
const target = document.createElement('textarea');
target.autofocus = 'autofocus';
const test = rejectIfEventsFired(preloadObserver.load, target, 'focus');
document.body.appendChild(target);
return test;
}
autofocusTest = createAutofocusTest(iframe.contentDocument);

scrollTest = rejectIfEventsFired(
preloadObserver.load,
iframe.contentDocument.getElementById('scroll-target'),
Expand Down Expand Up @@ -115,6 +123,7 @@
() => intersectionObserverTest,
'Should not run the update intersection observers step when render-blocked');
promise_test(async () => {
await iframe.contentDocument.fonts.ready;
const target = iframe.contentDocument.getElementById('target');
assert_equals(target.offsetHeight, 20);
assert_equals(target.offsetWidth, 220);
Expand Down
Expand Up @@ -11,8 +11,6 @@
</style>
<span id="target" style="font: 20px/1 custom-font">Lorem ipsum</span>

<textarea id="autofocus-target" autofocus></textarea>

<div id="scroll-target" style="height: 100px; overflow: scroll">
<div style="height: 200px"></div>
</div>
Expand All @@ -25,6 +23,12 @@
</style>
<div id="animation-target" style="height: 50px; animation: anim 100ms"></div>

<!-- We will use a script-inserted element to verify if the browser flushes
-- autofocus candidates. If we insert the element here via markup, it may
-- be focused before the subframe DOMContentLoaded event, giving the parent
-- frame no opportunity to add a 'focus' event handler.
-->

<!-- We should also verify that the context lost steps for canvas are not run,
-- but there's currently no way to reliably trigger a context lost in WPT.
-- See https://github.com/web-platform-tests/wpt/issues/30039
Expand Down
Expand Up @@ -5,12 +5,12 @@ class LoadObserver {
constructor(target) {
this.finishTime = null;
this.load = new Promise((resolve, reject) => {
if (target instanceof EventTarget) {
target.onload = ev => {
if (target.addEventListener) {
target.addEventListener('load', ev => {
this.finishTime = ev.timeStamp;
resolve(ev);
};
target.onerror = reject;
});
target.addEventListener('error', reject);
} else if (typeof target === 'string') {
const observer = new PerformanceObserver(() => {
if (numberOfResourceTimingEntries(target)) {
Expand Down

0 comments on commit 5367959

Please sign in to comment.