Commit 2d795fa0 authored by Dominic Farolino's avatar Dominic Farolino Committed by Commit Bot

Augment iframe lazyload tests for srcdoc

This CL augments the existing iframe lazyload test for srcdoc lazyload
support. Chrome currently does not implement this.

The test accompanies the spec change made at:
https://github.com/whatwg/html/pull/5579.

R=sclittle@chromium.org

Bug: 1101170
Change-Id: I5c5790c5d2eca3efbb01c5470e2267f2265858f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2276624Reviewed-by: default avatarScott Little <sclittle@chromium.org>
Commit-Queue: Dominic Farolino <dom@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784331}
parent 7c57ca14
This is a testharness.js-based test.
PASS In-viewport iframes load eagerly
PASS In-viewport srcdoc iframes load eagerly
PASS Below-viewport iframes load lazily
FAIL Below-viewport srcdoc iframes load lazily assert_true: The window.load() event should have fired before the below-viewport srcdoc iframe's subresource loads expected true got false
Harness: the test ran to completion.
...@@ -2,38 +2,56 @@ ...@@ -2,38 +2,56 @@
<head> <head>
<title>Iframes with loading='lazy' load when in the viewport</title> <title>Iframes with loading='lazy' load when in the viewport</title>
<link rel="author" title="Scott Little" href="mailto:sclittle@chromium.org"> <link rel="author" title="Scott Little" href="mailto:sclittle@chromium.org">
<link rel="help" href="https://github.com/scott-little/lazyload"> <link rel="author" title="Dom Farolino" href="mailto:dom@chromium.org">
<link rel="help" href="https://github.com/whatwg/html/pull/5579">
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
</head> </head>
<script> <script>
const t = async_test("Test that iframes with loading='lazy' load once they " + const t_in_viewport =
"enter the viewport."); async_test('In-viewport iframes load eagerly');
const t_in_viewport_srcdoc=
async_test('In-viewport srcdoc iframes load eagerly');
const t_below_viewport =
async_test('Below-viewport iframes load lazily');
const t_below_viewport_srcdoc =
async_test('Below-viewport srcdoc iframes load lazily');
let has_window_loaded = false; let has_window_loaded = false;
let has_in_viewport_loaded = false;
const in_viewport_iframe_onload = t.step_func(() => { const in_viewport_iframe_onload = t_in_viewport.step_func_done(() => {
assert_false(has_in_viewport_loaded, assert_false(has_window_loaded,
"The in_viewport element should load only once."); "The in_viewport iframe should not block the load event");
has_in_viewport_loaded = true;
}); });
window.addEventListener("load", t.step_func(() => { const in_viewport_srcdoc_iframe_onload = t_in_viewport_srcdoc.step_func_done(() => {
assert_true(has_in_viewport_loaded,
"The in_viewport element should have loaded before " +
"window.load().");
assert_false(has_window_loaded, assert_false(has_window_loaded,
"The window.load() event should only fire once."); "The in_viewport srcdoc iframe should not block the load event");
});
window.addEventListener("load", () => {
has_window_loaded = true; has_window_loaded = true;
document.getElementById("below_viewport").scrollIntoView(); document.getElementById("below_viewport_srcdoc").scrollIntoView();
})); });
const below_viewport_iframe_onload = t_below_viewport.step_func_done(() => {
assert_true(has_window_loaded,
"The window.load() event should have fired before " +
"the below-viewport iframe loads");
});
const below_viewport_iframe_onload = t.step_func_done(() => { // Must make this accessible to the srcdoc iframe's body.
window.below_viewport_srcdoc_iframe_subresource_onload = t_below_viewport_srcdoc.step_func(() => {
assert_true(has_window_loaded, assert_true(has_window_loaded,
"The window.load() event should have fired before " + "The window.load() event should have fired before " +
"below_viewport loaded."); "the below-viewport srcdoc iframe's subresource loads");
});
const below_viewport_srcdoc_iframe_onload = t_below_viewport_srcdoc.step_func_done(() => {
assert_true(has_window_loaded,
"The window.load() event should have fired before " +
"the below-viewport srcdoc iframe loads");
}); });
</script> </script>
...@@ -41,13 +59,24 @@ ...@@ -41,13 +59,24 @@
<iframe id="in_viewport" src="resources/subframe.html?in-viewport" <iframe id="in_viewport" src="resources/subframe.html?in-viewport"
loading="lazy" width="200px" height="100px" loading="lazy" width="200px" height="100px"
onload="in_viewport_iframe_onload();"></iframe> onload="in_viewport_iframe_onload();"></iframe>
<div style="height:1000vh;"></div> <iframe id="in_viewport_srcdoc"
srcdoc="<body><img src='/common/square.png?in-viewport'></body>"
loading="lazy" width="200px" height="100px"
onload="in_viewport_srcdoc_iframe_onload();"></iframe>
<div style="height:2000vh;"></div>
<iframe id="below_viewport" src="resources/subframe.html?below-viewport" <iframe id="below_viewport" src="resources/subframe.html?below-viewport"
loading="lazy" width="200px" height="100px" loading="lazy" width="200px" height="100px"
onload="below_viewport_iframe_onload();"></iframe> onload="below_viewport_iframe_onload();"></iframe>
<iframe id="below_viewport_srcdoc"
srcdoc="<body><img src='/common/square.png?below-viewport'
onload='parent.below_viewport_srcdoc_iframe_subresource_onload();'></body>"
loading="lazy" width="200px" height="100px"
onload="below_viewport_srcdoc_iframe_onload();"></iframe>
<!-- This async script loads very slowly in order to ensure that, if the <!-- This async script loads very slowly in order to ensure that, if the
below_viewport element has started loading, it has a chance to finish below_viewport* elements have started loading, it has a chance to finish
loading before window.load() happens, so that the test will dependably loading before window.load() happens, so that the test will dependably
fail in that case instead of potentially passing depending on how long fail in that case instead of potentially passing depending on how long
different resource fetches take. --> different resource fetches take. -->
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment