mirror of
https://github.com/servo/servo.git
synced 2025-08-15 18:35:33 +01:00
Update web-platform-tests to revision 8ae1ddbc812733c3a73b103eafad56fb43a2f4b5
This commit is contained in:
parent
d44e9aced2
commit
0e5e5db397
109 changed files with 2053 additions and 708 deletions
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<!---
|
||||
Tentative test against:
|
||||
https://github.com/whatwg/fetch/pull/853
|
||||
-->
|
||||
<meta charset="utf-8">
|
||||
<title>Tests Stale While Revalidate is not executed for fetch API</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
promise_test(async (test) => {
|
||||
const response = await fetch(`stale-script.py`);
|
||||
const response2 = await fetch(`stale-script.py`);
|
||||
|
||||
assert_not_equals(response.headers.get('Token'), response2.headers.get('Token'));
|
||||
}, 'Second fetch does not return same response');
|
||||
</script>
|
|
@ -0,0 +1,20 @@
|
|||
def main(request, response):
|
||||
|
||||
cookie = request.cookies.first("Count", None)
|
||||
count = 0
|
||||
if cookie != None:
|
||||
count = int(cookie.value)
|
||||
if request.GET.first("query", None) != None:
|
||||
headers = [("Count", count)]
|
||||
content = ""
|
||||
return 200, headers, content
|
||||
else:
|
||||
count = count + 1
|
||||
content = "body { background: rgb(0, 128, 0); }"
|
||||
if count > 1:
|
||||
content = "body { background: rgb(255, 0, 0); }"
|
||||
|
||||
headers = [("Content-Type", "text/css"),
|
||||
("Set-Cookie", "Count={}".format(count)),
|
||||
("Cache-Control", "private, max-age=0, stale-while-revalidate=10")]
|
||||
return 200, headers, content
|
|
@ -0,0 +1,47 @@
|
|||
<!DOCTYPE html>
|
||||
<!---
|
||||
Tentative test against:
|
||||
https://github.com/whatwg/fetch/pull/853
|
||||
-->
|
||||
<meta charset="utf-8">
|
||||
<title>Tests Stale While Revalidate works for css</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
step_timeout(() => {
|
||||
assert_equals(window.getComputedStyle(document.body).getPropertyValue('background-color'), "rgb(0, 128, 0)");
|
||||
var link2 = document.createElement("link");
|
||||
link2.onload = t.step_func(() => {
|
||||
assert_equals(window.getComputedStyle(document.body).getPropertyValue('background-color'), "rgb(0, 128, 0)");
|
||||
var checkResult = () => {
|
||||
// We poll because we don't know when the revalidation will occur.
|
||||
fetch("stale-css.py?query").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);
|
||||
});
|
||||
link2.rel = "stylesheet";
|
||||
link2.type = "text/css";
|
||||
link2.href = "stale-css.py";
|
||||
document.body.appendChild(link2);
|
||||
}, 0);
|
||||
});
|
||||
}, 'Cache returns stale resource');
|
||||
|
||||
var link = document.createElement("link");
|
||||
link.rel = "stylesheet";
|
||||
link.type = "text/css";
|
||||
link.href = "stale-css.py";
|
||||
document.body.appendChild(link);
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,30 @@
|
|||
import os.path
|
||||
|
||||
def main(request, response):
|
||||
|
||||
cookie = request.cookies.first("Count", None)
|
||||
count = 0
|
||||
if cookie != None:
|
||||
count = int(cookie.value)
|
||||
if request.GET.first("query", None) != None:
|
||||
headers = [("Count", count)]
|
||||
content = ""
|
||||
return 200, headers, content
|
||||
else:
|
||||
count = count + 1
|
||||
filename = "green-16x16.png"
|
||||
if cookie > 1:
|
||||
filename = "green-256x256.png"
|
||||
|
||||
path = os.path.join(os.path.dirname(__file__), "../../images", filename)
|
||||
body = open(path, "rb").read()
|
||||
|
||||
response.add_required_headers = False
|
||||
response.writer.write_status(200)
|
||||
response.writer.write_header("content-length", len(body))
|
||||
response.writer.write_header("Cache-Control", "private, max-age=0, stale-while-revalidate=10")
|
||||
response.writer.write_header("content-type", "image/png")
|
||||
response.writer.write_header("Set-Cookie", "Count={}".format(count))
|
||||
response.writer.end_headers()
|
||||
|
||||
response.writer.write(body)
|
|
@ -0,0 +1,51 @@
|
|||
<!DOCTYPE html>
|
||||
<!---
|
||||
Tentative test against:
|
||||
https://github.com/whatwg/fetch/pull/853
|
||||
-->
|
||||
<meta charset="utf-8">
|
||||
<title>Tests Stale While Revalidate works for images</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<body>
|
||||
<!--
|
||||
Use a child document to load the second stale image into because
|
||||
an image loaded into the same document will skip cache-control headers.
|
||||
See: https://html.spec.whatwg.org/#the-list-of-available-images
|
||||
-->
|
||||
<iframe id="child" srcdoc=""></iframe>
|
||||
<script>
|
||||
|
||||
async_test(t => {
|
||||
window.onload = t.step_func(() => {
|
||||
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("stale-image.py?query").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 = "stale-image.py";
|
||||
childDocument.body.appendChild(img2);
|
||||
}, 0);
|
||||
});
|
||||
}, 'Cache returns stale resource');
|
||||
|
||||
var img = document.createElement("img");
|
||||
img.src = "stale-image.py";
|
||||
img.id = "firstimage";
|
||||
document.body.appendChild(img);
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,25 @@
|
|||
import random, string, datetime
|
||||
|
||||
def token():
|
||||
letters = string.ascii_lowercase
|
||||
return ''.join(random.choice(letters) for i in range(20))
|
||||
|
||||
def main(request, response):
|
||||
cookie = request.cookies.first("Count", None)
|
||||
count = 0
|
||||
if cookie != None:
|
||||
count = int(cookie.value)
|
||||
if request.GET.first("query", None) != None:
|
||||
headers = [("Count", count)]
|
||||
content = ""
|
||||
return 200, headers, content
|
||||
else:
|
||||
count = count + 1
|
||||
|
||||
unique_id = token()
|
||||
headers = [("Content-Type", "text/javascript"),
|
||||
("Cache-Control", "private, max-age=0, stale-while-revalidate=10"),
|
||||
("Set-Cookie", "Count={}".format(count)),
|
||||
("Token", unique_id)]
|
||||
content = "report('{}')".format(unique_id)
|
||||
return 200, headers, content
|
|
@ -0,0 +1,55 @@
|
|||
<!DOCTYPE html>
|
||||
<!---
|
||||
Tentative test against:
|
||||
https://github.com/whatwg/fetch/pull/853
|
||||
-->
|
||||
<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>
|
||||
<body>
|
||||
<script>
|
||||
var last_modified;
|
||||
var last_modified_count = 0;
|
||||
|
||||
// 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 = "stale-script.py";
|
||||
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("stale-script.py?query").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 = "stale-script.py";
|
||||
document.body.appendChild(script);
|
||||
</script>
|
||||
</body>
|
Loading…
Add table
Add a link
Reference in a new issue