summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/embedded-content/the-img-element/picture-loading-lazy.html
blob: 08c01616bd6b4ba197627969f6dae7793e689abe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!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="../resources/common.js"></script>
</head>

<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>