mirror of
https://github.com/servo/servo.git
synced 2025-09-08 14:08:22 +01:00
Update web-platform-tests to revision c792ea26624bde49b72afce348de07ab72fb9ad7
This commit is contained in:
parent
e051c5880e
commit
ca45711d07
178 changed files with 2163 additions and 1807 deletions
|
@ -0,0 +1,25 @@
|
|||
def main(request, response):
|
||||
if "clear-vary-value-override-cookie" in request.GET:
|
||||
response.unset_cookie("vary-value-override")
|
||||
return "vary cookie cleared"
|
||||
|
||||
set_cookie_vary = request.GET.first("set-vary-value-override-cookie",
|
||||
default="")
|
||||
if set_cookie_vary:
|
||||
response.set_cookie("vary-value-override", set_cookie_vary)
|
||||
return "vary cookie set"
|
||||
|
||||
# If there is a vary-value-override cookie set, then use its value
|
||||
# for the VARY header no matter what the query string is set to. This
|
||||
# override is necessary to test the case when two URLs are identical
|
||||
# (including query), but differ by VARY header.
|
||||
cookie_vary = request.cookies.get("vary-value-override");
|
||||
if cookie_vary:
|
||||
response.headers.set("vary", cookie_vary)
|
||||
else:
|
||||
# If there is no cookie, then use the query string value, if present.
|
||||
query_vary = request.GET.first("vary", default="")
|
||||
if query_vary:
|
||||
response.headers.set("vary", query_vary)
|
||||
|
||||
return "vary response"
|
|
@ -267,4 +267,84 @@ cache_test(function(cache, test) {
|
|||
'twice.');
|
||||
}, 'Cache.addAll called with the same Request object specified twice');
|
||||
|
||||
cache_test(async function(cache, test) {
|
||||
const url = '../resources/vary.py?vary=x-shape';
|
||||
let requests = [
|
||||
new Request(url, { headers: { 'x-shape': 'circle' }}),
|
||||
new Request(url, { headers: { 'x-shape': 'square' }}),
|
||||
];
|
||||
let result = await cache.addAll(requests);
|
||||
assert_equals(result, undefined, 'Cache.addAll() should succeed');
|
||||
}, 'Cache.addAll should succeed when entries differ by vary header');
|
||||
|
||||
cache_test(async function(cache, test) {
|
||||
const url = '../resources/vary.py?vary=x-shape';
|
||||
let requests = [
|
||||
new Request(url, { headers: { 'x-shape': 'circle' }}),
|
||||
new Request(url, { headers: { 'x-shape': 'circle' }}),
|
||||
];
|
||||
await promise_rejects(
|
||||
test,
|
||||
'InvalidStateError',
|
||||
cache.addAll(requests),
|
||||
'Cache.addAll() should reject when entries are duplicate by vary header');
|
||||
}, 'Cache.addAll should reject when entries are duplicate by vary header');
|
||||
|
||||
// VARY header matching is asymmetric. Determining if two entries are duplicate
|
||||
// depends on which entry's response is used in the comparison. The target
|
||||
// response's VARY header determines what request headers are examined. This
|
||||
// test verifies that Cache.addAll() duplicate checking handles this asymmetric
|
||||
// behavior correctly.
|
||||
cache_test(async function(cache, test) {
|
||||
const base_url = '../resources/vary.py';
|
||||
|
||||
// Define a request URL that sets a VARY header in the
|
||||
// query string to be echoed back by the server.
|
||||
const url = base_url + '?vary=x-size';
|
||||
|
||||
// Set a cookie to override the VARY header of the response
|
||||
// when the request is made with credentials. This will
|
||||
// take precedence over the query string vary param. This
|
||||
// is a bit confusing, but it's necessary to construct a test
|
||||
// where the URL is the same, but the VARY headers differ.
|
||||
//
|
||||
// Note, the test could also pass this information in additional
|
||||
// request headers. If the cookie approach becomes too unwieldy
|
||||
// this test could be rewritten to use that technique.
|
||||
await fetch(base_url + '?set-vary-value-override-cookie=x-shape');
|
||||
test.add_cleanup(_ => fetch(base_url + '?clear-vary-value-override-cookie'));
|
||||
|
||||
let requests = [
|
||||
// This request will result in a Response with a "Vary: x-shape"
|
||||
// header. This *will not* result in a duplicate match with the
|
||||
// other entry.
|
||||
new Request(url, { headers: { 'x-shape': 'circle',
|
||||
'x-size': 'big' },
|
||||
credentials: 'same-origin' }),
|
||||
|
||||
// This request will result in a Response with a "Vary: x-size"
|
||||
// header. This *will* result in a duplicate match with the other
|
||||
// entry.
|
||||
new Request(url, { headers: { 'x-shape': 'square',
|
||||
'x-size': 'big' },
|
||||
credentials: 'omit' }),
|
||||
];
|
||||
await promise_rejects(
|
||||
test,
|
||||
'InvalidStateError',
|
||||
cache.addAll(requests),
|
||||
'Cache.addAll() should reject when one entry has a vary header ' +
|
||||
'matching an earlier entry.');
|
||||
|
||||
// Test the reverse order now.
|
||||
await promise_rejects(
|
||||
test,
|
||||
'InvalidStateError',
|
||||
cache.addAll(requests.reverse()),
|
||||
'Cache.addAll() should reject when one entry has a vary header ' +
|
||||
'matching a later entry.');
|
||||
|
||||
}, 'Cache.addAll should reject when one entry has a vary header ' +
|
||||
'matching another entry');
|
||||
|
||||
done();
|
||||
|
|
|
@ -148,4 +148,46 @@ promise_test(t => {
|
|||
});
|
||||
}, 'postMessage a transferable ArrayBuffer between ServiceWorker and Client' +
|
||||
' over MessagePort');
|
||||
|
||||
promise_test(t => {
|
||||
var script = 'resources/postmessage-dictionary-transferables-worker.js';
|
||||
var scope = 'resources/blank.html';
|
||||
var sw = navigator.serviceWorker;
|
||||
|
||||
var message = 'Hello, world!';
|
||||
var text_encoder = new TextEncoder;
|
||||
var text_decoder = new TextDecoder;
|
||||
|
||||
return service_worker_unregister_and_register(t, script, scope)
|
||||
.then(r => {
|
||||
t.add_cleanup(() => r.unregister());
|
||||
|
||||
var ab = text_encoder.encode(message);
|
||||
assert_equals(ab.byteLength, message.length);
|
||||
r.installing.postMessage(ab, {transfer: [ab.buffer]});
|
||||
assert_equals(text_decoder.decode(ab), '');
|
||||
assert_equals(ab.byteLength, 0);
|
||||
|
||||
return new Promise(resolve => { sw.onmessage = resolve; });
|
||||
})
|
||||
.then(e => {
|
||||
// Verify the integrity of the transferred array buffer.
|
||||
assert_equals(e.data.content, message);
|
||||
assert_equals(e.data.byteLength, message.length);
|
||||
return new Promise(resolve => { sw.onmessage = resolve; });
|
||||
})
|
||||
.then(e => {
|
||||
// Verify the integrity of the array buffer sent back from
|
||||
// ServiceWorker via Client.postMessage.
|
||||
assert_equals(text_decoder.decode(e.data), message);
|
||||
assert_equals(e.data.byteLength, message.length);
|
||||
return new Promise(resolve => { sw.onmessage = resolve; });
|
||||
})
|
||||
.then(e => {
|
||||
// Verify that the array buffer on ServiceWorker is neutered.
|
||||
assert_equals(e.data.content, '');
|
||||
assert_equals(e.data.byteLength, 0);
|
||||
});
|
||||
}, 'postMessage with dictionary a transferable ArrayBuffer between ServiceWorker and Client');
|
||||
|
||||
</script>
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
var messageHandler = function(port, e) {
|
||||
var text_decoder = new TextDecoder;
|
||||
port.postMessage({
|
||||
content: text_decoder.decode(e.data),
|
||||
byteLength: e.data.byteLength
|
||||
});
|
||||
|
||||
// Send back the array buffer via Client.postMessage.
|
||||
port.postMessage(e.data, {transfer: [e.data.buffer]});
|
||||
|
||||
port.postMessage({
|
||||
content: text_decoder.decode(e.data),
|
||||
byteLength: e.data.byteLength
|
||||
});
|
||||
};
|
||||
|
||||
self.addEventListener('message', e => {
|
||||
if (e.ports[0]) {
|
||||
// Wait for messages sent via MessagePort.
|
||||
e.ports[0].onmessage = messageHandler.bind(null, e.ports[0]);
|
||||
return;
|
||||
}
|
||||
messageHandler(e.source, e);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue