Skip to content

Commit

Permalink
Augment iframe lazyload tests for srcdoc
Browse files Browse the repository at this point in the history
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:
whatwg/html#5579.

R=sclittle@chromium.org

Bug: 1101170
Change-Id: I5c5790c5d2eca3efbb01c5470e2267f2265858f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2276624
Reviewed-by: Scott Little <sclittle@chromium.org>
Commit-Queue: Dominic Farolino <dom@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784331}
  • Loading branch information
domfarolino authored and chromium-wpt-export-bot committed Jul 1, 2020
1 parent e5fea0a commit 36c3b7d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
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
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

0 comments on commit 36c3b7d

Please sign in to comment.