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

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

Issue 1926813004: Replace assert_promise_rejects with upstream promise_rejects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update testharness.js and rebase Created 4 years, 7 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
1 if (self.importScripts) { 1 if (self.importScripts) {
2 importScripts('/resources/testharness.js'); 2 importScripts('/resources/testharness.js');
3 importScripts('/resources/testharness-helpers.js'); 3 importScripts('/resources/testharness-helpers.js');
4 importScripts('../resources/test-helpers.js'); 4 importScripts('../resources/test-helpers.js');
5 } 5 }
6 6
7 var test_url = 'https://example.com/foo'; 7 var test_url = 'https://example.com/foo';
8 var test_body = 'Hello world!'; 8 var test_body = 'Hello world!';
9 9
10 cache_test(function(cache) { 10 cache_test(function(cache) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 var url = 'http://example.com/foo'; 183 var url = 'http://example.com/foo';
184 return cache.put(url, new Response('some body')) 184 return cache.put(url, new Response('some body'))
185 .then(function() { return cache.match(url); }) 185 .then(function() { return cache.match(url); })
186 .then(function(response) { return response.text(); }) 186 .then(function(response) { return response.text(); })
187 .then(function(body) { 187 .then(function(body) {
188 assert_equals(body, 'some body', 188 assert_equals(body, 'some body',
189 'Cache.put should accept a string as request.'); 189 'Cache.put should accept a string as request.');
190 }); 190 });
191 }, 'Cache.put with a string request'); 191 }, 'Cache.put with a string request');
192 192
193 cache_test(function(cache) { 193 cache_test(function(cache, test) {
194 return assert_promise_rejects( 194 return promise_rejects(
195 test,
196 new TypeError(),
195 cache.put(new Request(test_url), 'Hello world!'), 197 cache.put(new Request(test_url), 'Hello world!'),
196 new TypeError(),
197 'Cache.put should only accept a Response object as the response.'); 198 'Cache.put should only accept a Response object as the response.');
198 }, 'Cache.put with an invalid response'); 199 }, 'Cache.put with an invalid response');
199 200
200 cache_test(function(cache) { 201 cache_test(function(cache, test) {
201 return assert_promise_rejects( 202 return promise_rejects(
203 test,
204 new TypeError(),
202 cache.put(new Request('file:///etc/passwd'), 205 cache.put(new Request('file:///etc/passwd'),
203 new Response(test_body)), 206 new Response(test_body)),
204 new TypeError(),
205 'Cache.put should reject non-HTTP/HTTPS requests with a TypeError.'); 207 'Cache.put should reject non-HTTP/HTTPS requests with a TypeError.');
206 }, 'Cache.put with a non-HTTP/HTTPS request'); 208 }, 'Cache.put with a non-HTTP/HTTPS request');
207 209
208 cache_test(function(cache) { 210 cache_test(function(cache) {
209 var response = new Response(test_body); 211 var response = new Response(test_body);
210 return cache.put(new Request('relative-url'), response.clone()) 212 return cache.put(new Request('relative-url'), response.clone())
211 .then(function() { 213 .then(function() {
212 return cache.match(new URL('relative-url', location.href).href); 214 return cache.match(new URL('relative-url', location.href).href);
213 }) 215 })
214 .then(function(result) { 216 .then(function(result) {
215 assert_response_equals(result, response, 217 assert_response_equals(result, response,
216 'Cache.put should accept a relative URL ' + 218 'Cache.put should accept a relative URL ' +
217 'as the request.'); 219 'as the request.');
218 }); 220 });
219 }, 'Cache.put with a relative URL'); 221 }, 'Cache.put with a relative URL');
220 222
221 cache_test(function(cache) { 223 cache_test(function(cache, test) {
222 var request = new Request('http://example.com/foo', { method: 'HEAD' }); 224 var request = new Request('http://example.com/foo', { method: 'HEAD' });
223 return assert_promise_rejects( 225 return promise_rejects(
226 test,
227 new TypeError(),
224 cache.put(request, new Response(test_body)), 228 cache.put(request, new Response(test_body)),
225 new TypeError(),
226 'Cache.put should throw a TypeError for non-GET requests.'); 229 'Cache.put should throw a TypeError for non-GET requests.');
227 }, 'Cache.put with a non-GET request'); 230 }, 'Cache.put with a non-GET request');
228 231
229 cache_test(function(cache) { 232 cache_test(function(cache, test) {
230 return assert_promise_rejects( 233 return promise_rejects(
234 test,
235 new TypeError(),
231 cache.put(new Request(test_url), null), 236 cache.put(new Request(test_url), null),
232 new TypeError(),
233 'Cache.put should throw a TypeError for a null response.'); 237 'Cache.put should throw a TypeError for a null response.');
234 }, 'Cache.put with a null response'); 238 }, 'Cache.put with a null response');
235 239
236 cache_test(function(cache) { 240 cache_test(function(cache, test) {
237 var request = new Request(test_url, {method: 'POST', body: test_body}); 241 var request = new Request(test_url, {method: 'POST', body: test_body});
238 return assert_promise_rejects( 242 return promise_rejects(
243 test,
244 new TypeError(),
239 cache.put(request, new Response(test_body)), 245 cache.put(request, new Response(test_body)),
240 new TypeError(),
241 'Cache.put should throw a TypeError for a POST request.'); 246 'Cache.put should throw a TypeError for a POST request.');
242 }, 'Cache.put with a POST request'); 247 }, 'Cache.put with a POST request');
243 248
244 cache_test(function(cache) { 249 cache_test(function(cache) {
245 var response = new Response(test_body); 250 var response = new Response(test_body);
246 assert_false(response.bodyUsed, 251 assert_false(response.bodyUsed,
247 '[https://fetch.spec.whatwg.org/#dom-body-bodyused] ' + 252 '[https://fetch.spec.whatwg.org/#dom-body-bodyused] ' +
248 'Response.bodyUsed should be initially false.'); 253 'Response.bodyUsed should be initially false.');
249 return response.text().then(function() { 254 return response.text().then(function() {
250 assert_true( 255 assert_true(
251 response.bodyUsed, 256 response.bodyUsed,
252 '[https://fetch.spec.whatwg.org/#concept-body-consume-body] ' + 257 '[https://fetch.spec.whatwg.org/#concept-body-consume-body] ' +
253 'The text() method should make the body disturbed.'); 258 'The text() method should make the body disturbed.');
254 var request = new Request(test_url); 259 var request = new Request(test_url);
255 return cache.put(request, response).then(() => { 260 return cache.put(request, response).then(() => {
256 assert_unreached('cache.put should be rejected'); 261 assert_unreached('cache.put should be rejected');
257 }, () => {}); 262 }, () => {});
258 }); 263 });
259 }, 'Cache.put with a used response body'); 264 }, 'Cache.put with a used response body');
260 265
261 cache_test(function(cache) { 266 cache_test(function(cache) {
262 var response = new Response(test_body); 267 var response = new Response(test_body);
263 return cache.put(new Request(test_url), response) 268 return cache.put(new Request(test_url), response)
264 .then(function() { 269 .then(function() {
265 assert_throws(new TypeError(), () => response.body.getReader()); 270 assert_throws(new TypeError(), () => response.body.getReader());
266 }); 271 });
267 }, 'getReader() after Cache.put'); 272 }, 'getReader() after Cache.put');
268 273
269 cache_test(function(cache) { 274 cache_test(function(cache, test) {
270 return assert_promise_rejects( 275 return promise_rejects(
276 test,
277 new TypeError(),
271 cache.put(new Request(test_url), 278 cache.put(new Request(test_url),
272 new Response(test_body, { headers: { VARY: '*' }})), 279 new Response(test_body, { headers: { VARY: '*' }})),
273 new TypeError(),
274 'Cache.put should reject VARY:* Responses with a TypeError.'); 280 'Cache.put should reject VARY:* Responses with a TypeError.');
275 }, 'Cache.put with a VARY:* Response'); 281 }, 'Cache.put with a VARY:* Response');
276 282
277 cache_test(function(cache) { 283 cache_test(function(cache, test) {
278 return assert_promise_rejects( 284 return promise_rejects(
285 test,
286 new TypeError(),
279 cache.put(new Request(test_url), 287 cache.put(new Request(test_url),
280 new Response(test_body, 288 new Response(test_body,
281 { headers: { VARY: 'Accept-Language,*' }})), 289 { headers: { VARY: 'Accept-Language,*' }})),
282 new TypeError(),
283 'Cache.put should reject Responses with an embedded VARY:* with a ' + 290 'Cache.put should reject Responses with an embedded VARY:* with a ' +
284 'TypeError.'); 291 'TypeError.');
285 }, 'Cache.put with an embedded VARY:* Response'); 292 }, 'Cache.put with an embedded VARY:* Response');
286 293
287 done(); 294 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698