Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LazyLoad: add new test for changing base URL #20683

Merged
merged 1 commit into from
Dec 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
domfarolino marked this conversation as resolved.
Show resolved Hide resolved

// 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>