Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LazyLoad: Implement support for "lazyload" attribute on images
This CL implements support for the "lazyload" attribute on images, according to whatwg/html#3752, and as part of the LazyLoad feature. The accepted values are: "off", which causes the browser to avoid lazily loading the <img> element "on" and "auto", activate the default behavior of lazily load the <img> element When the attribute is changed to "off", the deferred image loads immediately. Bug: 875080 Change-Id: I839926a9827d019f23aafc40f8315476fe1b3048 Reviewed-on: https://chromium-review.googlesource.com/1197782 Reviewed-by: Hiroshige Hayashizaki <hiroshige@chromium.org> Reviewed-by: Takashi Toyoshima <toyoshim@chromium.org> Commit-Queue: rajendrant <rajendrant@chromium.org> Cr-Commit-Position: refs/heads/master@{#592599}
- Loading branch information
rajendrant
authored and
Commit Bot
committed
Sep 19, 2018
1 parent
2508fd4
commit 713811d
Showing
9 changed files
with
112 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
third_party/WebKit/LayoutTests/http/tests/lazyload/attribute.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="placeholder.js"></script> | ||
|
||
<body> | ||
<div style="height:10000px;"></div> | ||
<img id="no_attribute_img" src='../loading/resources/base-image1.png'> | ||
<img id="auto_attribute_img" src='../loading/resources/base-image2.png' lazyload="auto"> | ||
<img id="invalid_attribute_img" src='../loading/resources/base-image3.png' lazyload="invalid-value-default"> | ||
<img id="on_attribute_img" src='../loading/resources/dup-image1.png' lazyload="on"> | ||
<img id="off_attribute_img" src='../loading/resources/dup-image2.png' lazyload="off"> | ||
</body> | ||
|
||
<script> | ||
var no_attribute_img = document.getElementById("no_attribute_img"); | ||
var auto_attribute_img = document.getElementById("auto_attribute_img"); | ||
var invalid_attribute_img = document.getElementById("invalid_attribute_img"); | ||
var on_attribute_img = document.getElementById("on_attribute_img"); | ||
var off_attribute_img = document.getElementById("off_attribute_img"); | ||
|
||
async_test(function(t) { | ||
window.addEventListener("load", t.step_func_done()); | ||
}, "Test that document load event is fired"); | ||
|
||
async_test(function(t) { | ||
window.addEventListener("load", t.step_func_done(function() { | ||
assert_false(is_image_fully_loaded(on_attribute_img)); | ||
assert_false(is_image_fully_loaded(no_attribute_img)); | ||
})); | ||
on_attribute_img.addEventListener("load", | ||
t.unreached_func("Load event should not be fired for below viewport image with lazyload=on")); | ||
auto_attribute_img.addEventListener("load", | ||
t.unreached_func("Load event should not be fired for below viewport image with lazyload=auto")); | ||
no_attribute_img.addEventListener("load", | ||
t.unreached_func("Load event should not be fired for below viewport image with no lazyload attribute")); | ||
invalid_attribute_img.addEventListener("load", | ||
t.unreached_func("Load event should not be fired for below viewport image with invalid lazyload attribute")); | ||
}, "Test that <img> with lazyload=on or auto or no attribute or invalid value are loaded as a placeholder"); | ||
|
||
async_test(function(t) { | ||
off_attribute_img.addEventListener("load", | ||
t.step_func_done(function() { | ||
assert_true(is_image_fully_loaded(off_attribute_img)); | ||
})); | ||
}, "Test that <img> with lazyload=off is fully loaded, and not a placeholder"); | ||
|
||
async_test(function(t) { | ||
var complete = 0; | ||
var onload_callback = function() { | ||
if (++complete == 4) { | ||
// The four images with lazyload=on,auto or default or invalid attribute are loaded. | ||
assert_true(is_image_fully_loaded(no_attribute_img)); | ||
assert_true(is_image_fully_loaded(on_attribute_img)); | ||
assert_true(is_image_fully_loaded(auto_attribute_img)); | ||
assert_true(is_image_fully_loaded(invalid_attribute_img)); | ||
t.done(); | ||
} | ||
assert_equals("off", this.getAttribute('lazyload')); | ||
}; | ||
no_attribute_img.addEventListener("load", onload_callback); | ||
on_attribute_img.addEventListener("load", onload_callback); | ||
auto_attribute_img.addEventListener("load", onload_callback); | ||
invalid_attribute_img.addEventListener("load", onload_callback); | ||
window.addEventListener("load", t.step_func(function() { | ||
assert_equals(null, no_attribute_img.getAttribute('lazyload')); | ||
assert_equals("on", on_attribute_img.getAttribute('lazyload')); | ||
assert_equals("auto", auto_attribute_img.getAttribute('lazyload')); | ||
assert_equals("invalid-value-default", invalid_attribute_img.getAttribute('lazyload')); | ||
no_attribute_img.setAttribute('lazyload', 'off'); | ||
on_attribute_img.setAttribute('lazyload', 'off'); | ||
auto_attribute_img.setAttribute('lazyload', 'off'); | ||
invalid_attribute_img.setAttribute('lazyload', 'off'); | ||
})); | ||
}, "Test that deferred <img> are fully loaded when lazyload attribute is turned off"); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters