Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /html/semantics/embedded-content/the-iframe-element/cross-site/iframe-loading-lazy-siblings-cross-site.sub.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<head>
<title>Side-by-side cross-site iframes with loading='lazy' load when in the viewport</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<script>
const t_in_viewport_left =
async_test('In-viewport left iframe loads eagerly');
const t_below_viewport_left =
async_test('Below-viewport left iframe loads lazily');
const t_in_viewport_right =
async_test('In-viewport right iframe loads eagerly');
const t_below_viewport_right =
async_test('Below-viewport right iframe loads lazily');
const expected_left_url = "http://{{hosts[alt][]}}:{{ports[http][0]}}/html/semantics/embedded-content/the-iframe-element/cross-site/resources/subframe-post-msg.html?below-viewport-left";
const expected_right_url = "https://{{hosts[alt][]}}:{{ports[https][0]}}/html/semantics/embedded-content/the-iframe-element/cross-site/resources/subframe-post-msg.html?below-viewport-right";
let has_window_loaded = false;
const in_viewport_left_iframe_onload = t_in_viewport_left.step_func_done(() => {
assert_false(has_window_loaded,
"The left in_viewport iframe should not block the load event");
});
const in_viewport_right_iframe_onload = t_in_viewport_right.step_func_done(() => {
assert_false(has_window_loaded,
"The right in_viewport iframe should not block the load event");
});
window.addEventListener("load", () => {
has_window_loaded = true;
document.getElementById("below_viewport_left").scrollIntoView();
});
window.addEventListener("message", event => {
if (event.source === document.getElementById("below_viewport_left").contentWindow) {
t_below_viewport_left.step_func_done(() => {
assert_equals(event.data, expected_left_url,
"The left below-viewport iframe should have loaded its cross-site document");
assert_true(has_window_loaded,
"The window load event should have fired before the left below-viewport iframe loads");
})();
} else if (event.source === document.getElementById("below_viewport_right").contentWindow) {
t_below_viewport_right.step_func_done(() => {
assert_equals(event.data, expected_right_url,
"The right below-viewport iframe should have loaded its cross-site document");
assert_true(has_window_loaded,
"The window load event should have fired before the right below-viewport iframe loads");
})();
}
});
</script>
<body>
<div style="display: flex; gap: 10px;">
<iframe id="in_viewport_left"
loading="lazy" width="200px" height="100px"
onload="in_viewport_left_iframe_onload();"></iframe>
<iframe id="in_viewport_right"
loading="lazy" width="200px" height="100px"
onload="in_viewport_right_iframe_onload();"></iframe>
</div>
<div style="height:2000vh;"></div>
<div style="display: flex; gap: 10px;">
<iframe id="below_viewport_left"
loading="lazy" width="200px" height="100px"></iframe>
<iframe id="below_viewport_right"
loading="lazy" width="200px" height="100px"></iframe>
</div>
<!-- This async script loads very slowly in order to ensure that, if the
below_viewport* elements have started loading, it has a chance to finish
loading before window load event fires, so that the test will dependably
fail in that case instead of potentially passing depending on how long
different resource fetches take. -->
<script async src="/common/slow.py"></script>
</body>