Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 if (self.importScripts) { | 1 if (self.importScripts) { |
| 2 importScripts('../resources/fetch-test-helpers.js'); | 2 importScripts('../resources/fetch-test-helpers.js'); |
| 3 } | 3 } |
| 4 | 4 |
| 5 function consume(reader) { | 5 function consume(reader) { |
| 6 var chunks = []; | 6 var chunks = []; |
| 7 function rec(reader) { | 7 function rec(reader) { |
| 8 return reader.read().then(function(r) { | 8 return reader.read().then(function(r) { |
| 9 if (r.done) { | 9 if (r.done) { |
| 10 return chunks; | 10 return chunks; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 'Response.headers must not have Content-Type ' + | 110 'Response.headers must not have Content-Type ' + |
| 111 'for Blob with type = empty string (2)'); | 111 'for Blob with type = empty string (2)'); |
| 112 }, 'Response content type test'); | 112 }, 'Response content type test'); |
| 113 | 113 |
| 114 test(function() { | 114 test(function() { |
| 115 [0, 1, 100, 199, 600, 700].forEach(function(status) { | 115 [0, 1, 100, 199, 600, 700].forEach(function(status) { |
| 116 assert_throws({name: 'RangeError'}, | 116 assert_throws({name: 'RangeError'}, |
| 117 function() { | 117 function() { |
| 118 new Response(new Blob(), {status: status}); | 118 new Response(new Blob(), {status: status}); |
| 119 }, | 119 }, |
| 120 'new Response with status = ' + status + ' should throw'); | 120 'new Response with status = ' + status + |
| 121 'should throw'); | |
| 121 }); | 122 }); |
| 123 | |
| 124 [300, 0, 304, 305, 306, 309, 500].forEach(function(status) { | |
| 125 assert_throws({name: 'RangeError'}, | |
| 126 function() { | |
| 127 Response.redirect('https://www.example.com/test.html', | |
| 128 status); | |
| 129 }, | |
| 130 'Response.redirect() with invalid status = ' + status + | |
| 131 'should throw'); | |
| 132 }); | |
| 133 | |
| 134 assert_throws( | |
| 135 {name: 'TypeError'}, | |
| 136 function() { | |
| 137 Response.redirect('https://', 301); | |
| 138 }, | |
| 139 'Response.redirect() with invalid URL https:// ' + | |
| 140 ' and status 301 should throw'); | |
| 141 | |
| 142 INVALID_URLS.forEach(function(url) { | |
| 143 assert_throws( | |
| 144 {name: 'TypeError'}, | |
| 145 function() { | |
| 146 Response.redirect(url); | |
| 147 }, | |
| 148 'Response.redirect() with invalid URL ' + url + | |
| 149 ' and default status value should throw'); | |
| 150 }); | |
| 151 | |
| 152 assert_throws( | |
| 153 {name: 'TypeError'}, | |
| 154 function() { | |
| 155 Response.redirect('https://', 300); | |
| 156 }, | |
| 157 'Response.redirect() with invalid URL https:// ' + | |
| 158 ' and invalid status 300 should throw TypeError'); | |
| 159 | |
| 122 [200, 300, 400, 500, 599].forEach(function(status) { | 160 [200, 300, 400, 500, 599].forEach(function(status) { |
| 123 var response = new Response(new Blob(), {status: status}); | 161 var response = new Response(new Blob(), {status: status}); |
| 124 assert_equals(response.status, status, 'Response.status should match'); | 162 assert_equals(response.status, status, 'Response.status should match'); |
| 125 if (200 <= status && status <= 299) | 163 if (200 <= status && status <= 299) |
| 126 assert_true(response.ok, 'Response.ok must be true for ' + status); | 164 assert_true(response.ok, 'Response.ok must be true for ' + status); |
| 127 else | 165 else |
| 128 assert_false(response.ok, 'Response.ok must be false for ' + status); | 166 assert_false(response.ok, 'Response.ok must be false for ' + status); |
| 129 }); | 167 }); |
| 130 | 168 |
| 131 INVALID_HEADER_NAMES.forEach(function(name) { | 169 INVALID_HEADER_NAMES.forEach(function(name) { |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 promise_test(function(t) { | 339 promise_test(function(t) { |
| 302 var res = new Response(new Blob([''])); | 340 var res = new Response(new Blob([''])); |
| 303 return res.blob() | 341 return res.blob() |
| 304 .then(function(blob) { | 342 .then(function(blob) { |
| 305 assert_equals(blob.type, ''); | 343 assert_equals(blob.type, ''); |
| 306 assert_equals(res.headers.get('Content-Type'), null); | 344 assert_equals(res.headers.get('Content-Type'), null); |
| 307 }); | 345 }); |
| 308 }, 'MIME type for Blob'); | 346 }, 'MIME type for Blob'); |
| 309 | 347 |
| 310 promise_test(function(t) { | 348 promise_test(function(t) { |
| 311 var res = new Response(new Blob(['hello'], {type: 'Text/Plain'})); | 349 var res = new Response(new Blob([''], {type: 'Text/Plain'})); |
| 312 return res.blob() | 350 return res.blob() |
| 313 .then(function(blob) { | 351 .then(function(blob) { |
| 314 assert_equals(blob.type, 'text/plain'); | 352 assert_equals(blob.type, 'text/plain'); |
| 315 assert_equals(blob.size, 5); | |
| 316 assert_equals(res.headers.get('Content-Type'), 'text/plain'); | |
| 317 return res.blob(); | |
| 318 }).then(function(blob) { | |
| 319 // When we read from a response twice, it returns an empty contents. | |
| 320 // But the type should remain. | |
| 321 assert_equals(blob.type, 'text/plain'); | |
| 322 assert_equals(blob.size, 0); | |
|
tyoshino (SeeGerritForStatus)
2015/04/30 06:14:40
why these assertions have been removed?
yhirano
2015/04/30 06:21:17
Maybe it's a rebase failure. I added the test at h
shiva.jm
2015/04/30 06:28:59
shall we make new patch to add these deleted chang
| |
| 323 assert_equals(res.headers.get('Content-Type'), 'text/plain'); | 353 assert_equals(res.headers.get('Content-Type'), 'text/plain'); |
| 324 }); | 354 }); |
| 325 }, 'MIME type for Blob with non-empty type'); | 355 }, 'MIME type for Blob with non-empty type'); |
| 326 | 356 |
| 327 promise_test(function(t) { | 357 promise_test(function(t) { |
| 328 var res = new Response(new FormData()); | 358 var res = new Response(new FormData()); |
| 329 return res.blob() | 359 return res.blob() |
| 330 .then(function(blob) { | 360 .then(function(blob) { |
| 331 assert_equals(blob.type.indexOf('multipart/form-data; boundary='), | 361 assert_equals(blob.type.indexOf('multipart/form-data; boundary='), |
| 332 0); | 362 0); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 }).then(function(texts) { | 456 }).then(function(texts) { |
| 427 assert_equals(texts[0], ''); | 457 assert_equals(texts[0], ''); |
| 428 assert_equals(texts[1], ''); | 458 assert_equals(texts[1], ''); |
| 429 return res.body.getReader().read(); | 459 return res.body.getReader().read(); |
| 430 }).then(function(r) { | 460 }).then(function(r) { |
| 431 assert_true(r.done); | 461 assert_true(r.done); |
| 432 assert_equals(r.value, undefined); | 462 assert_equals(r.value, undefined); |
| 433 }); | 463 }); |
| 434 }, 'Read after text()'); | 464 }, 'Read after text()'); |
| 435 | 465 |
| 466 promise_test(function() { | |
| 467 var response = Response.redirect('https://www.example.com/test.html'); | |
| 468 return response.text().then(function(text) { | |
| 469 assert_equals(response.status, 302, | |
| 470 'default value of status is always 302'); | |
| 471 assert_equals(response.headers.get('location'), | |
| 472 'https://www.example.com/test.html', | |
| 473 'Location header should be correct absoulte URL'); | |
| 474 assert_throws({name: 'TypeError'}, | |
| 475 function() { | |
| 476 response.headers.append('Accept-Language', 'test'); | |
| 477 }, | |
| 478 'response.headers must throw since guard is immutable'); | |
| 479 }); | |
| 480 }, 'Response.redirect() with default status value'); | |
| 481 | |
| 482 promise_test(function() { | |
| 483 var response = Response.redirect('https://www.example.com/test.html', | |
| 484 301); | |
| 485 return response.text().then(function(text) { | |
| 486 assert_equals(response.status, 301, | |
| 487 'value of status is 301'); | |
| 488 assert_equals(response.headers.get('location'), | |
| 489 'https://www.example.com/test.html', | |
| 490 'Location header should be correct absoulte URL'); | |
| 491 assert_equals(size(response.headers), 1, | |
| 492 'Response.redirect().headers must contain ' + | |
| 493 'a Location header only'); | |
| 494 }); | |
| 495 }, 'Response.redirect() with 301'); | |
| 496 | |
| 497 test(function() { | |
| 498 ['http://ex\x0aample.com', | |
| 499 'http://ex\x0dample.com'].forEach(function(url) { | |
| 500 assert_equals(Response.redirect(url).headers.get('Location'), | |
| 501 'http://example.com/', | |
| 502 'Location header value must not contain CR or LF'); | |
| 503 }); | |
| 504 }, 'Response.redirect() with URLs with CR or LF'); | |
| 505 | |
| 436 done(); | 506 done(); |
| OLD | NEW |