Update web-platform-tests to revision 2dda7b8c10c7566fa6167a32b09c85d51baf2a85

This commit is contained in:
WPT Sync Bot 2018-08-16 21:32:15 -04:00
parent 25ebde78aa
commit 8edc7686ef
129 changed files with 5280 additions and 820 deletions

View file

@ -1,25 +0,0 @@
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"

View file

@ -267,84 +267,4 @@ 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();

View file

@ -1,19 +1,37 @@
async function wait_for_performance_entries(url) {
let entries = performance.getEntriesByName(url);
if (entries.length > 0) {
return entries;
}
return new Promise((resolve) => {
new PerformanceObserver((list) => {
const entries = list.getEntriesByName(url);
if (entries.length > 0) {
resolve(entries);
}
}).observe({ entryTypes: ['resource'] });
});
}
self.addEventListener('activate', event => {
event.waitUntil(self.registration.navigationPreload.enable());
});
self.addEventListener('fetch', event => {
let headers;
event.respondWith(
event.preloadResponse
.then(response => {
var headers = response.headers;
return response.text().then(text =>
new Response(
JSON.stringify({
decodedBodySize: headers.get('X-Decoded-Body-Size'),
encodedBodySize: headers.get('X-Encoded-Body-Size'),
timingEntries: performance.getEntriesByName(event.request.url)
}),
{headers: {'Content-Type': 'text/html'}}));
}));
headers = response.headers;
return response.text()
})
.then(_ => wait_for_performance_entries(event.request.url))
.then(entries =>
new Response(
JSON.stringify({
decodedBodySize: headers.get('X-Decoded-Body-Size'),
encodedBodySize: headers.get('X-Encoded-Body-Size'),
timingEntries: entries
}),
{headers: {'Content-Type': 'text/html'}})));
});