Commit ea0168f8 authored by arthursonzogni's avatar arthursonzogni Committed by Commit Bot

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: default avatarDave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760574}
parent 9ca07884
...@@ -14,36 +14,41 @@ See: https://html.spec.whatwg.org/#the-list-of-available-images ...@@ -14,36 +14,41 @@ See: https://html.spec.whatwg.org/#the-list-of-available-images
<script> <script>
var request_token = token(); var request_token = token();
async_test(t => { let image_src = "resources/stale-image.py?token=" + request_token;
window.onload = t.step_func(() => {
t.step_timeout(() => { let loadImage = async () => {
assert_equals(document.getElementById("firstimage").width, 16, "Width is 16"); let img = document.createElement("img");
var childDocument = document.getElementById('child').contentDocument; img.src = image_src;
var img2 = childDocument.createElement("img"); let loaded = new Promise(r => img.onload = r);
img2.onload = t.step_func(() => { document.body.appendChild(img);
assert_equals(img2.width, 16, "image dimension"); await loaded;
var checkResult = () => { return img;
// 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"); promise_test(async t => {
if (count == '2') { await new Promise(r => window.onload = r);
t.done();
} else { let img1 = await loadImage();
t.step_timeout(checkResult, 25); assert_equals(img1.width, 16, "(initial version loaded)");
}
})); let img2 = await loadImage();
}; assert_equals(img2.width, 16, "(stale version loaded)");
t.step_timeout(checkResult, 25);
}); // Query the server again and again. At some point it must have received the
img2.src = "resources/stale-image.py?token=" + request_token; // revalidation request. We poll, because we don't know when the revalidation
childDocument.body.appendChild(img2); // will occur.
}, 0); 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'); }, '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> </script>
</body> </body>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment