/
image-loading-lazy.tentative.html
52 lines (44 loc) · 1.82 KB
/
image-loading-lazy.tentative.html
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
<!DOCTYPE html>
<head>
<title>Images 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">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<!--
Marked as tentative until https://github.com/whatwg/html/pull/3752 is landed.
-->
<body>
<img id="in_viewport" src="resources/image.png?first" loading="lazy">
<div style="height:10000px;"></div>
<img id="below_viewport" src="resources/image.png?second" loading="lazy">
<!--
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
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>
<script>
let t = async_test("Test that images with loading='lazy' load once they enter the viewport.");
let has_in_viewport_loaded = false;
let has_window_loaded = false;
document.getElementById("in_viewport").addEventListener("load", t.step_func(function() {
assert_false(has_in_viewport_loaded);
assert_false(has_window_loaded);
has_in_viewport_loaded = true;
}));
window.addEventListener("load", t.step_func(function() {
assert_true(has_in_viewport_loaded);
assert_false(has_window_loaded);
has_window_loaded = true;
document.getElementById("below_viewport").scrollIntoView();
}));
document.getElementById("below_viewport").addEventListener("load", t.step_func_done(function() {
assert_true(has_in_viewport_loaded);
assert_true(has_window_loaded);
}));
</script>