Commit c1141f37 authored by Ben Kelly's avatar Ben Kelly Committed by Commit Bot

Reland cache.addAll() duplicate VARY header WPT tests.

R=jsbell@chromium.org

Bug: 720919
Change-Id: I88447c05f40937eb7f73cc2399ce5b1a025e1911
Reviewed-on: https://chromium-review.googlesource.com/1179942Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Commit-Queue: Ben Kelly <wanderview@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584105}
parent 70a9197c
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) { ...@@ -267,4 +267,84 @@ cache_test(function(cache, test) {
'twice.'); 'twice.');
}, 'Cache.addAll called with the same Request object specified 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(); done();
...@@ -18,5 +18,8 @@ PASS Cache.addAll with string URL arguments ...@@ -18,5 +18,8 @@ PASS Cache.addAll with string URL arguments
PASS Cache.addAll with Request arguments PASS Cache.addAll with Request arguments
PASS Cache.addAll with a mix of succeeding and failing requests PASS Cache.addAll with a mix of succeeding and failing requests
FAIL Cache.addAll called with the same Request object specified twice assert_unreached: Should have rejected: Cache.addAll should throw InvalidStateError if the same request is added twice. Reached unreachable code FAIL Cache.addAll called with the same Request object specified twice assert_unreached: Should have rejected: Cache.addAll should throw InvalidStateError if the same request is added twice. Reached unreachable code
PASS Cache.addAll should succeed when entries differ by vary header
FAIL Cache.addAll should reject when entries are duplicate by vary header assert_unreached: Should have rejected: Cache.addAll() should reject when entries are duplicate by vary header Reached unreachable code
FAIL Cache.addAll should reject when one entry has a vary header matching another entry assert_unreached: Should have rejected: Cache.addAll() should reject when one entry has a vary header matching an earlier entry. Reached unreachable code
Harness: the test ran to completion. Harness: the test ran to completion.
...@@ -17,5 +17,8 @@ PASS Cache.addAll with string URL arguments ...@@ -17,5 +17,8 @@ PASS Cache.addAll with string URL arguments
PASS Cache.addAll with Request arguments PASS Cache.addAll with Request arguments
PASS Cache.addAll with a mix of succeeding and failing requests PASS Cache.addAll with a mix of succeeding and failing requests
FAIL Cache.addAll called with the same Request object specified twice assert_unreached: Should have rejected: Cache.addAll should throw InvalidStateError if the same request is added twice. Reached unreachable code FAIL Cache.addAll called with the same Request object specified twice assert_unreached: Should have rejected: Cache.addAll should throw InvalidStateError if the same request is added twice. Reached unreachable code
PASS Cache.addAll should succeed when entries differ by vary header
FAIL Cache.addAll should reject when entries are duplicate by vary header assert_unreached: Should have rejected: Cache.addAll() should reject when entries are duplicate by vary header Reached unreachable code
FAIL Cache.addAll should reject when one entry has a vary header matching another entry assert_unreached: Should have rejected: Cache.addAll() should reject when one entry has a vary header matching an earlier entry. Reached unreachable code
Harness: the test ran to completion. Harness: the test ran to completion.
...@@ -17,5 +17,8 @@ PASS Cache.addAll with string URL arguments ...@@ -17,5 +17,8 @@ PASS Cache.addAll with string URL arguments
PASS Cache.addAll with Request arguments PASS Cache.addAll with Request arguments
PASS Cache.addAll with a mix of succeeding and failing requests PASS Cache.addAll with a mix of succeeding and failing requests
FAIL Cache.addAll called with the same Request object specified twice assert_unreached: Should have rejected: Cache.addAll should throw InvalidStateError if the same request is added twice. Reached unreachable code FAIL Cache.addAll called with the same Request object specified twice assert_unreached: Should have rejected: Cache.addAll should throw InvalidStateError if the same request is added twice. Reached unreachable code
PASS Cache.addAll should succeed when entries differ by vary header
FAIL Cache.addAll should reject when entries are duplicate by vary header assert_unreached: Should have rejected: Cache.addAll() should reject when entries are duplicate by vary header Reached unreachable code
FAIL Cache.addAll should reject when one entry has a vary header matching another entry assert_unreached: Should have rejected: Cache.addAll() should reject when one entry has a vary header matching an earlier entry. Reached unreachable code
Harness: the test ran to completion. Harness: the test ran to completion.
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