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 var URL = 'https://www.example.com/test.html'; | 5 var URL = 'https://www.example.com/test.html'; |
6 | 6 |
7 test(function() { | 7 test(function() { |
8 var headers = new Headers; | 8 var headers = new Headers; |
9 headers.set('User-Agent', 'Mozilla/5.0'); | 9 headers.set('User-Agent', 'Mozilla/5.0'); |
10 headers.set('Accept', 'text/html'); | 10 headers.set('Accept', 'text/html'); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 'method should not be changed when normalized: ' + | 315 'method should not be changed when normalized: ' + |
316 method); | 316 method); |
317 }); | 317 }); |
318 }, 'Request: valid method names and normalize test'); | 318 }, 'Request: valid method names and normalize test'); |
319 | 319 |
320 test(function() { | 320 test(function() { |
321 var req = new Request(URL); | 321 var req = new Request(URL); |
322 assert_false(req.bodyUsed, | 322 assert_false(req.bodyUsed, |
323 'Request should not be flagged as used if it has not been ' + | 323 'Request should not be flagged as used if it has not been ' + |
324 'consumed.'); | 324 'consumed.'); |
325 // See https://crbug.com/501195. | |
326 var req2 = new Request(req); | 325 var req2 = new Request(req); |
327 assert_true(req.bodyUsed, | 326 assert_false(req.bodyUsed, |
328 'Request should be flagged as used if it does not have' + | 327 'Request should not be flagged as used if it does not have' + |
tyoshino (SeeGerritForStatus)
2015/11/18 09:55:36
indent
yhirano
2015/11/19 08:41:29
Done.
| |
329 'body.'); | 328 'body.'); |
330 assert_false(req2.bodyUsed, | 329 assert_false(req2.bodyUsed, |
331 'Request should not be flagged as used if it has not been ' + | 330 'Request should not be flagged as used if it has not been ' + |
332 'consumed.'); | 331 'consumed.'); |
333 }, 'Request construction without body behavior regardning "bodyUsed"'); | 332 }, 'Request construction without body behavior regardning "bodyUsed"'); |
334 | 333 |
335 test(function() { | 334 test(function() { |
336 var req = new Request(URL, {method: 'POST', body: 'hello'}); | 335 var req = new Request(URL, {method: 'POST', body: 'hello'}); |
337 assert_false(req.bodyUsed, | 336 assert_false(req.bodyUsed, |
338 'Request should not be flagged as used if it has not been ' + | 337 'Request should not be flagged as used if it has not been ' + |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 | 467 |
469 promise_test(function() { | 468 promise_test(function() { |
470 var headers = new Headers; | 469 var headers = new Headers; |
471 headers.set('Content-Language', 'ja'); | 470 headers.set('Content-Language', 'ja'); |
472 var req = new Request(URL, { | 471 var req = new Request(URL, { |
473 method: 'POST', | 472 method: 'POST', |
474 headers: headers, | 473 headers: headers, |
475 body: new Blob(['Test Blob'], {type: 'test/type'}) | 474 body: new Blob(['Test Blob'], {type: 'test/type'}) |
476 }); | 475 }); |
477 var req2 = req.clone(); | 476 var req2 = req.clone(); |
477 assert_false(req.bodyUsed); | |
478 assert_false(req2.bodyUsed); | |
478 // Change headers and of original request. | 479 // Change headers and of original request. |
479 req.headers.set('Content-Language', 'en'); | 480 req.headers.set('Content-Language', 'en'); |
480 assert_equals(req2.headers.get('Content-Language'), 'ja', | 481 assert_equals(req2.headers.get('Content-Language'), 'ja', |
481 'Headers of cloned request should not change when ' + | 482 'Headers of cloned request should not change when ' + |
482 'original request headers are changed.'); | 483 'original request headers are changed.'); |
483 | 484 |
484 return req.text().then(function(text) { | 485 return req.text().then(function(text) { |
485 assert_equals(text, 'Test Blob', 'Body of request should match.'); | 486 assert_equals(text, 'Test Blob', 'Body of request should match.'); |
486 return req2.text(); | 487 return req2.text(); |
487 }).then(function(text) { | 488 }).then(function(text) { |
488 assert_equals(text, 'Test Blob', 'Cloned request body should match.'); | 489 assert_equals(text, 'Test Blob', 'Cloned request body should match.'); |
489 return Promise.all([req.text(), req2.text()]); | |
490 }).then(function(texts) { | |
491 assert_equals(texts[0], '', 'The body is consumed.'); | |
492 assert_equals(texts[1], '', 'The body is consumed.'); | |
493 return req.clone().text(); | |
494 }).then(function(text) { | |
495 assert_equals(text, '', 'The body was consumed before cloned.'); | |
496 }); | 490 }); |
497 }, 'Test clone behavior with loading content from Request.'); | 491 }, 'Test clone behavior with loading content from Request.'); |
498 | 492 |
499 async_test(function(t) { | 493 async_test(function(t) { |
500 var request = | 494 var request = |
501 new Request(URL, | 495 new Request(URL, |
502 { | 496 { |
503 method: 'POST', | 497 method: 'POST', |
504 body: new Blob(['Test Blob'], {type: 'test/type'}) | 498 body: new Blob(['Test Blob'], {type: 'test/type'}) |
505 }); | 499 }); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
642 }, 'MIME type for Blob'); | 636 }, 'MIME type for Blob'); |
643 | 637 |
644 promise_test(function(t) { | 638 promise_test(function(t) { |
645 var req = new Request('http://localhost/', | 639 var req = new Request('http://localhost/', |
646 {method: 'POST', | 640 {method: 'POST', |
647 body: new Blob([''], {type: 'Text/Plain'})}); | 641 body: new Blob([''], {type: 'Text/Plain'})}); |
648 return req.blob() | 642 return req.blob() |
649 .then(function(blob) { | 643 .then(function(blob) { |
650 assert_equals(blob.type, 'text/plain'); | 644 assert_equals(blob.type, 'text/plain'); |
651 assert_equals(req.headers.get('Content-Type'), 'text/plain'); | 645 assert_equals(req.headers.get('Content-Type'), 'text/plain'); |
652 return new Request(req).blob(); | |
653 }).then(function(blob) { | |
654 assert_equals(blob.type, 'text/plain'); | |
655 }); | 646 }); |
656 }, 'MIME type for Blob with non-empty type'); | 647 }, 'MIME type for Blob with non-empty type'); |
657 | 648 |
658 promise_test(function(t) { | 649 promise_test(function(t) { |
659 var req = new Request('http://localhost/', | 650 var req = new Request('http://localhost/', |
660 {method: 'POST', body: new FormData()}); | 651 {method: 'POST', body: new FormData()}); |
661 return req.blob() | 652 return req.blob() |
662 .then(function(blob) { | 653 .then(function(blob) { |
663 assert_equals(blob.type.indexOf('multipart/form-data; boundary='), | 654 assert_equals(blob.type.indexOf('multipart/form-data; boundary='), |
664 0); | 655 0); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
712 {method: 'POST', | 703 {method: 'POST', |
713 body: new Blob([''], {type: 'Text/Plain'}), | 704 body: new Blob([''], {type: 'Text/Plain'}), |
714 headers: [['Content-Type', 'Text/Html']]}); | 705 headers: [['Content-Type', 'Text/Html']]}); |
715 return req.blob() | 706 return req.blob() |
716 .then(function(blob) { | 707 .then(function(blob) { |
717 assert_equals(blob.type, 'text/html'); | 708 assert_equals(blob.type, 'text/html'); |
718 assert_equals(req.headers.get('Content-Type'), 'Text/Html'); | 709 assert_equals(req.headers.get('Content-Type'), 'Text/Html'); |
719 }); | 710 }); |
720 }, 'Extract a MIME type (1)'); | 711 }, 'Extract a MIME type (1)'); |
721 | 712 |
722 promise_test(function(t) { | |
723 var req = new Request('http://localhost/', {method: 'POST', body: 'hello'}); | |
724 return req.text().then(function(text) { | |
725 assert_equals(text, 'hello'); | |
726 var req2 = new Request(req); | |
727 assert_true(req.bodyUsed); | |
728 assert_false(req2.bodyUsed); | |
729 return req2.text(); | |
730 }).then(function(text) { | |
731 assert_equals(text, ''); | |
732 }); | |
733 }, 'Consume and pass'); | |
734 | |
735 done(); | 713 done(); |
OLD | NEW |