Skip to content

Commit

Permalink
LazyLoad: Add external web platform tests for the lazyload attribute.
Browse files Browse the repository at this point in the history
This CL includes the test for the setting the attribute lazyload="off"
on iframes and image elements, which should prevent those elements from
being lazily loaded.

Bug: 916260
Change-Id: I323faa31c7683663d0d0136a719cf83c25758ad6
  • Loading branch information
scott-little authored and chromium-wpt-export-bot committed Jan 17, 2019
1 parent 2ade7dc commit 731a86d
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<head>
<title>Loading cross-origin iframes with lazyload="off"</title>
<link rel="author" title="Scott Little" href="mailto:[email protected]">
<link rel="help" href="https://github.com/whatwg/html/pull/3752">
<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>
<iframe id="in_viewport" src="https://{{hosts[][www]}}:{{ports[https][0]}}/loading/lazyload/resources/subframe_1.html" width="200px" height="100px" lazyload="off"></iframe>
<div style="height:10000px;"></div>
<iframe id="below_viewport" src="https://{{hosts[][www]}}:{{ports[https][0]}}/loading/lazyload/resources/subframe_2.html" width="200px" height="100px" lazyload="off"></iframe>
</body>

<script>
async_test(function(t) {
window.addEventListener("load", t.step_func_done());
}, "Test that document load event is fired");

async_test(function(t) {
var has_in_viewport_iframe_loaded = false;
document.getElementById("in_viewport").addEventListener("load",
t.step_func(function() {
assert_false(has_in_viewport_iframe_loaded);
has_in_viewport_iframe_loaded = true;
}));
window.addEventListener("load", t.step_func_done(function() {
assert_true(has_in_viewport_iframe_loaded);
}));
}, "Test that the in-viewport iframe loads immediately.");

async_test(function(t) {
var has_below_viewport_iframe_loaded = false;
document.getElementById("below_viewport").addEventListener("load",
t.step_func(function() {
assert_false(has_below_viewport_iframe_loaded);
has_below_viewport_iframe_loaded = true;
}));
window.addEventListener("load", t.step_func_done(function() {
assert_true(has_below_viewport_iframe_loaded);
}));
}, "Test that the below-viewport iframe loads immediately.");
</script>
48 changes: 48 additions & 0 deletions loading/lazyload/attribute_off_iframe_same_origin.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<head>
<title>Loading same-origin iframes with lazyload="off"</title>
<link rel="author" title="Scott Little" href="mailto:[email protected]">
<link rel="help" href="https://github.com/whatwg/html/pull/3752">
<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>
<iframe id="in_viewport" src="resources/subframe_1.html" width="200px" height="100px" lazyload="off"></iframe>
<div style="height:10000px;"></div>
<iframe id="below_viewport" src="resources/subframe_2.html" width="200px" height="100px" lazyload="off"></iframe>
</body>

<script>
async_test(function(t) {
window.addEventListener("load", t.step_func_done());
}, "Test that document load event is fired");

async_test(function(t) {
var has_in_viewport_iframe_loaded = false;
document.getElementById("in_viewport").addEventListener("load",
t.step_func(function() {
assert_false(has_in_viewport_iframe_loaded);
has_in_viewport_iframe_loaded = true;
}));
window.addEventListener("load", t.step_func_done(function() {
assert_true(has_in_viewport_iframe_loaded);
}));
}, "Test that the in-viewport iframe loads immediately.");

async_test(function(t) {
var has_below_viewport_iframe_loaded = false;
document.getElementById("below_viewport").addEventListener("load",
t.step_func(function() {
assert_false(has_below_viewport_iframe_loaded);
has_below_viewport_iframe_loaded = true;
}));
window.addEventListener("load", t.step_func_done(function() {
assert_true(has_below_viewport_iframe_loaded);
}));
}, "Test that the below-viewport iframe loads immediately.");
</script>
48 changes: 48 additions & 0 deletions loading/lazyload/attribute_off_image.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<head>
<title>Loading images with lazyload="off"</title>
<link rel="author" title="Scott Little" href="mailto:[email protected]">
<link rel="help" href="https://github.com/whatwg/html/pull/3752">
<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_1.png" lazyload="off">
<div style="height:10000px;"></div>
<img id="below_viewport" src="resources/image_2.png" lazyload="off">
</body>

<script>
async_test(function(t) {
window.addEventListener("load", t.step_func_done());
}, "Test that document load event is fired");

async_test(function(t) {
var has_in_viewport_image_loaded = false;
document.getElementById("in_viewport").addEventListener("load",
t.step_func(function() {
assert_false(has_in_viewport_image_loaded);
has_in_viewport_image_loaded = true;
}));
window.addEventListener("load", t.step_func_done(function() {
assert_true(has_in_viewport_image_loaded);
}));
}, "Test that the in-viewport image loads immediately.");

async_test(function(t) {
var has_below_viewport_image_loaded = false;
document.getElementById("below_viewport").addEventListener("load",
t.step_func(function() {
assert_false(has_below_viewport_image_loaded);
has_below_viewport_image_loaded = true;
}));
window.addEventListener("load", t.step_func_done(function() {
assert_true(has_below_viewport_image_loaded);
}));
}, "Test that the below-viewport image loads immediately.");
</script>
Binary file added loading/lazyload/resources/image_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added loading/lazyload/resources/image_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions loading/lazyload/resources/subframe_1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<p>Subframe 1.</p>
</body>
</html>
5 changes: 5 additions & 0 deletions loading/lazyload/resources/subframe_2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<p>Subframe 2.</p>
</body>
</html>

0 comments on commit 731a86d

Please sign in to comment.