Bug 1638176 [wpt PR 23623] - [Lazyload]: Add image lazy loading relevant mutation tests, a=testonly

Automatic update from web-platform-tests
[Lazyload]: Add image lazy loading relevant mutation tests

The bug https://crbug.com/1082961 outlines an issue whereby when
relevant mutations take place on a deferred loading=lazy image, these
mutations cause the image to be fetched immediately, which is the
incorrect behavior.

Bug: 1082961
Change-Id: I2eaeb0815266df55aa451e02cc29f91ca065c781
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2202684
Commit-Queue: Dominic Farolino <dom@chromium.org>
Reviewed-by: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#769299}

--

wpt-commits: 64380e1f01ea0a603ec65ff2c3101239aceada00
wpt-pr: 23623
This commit is contained in:
Dominic Farolino 2020-05-21 10:22:21 +00:00 коммит произвёл moz-wptsync-bot
Родитель 5d74689ad5
Коммит 4880917b27
1 изменённых файлов: 83 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,83 @@
<!DOCTYPE html>
<head>
<title>Relevant mutations on deferred loading=lazy images should not trigger
a request</title>
<link rel="author" title="Dom Farolino" href="mailto:dom@chromium.org">
<link rel="help" href="https://html.spec.whatwg.org/multipage/images.html#updating-the-image-data">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<script>
let below_viewport_1_loaded = false,
below_viewport_2_loaded = false,
below_viewport_3_loaded = false
// For general lazy loading behavior.
promise_test(() => {
// When the page loads, start the rest of the tests.
return new Promise(resolve => {
window.addEventListener("load", e => {
const kAssertion = 'image should never load';
assert_false(below_viewport_1_loaded, `below-viewport-1 ${kAssertion}`);
assert_false(below_viewport_2_loaded, `below-viewport-2 ${kAssertion}`);
assert_false(below_viewport_3_loaded, `below-viewport-3 ${kAssertion}`);
resolve();
});
});
}, "Images are lazyloaded");
// For `referrerPolicy` attribute mutations.
promise_test(t => {
return new Promise((resolve, reject) => {
const below_viewport_1 = document.querySelector('img#below-viewport-1');
below_viewport_1.onload = reject;
below_viewport_1.onerror = reject;
t.step_timeout(resolve, 1000);
below_viewport_1.referrerPolicy = 'no-referrer';
});
}, "Image referrerPolicy mutation does not cause deferred loading=lazy " +
"images to be fetched");
// For `crossOrigin` attribute mutations.
promise_test(t => {
return new Promise((resolve, reject) => {
const below_viewport_2 = document.querySelector('img#below-viewport-2');
below_viewport_2.onload = reject;
below_viewport_2.onerror = reject;
t.step_timeout(resolve, 1000);
below_viewport_2.crossOrigin = 'anonymous';
});
}, "Image crossOrigin mutation does not cause deferred loading=lazy " +
"images to be fetched");
// For `src` attribute mutations.
promise_test(t => {
return new Promise((resolve, reject) => {
const below_viewport_3 = document.querySelector('img#below-viewport-3');
below_viewport_3.onload = reject;
below_viewport_3.onerror = reject;
t.step_timeout(resolve, 1000);
below_viewport_3.src = "resources/image.png?change";
});
}, "Image src mutation does not cause deferred loading=lazy " +
"images to be fetched");
</script>
<body>
<div style="height:1000vh;"></div>
<img id="below-viewport-1" src="resources/image.png?1" loading="lazy"
onload="below_viewport_1_loaded = true"
onerror="below_viewport_1_loaded = true">
<img id="below-viewport-2" src="resources/image.png?2" loading="lazy"
onload="below_viewport_2_loaded = true"
onerror="below_viewport_2_loaded = true">
<img id="below-viewport-3" src="resources/image.png?3" loading="lazy"
onload="below_viewport_3_loaded = true"
onerror="below_viewport_3_loaded = true">
</body>