Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Augment iframe lazyload tests for srcdoc #24361

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added common/square.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,81 @@
<head>
<title>Iframes with loading='lazy' load when in the viewport</title>
<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/testharnessreport.js"></script>
</head>

<script>
const t = async_test("Test that iframes with loading='lazy' load once they " +
"enter the viewport.");
const t_in_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_in_viewport_loaded = false;

const in_viewport_iframe_onload = t.step_func(() => {
assert_false(has_in_viewport_loaded,
"The in_viewport element should load only once.");
has_in_viewport_loaded = true;
const in_viewport_iframe_onload = t_in_viewport.step_func_done(() => {
assert_false(has_window_loaded,
"The in_viewport iframe should not block the load event");
});

window.addEventListener("load", t.step_func(() => {
assert_true(has_in_viewport_loaded,
"The in_viewport element should have loaded before " +
"window.load().");
const in_viewport_srcdoc_iframe_onload = t_in_viewport_srcdoc.step_func_done(() => {
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;
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,
"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>

<body>
<iframe id="in_viewport" src="resources/subframe.html?in-viewport"
loading="lazy" width="200px" height="100px"
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"
loading="lazy" width="200px" height="100px"
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
below_viewport element has started loading, it has a chance to finish
below_viewport* elements have started loading, it has a chance to finish
domfarolino marked this conversation as resolved.
Show resolved Hide resolved
loading before window.load() happens, so that the test will dependably
fail in that case instead of potentially passing depending on how long
different resource fetches take. -->
Expand Down