Update web-platform-tests to revision 8ba782c9d5a545b850cd8920032cb14cfbab2c35

This commit is contained in:
WPT Sync Bot 2020-07-17 08:20:46 +00:00
parent b17a302356
commit 986610f6ed
91 changed files with 1030 additions and 429 deletions

View file

@ -1,51 +0,0 @@
<!DOCTYPE html>
<head>
<title>In-viewport loading=lazy images do not block the window load event</title>
<link rel="author" title="Rob Buis" href="mailto:rbuis@igalia.com">
<link rel="author" title="Dom Farolino" href="mailto:dom@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/common.js"></script>
</head>
<body>
<!-- This image blocks the window load event for 1 second -->
<img src="resources/image.png?window-load-blocking&pipe=trickle(d1)">
<!-- These images must load because they intersect the viewport, but they must
not block the window load event, because they are loading=lazy -->
<img id="visible"
src="resources/image.png?visible&pipe=trickle(d3)" loading="lazy"
onload="visible_img.resolve();" onerror="visible_img.reject();">
<img id="visibility_hidden" style="visibility:hidden;"
src="resources/image.png?visibility_hidden&pipe=trickle(d3)" loading="lazy"
onload="visibility_hidden_img.resolve();" onerror="visibility_hidden_img.reject();">
</body>
<script>
const visible_img = new ElementLoadPromise("visible");
const visibility_hidden_img = new ElementLoadPromise("visibility_hidden");
async_test(t => {
let has_window_loaded = false;
window.addEventListener("load", t.step_func(() => {
has_window_loaded = true;
}));
Promise.all([visible_img.promise, visibility_hidden_img.promise])
.then(t.step_func_done(() => {
assert_true(has_window_loaded,
"The window load event should fire before the " +
"in-viewport loading=lazy images load");
assert_true(visible_img.element().complete,
"The in-viewport loading=lazy visible image is complete");
assert_true(visibility_hidden_img.element().complete,
"The in-viewport loading=lazy visibility:hidden image is " +
"complete");
}))
.catch(t.unreached_func("The images should load successfully"));
}, "In-viewport loading=lazy images do not block the window load event");
</script>

View file

@ -1,38 +1,95 @@
<!DOCTYPE html>
<head>
<title>Images with loading='lazy' load only when in the viewport</title>
<link rel="author" title="Scott Little" href="mailto:sclittle@chromium.org">
<link rel="author" title="Dom Farolino" href="mailto:dom@chromium.org">
<link rel="author" title="Scott Little" href="mailto:sclittle@chromium.org">
<link rel="help" href="https://github.com/scott-little/lazyload">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<script>
const t = async_test("Images with loading='lazy' load only when in the viewport");
const in_viewport_test =
async_test("In-viewport loading=lazy images load immediately but do not " +
"block the window load event");
const below_viewport_test =
async_test("Below-viewport loading=lazy images only load when in the " +
"viewport and do not block the window load event");
const below_viewport_data_url_test =
async_test("Below-viewport data:url images only load when in the " +
"viewport and do not block the window load event");
const below_viewport_blob_url_test =
async_test("Below-viewport blob URL images only load when in the " +
"viewport and do not block the window load event");
document.addEventListener('DOMContentLoaded', e => {
const img = document.querySelector('#below_viewport_blob_url');
// Blob URL helper.
// Source: https://bl.ocks.org/nolanlawson/0eac306e4dac2114c752.
function fixBinary(bin) {
const length = bin.length;
const buf = new ArrayBuffer(length);
const arr = new Uint8Array(buf);
for (var i = 0; i < length; i++) {
arr[i] = bin.charCodeAt(i);
}
return buf;
}
const base64 =
"R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA";
const binary = fixBinary(atob(base64));
const blob = new Blob([binary], {type: 'image/png'});
const url = URL.createObjectURL(blob);
img.src = url;
}) // DOMContentLoaded.
let has_in_viewport_loaded = false;
let has_window_load_fired = false;
let has_in_viewport_loaded = false;
const in_viewport_img_onload = t.step_func(() => {
assert_false(has_in_viewport_loaded,
"The in_viewport element should load only once.");
window.onload = e => {
has_window_load_fired = true;
}
// Helper assertion messages for the below tests.
const kScrollAssertion = "images only load when scrolled into view";
const kWindowLoadAssertion = "images do not block the load event";
const in_viewport_img_onload = in_viewport_test.step_func_done(() => {
has_in_viewport_loaded = true;
assert_true(document.getElementById("in_viewport").complete);
document.getElementById("below_viewport").scrollIntoView();
document.querySelector('#bottom').scrollIntoView();
assert_true(has_window_load_fired,
"In-viewport loading=lazy images do not block the window " +
"load event");
});
window.addEventListener("load", t.step_func(() => {
has_window_load_fired = true;
}));
const below_viewport_img_onload = t.step_func_done(() => {
const below_viewport_img_onload = below_viewport_test.step_func_done(() => {
assert_true(has_in_viewport_loaded,
"The below-viewport image should not load until it has been " +
"scrolled into viewport, after the in-viewport image loads");
"Below-viewport loading=lazy images only load once loaded " +
"into the viewport");
assert_true(has_window_load_fired,
"Below-viewport loading=lazy images should not block the " +
"window load event from firing");
"window load event");
});
const below_viewport_data_url_img_onload = below_viewport_data_url_test.step_func_done(() => {
assert_true(has_in_viewport_loaded,
"Below-viewport loading=lazy data: url images " +
kScrollAssertion);
assert_true(has_window_load_fired,
"Below-viewport loading=lazy data: url images " +
kWindowLoadAssertion);
});
const below_viewport_blob_url_img_onload = below_viewport_blob_url_test.step_func_done(() => {
assert_true(has_in_viewport_loaded,
"Below-viewport loading=lazy blob url images " +
kScrollAssertion);
assert_true(has_window_load_fired,
"Below-viewport loading=lazy blob url images " +
kWindowLoadAssertion);
});
</script>
@ -41,8 +98,15 @@
support lazy loading, |below_viewport| finishes before |in_viewport|, and
the test will dependably fail without relying on a timeout. -->
<img id="in_viewport" loading="lazy" src="resources/image.png?first&pipe=trickle(d2)"
onload="in_viewport_img_onload();">
onload="in_viewport_img_onload()">
<div style="height:1000vh;"></div>
<img id="below_viewport" loading="lazy" src="resources/image.png?second"
onload="below_viewport_img_onload();">
onload="below_viewport_img_onload()">
<img id="below_viewport_data_url" loading="lazy"
src="data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA"
onload="below_viewport_data_url_img_onload()">
<!-- This image has its `src` set to a blob URL dynamically above -->
<img id="below_viewport_blob_url" loading="lazy"
onload="below_viewport_blob_url_img_onload()">
<div id="bottom"></div>
</body>