-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LazyLoad: add new test for changing base URL
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
1 parent
a9e454c
commit 96828fe
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
loading/lazyload/original-base-url-applied-2-tentative.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,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
49
loading/lazyload/original-base-url-applied-iframe-tentative.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,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> |