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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/service-workers/cache-storage/resources/test-helpers.js

Issue 2806793002: Cache API tests: prepopulate cache in deterministic order (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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 (function() { 1 (function() {
2 var next_cache_index = 1; 2 var next_cache_index = 1;
3 3
4 // Returns a promise that resolves to a newly created Cache object. The 4 // Returns a promise that resolves to a newly created Cache object. The
5 // returned Cache will be destroyed when |test| completes. 5 // returned Cache will be destroyed when |test| completes.
6 function create_temporary_cache(test) { 6 function create_temporary_cache(test) {
7 var uniquifier = String(++next_cache_index); 7 var uniquifier = String(++next_cache_index);
8 var cache_name = self.location.pathname + '/' + uniquifier; 8 var cache_name = self.location.pathname + '/' + uniquifier;
9 9
10 test.add_cleanup(function() { 10 test.add_cleanup(function() {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 name: 'vary_cookie_absent', 134 name: 'vary_cookie_absent',
135 request: new Request('http://example.com/c'), 135 request: new Request('http://example.com/c'),
136 response: new Response('', 136 response: new Response('',
137 {headers: {'Vary': 'Cookies'}}) 137 {headers: {'Vary': 'Cookies'}})
138 } 138 }
139 ]; 139 ];
140 140
141 // Run |test_function| with a Cache object and a map of entries. Prior to the 141 // Run |test_function| with a Cache object and a map of entries. Prior to the
142 // call, the Cache is populated by cache entries from |entries|. The latter is 142 // call, the Cache is populated by cache entries from |entries|. The latter is
143 // expected to be an Object mapping arbitrary keys to objects of the form 143 // expected to be an Object mapping arbitrary keys to objects of the form
144 // {request: <Request object>, response: <Response object>}. There's no 144 // {request: <Request object>, response: <Response object>}. Entries are
145 // guarantee on the order in which entries will be added to the cache. 145 // serially added to the cache in the order specified.
146 // 146 //
147 // |test_function| should return a Promise that can be used with promise_test. 147 // |test_function| should return a Promise that can be used with promise_test.
148 function prepopulated_cache_test(entries, test_function, description) { 148 function prepopulated_cache_test(entries, test_function, description) {
149 cache_test(function(cache) { 149 cache_test(function(cache) {
150 var p = Promise.resolve(); 150 var p = Promise.resolve();
151 var hash = {}; 151 var hash = {};
152 return Promise.all(entries.map(function(entry) { 152 entries.forEach(function(entry) {
153 hash[entry.name] = entry; 153 hash[entry.name] = entry;
154 return cache.put(entry.request.clone(), 154 p = p.then(function() {
155 entry.response.clone()) 155 return cache.put(entry.request.clone(), entry.response.clone())
156 .catch(function(e) { 156 .catch(function(e) {
157 assert_unreached( 157 assert_unreached(
158 'Test setup failed for entry ' + entry.name + ': ' + e); 158 'Test setup failed for entry ' + entry.name + ': ' + e
159 }); 159 );
160 })) 160 });
161 });
162 });
163 return p
161 .then(function() { 164 .then(function() {
162 assert_equals(Object.keys(hash).length, entries.length); 165 assert_equals(Object.keys(hash).length, entries.length);
163 }) 166 })
164 .then(function() { 167 .then(function() {
165 return test_function(cache, hash); 168 return test_function(cache, hash);
166 }); 169 });
167 }, description); 170 }, description);
168 } 171 }
169 172
170 // Helper for testing with Headers objects. Compares Headers instances 173 // Helper for testing with Headers objects. Compares Headers instances
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 }); 263 });
261 } 264 }
262 265
263 // Deletes all caches, returning a promise indicating success. 266 // Deletes all caches, returning a promise indicating success.
264 function delete_all_caches() { 267 function delete_all_caches() {
265 return self.caches.keys() 268 return self.caches.keys()
266 .then(function(keys) { 269 .then(function(keys) {
267 return Promise.all(keys.map(self.caches.delete.bind(self.caches))); 270 return Promise.all(keys.map(self.caches.delete.bind(self.caches)));
268 }); 271 });
269 } 272 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698