mirror of
https://github.com/servo/servo.git
synced 2025-08-10 07:55:33 +01:00
Update web-platform-tests to revision 95aad3bd9b82b5c65d84d53517b65ba084de9394
This commit is contained in:
parent
5942e9e3cb
commit
e8ed816728
145 changed files with 2024 additions and 578 deletions
|
@ -0,0 +1,2 @@
|
|||
@inexorabletash
|
||||
@wanderview
|
|
@ -35,3 +35,203 @@ function cache_test(test_function, description) {
|
|||
.then(test_function);
|
||||
}, description);
|
||||
}
|
||||
|
||||
// A set of Request/Response pairs to be used with prepopulated_cache_test().
|
||||
var simple_entries = [
|
||||
{
|
||||
name: 'a',
|
||||
request: new Request('http://example.com/a'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'b',
|
||||
request: new Request('http://example.com/b'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'a_with_query',
|
||||
request: new Request('http://example.com/a?q=r'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'A',
|
||||
request: new Request('http://example.com/A'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'a_https',
|
||||
request: new Request('https://example.com/a'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'a_org',
|
||||
request: new Request('http://example.org/a'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'cat',
|
||||
request: new Request('http://example.com/cat'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'catmandu',
|
||||
request: new Request('http://example.com/catmandu'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'cat_num_lives',
|
||||
request: new Request('http://example.com/cat?lives=9'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'cat_in_the_hat',
|
||||
request: new Request('http://example.com/cat/in/the/hat'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'non_2xx_response',
|
||||
request: new Request('http://example.com/non2xx'),
|
||||
response: new Response('', {status: 404, statusText: 'nope'})
|
||||
},
|
||||
|
||||
{
|
||||
name: 'error_response',
|
||||
request: new Request('http://example.com/error'),
|
||||
response: Response.error()
|
||||
},
|
||||
];
|
||||
|
||||
// A set of Request/Response pairs to be used with prepopulated_cache_test().
|
||||
// These contain a mix of test cases that use Vary headers.
|
||||
var vary_entries = [
|
||||
{
|
||||
name: 'vary_cookie_is_cookie',
|
||||
request: new Request('http://example.com/c',
|
||||
{headers: {'Cookies': 'is-for-cookie'}}),
|
||||
response: new Response('',
|
||||
{headers: {'Vary': 'Cookies'}})
|
||||
},
|
||||
|
||||
{
|
||||
name: 'vary_cookie_is_good',
|
||||
request: new Request('http://example.com/c',
|
||||
{headers: {'Cookies': 'is-good-enough-for-me'}}),
|
||||
response: new Response('',
|
||||
{headers: {'Vary': 'Cookies'}})
|
||||
},
|
||||
|
||||
{
|
||||
name: 'vary_cookie_absent',
|
||||
request: new Request('http://example.com/c'),
|
||||
response: new Response('',
|
||||
{headers: {'Vary': 'Cookies'}})
|
||||
}
|
||||
];
|
||||
|
||||
// Run |test_function| with a Cache object and a map of entries. Prior to the
|
||||
// call, the Cache is populated by cache entries from |entries|. The latter is
|
||||
// expected to be an Object mapping arbitrary keys to objects of the form
|
||||
// {request: <Request object>, response: <Response object>}. There's no
|
||||
// guarantee on the order in which entries will be added to the cache.
|
||||
//
|
||||
// |test_function| should return a Promise that can be used with promise_test.
|
||||
function prepopulated_cache_test(entries, test_function, description) {
|
||||
cache_test(function(cache) {
|
||||
var p = Promise.resolve();
|
||||
var hash = {};
|
||||
return Promise.all(entries.map(function(entry) {
|
||||
hash[entry.name] = entry;
|
||||
return cache.put(entry.request.clone(),
|
||||
entry.response.clone())
|
||||
.catch(function(e) {
|
||||
assert_unreached(
|
||||
'Test setup failed for entry ' + entry.name + ': ' + e);
|
||||
});
|
||||
}))
|
||||
.then(function() {
|
||||
assert_equals(Object.keys(hash).length, entries.length);
|
||||
})
|
||||
.then(function() {
|
||||
return test_function(cache, hash);
|
||||
});
|
||||
}, description);
|
||||
}
|
||||
|
||||
// Helper for testing with Headers objects. Compares Headers instances
|
||||
// by serializing |expected| and |actual| to arrays and comparing.
|
||||
function assert_header_equals(actual, expected, description) {
|
||||
assert_class_string(actual, "Headers", description);
|
||||
var header;
|
||||
var actual_headers = [];
|
||||
var expected_headers = [];
|
||||
for (header of actual)
|
||||
actual_headers.push(header[0] + ": " + header[1]);
|
||||
for (header of expected)
|
||||
expected_headers.push(header[0] + ": " + header[1]);
|
||||
assert_array_equals(actual_headers, expected_headers,
|
||||
description + " Headers differ.");
|
||||
}
|
||||
|
||||
// Helper for testing with Response objects. Compares simple
|
||||
// attributes defined on the interfaces, as well as the headers. It
|
||||
// does not compare the response bodies.
|
||||
function assert_response_equals(actual, expected, description) {
|
||||
assert_class_string(actual, "Response", description);
|
||||
["type", "url", "status", "ok", "statusText"].forEach(function(attribute) {
|
||||
assert_equals(actual[attribute], expected[attribute],
|
||||
description + " Attributes differ: " + attribute + ".");
|
||||
});
|
||||
assert_header_equals(actual.headers, expected.headers, description);
|
||||
}
|
||||
|
||||
// Assert that the two arrays |actual| and |expected| contain the same
|
||||
// set of Responses as determined by assert_response_equals. The order
|
||||
// is not significant.
|
||||
//
|
||||
// |expected| is assumed to not contain any duplicates.
|
||||
function assert_response_array_equivalent(actual, expected, description) {
|
||||
assert_true(Array.isArray(actual), description);
|
||||
assert_equals(actual.length, expected.length, description);
|
||||
expected.forEach(function(expected_element) {
|
||||
// assert_response_in_array treats the first argument as being
|
||||
// 'actual', and the second as being 'expected array'. We are
|
||||
// switching them around because we want to be resilient
|
||||
// against the |actual| array containing duplicates.
|
||||
assert_response_in_array(expected_element, actual, description);
|
||||
});
|
||||
}
|
||||
|
||||
// Asserts that two arrays |actual| and |expected| contain the same
|
||||
// set of Responses as determined by assert_response_equals(). The
|
||||
// corresponding elements must occupy corresponding indices in their
|
||||
// respective arrays.
|
||||
function assert_response_array_equals(actual, expected, description) {
|
||||
assert_true(Array.isArray(actual), description);
|
||||
assert_equals(actual.length, expected.length, description);
|
||||
actual.forEach(function(value, index) {
|
||||
assert_response_equals(value, expected[index],
|
||||
description + " : object[" + index + "]");
|
||||
});
|
||||
}
|
||||
|
||||
// Equivalent to assert_in_array, but uses assert_response_equals.
|
||||
function assert_response_in_array(actual, expected_array, description) {
|
||||
assert_true(expected_array.some(function(element) {
|
||||
try {
|
||||
assert_response_equals(actual, element);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}), description);
|
||||
}
|
||||
|
|
|
@ -31,70 +31,3 @@ function assert_promise_rejects(promise, code, description) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Helper for testing with Headers objects. Compares Headers instances
|
||||
// by serializing |expected| and |actual| to arrays and comparing.
|
||||
function assert_header_equals(actual, expected, description) {
|
||||
assert_class_string(actual, "Headers", description);
|
||||
var header, actual_headers = [], expected_headers = [];
|
||||
for (header of actual)
|
||||
actual_headers.push(header[0] + ": " + header[1]);
|
||||
for (header of expected)
|
||||
expected_headers.push(header[0] + ": " + header[1]);
|
||||
assert_array_equals(actual_headers, expected_headers,
|
||||
description + " Headers differ.");
|
||||
}
|
||||
|
||||
// Helper for testing with Response objects. Compares simple
|
||||
// attributes defined on the interfaces, as well as the headers. It
|
||||
// does not compare the response bodies.
|
||||
function assert_response_equals(actual, expected, description) {
|
||||
assert_class_string(actual, "Response", description);
|
||||
["type", "url", "status", "ok", "statusText"].forEach(function(attribute) {
|
||||
assert_equals(actual[attribute], expected[attribute],
|
||||
description + " Attributes differ: " + attribute + ".");
|
||||
});
|
||||
assert_header_equals(actual.headers, expected.headers, description);
|
||||
}
|
||||
|
||||
// Assert that the two arrays |actual| and |expected| contain the same
|
||||
// set of Responses as determined by assert_response_equals. The order
|
||||
// is not significant.
|
||||
//
|
||||
// |expected| is assumed to not contain any duplicates.
|
||||
function assert_response_array_equivalent(actual, expected, description) {
|
||||
assert_true(Array.isArray(actual), description);
|
||||
assert_equals(actual.length, expected.length, description);
|
||||
expected.forEach(function(expected_element) {
|
||||
// assert_response_in_array treats the first argument as being
|
||||
// 'actual', and the second as being 'expected array'. We are
|
||||
// switching them around because we want to be resilient
|
||||
// against the |actual| array containing duplicates.
|
||||
assert_response_in_array(expected_element, actual, description);
|
||||
});
|
||||
}
|
||||
|
||||
// Asserts that two arrays |actual| and |expected| contain the same
|
||||
// set of Responses as determined by assert_response_equals(). The
|
||||
// corresponding elements must occupy corresponding indices in their
|
||||
// respective arrays.
|
||||
function assert_response_array_equals(actual, expected, description) {
|
||||
assert_true(Array.isArray(actual), description);
|
||||
assert_equals(actual.length, expected.length, description);
|
||||
actual.forEach(function(value, index) {
|
||||
assert_response_equals(value, expected[index],
|
||||
description + " : object[" + index + "]");
|
||||
});
|
||||
}
|
||||
|
||||
// Equivalent to assert_in_array, but uses assert_response_equals.
|
||||
function assert_response_in_array(actual, expected_array, description) {
|
||||
assert_true(expected_array.some(function(element) {
|
||||
try {
|
||||
assert_response_equals(actual, element);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}), description);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,16 @@ cache_test(function(cache) {
|
|||
.then(function(result) {
|
||||
assert_equals(result, undefined,
|
||||
'Cache.add should resolve with undefined on success.');
|
||||
return cache.match('../resources/simple.txt');
|
||||
})
|
||||
.then(function(response) {
|
||||
assert_class_string(response, 'Response',
|
||||
'Cache.add should put a resource in the cache.');
|
||||
return response.text();
|
||||
})
|
||||
.then(function(body) {
|
||||
assert_equals(body, 'a simple text file\n',
|
||||
'Cache.add should retrieve the correct body.');
|
||||
});
|
||||
}, 'Cache.add called with relative URL specified as a string');
|
||||
|
||||
|
@ -35,6 +45,15 @@ cache_test(function(cache) {
|
|||
});
|
||||
}, 'Cache.add called with Request object');
|
||||
|
||||
cache_test(function(cache) {
|
||||
var request = new Request('../resources/simple.txt',
|
||||
{method: 'POST', body: 'This is a body.'});
|
||||
return assert_promise_rejects(
|
||||
cache.add(request),
|
||||
new TypeError(),
|
||||
'Cache.add should throw a TypeError for non-GET requests.');
|
||||
}, 'Cache.add called with POST request');
|
||||
|
||||
cache_test(function(cache) {
|
||||
var request = new Request('../resources/simple.txt');
|
||||
return cache.add(request)
|
||||
|
@ -51,6 +70,17 @@ cache_test(function(cache) {
|
|||
});
|
||||
}, 'Cache.add called twice with the same Request object');
|
||||
|
||||
cache_test(function(cache) {
|
||||
var request = new Request('../resources/simple.txt');
|
||||
return request.text()
|
||||
.then(function() {
|
||||
assert_false(request.bodyUsed);
|
||||
})
|
||||
.then(function() {
|
||||
return cache.add(request);
|
||||
});
|
||||
}, 'Cache.add with request with null body (not consumed)');
|
||||
|
||||
cache_test(function(cache) {
|
||||
return cache.add('this-does-not-exist-please-dont-create-it')
|
||||
.then(function(result) {
|
||||
|
@ -84,19 +114,62 @@ cache_test(function(cache) {
|
|||
}, 'Cache.addAll with a mix of valid and undefined arguments');
|
||||
|
||||
cache_test(function(cache) {
|
||||
// Assumes the existence of ../resources/simple.txt and ../resources/blank.html
|
||||
var urls = ['../resources/simple.txt', self.location.href, '../resources/blank.html'];
|
||||
return cache.addAll([])
|
||||
.then(function(result) {
|
||||
assert_equals(result, undefined,
|
||||
'Cache.addAll should resolve with undefined on ' +
|
||||
'success.');
|
||||
return cache.keys();
|
||||
})
|
||||
.then(function(result) {
|
||||
assert_equals(result.length, 0,
|
||||
'There should be no entry in the cache.');
|
||||
});
|
||||
}, 'Cache.addAll with an empty array');
|
||||
|
||||
cache_test(function(cache) {
|
||||
// Assumes the existence of ../resources/simple.txt and
|
||||
// ../resources/blank.html
|
||||
var urls = ['../resources/simple.txt',
|
||||
self.location.href,
|
||||
'../resources/blank.html'];
|
||||
return cache.addAll(urls)
|
||||
.then(function(result) {
|
||||
assert_equals(result, undefined,
|
||||
'Cache.addAll should resolve with undefined on ' +
|
||||
'success.');
|
||||
return Promise.all(
|
||||
urls.map(function(url) { return cache.match(url); }));
|
||||
})
|
||||
.then(function(responses) {
|
||||
assert_class_string(
|
||||
responses[0], 'Response',
|
||||
'Cache.addAll should put a resource in the cache.');
|
||||
assert_class_string(
|
||||
responses[1], 'Response',
|
||||
'Cache.addAll should put a resource in the cache.');
|
||||
assert_class_string(
|
||||
responses[2], 'Response',
|
||||
'Cache.addAll should put a resource in the cache.');
|
||||
return Promise.all(
|
||||
responses.map(function(response) { return response.text(); }));
|
||||
})
|
||||
.then(function(bodies) {
|
||||
assert_equals(
|
||||
bodies[0], 'a simple text file\n',
|
||||
'Cache.add should retrieve the correct body.');
|
||||
assert_equals(
|
||||
bodies[2], '<!DOCTYPE html>\n<title>Empty doc</title>\n',
|
||||
'Cache.add should retrieve the correct body.');
|
||||
});
|
||||
}, 'Cache.addAll with string URL arguments');
|
||||
|
||||
cache_test(function(cache) {
|
||||
// Assumes the existence of ../resources/simple.txt and ../resources/blank.html
|
||||
var urls = ['../resources/simple.txt', self.location.href, '../resources/blank.html'];
|
||||
// Assumes the existence of ../resources/simple.txt and
|
||||
// ../resources/blank.html
|
||||
var urls = ['../resources/simple.txt',
|
||||
self.location.href,
|
||||
'../resources/blank.html'];
|
||||
var requests = urls.map(function(url) {
|
||||
return new Request(url);
|
||||
});
|
||||
|
@ -105,13 +178,38 @@ cache_test(function(cache) {
|
|||
assert_equals(result, undefined,
|
||||
'Cache.addAll should resolve with undefined on ' +
|
||||
'success.');
|
||||
return Promise.all(
|
||||
urls.map(function(url) { return cache.match(url); }));
|
||||
})
|
||||
.then(function(responses) {
|
||||
assert_class_string(
|
||||
responses[0], 'Response',
|
||||
'Cache.addAll should put a resource in the cache.');
|
||||
assert_class_string(
|
||||
responses[1], 'Response',
|
||||
'Cache.addAll should put a resource in the cache.');
|
||||
assert_class_string(
|
||||
responses[2], 'Response',
|
||||
'Cache.addAll should put a resource in the cache.');
|
||||
return Promise.all(
|
||||
responses.map(function(response) { return response.text(); }));
|
||||
})
|
||||
.then(function(bodies) {
|
||||
assert_equals(
|
||||
bodies[0], 'a simple text file\n',
|
||||
'Cache.add should retrieve the correct body.');
|
||||
assert_equals(
|
||||
bodies[2], '<!DOCTYPE html>\n<title>Empty doc</title>\n',
|
||||
'Cache.add should retrieve the correct body.');
|
||||
});
|
||||
}, 'Cache.addAll with Request arguments');
|
||||
|
||||
cache_test(function(cache) {
|
||||
// Assumes that ../resources/simple.txt and ../resources/blank.html exist. The second
|
||||
// resource does not.
|
||||
var urls = ['../resources/simple.txt', 'this-resource-should-not-exist', '../resources/blank.html'];
|
||||
// Assumes that ../resources/simple.txt and ../resources/blank.html exist.
|
||||
// The second resource does not.
|
||||
var urls = ['../resources/simple.txt',
|
||||
'this-resource-should-not-exist',
|
||||
'../resources/blank.html'];
|
||||
var requests = urls.map(function(url) {
|
||||
return new Request(url);
|
||||
});
|
||||
|
@ -120,6 +218,32 @@ cache_test(function(cache) {
|
|||
assert_equals(result, undefined,
|
||||
'Cache.addAll should resolve with undefined on ' +
|
||||
'success.');
|
||||
return Promise.all(
|
||||
urls.map(function(url) { return cache.match(url); }));
|
||||
})
|
||||
.then(function(responses) {
|
||||
assert_class_string(
|
||||
responses[0], 'Response',
|
||||
'Cache.addAll should put a resource in the cache.');
|
||||
assert_class_string(
|
||||
responses[1], 'Response',
|
||||
'Cache.addAll should put a resource in the cache.');
|
||||
assert_equals(
|
||||
responses[1].status, 404,
|
||||
'Cache.addAll should put a 404 resource in the cache.');
|
||||
assert_class_string(
|
||||
responses[2], 'Response',
|
||||
'Cache.addAll should put a resource in the cache.');
|
||||
return Promise.all(
|
||||
responses.map(function(response) { return response.text(); }));
|
||||
})
|
||||
.then(function(bodies) {
|
||||
assert_equals(
|
||||
bodies[0], 'a simple text file\n',
|
||||
'Cache.add should retrieve the correct body.');
|
||||
assert_equals(
|
||||
bodies[2], '<!DOCTYPE html>\n<title>Empty doc</title>\n',
|
||||
'Cache.add should retrieve the correct body.');
|
||||
});
|
||||
}, 'Cache.addAll with a mix of succeeding and failing requests');
|
||||
|
||||
|
|
|
@ -4,105 +4,6 @@ if (self.importScripts) {
|
|||
importScripts('../resources/test-helpers.js');
|
||||
}
|
||||
|
||||
// A set of Request/Response pairs to be used with prepopulated_cache_test().
|
||||
var simple_entries = [
|
||||
{
|
||||
name: 'a',
|
||||
request: new Request('http://example.com/a'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'b',
|
||||
request: new Request('http://example.com/b'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'a_with_query',
|
||||
request: new Request('http://example.com/a?q=r'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'A',
|
||||
request: new Request('http://example.com/A'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'a_https',
|
||||
request: new Request('https://example.com/a'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'a_org',
|
||||
request: new Request('http://example.org/a'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'cat',
|
||||
request: new Request('http://example.com/cat'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'catmandu',
|
||||
request: new Request('http://example.com/catmandu'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'cat_num_lives',
|
||||
request: new Request('http://example.com/cat?lives=9'),
|
||||
response: new Response('')
|
||||
},
|
||||
|
||||
{
|
||||
name: 'cat_in_the_hat',
|
||||
request: new Request('http://example.com/cat/in/the/hat'),
|
||||
response: new Response('')
|
||||
}
|
||||
];
|
||||
|
||||
// A set of Request/Response pairs to be used with prepopulated_cache_test().
|
||||
// These contain a mix of test cases that use Vary headers.
|
||||
var vary_entries = [
|
||||
{
|
||||
name: 'vary_cookie_is_cookie',
|
||||
request: new Request('http://example.com/c',
|
||||
{headers: {'Cookies': 'is-for-cookie'}}),
|
||||
response: new Response('',
|
||||
{headers: {'Vary': 'Cookies'}})
|
||||
},
|
||||
|
||||
{
|
||||
name: 'vary_cookie_is_good',
|
||||
request: new Request('http://example.com/c',
|
||||
{headers: {'Cookies': 'is-good-enough-for-me'}}),
|
||||
response: new Response('',
|
||||
{headers: {'Vary': 'Cookies'}})
|
||||
},
|
||||
|
||||
{
|
||||
name: 'vary_cookie_absent',
|
||||
request: new Request('http://example.com/c'),
|
||||
response: new Response('',
|
||||
{headers: {'Vary': 'Cookies'}})
|
||||
}
|
||||
];
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.matchAll('not-present-in-the-cache')
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result, [],
|
||||
'Cache.matchAll should resolve with an empty array on failure.');
|
||||
});
|
||||
}, 'Cache.matchAll with no matching entries');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.match('not-present-in-the-cache')
|
||||
.then(function(result) {
|
||||
|
@ -111,14 +12,6 @@ prepopulated_cache_test(simple_entries, function(cache, entries) {
|
|||
});
|
||||
}, 'Cache.match with no matching entries');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.matchAll(entries.a.request.url)
|
||||
.then(function(result) {
|
||||
assert_response_array_equals(result, [entries.a.response],
|
||||
'Cache.matchAll should match by URL.');
|
||||
});
|
||||
}, 'Cache.matchAll with URL');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.match(entries.a.request.url)
|
||||
.then(function(result) {
|
||||
|
@ -127,15 +20,6 @@ prepopulated_cache_test(simple_entries, function(cache, entries) {
|
|||
});
|
||||
}, 'Cache.match with URL');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.matchAll(entries.a.request)
|
||||
.then(function(result) {
|
||||
assert_response_array_equals(
|
||||
result, [entries.a.response],
|
||||
'Cache.matchAll should match by Request.');
|
||||
});
|
||||
}, 'Cache.matchAll with Request');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.match(entries.a.request)
|
||||
.then(function(result) {
|
||||
|
@ -144,15 +28,6 @@ prepopulated_cache_test(simple_entries, function(cache, entries) {
|
|||
});
|
||||
}, 'Cache.match with Request');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.matchAll(new Request(entries.a.request.url))
|
||||
.then(function(result) {
|
||||
assert_response_array_equals(
|
||||
result, [entries.a.response],
|
||||
'Cache.matchAll should match by Request.');
|
||||
});
|
||||
}, 'Cache.matchAll with new Request');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.match(new Request(entries.a.request.url))
|
||||
.then(function(result) {
|
||||
|
@ -161,23 +36,6 @@ prepopulated_cache_test(simple_entries, function(cache, entries) {
|
|||
});
|
||||
}, 'Cache.match with new Request');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.matchAll(entries.a.request,
|
||||
{ignoreSearch: true})
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result,
|
||||
[
|
||||
entries.a.response,
|
||||
entries.a_with_query.response
|
||||
],
|
||||
'Cache.matchAll with ignoreSearch should ignore the ' +
|
||||
'search parameters of cached request.');
|
||||
});
|
||||
},
|
||||
'Cache.matchAll with ignoreSearch option (request with no search ' +
|
||||
'parameters)');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.match(entries.a.request,
|
||||
{ignoreSearch: true})
|
||||
|
@ -195,22 +53,6 @@ prepopulated_cache_test(simple_entries, function(cache, entries) {
|
|||
'Cache.match with ignoreSearch option (request with no search ' +
|
||||
'parameters)');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.matchAll(entries.a_with_query.request,
|
||||
{ignoreSearch: true})
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result,
|
||||
[
|
||||
entries.a.response,
|
||||
entries.a_with_query.response
|
||||
],
|
||||
'Cache.matchAll with ignoreSearch should ignore the ' +
|
||||
'search parameters of request.');
|
||||
});
|
||||
},
|
||||
'Cache.matchAll with ignoreSearch option (request with search parameter)');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.match(entries.a_with_query.request,
|
||||
{ignoreSearch: true})
|
||||
|
@ -227,18 +69,6 @@ prepopulated_cache_test(simple_entries, function(cache, entries) {
|
|||
},
|
||||
'Cache.match with ignoreSearch option (request with search parameter)');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.matchAll(entries.cat.request.url + '#mouse')
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result,
|
||||
[
|
||||
entries.cat.response,
|
||||
],
|
||||
'Cache.matchAll should ignore URL fragment.');
|
||||
});
|
||||
}, 'Cache.matchAll with URL containing fragment');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.match(entries.cat.request.url + '#mouse')
|
||||
.then(function(result) {
|
||||
|
@ -247,16 +77,6 @@ prepopulated_cache_test(simple_entries, function(cache, entries) {
|
|||
});
|
||||
}, 'Cache.match with URL containing fragment');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.matchAll('http')
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result, [],
|
||||
'Cache.matchAll should treat query as a URL and not ' +
|
||||
'just a string fragment.');
|
||||
});
|
||||
}, 'Cache.matchAll with string fragment "http" as query');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.match('http')
|
||||
.then(function(result) {
|
||||
|
@ -267,48 +87,6 @@ prepopulated_cache_test(simple_entries, function(cache, entries) {
|
|||
});
|
||||
}, 'Cache.match with string fragment "http" as query');
|
||||
|
||||
prepopulated_cache_test(vary_entries, function(cache, entries) {
|
||||
return cache.matchAll('http://example.com/c')
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result,
|
||||
[
|
||||
entries.vary_cookie_absent.response
|
||||
],
|
||||
'Cache.matchAll should exclude matches if a vary header is ' +
|
||||
'missing in the query request, but is present in the cached ' +
|
||||
'request.');
|
||||
})
|
||||
|
||||
.then(function() {
|
||||
return cache.matchAll(
|
||||
new Request('http://example.com/c',
|
||||
{headers: {'Cookies': 'none-of-the-above'}}));
|
||||
})
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result,
|
||||
[
|
||||
],
|
||||
'Cache.matchAll should exclude matches if a vary header is ' +
|
||||
'missing in the cached request, but is present in the query ' +
|
||||
'request.');
|
||||
})
|
||||
|
||||
.then(function() {
|
||||
return cache.matchAll(
|
||||
new Request('http://example.com/c',
|
||||
{headers: {'Cookies': 'is-for-cookie'}}));
|
||||
})
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result,
|
||||
[entries.vary_cookie_is_cookie.response],
|
||||
'Cache.matchAll should match the entire header if a vary header ' +
|
||||
'is present in both the query and cached requests.');
|
||||
});
|
||||
}, 'Cache.matchAll with responses containing "Vary" header');
|
||||
|
||||
prepopulated_cache_test(vary_entries, function(cache, entries) {
|
||||
return cache.match('http://example.com/c')
|
||||
.then(function(result) {
|
||||
|
@ -321,21 +99,6 @@ prepopulated_cache_test(vary_entries, function(cache, entries) {
|
|||
});
|
||||
}, 'Cache.match with responses containing "Vary" header');
|
||||
|
||||
prepopulated_cache_test(vary_entries, function(cache, entries) {
|
||||
return cache.matchAll('http://example.com/c',
|
||||
{ignoreVary: true})
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result,
|
||||
[
|
||||
entries.vary_cookie_is_cookie.response,
|
||||
entries.vary_cookie_is_good.response,
|
||||
entries.vary_cookie_absent.response,
|
||||
],
|
||||
'Cache.matchAll should honor "ignoreVary" parameter.');
|
||||
});
|
||||
}, 'Cache.matchAll with "ignoreVary" parameter');
|
||||
|
||||
cache_test(function(cache) {
|
||||
var request = new Request('http://example.com');
|
||||
var response;
|
||||
|
@ -397,7 +160,7 @@ cache_test(function(cache) {
|
|||
}, 'Cache.match invoked multiple times for the same Request/Response');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
var request = new Request(entries.a.request, { method: 'POST' });
|
||||
var request = new Request(entries.a.request.clone(), {method: 'POST'});
|
||||
return cache.match(request)
|
||||
.then(function(result) {
|
||||
assert_equals(result, undefined,
|
||||
|
@ -405,38 +168,26 @@ prepopulated_cache_test(simple_entries, function(cache, entries) {
|
|||
});
|
||||
}, 'Cache.match with POST Request');
|
||||
|
||||
// Helpers ---
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
var response = entries.non_2xx_response.response;
|
||||
return cache.match(entries.non_2xx_response.request.url)
|
||||
.then(function(result) {
|
||||
assert_response_equals(
|
||||
result, entries.non_2xx_response.response,
|
||||
'Cache.match should return a Response object that has the ' +
|
||||
'same properties as a stored non-2xx response.');
|
||||
});
|
||||
}, 'Cache.match with a non-2xx Response');
|
||||
|
||||
// Run |test_function| with a Cache object as its only parameter. Prior to the
|
||||
// call, the Cache is populated by cache entries from |entries|. The latter is
|
||||
// expected to be an Object mapping arbitrary keys to objects of the form
|
||||
// {request: <Request object>, response: <Response object>}. There's no
|
||||
// guarantee on the order in which entries will be added to the cache.
|
||||
//
|
||||
// |test_function| should return a Promise that can be used with promise_test.
|
||||
function prepopulated_cache_test(entries, test_function, description) {
|
||||
cache_test(function(cache) {
|
||||
var p = Promise.resolve();
|
||||
var hash = {};
|
||||
entries.forEach(function(entry) {
|
||||
p = p.then(function() {
|
||||
return cache.put(entry.request.clone(),
|
||||
entry.response.clone())
|
||||
.catch(function(e) {
|
||||
assert_unreached('Test setup failed for entry ' +
|
||||
entry.name + ': ' + e);
|
||||
});
|
||||
});
|
||||
hash[entry.name] = entry;
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
var response = entries.error_response.response;
|
||||
return cache.match(entries.error_response.request.url)
|
||||
.then(function(result) {
|
||||
assert_response_equals(
|
||||
result, entries.error_response.response,
|
||||
'Cache.match should return a Response object that has the ' +
|
||||
'same properties as a stored network error response.');
|
||||
});
|
||||
p = p.then(function() {
|
||||
assert_equals(Object.keys(hash).length, entries.length);
|
||||
});
|
||||
|
||||
return p.then(function() {
|
||||
return test_function(cache, hash);
|
||||
});
|
||||
}, description);
|
||||
}
|
||||
}, 'Cache.match with a network error Response');
|
||||
|
||||
done();
|
||||
|
|
|
@ -0,0 +1,154 @@
|
|||
if (self.importScripts) {
|
||||
importScripts('/resources/testharness.js');
|
||||
importScripts('../resources/testharness-helpers.js');
|
||||
importScripts('../resources/test-helpers.js');
|
||||
}
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.matchAll('not-present-in-the-cache')
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result, [],
|
||||
'Cache.matchAll should resolve with an empty array on failure.');
|
||||
});
|
||||
}, 'Cache.matchAll with no matching entries');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.matchAll(entries.a.request.url)
|
||||
.then(function(result) {
|
||||
assert_response_array_equals(result, [entries.a.response],
|
||||
'Cache.matchAll should match by URL.');
|
||||
});
|
||||
}, 'Cache.matchAll with URL');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.matchAll(entries.a.request)
|
||||
.then(function(result) {
|
||||
assert_response_array_equals(
|
||||
result, [entries.a.response],
|
||||
'Cache.matchAll should match by Request.');
|
||||
});
|
||||
}, 'Cache.matchAll with Request');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.matchAll(new Request(entries.a.request.url))
|
||||
.then(function(result) {
|
||||
assert_response_array_equals(
|
||||
result, [entries.a.response],
|
||||
'Cache.matchAll should match by Request.');
|
||||
});
|
||||
}, 'Cache.matchAll with new Request');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.matchAll(entries.a.request,
|
||||
{ignoreSearch: true})
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result,
|
||||
[
|
||||
entries.a.response,
|
||||
entries.a_with_query.response
|
||||
],
|
||||
'Cache.matchAll with ignoreSearch should ignore the ' +
|
||||
'search parameters of cached request.');
|
||||
});
|
||||
},
|
||||
'Cache.matchAll with ignoreSearch option (request with no search ' +
|
||||
'parameters)');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.matchAll(entries.a_with_query.request,
|
||||
{ignoreSearch: true})
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result,
|
||||
[
|
||||
entries.a.response,
|
||||
entries.a_with_query.response
|
||||
],
|
||||
'Cache.matchAll with ignoreSearch should ignore the ' +
|
||||
'search parameters of request.');
|
||||
});
|
||||
},
|
||||
'Cache.matchAll with ignoreSearch option (request with search parameter)');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.matchAll(entries.cat.request.url + '#mouse')
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result,
|
||||
[
|
||||
entries.cat.response,
|
||||
],
|
||||
'Cache.matchAll should ignore URL fragment.');
|
||||
});
|
||||
}, 'Cache.matchAll with URL containing fragment');
|
||||
|
||||
prepopulated_cache_test(simple_entries, function(cache, entries) {
|
||||
return cache.matchAll('http')
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result, [],
|
||||
'Cache.matchAll should treat query as a URL and not ' +
|
||||
'just a string fragment.');
|
||||
});
|
||||
}, 'Cache.matchAll with string fragment "http" as query');
|
||||
|
||||
prepopulated_cache_test(vary_entries, function(cache, entries) {
|
||||
return cache.matchAll('http://example.com/c')
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result,
|
||||
[
|
||||
entries.vary_cookie_absent.response
|
||||
],
|
||||
'Cache.matchAll should exclude matches if a vary header is ' +
|
||||
'missing in the query request, but is present in the cached ' +
|
||||
'request.');
|
||||
})
|
||||
|
||||
.then(function() {
|
||||
return cache.matchAll(
|
||||
new Request('http://example.com/c',
|
||||
{headers: {'Cookies': 'none-of-the-above'}}));
|
||||
})
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result,
|
||||
[
|
||||
],
|
||||
'Cache.matchAll should exclude matches if a vary header is ' +
|
||||
'missing in the cached request, but is present in the query ' +
|
||||
'request.');
|
||||
})
|
||||
|
||||
.then(function() {
|
||||
return cache.matchAll(
|
||||
new Request('http://example.com/c',
|
||||
{headers: {'Cookies': 'is-for-cookie'}}));
|
||||
})
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result,
|
||||
[entries.vary_cookie_is_cookie.response],
|
||||
'Cache.matchAll should match the entire header if a vary header ' +
|
||||
'is present in both the query and cached requests.');
|
||||
});
|
||||
}, 'Cache.matchAll with responses containing "Vary" header');
|
||||
|
||||
prepopulated_cache_test(vary_entries, function(cache, entries) {
|
||||
return cache.matchAll('http://example.com/c',
|
||||
{ignoreVary: true})
|
||||
.then(function(result) {
|
||||
assert_response_array_equivalent(
|
||||
result,
|
||||
[
|
||||
entries.vary_cookie_is_cookie.response,
|
||||
entries.vary_cookie_is_good.response,
|
||||
entries.vary_cookie_absent.response
|
||||
],
|
||||
'Cache.matchAll should honor "ignoreVary" parameter.');
|
||||
});
|
||||
}, 'Cache.matchAll with "ignoreVary" parameter');
|
||||
|
||||
done();
|
|
@ -250,16 +250,22 @@ cache_test(function(cache) {
|
|||
assert_true(
|
||||
response.bodyUsed,
|
||||
'[https://fetch.spec.whatwg.org/#concept-body-consume-body] ' +
|
||||
'The text() method should set "body used" flag.');
|
||||
return assert_promise_rejects(
|
||||
cache.put(new Request(test_url), response),
|
||||
new TypeError,
|
||||
'[https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#cache-put] ' +
|
||||
'Cache put should reject with TypeError when Response ' +
|
||||
'body is already used.');
|
||||
});
|
||||
'The text() method should make the body disturbed.');
|
||||
var request = new Request(test_url);
|
||||
return cache.put(request, response).then(() => {
|
||||
assert_unreached('cache.put should be rejected');
|
||||
}, () => {});
|
||||
});
|
||||
}, 'Cache.put with a used response body');
|
||||
|
||||
cache_test(function(cache) {
|
||||
var response = new Response(test_body);
|
||||
return cache.put(new Request(test_url), response)
|
||||
.then(function() {
|
||||
assert_throws(new TypeError(), () => response.body.getReader());
|
||||
});
|
||||
}, 'getReader() after Cache.put');
|
||||
|
||||
cache_test(function(cache) {
|
||||
return assert_promise_rejects(
|
||||
cache.put(new Request(test_url),
|
||||
|
|
|
@ -106,7 +106,6 @@ promise_test(function(t) {
|
|||
|
||||
promise_test(function(t) {
|
||||
var cache_name = 'cache-storage/open';
|
||||
var url = '../resources/simple.txt';
|
||||
var cache;
|
||||
return self.caches.delete(cache_name)
|
||||
.then(function() {
|
||||
|
@ -135,7 +134,7 @@ promise_test(function(t) {
|
|||
assert_array_equals(actual_urls, expected_urls,
|
||||
'CacheStorage.open should return a new Cache ' +
|
||||
'object for the same backing store.');
|
||||
})
|
||||
});
|
||||
}, 'CacheStorage.open with existing cache');
|
||||
|
||||
promise_test(function(t) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Cache.match and Cache.matchAll</title>
|
||||
<title>Cache.match</title>
|
||||
<link rel="help" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#cache-match">
|
||||
<meta name="timeout" content="long">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Cache.matchAll</title>
|
||||
<link rel="help" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#cache-matchall">
|
||||
<meta name="timeout" content="long">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="../../service-workers/resources/test-helpers.js"></script>
|
||||
<script>
|
||||
service_worker_test('../script-tests/cache-matchAll.js');
|
||||
</script>
|
|
@ -1,5 +1,5 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Cache Storage: Cache.match and Cache.matchAll</title>
|
||||
<title>Cache Storage: Cache.match</title>
|
||||
<link rel="help" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#cache-match">
|
||||
<meta name="timeout" content="long">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Cache.matchAll</title>
|
||||
<link rel="help" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#cache-matchall">
|
||||
<meta name="timeout" content="long">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="../resources/testharness-helpers.js"></script>
|
||||
<script src="../resources/test-helpers.js"></script>
|
||||
<script src="../script-tests/cache-matchAll.js"></script>
|
|
@ -1,5 +1,5 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Cache.match and Cache.matchAll</title>
|
||||
<title>Cache.match</title>
|
||||
<link rel="help" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#cache-match">
|
||||
<meta name="timeout" content="long">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Cache.matchAll</title>
|
||||
<link rel="help" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#cache-matchall">
|
||||
<meta name="timeout" content="long">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
fetch_tests_from_worker(new Worker('../script-tests/cache-matchAll.js'));
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue