1 if (self.importScripts) {
2 importScripts('/resources/testharness.js');
3 importScripts('/resources/testharness-helpers.js');
4 importScripts('../resources/test-helpers.js');
7 var test_url = 'https://example.com/foo';
9 // Construct a generic Request object. The URL is |test_url|. All other fields
11 function new_test_request() {
12 return new Request(test_url);
15 // Construct a generic Response object.
16 function new_test_response() {
17 return new Response('Hello world!', { status: 200 });
20 cache_test(function(cache) {
21 return assert_promise_rejects(
24 'Cache.delete should reject with a TypeError when called with no ' +
26 }, 'Cache.delete with no arguments');
28 cache_test(function(cache) {
29 return cache.put(new_test_request(), new_test_response())
31 return cache.delete(test_url);
33 .then(function(result) {
35 'Cache.delete should resolve with "true" if an entry ' +
36 'was successfully deleted.');
37 return cache.match(test_url);
39 .then(function(result) {
40 assert_equals(result, undefined,
41 'Cache.delete should remove matching entries from cache.');
43 }, 'Cache.delete called with a string URL');
45 cache_test(function(cache) {
46 var request = new Request(test_url);
47 return cache.put(request, new_test_response())
49 return cache.delete(request);
51 .then(function(result) {
53 'Cache.delete should resolve with "true" if an entry ' +
54 'was successfully deleted.');
56 }, 'Cache.delete called with a Request object');
58 cache_test(function(cache) {
59 return cache.delete(test_url)
60 .then(function(result) {
62 'Cache.delete should resolve with "false" if there ' +
63 'are no matching entries.');
65 }, 'Cache.delete with a non-existent entry');
69 request: new Request('http://example.com/abc'),
70 response: new Response('')
74 request: new Request('http://example.com/b'),
75 response: new Response('')
79 request: new Request('http://example.com/abc?q=r'),
80 response: new Response('')
84 function prepopulated_cache_test(test_function, description) {
85 cache_test(function(cache) {
86 return Promise.all(Object.keys(cache_entries).map(function(k) {
87 return cache.put(cache_entries[k].request.clone(),
88 cache_entries[k].response.clone());
91 return test_function(cache);