Bug 1631033 [wpt PR 23068] - Rework WPT: /fetch/stale-while-revalidate/stale-image.html, a=testonly

Automatic update from web-platform-tests
Rework WPT: /fetch/stale-while-revalidate/stale-image.html

Previous patch:
https://chromium-review.googlesource.com/c/chromium/src/+/2154786
improves ./stale-script.html

For consistency and because the test looks slightly nicer, this patch
applies the same kind of refactoring to ./stale-image.html

Bug: 1070117
Change-Id: Idae5a373154d9f6e8cc63d054d3abfe2662b621e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2152797
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: Dave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760574}

--

wpt-commits: fddc3a878fbc036ae2c5d9cda328814e8c0f4f60
wpt-pr: 23068
This commit is contained in:
arthursonzogni 2020-04-28 11:33:03 +00:00 коммит произвёл moz-wptsync-bot
Родитель b6d390bac8
Коммит d00c2377f3
1 изменённых файлов: 34 добавлений и 29 удалений

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

@ -14,36 +14,41 @@ See: https://html.spec.whatwg.org/#the-list-of-available-images
<script>
var request_token = token();
async_test(t => {
window.onload = t.step_func(() => {
t.step_timeout(() => {
assert_equals(document.getElementById("firstimage").width, 16, "Width is 16");
var childDocument = document.getElementById('child').contentDocument;
var img2 = childDocument.createElement("img");
img2.onload = t.step_func(() => {
assert_equals(img2.width, 16, "image dimension");
var checkResult = () => {
// We poll because we don't know when the revalidation will occur.
fetch("resources/stale-image.py?query&token=" + request_token).then(t.step_func((response) => {
var count = response.headers.get("Count");
if (count == '2') {
t.done();
} else {
t.step_timeout(checkResult, 25);
}
}));
};
t.step_timeout(checkResult, 25);
});
img2.src = "resources/stale-image.py?token=" + request_token;
childDocument.body.appendChild(img2);
}, 0);
});
let image_src = "resources/stale-image.py?token=" + request_token;
let loadImage = async () => {
let img = document.createElement("img");
img.src = image_src;
let loaded = new Promise(r => img.onload = r);
document.body.appendChild(img);
await loaded;
return img;
};
promise_test(async t => {
await new Promise(r => window.onload = r);
let img1 = await loadImage();
assert_equals(img1.width, 16, "(initial version loaded)");
let img2 = await loadImage();
assert_equals(img2.width, 16, "(stale version loaded)");
// Query the server again and again. At some point it must have received the
// revalidation request. We poll, because we don't know when the revalidation
// will occur.
while(true) {
await new Promise(r => step_timeout(r, 25));
let response = await fetch(image_src + "&query");
let count = response.headers.get("Count");
if (count == '2')
break;
}
let img3 = await loadImage();
assert_equals(img3.width, 256, "(revalidated version loaded)");
}, 'Cache returns stale resource');
var img = document.createElement("img");
img.src = "resources/stale-image.py?token=" + request_token;
img.id = "firstimage";
document.body.appendChild(img);
</script>
</body>