Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/cachestorage/script-tests/cache-storage-match.js

Issue 2790143003: Cache Storage API tests: Fix WPT test bugs, remove redundant local copies (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 if (self.importScripts) {
2 importScripts('/resources/testharness.js');
3 importScripts('../resources/test-helpers.js');
4 }
5
6 (function() {
7 var next_index = 1;
8
9 // Returns a transaction (request, response, and url) for a unique URL.
10 function create_unique_transaction(test) {
11 var uniquifier = String(next_index++);
12 var url = 'http://example.com/' + uniquifier;
13
14 return {
15 request: new Request(url),
16 response: new Response('hello'),
17 url: url
18 };
19 }
20
21 self.create_unique_transaction = create_unique_transaction;
22 })();
23
24 cache_test(function(cache) {
25 var transaction = create_unique_transaction();
26
27 return cache.put(transaction.request.clone(), transaction.response.clone())
28 .then(function() {
29 return self.caches.match(transaction.request);
30 })
31 .then(function(response) {
32 assert_response_equals(response, transaction.response,
33 'The response should not have changed.');
34 });
35 }, 'CacheStorageMatch with no cache name provided');
36
37 cache_test(function(cache) {
38 var transaction = create_unique_transaction();
39
40 var test_cache_list = ['a', 'b', 'c'];
41 return cache.put(transaction.request.clone(), transaction.response.clone())
42 .then(function() {
43 return Promise.all(test_cache_list.map(function(key) {
44 return self.caches.open(key);
45 }));
46 })
47 .then(function() {
48 return self.caches.match(transaction.request);
49 })
50 .then(function(response) {
51 assert_response_equals(response, transaction.response,
52 'The response should not have changed.');
53 });
54 }, 'CacheStorageMatch from one of many caches');
55
56 promise_test(function(test) {
57 var transaction = create_unique_transaction();
58
59 var test_cache_list = ['x', 'y', 'z'];
60 return Promise.all(test_cache_list.map(function(key) {
61 return self.caches.open(key);
62 }))
63 .then(function() { return self.caches.open('x'); })
64 .then(function(cache) {
65 return cache.put(transaction.request.clone(),
66 transaction.response.clone());
67 })
68 .then(function() {
69 return self.caches.match(transaction.request, {cacheName: 'x'});
70 })
71 .then(function(response) {
72 assert_response_equals(response, transaction.response,
73 'The response should not have changed.');
74 })
75 .then(function() {
76 return self.caches.match(transaction.request, {cacheName: 'y'});
77 })
78 .then(function(response) {
79 assert_equals(response, undefined,
80 'Cache y should not have a response for the request.');
81 });
82 }, 'CacheStorageMatch from one of many caches by name');
83
84 cache_test(function(cache) {
85 var transaction = create_unique_transaction();
86 return cache.put(transaction.url, transaction.response.clone())
87 .then(function() {
88 return self.caches.match(transaction.request);
89 })
90 .then(function(response) {
91 assert_response_equals(response, transaction.response,
92 'The response should not have changed.');
93 });
94 }, 'CacheStorageMatch a string request');
95
96 cache_test(function(cache) {
97 var transaction = create_unique_transaction();
98 return cache.put(transaction.request.clone(), transaction.response.clone())
99 .then(function() {
100 return self.caches.match(new Request(transaction.request.url,
101 {method: 'HEAD'}));
102 })
103 .then(function(response) {
104 assert_equals(response, undefined,
105 'A HEAD request should not be matched');
106 });
107 }, 'CacheStorageMatch a HEAD request');
108
109 promise_test(function(test) {
110 var transaction = create_unique_transaction();
111 return self.caches.match(transaction.request)
112 .then(function(response) {
113 assert_equals(response, undefined,
114 'The response should not be found.');
115 });
116 }, 'CacheStorageMatch with no cached entry');
117
118 promise_test(function(test) {
119 var transaction = create_unique_transaction();
120 return self.caches.has('foo')
121 .then(function(has_foo) {
122 assert_false(has_foo, "The cache should not exist.");
123 return self.caches.match(transaction.request, {cacheName: 'foo'});
124 })
125 .then(function(response) {
126 assert_equals(response, undefined,
127 'The match with bad cache name should resolve to ' +
128 'undefined.');
129 return self.caches.has('foo');
130 })
131 .then(function(has_foo) {
132 assert_false(has_foo, "The cache should still not exist.");
133 });
134 }, 'CacheStorageMatch with no caches available but name provided');
135
136 cache_test(function(cache) {
137 var transaction = create_unique_transaction();
138
139 return self.caches.delete('')
140 .then(function() {
141 return self.caches.has('');
142 })
143 .then(function(has_cache) {
144 assert_false(has_cache, "The cache should not exist.");
145 return cache.put(transaction.request, transaction.response.clone());
146 })
147 .then(function() {
148 return self.caches.match(transaction.request, {cacheName: ''});
149 })
150 .then(function(response) {
151 assert_equals(response, undefined,
152 'The response should not be found.');
153 return self.caches.open('');
154 })
155 .then(function(cache) {
156 return cache.put(transaction.request, transaction.response);
157 })
158 .then(function() {
159 return self.caches.match(transaction.request, {cacheName: ''});
160 })
161 .then(function(response) {
162 assert_response_equals(response, transaction.response,
163 'The response should be matched.');
164 return self.caches.delete('');
165 });
166 }, 'CacheStorageMatch with empty cache name provided');
167
168
169 cache_test(function(cache) {
170 var request = new Request('http://example.com/?foo');
171 var no_query_request = new Request('http://example.com/');
172 var response = new Response('foo');
173 return cache.put(request.clone(), response.clone())
174 .then(function() {
175 return self.caches.match(no_query_request.clone());
176 })
177 .then(function(result) {
178 assert_equals(
179 result, undefined,
180 'CacheStorageMatch should resolve as undefined with a ' +
181 'mismatched query.');
182 return self.caches.match(no_query_request.clone(),
183 {ignoreSearch: true});
184 })
185 .then(function(result) {
186 assert_response_equals(
187 result, response,
188 'CacheStorageMatch with ignoreSearch should ignore the ' +
189 'query of the request.');
190 });
191 }, 'CacheStorageMatch supports ignoreSearch');
192
193 cache_test(function(cache) {
194 var request = new Request('http://example.com/');
195 var head_request = new Request('http://example.com/', {method: 'HEAD'});
196 var response = new Response('foo');
197 return cache.put(request.clone(), response.clone())
198 .then(function() {
199 return self.caches.match(head_request.clone());
200 })
201 .then(function(result) {
202 assert_equals(
203 result, undefined,
204 'CacheStorageMatch should resolve as undefined with a ' +
205 'mismatched method.');
206 return self.caches.match(head_request.clone(),
207 {ignoreMethod: true});
208 })
209 .then(function(result) {
210 assert_response_equals(
211 result, response,
212 'CacheStorageMatch with ignoreMethod should ignore the ' +
213 'method of request.');
214 });
215 }, 'Cache.match supports ignoreMethod');
216
217 cache_test(function(cache) {
218 var vary_request = new Request('http://example.com/c',
219 {headers: {'Cookies': 'is-for-cookie'}});
220 var vary_response = new Response('', {headers: {'Vary': 'Cookies'}});
221 var mismatched_vary_request = new Request('http://example.com/c');
222
223 return cache.put(vary_request.clone(), vary_response.clone())
224 .then(function() {
225 return self.caches.match(mismatched_vary_request.clone());
226 })
227 .then(function(result) {
228 assert_equals(
229 result, undefined,
230 'CacheStorageMatch should resolve as undefined with a ' +
231 ' mismatched vary.');
232 return self.caches.match(mismatched_vary_request.clone(),
233 {ignoreVary: true});
234 })
235 .then(function(result) {
236 assert_response_equals(
237 result, vary_response,
238 'CacheStorageMatch with ignoreVary should ignore the ' +
239 'vary of request.');
240 });
241 }, 'CacheStorageMatch supports ignoreVary');
242
243 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698