OLD | NEW |
| (Empty) |
1 if (self.importScripts) { | |
2 importScripts('/resources/testharness.js'); | |
3 importScripts('../resources/test-helpers.js'); | |
4 } | |
5 | |
6 var test_url = 'https://example.com/foo'; | |
7 | |
8 // Construct a generic Request object. The URL is |test_url|. All other fields | |
9 // are defaults. | |
10 function new_test_request() { | |
11 return new Request(test_url); | |
12 } | |
13 | |
14 // Construct a generic Response object. | |
15 function new_test_response() { | |
16 return new Response('Hello world!', { status: 200 }); | |
17 } | |
18 | |
19 cache_test(function(cache, test) { | |
20 return promise_rejects( | |
21 test, | |
22 new TypeError(), | |
23 cache.delete(), | |
24 'Cache.delete should reject with a TypeError when called with no ' + | |
25 'arguments.'); | |
26 }, 'Cache.delete with no arguments'); | |
27 | |
28 cache_test(function(cache) { | |
29 return cache.put(new_test_request(), new_test_response()) | |
30 .then(function() { | |
31 return cache.delete(test_url); | |
32 }) | |
33 .then(function(result) { | |
34 assert_true(result, | |
35 'Cache.delete should resolve with "true" if an entry ' + | |
36 'was successfully deleted.'); | |
37 return cache.match(test_url); | |
38 }) | |
39 .then(function(result) { | |
40 assert_equals(result, undefined, | |
41 'Cache.delete should remove matching entries from cache.'); | |
42 }); | |
43 }, 'Cache.delete called with a string URL'); | |
44 | |
45 cache_test(function(cache) { | |
46 var request = new Request(test_url); | |
47 return cache.put(request, new_test_response()) | |
48 .then(function() { | |
49 return cache.delete(request); | |
50 }) | |
51 .then(function(result) { | |
52 assert_true(result, | |
53 'Cache.delete should resolve with "true" if an entry ' + | |
54 'was successfully deleted.'); | |
55 }); | |
56 }, 'Cache.delete called with a Request object'); | |
57 | |
58 cache_test(function(cache) { | |
59 var request = new Request(test_url); | |
60 var response = new_test_response(); | |
61 return cache.put(request, response) | |
62 .then(function() { | |
63 return cache.delete(new Request(test_url, {method: 'HEAD'})); | |
64 }) | |
65 .then(function(result) { | |
66 assert_false(result, | |
67 'Cache.delete should not match a non-GET request ' + | |
68 'unless ignoreMethod option is set.'); | |
69 return cache.match(test_url); | |
70 }) | |
71 .then(function(result) { | |
72 assert_response_equals(result, response, | |
73 'Cache.delete should leave non-matching response in the cache.'); | |
74 return cache.delete(new Request(test_url, {method: 'HEAD'}), | |
75 {ignoreMethod: true}); | |
76 }) | |
77 .then(function(result) { | |
78 assert_true(result, | |
79 'Cache.delete should match a non-GET request ' + | |
80 ' if ignoreMethod is true.') | |
81 }); | |
82 }, 'Cache.delete called with a HEAD request'); | |
83 | |
84 cache_test(function(cache) { | |
85 var vary_request = new Request('http://example.com/c', | |
86 {headers: {'Cookies': 'is-for-cookie'}}); | |
87 var vary_response = new Response('', {headers: {'Vary': 'Cookies'}}); | |
88 var mismatched_vary_request = new Request('http://example.com/c'); | |
89 | |
90 return cache.put(vary_request.clone(), vary_response.clone()) | |
91 .then(function() { | |
92 return cache.delete(mismatched_vary_request.clone()); | |
93 }) | |
94 .then(function(result) { | |
95 assert_false(result, | |
96 'Cache.delete should not delete if vary does not ' + | |
97 'match unless ignoreVary is true'); | |
98 return cache.delete(mismatched_vary_request.clone(), | |
99 {ignoreVary: true}); | |
100 }) | |
101 .then(function(result) { | |
102 assert_true(result, | |
103 'Cache.delete should ignore vary if ignoreVary is true'); | |
104 }); | |
105 }, 'Cache.delete supports ignoreVary'); | |
106 | |
107 cache_test(function(cache) { | |
108 return cache.delete(test_url) | |
109 .then(function(result) { | |
110 assert_false(result, | |
111 'Cache.delete should resolve with "false" if there ' + | |
112 'are no matching entries.'); | |
113 }); | |
114 }, 'Cache.delete with a non-existent entry'); | |
115 | |
116 prepopulated_cache_test(simple_entries, function(cache, entries) { | |
117 return cache.matchAll(entries.a_with_query.request, | |
118 { ignoreSearch: true }) | |
119 .then(function(result) { | |
120 assert_response_array_equals( | |
121 result, | |
122 [ | |
123 entries.a.response, | |
124 entries.a_with_query.response | |
125 ]); | |
126 return cache.delete(entries.a_with_query.request, | |
127 { ignoreSearch: true }); | |
128 }) | |
129 .then(function(result) { | |
130 return cache.matchAll(entries.a_with_query.request, | |
131 { ignoreSearch: true }); | |
132 }) | |
133 .then(function(result) { | |
134 assert_response_array_equals(result, []); | |
135 }); | |
136 }, | |
137 'Cache.delete with ignoreSearch option (request with search parameters)'); | |
138 | |
139 prepopulated_cache_test(simple_entries, function(cache, entries) { | |
140 return cache.matchAll(entries.a_with_query.request, | |
141 { ignoreSearch: true }) | |
142 .then(function(result) { | |
143 assert_response_array_equals( | |
144 result, | |
145 [ | |
146 entries.a.response, | |
147 entries.a_with_query.response | |
148 ]); | |
149 // cache.delete()'s behavior should be the same if ignoreSearch is | |
150 // not provided or if ignoreSearch is false. | |
151 return cache.delete(entries.a_with_query.request, | |
152 { ignoreSearch: false }); | |
153 }) | |
154 .then(function(result) { | |
155 return cache.matchAll(entries.a_with_query.request, | |
156 { ignoreSearch: true }); | |
157 }) | |
158 .then(function(result) { | |
159 assert_response_array_equals(result, [ entries.a.response ]); | |
160 }); | |
161 }, | |
162 'Cache.delete with ignoreSearch option (when it is specified as false)'); | |
163 | |
164 done(); | |
OLD | NEW |