Bug 1568090 [wpt PR 17985] - LazyImage: Add WPT tests for picture elements, a=testonly

Automatic update from web-platform-tests
LazyImage: Add WPT tests for picture elements

Bug: 985857
Change-Id: I405e210985953effd5b258a1de2c1ce560e2e2ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1714211
Commit-Queue: rajendrant <rajendrant@chromium.org>
Reviewed-by: Dominic Farolino <dom@chromium.org>
Reviewed-by: Tarun Bansal <tbansal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680029}

--

wpt-commits: a3fac97d07a108cb35b9994e75712c830e2a4fcd
wpt-pr: 17985
This commit is contained in:
rajendrant 2019-07-30 17:53:36 +00:00 committed by moz-wptsync-bot
parent 3884c2b471
commit 0a8e4dbf3b

View File

@ -0,0 +1,68 @@
<!DOCTYPE html>
<head>
<title>Images with loading='lazy' in picture elements load when near the viewport</title>
<link rel="author" title="Raj T" href="mailto:rajendrant@chromium.org">
<link rel="help" href="https://github.com/scott-little/lazyload">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="common.js"></script>
</head>
<!--
Marked as tentative until https://github.com/whatwg/html/pull/3752 is landed.
-->
<script>
const in_viewport_img = new ElementLoadPromise("in_viewport_img");
const lazy_attribute_img = new ElementLoadPromise("lazy_attribute_img");
const eager_attribute_img = new ElementLoadPromise("eager_attribute_img");
const document_load_promise = new Promise(resolve => {
window.addEventListener("load", resolve);
});
async_test(function(t) {
document_load_promise.then(t.step_func_done(function() {
assert_false(lazy_attribute_img.element().complete);
lazy_attribute_img.element().scrollIntoView();
}));
}, "Test that the loading=lazy <picture> element below viewport was deferred, on document load.");
async_test(function(t) {
in_viewport_img.promise.then(t.step_func_done());
}, "Test that in viewport <picture> element was loaded");
async_test(function(t) {
eager_attribute_img.promise.then(t.step_func_done());
}, "Test that eager <picture> element was loaded");
async_test(function(t) {
lazy_attribute_img.promise.then(t.step_func_done());
}, "Test that deferred <picture> element was loaded-in as well, after scrolled down");
</script>
<body>
<picture>
<source sizes='50vw' srcset='resources/image.png?in_viewport_img'>
<img id='in_viewport_img' src='img-not-loaded.png' loading="lazy" onload="in_viewport_img.resolve();">
</picture>
<div style="height:10000px;"></div>
<picture>
<source sizes='50vw' srcset='resources/image.png?lazy_attribute_img'>
<img id='lazy_attribute_img' src='img-not-loaded.png' loading="lazy" onload="lazy_attribute_img.resolve();">
</picture>
<picture>
<source sizes='50vw' srcset='resources/image.png?eager_attribute_img'>
<img id='eager_attribute_img' src='img-not-loaded.png' loading="eager" onload="eager_attribute_img.resolve();">
</picture>
<!--
This async script loads very slowly in order to ensure that, if the
below_viewport image has 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.
-->
<script async src="/common/slow.py"></script>
</body>