Skip to content

Commit

Permalink
LazyLoad: add new test for changing base URL
Browse files Browse the repository at this point in the history
Add new test for changing base URL, the test
original-base-url-applied-tentative.html only changed the document URL.

Bug: 984983
Change-Id: I5ab855aaecc8bd12502eb32a3b1d26ae5ced31a3
  • Loading branch information
rwlbuis authored and chromium-wpt-export-bot committed Dec 12, 2019
1 parent 1db21a0 commit 8ba6efc
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
46 changes: 46 additions & 0 deletions loading/lazyload/original-base-url-applied-2-tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<head>
<title>Deferred images with loading='lazy' use the original
base URL specified at the parse time</title>
<link rel="author" title="Rob Buis" href="mailto:rbuis@igalia.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="common.js"></script>
<base href='/loading/lazyload/resources/'>
</head>

<!--
Marked as tentative until https://github.com/whatwg/html/pull/3752 is landed.
-->

<script>
let has_window_loaded = false;

async_test(function(t) {
const below_viewport_img = new ElementLoadPromise("below_viewport_img");

// Change the base URL and scroll down to load the deferred elements.
window.addEventListener("load", () => {
var base = document.getElementsByTagName('base')[0];
base.href = '/invalid-url-where-no-subresources-exist/';
has_window_loaded = true;
below_viewport_img.element().scrollIntoView();
});

below_viewport_img.promise.then(
t.step_func_done(function() {
assert_true(has_window_loaded);
assert_true(below_viewport_img.element().complete);
assert_greater_than(below_viewport_img.element().naturalWidth, 0);
})
).catch(t.unreached_func("The image load should not fail, trying to" +
" load with invalid base URL."));
}, "Test that when deferred img is loaded, it uses the parse time base URL.");
</script>

<body>
<div style="height:110vh"></div>
<img id="below_viewport_img" src="image.png" loading="lazy"
onload="below_viewport_img.resolve();"
onerror="below_viewport_img.reject();">
</body>
44 changes: 44 additions & 0 deletions loading/lazyload/original-base-url-applied-iframe-tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<head>
<title>Deferred iframes with loading='lazy' use the original
base URL specified at the parse time</title>
<link rel="author" title="Rob Buis" href="mailto:rbuis@igalia.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="common.js"></script>
<base href='/loading/lazyload/resources/'>
</head>

<!--
Marked as tentative until https://github.com/whatwg/html/pull/3752 is landed.
-->

<script>
let has_window_loaded = false;

async_test(function(t) {
const below_viewport_iframe = new ElementLoadPromise("below_viewport_iframe");

// Change the base URL and scroll down to load the deferred elements.
window.addEventListener("load", () => {
var base = document.getElementsByTagName('base')[0];
base.href = '/invalid-url-where-no-subresources-exist/';
has_window_loaded = true;
below_viewport_iframe.element().scrollIntoView();
});

below_viewport_iframe.promise.then(
t.step_func_done(function() {
assert_true(has_window_loaded);
assert_true(below_viewport_iframe.element().contentDocument.body.
innerHTML.includes("<p>Subframe</p>"));
}));
}, "Test that when deferred iframe is loaded, the parse time base URL is used.");
</script>

<body>
<div style="height:110vh"></div>
<iframe id="below_viewport_iframe" src="subframe.html" loading="lazy"
width="200px" height="100px" onload="below_viewport_iframe.resolve();">
</iframe>
</body>

0 comments on commit 8ba6efc

Please sign in to comment.