| OLD | NEW |
| 1 importScripts('worker-testharness.js'); | 1 importScripts('worker-testharness.js'); |
| 2 importScripts('/resources/testharness-helpers.js'); | 2 importScripts('/resources/testharness-helpers.js'); |
| 3 | 3 |
| 4 var test_url = 'https://example.com/foo'; | 4 var test_url = 'https://example.com/foo'; |
| 5 | 5 |
| 6 // Construct a generic Request object. The URL is |test_url|. All other fields | 6 // Construct a generic Request object. The URL is |test_url|. All other fields |
| 7 // are defaults. | 7 // are defaults. |
| 8 function new_test_request() { | 8 function new_test_request() { |
| 9 return new Request(test_url); | 9 return new Request(test_url); |
| 10 } | 10 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 assert_equals(result, undefined, | 28 assert_equals(result, undefined, |
| 29 'Cache.put should resolve with undefined on success.'); | 29 'Cache.put should resolve with undefined on success.'); |
| 30 }); | 30 }); |
| 31 }, 'Cache.put called with simple Request and Response'); | 31 }, 'Cache.put called with simple Request and Response'); |
| 32 | 32 |
| 33 cache_test(function(cache) { | 33 cache_test(function(cache) { |
| 34 var test_url = new URL('simple.txt', location.href).href; | 34 var test_url = new URL('simple.txt', location.href).href; |
| 35 var request = new Request(test_url); | 35 var request = new Request(test_url); |
| 36 var response; | 36 var response; |
| 37 return fetch(test_url) | 37 return fetch(test_url) |
| 38 .then(function(fetch_result) { | 38 .then(function(fetch_result) { |
| 39 response = fetch_result.clone(); | 39 response = fetch_result.clone(); |
| 40 return cache.put(request, fetch_result); | 40 return cache.put(request, fetch_result); |
| 41 }) | 41 }) |
| 42 .then(function() { | 42 .then(function() { |
| 43 return cache.match(test_url); | 43 return cache.match(test_url); |
| 44 }) | 44 }) |
| 45 .then(function(result) { | 45 .then(function(result) { |
| 46 assert_object_equals(result, response, | 46 assert_object_equals(result, response, |
| 47 'Cache.put should update the cache with ' + | 47 'Cache.put should update the cache with ' + |
| 48 'new request and response.'); | 48 'new request and response.'); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 'new request and response.'); | 131 'new request and response.'); |
| 132 return result.text(); | 132 return result.text(); |
| 133 }) | 133 }) |
| 134 .then(function(body) { | 134 .then(function(body) { |
| 135 assert_equals(body, '', | 135 assert_equals(body, '', |
| 136 'Cache.put should store response body.'); | 136 'Cache.put should store response body.'); |
| 137 }); | 137 }); |
| 138 }, 'Cache.put with HTTP 500 response'); | 138 }, 'Cache.put with HTTP 500 response'); |
| 139 | 139 |
| 140 cache_test(function(cache) { | 140 cache_test(function(cache) { |
| 141 var alternate_response = new_test_response('Lorem ipsum'); | 141 var alternate_response = new_test_response('Lorem ipsum'); |
| 142 return cache.put(new_test_request(), new_test_response()) | 142 return cache.put(new_test_request(), new_test_response()) |
| 143 .then(function() { | 143 .then(function() { |
| 144 return cache.put(new_test_request(), alternate_response); | 144 return cache.put(new_test_request(), alternate_response); |
| 145 }) | 145 }) |
| 146 .then(function() { | 146 .then(function() { |
| 147 return cache.match(test_url); | 147 return cache.match(test_url); |
| 148 }) | 148 }) |
| 149 .then(function(result) { | 149 .then(function(result) { |
| 150 assert_object_equals(result, alternate_response, | 150 assert_object_equals(result, alternate_response, |
| 151 'Cache.put should replace existing ' + | 151 'Cache.put should replace existing ' + |
| 152 'response with new response.'); | 152 'response with new response.'); |
| 153 }); | 153 }); |
| 154 }, 'Cache.put called twice with same Request and different Responses'); | 154 }, 'Cache.put called twice with same Request and different Responses'); |
| 155 | 155 |
| 156 cache_test(function(cache) { | 156 cache_test(function(cache) { |
| 157 var url = 'http://example.com/foo'; | 157 var url = 'http://example.com/foo'; |
| 158 return cache.put(url, new_test_response('some body')) | 158 return cache.put(url, new_test_response('some body')) |
| 159 .then(function() { return cache.match(url); }) | 159 .then(function() { return cache.match(url); }) |
| 160 .then(function(response) { return response.text(); }) | 160 .then(function(response) { return response.text(); }) |
| 161 .then(function(body) { | 161 .then(function(body) { |
| 162 assert_equals(body, 'some body', | 162 assert_equals(body, 'some body', |
| 163 'Cache.put should accept a string as request.'); | 163 'Cache.put should accept a string as request.'); |
| 164 }); | 164 }); |
| 165 }, 'Cache.put with an string request'); | 165 }, 'Cache.put with an string request'); |
| 166 | 166 |
| 167 cache_test(function(cache) { | 167 cache_test(function(cache) { |
| 168 return assert_promise_rejects( | 168 return assert_promise_rejects( |
| 169 cache.put(new_test_request(), 'Hello world!'), | 169 cache.put(new_test_request(), 'Hello world!'), |
| 170 new TypeError(), | 170 new TypeError(), |
| 171 'Cache.put should only accept a Response object as the response.'); | 171 'Cache.put should only accept a Response object as the response.'); |
| 172 }, 'Cache.put with an invalid response'); | 172 }, 'Cache.put with an invalid response'); |
| 173 | 173 |
| 174 cache_test(function(cache) { | 174 cache_test(function(cache) { |
| 175 return assert_promise_rejects( | 175 return assert_promise_rejects( |
| 176 cache.put(new Request('file:///etc/passwd'), new_test_response()), | 176 cache.put(new Request('file:///etc/passwd'), new_test_response()), |
| 177 new TypeError(), | 177 new TypeError(), |
| 178 'Cache.put should reject non-HTTP/HTTPS requests with a TypeError.'); | 178 'Cache.put should reject non-HTTP/HTTPS requests with a TypeError.'); |
| 179 }, 'Cache.put with a non-HTTP/HTTPS request'); | 179 }, 'Cache.put with a non-HTTP/HTTPS request'); |
| 180 | 180 |
| 181 cache_test(function(cache) { | 181 cache_test(function(cache) { |
| 182 var response = new_test_response(); | 182 var response = new_test_response(); |
| 183 return cache.put(new Request('relative-url'), response) | 183 return cache.put(new Request('relative-url'), response) |
| 184 .then(function() { | 184 .then(function() { |
| 185 return cache.match(new URL('relative-url', location.href).href); | 185 return cache.match(new URL('relative-url', location.href).href); |
| 186 }) | 186 }) |
| 187 .then(function(result) { | 187 .then(function(result) { |
| 188 assert_object_equals(result, response, | 188 assert_object_equals(result, response, |
| 189 'Cache.put should accept a relative URL ' + | 189 'Cache.put should accept a relative URL ' + |
| 190 'as the request.'); | 190 'as the request.'); |
| 191 }); | 191 }); |
| 192 }, 'Cache.put with a relative URL'); | 192 }, 'Cache.put with a relative URL'); |
| 193 | 193 |
| 194 cache_test(function(cache) { | 194 cache_test(function(cache) { |
| 195 var request = new Request('http://example.com/foo', {method: 'HEAD'}); | 195 var request = new Request('http://example.com/foo', {method: 'HEAD'}); |
| 196 return assert_promise_rejects( | 196 return assert_promise_rejects( |
| 197 cache.put(request, new_test_response()), | 197 cache.put(request, new_test_response()), |
| 198 new TypeError(), | 198 new TypeError(), |
| 199 'Cache.put should throw a TypeError for non-GET requests.'); | 199 'Cache.put should throw a TypeError for non-GET requests.'); |
| 200 }, 'Cache.put with a non-GET request'); | 200 }, 'Cache.put with a non-GET request'); |
| 201 | 201 |
| 202 cache_test(function(cache) { | 202 cache_test(function(cache) { |
| 203 return assert_promise_rejects( | 203 return assert_promise_rejects( |
| 204 cache.put(new_test_request(), null), | 204 cache.put(new_test_request(), null), |
| 205 new TypeError(), | 205 new TypeError(), |
| 206 'Cache.put should throw a TypeError for an empty response.'); | 206 'Cache.put should throw a TypeError for an empty response.'); |
| 207 }, 'Cache.put with an empty response'); | 207 }, 'Cache.put with an empty response'); |
| OLD | NEW |