| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 importScripts('worker-testharness.js'); |  | 
| 2 importScripts('/resources/testharness-helpers.js'); |  | 
| 3 |  | 
| 4 var test_url = 'https://example.com/foo'; |  | 
| 5 |  | 
| 6 // Construct a generic Request object. The URL is |test_url|. All other fields |  | 
| 7 // are defaults. |  | 
| 8 function new_test_request() { |  | 
| 9   return new Request(test_url); |  | 
| 10 } |  | 
| 11 |  | 
| 12 // Construct a generic Response object. |  | 
| 13 function new_test_response() { |  | 
| 14   return new Response('Hello world!', { status: 200 }); |  | 
| 15 } |  | 
| 16 |  | 
| 17 cache_test(function(cache) { |  | 
| 18     return assert_promise_rejects( |  | 
| 19       cache.delete(), |  | 
| 20       new TypeError(), |  | 
| 21       'Cache.delete should reject with a TypeError when called with no ' + |  | 
| 22       'arguments.'); |  | 
| 23   }, 'Cache.delete with no arguments'); |  | 
| 24 |  | 
| 25 cache_test(function(cache) { |  | 
| 26     return cache.put(new_test_request(), new_test_response()) |  | 
| 27       .then(function() { |  | 
| 28           return cache.delete(test_url); |  | 
| 29         }) |  | 
| 30       .then(function(result) { |  | 
| 31           assert_true(result, |  | 
| 32                       'Cache.delete should resolve with "true" if an entry ' + |  | 
| 33                       'was successfully deleted.'); |  | 
| 34         }) |  | 
| 35       .then(function() { |  | 
| 36           assert_promise_rejects( |  | 
| 37             cache.match(test_url), |  | 
| 38             'NotFoundError', |  | 
| 39             'Cache.delete should remove matching entries from cache.'); |  | 
| 40         }); |  | 
| 41   }, 'Cache.delete called with a string URL'); |  | 
| 42 |  | 
| 43 cache_test(function(cache) { |  | 
| 44     var request = new Request(test_url, { method: 'POST', body: 'Abc' }); |  | 
| 45     return cache.put(request.clone(), new_test_response()) |  | 
| 46       .then(function() { |  | 
| 47           return cache.delete(request); |  | 
| 48         }) |  | 
| 49       .then(function(result) { |  | 
| 50           assert_true(result, |  | 
| 51                       'Cache.delete should resolve with "true" if an entry ' + |  | 
| 52                       'was successfully deleted.'); |  | 
| 53           assert_false(request.bodyUsed, |  | 
| 54                        'Cache.delete should not consume request body.'); |  | 
| 55         }); |  | 
| 56   }, 'Cache.delete called with a Request object'); |  | 
| 57 |  | 
| 58 cache_test(function(cache) { |  | 
| 59     var request = new Request(test_url, { method: 'POST', body: 'Abc' }); |  | 
| 60     return cache.put(request.clone(), new_test_response()) |  | 
| 61       .then(function() { |  | 
| 62           return request.text(); |  | 
| 63         }) |  | 
| 64       .then(function() { |  | 
| 65           assert_true(request.bodyUsed, |  | 
| 66                       '[https://fetch.spec.whatwg.org/#body-mixin] ' + |  | 
| 67                       'Request.bodyUsed should be true after text() method ' + |  | 
| 68                       'resolves.'); |  | 
| 69         }) |  | 
| 70       .then(function() { |  | 
| 71           return cache.delete(request); |  | 
| 72         }) |  | 
| 73       .then(function(result) { |  | 
| 74           assert_true(result, |  | 
| 75                       'Cache.delete should resolve with "true" if an entry ' + |  | 
| 76                       'was successfully deleted.'); |  | 
| 77         }); |  | 
| 78   }, 'Cache.delete with a Request object containing used body'); |  | 
| 79 |  | 
| 80 cache_test(function(cache) { |  | 
| 81     return cache.delete(test_url) |  | 
| 82       .then(function(result) { |  | 
| 83           assert_false(result, |  | 
| 84                        'Cache.delete should resolve with "false" if there ' + |  | 
| 85                        'are no matching entries.'); |  | 
| 86         }); |  | 
| 87   }, 'Cache.delete with a non-existent entry'); |  | 
| 88 |  | 
| 89 var cache_entries = { |  | 
| 90   a: { |  | 
| 91     request: new Request('http://example.com/abc'), |  | 
| 92     response: new Response('') |  | 
| 93   }, |  | 
| 94 |  | 
| 95   b: { |  | 
| 96     request: new Request('http://example.com/b'), |  | 
| 97     response: new Response('') |  | 
| 98   }, |  | 
| 99 |  | 
| 100   a_with_query: { |  | 
| 101     request: new Request('http://example.com/abc?q=r'), |  | 
| 102     response: new Response('') |  | 
| 103   } |  | 
| 104 }; |  | 
| 105 |  | 
| 106 function prepopulated_cache_test(test_function, description) { |  | 
| 107   cache_test(function(cache) { |  | 
| 108       return Promise.all(Object.keys(cache_entries).map(function(k) { |  | 
| 109           return cache.put(cache_entries[k].request.clone(), |  | 
| 110                            cache_entries[k].response.clone()); |  | 
| 111         })) |  | 
| 112         .then(function() { |  | 
| 113             return test_function(cache); |  | 
| 114           }); |  | 
| 115     }, description); |  | 
| 116 } |  | 
| OLD | NEW | 
|---|