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 tests for changing base URL, the test
original-base-url-applied-tentative.html changed the document URL, which
only implicitly changed the document's base URL. These tests explicitly
change the document's base URL via the <base> element.

Bug: 984983
Change-Id: I5ab855aaecc8bd12502eb32a3b1d26ae5ced31a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1954508
Reviewed-by: Dominic Farolino <dom@chromium.org>
Commit-Queue: Rob Buis <rbuis@igalia.com>
Cr-Commit-Position: refs/heads/master@{#724964}
  • Loading branch information
rwlbuis authored and chromium-wpt-export-bot committed Dec 15, 2019
1 parent a9e454c commit 96828fe
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
47 changes: 47 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,47 @@
<!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>
const below_viewport_img_promise = new ElementLoadPromise("below_viewport_img");

let has_window_loaded = false;

async_test(function(t) {

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

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

<body>
<div style="height:1000vh"></div>
<img id="below_viewport_img" src="image.png" loading="lazy"
onload="below_viewport_img_promise.resolve();"
onerror="below_viewport_img_promise.reject();">
</body>
49 changes: 49 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,49 @@
<!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 Marked as tentative until the HTML Standard
specifies this.
-->

<script>
const below_viewport_iframe_promise = new ElementLoadPromise("below_viewport_iframe");

let has_window_loaded = false;

async_test(function(t) {

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

below_viewport_iframe_promise.promise.then(
t.step_func_done(function() {
assert_true(has_window_loaded);
assert_true(below_viewport_iframe_promise.element().contentDocument.body.
innerHTML.includes("<p>Subframe</p>"));
})
).catch(t.unreached_func("The iframe request should not load relative to " +
"the current (incorrect) base URL."));
}, "Test that when deferred iframe is loaded, the parse time base URL is used.");
</script>

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

0 comments on commit 96828fe

Please sign in to comment.