mirror of
https://github.com/servo/servo.git
synced 2025-07-12 09:53:40 +01:00
53 lines
1.7 KiB
HTML
53 lines
1.7 KiB
HTML
<!DOCTYPE html>
|
|
<meta charset="utf-8">
|
|
<title>Tests Stale While Revalidate works for scripts</title>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="/common/utils.js"></script>
|
|
<body>
|
|
<script>
|
|
var last_modified;
|
|
var last_modified_count = 0;
|
|
var request_token = token();
|
|
|
|
// The script will call report via a uniquely generated ID on the subresource.
|
|
// If it is a cache hit the ID will be the same and the test will pass.
|
|
function report(mod) {
|
|
if (!last_modified) {
|
|
last_modified = mod;
|
|
last_modified_count = 1;
|
|
} else if (last_modified == mod) {
|
|
last_modified_count++;
|
|
}
|
|
}
|
|
|
|
async_test(t => {
|
|
window.onload = t.step_func(() => {
|
|
step_timeout(() => {
|
|
var script = document.createElement("script");
|
|
script.src = "resources/stale-script.py?token=" + request_token;
|
|
document.body.appendChild(script);
|
|
script.onload = t.step_func(() => {
|
|
assert_equals(last_modified_count, 2, "last modified");
|
|
var checkResult = () => {
|
|
// We poll because we don't know when the revalidation will occur.
|
|
fetch("resources/stale-script.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);
|
|
});
|
|
}, 0);
|
|
});
|
|
}, 'Cache returns stale resource');
|
|
|
|
var script = document.createElement("script");
|
|
script.src = "resources/stale-script.py?token=" + request_token;
|
|
document.body.appendChild(script);
|
|
</script>
|
|
</body>
|