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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 'method should not be changed when normalized: ' + | 328 'method should not be changed when normalized: ' + |
329 method); | 329 method); |
330 }); | 330 }); |
331 }, 'Request: valid method names and normalize test'); | 331 }, 'Request: valid method names and normalize test'); |
332 | 332 |
333 test(function() { | 333 test(function() { |
334 var req = new Request(URL); | 334 var req = new Request(URL); |
335 assert_false(req.bodyUsed, | 335 assert_false(req.bodyUsed, |
336 'Request should not be flagged as used if it has not been ' + | 336 'Request should not be flagged as used if it has not been ' + |
337 'consumed.'); | 337 'consumed.'); |
338 // See https://crbug.com/501195. | |
339 var req2 = new Request(req); | 338 var req2 = new Request(req); |
340 assert_true(req.bodyUsed, | 339 assert_false(req.bodyUsed, |
341 'Request should be flagged as used if it does not have' + | 340 'Request should not be flagged as used if it does not have' + |
hiroshige
2015/11/19 12:50:36
nit: ' ' at end of the string (current: 'does not
yhirano
2015/11/19 13:19:03
Done.
| |
342 'body.'); | 341 'body.'); |
343 assert_false(req2.bodyUsed, | 342 assert_false(req2.bodyUsed, |
344 'Request should not be flagged as used if it has not been ' + | 343 'Request should not be flagged as used if it has not been ' + |
345 'consumed.'); | 344 'consumed.'); |
346 }, 'Request construction without body behavior regardning "bodyUsed"'); | 345 }, 'Request construction without body behavior regardning "bodyUsed"'); |
347 | 346 |
348 test(function() { | 347 test(function() { |
349 var req = new Request(URL, {method: 'POST', body: 'hello'}); | 348 var req = new Request(URL, {method: 'POST', body: 'hello'}); |
350 assert_false(req.bodyUsed, | 349 assert_false(req.bodyUsed, |
351 'Request should not be flagged as used if it has not been ' + | 350 'Request should not be flagged as used if it has not been ' + |
352 'consumed.'); | 351 'consumed.'); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 function() { | 471 function() { |
473 new Request(URL, | 472 new Request(URL, |
474 {method: method, | 473 {method: method, |
475 body: new Blob(['Test Blob'], {type: 'test/type'}) | 474 body: new Blob(['Test Blob'], {type: 'test/type'}) |
476 }); | 475 }); |
477 }, | 476 }, |
478 'Request of GET/HEAD method cannot have RequestInit body.'); | 477 'Request of GET/HEAD method cannot have RequestInit body.'); |
479 }); | 478 }); |
480 }, 'Request of GET/HEAD method cannot have RequestInit body.'); | 479 }, 'Request of GET/HEAD method cannot have RequestInit body.'); |
481 | 480 |
481 test(() => { | |
482 var req = new Request(URL, {method: 'POST', body: 'hello'}); | |
483 req.text(); | |
484 assert_true(req.bodyUsed); | |
485 assert_throws({name: 'TypeError'}, () => { req.clone(); }); | |
486 }, 'Used => clone'); | |
487 | |
482 promise_test(function() { | 488 promise_test(function() { |
483 var headers = new Headers; | 489 var headers = new Headers; |
484 headers.set('Content-Language', 'ja'); | 490 headers.set('Content-Language', 'ja'); |
485 var req = new Request(URL, { | 491 var req = new Request(URL, { |
486 method: 'POST', | 492 method: 'POST', |
487 headers: headers, | 493 headers: headers, |
488 body: new Blob(['Test Blob'], {type: 'test/type'}) | 494 body: new Blob(['Test Blob'], {type: 'test/type'}) |
489 }); | 495 }); |
490 var req2 = req.clone(); | 496 var req2 = req.clone(); |
497 assert_false(req.bodyUsed); | |
498 assert_false(req2.bodyUsed); | |
491 // Change headers and of original request. | 499 // Change headers and of original request. |
492 req.headers.set('Content-Language', 'en'); | 500 req.headers.set('Content-Language', 'en'); |
493 assert_equals(req2.headers.get('Content-Language'), 'ja', | 501 assert_equals(req2.headers.get('Content-Language'), 'ja', |
494 'Headers of cloned request should not change when ' + | 502 'Headers of cloned request should not change when ' + |
495 'original request headers are changed.'); | 503 'original request headers are changed.'); |
496 | 504 |
497 return req.text().then(function(text) { | 505 return req.text().then(function(text) { |
498 assert_equals(text, 'Test Blob', 'Body of request should match.'); | 506 assert_equals(text, 'Test Blob', 'Body of request should match.'); |
499 return req2.text(); | 507 return req2.text(); |
500 }).then(function(text) { | 508 }).then(function(text) { |
501 assert_equals(text, 'Test Blob', 'Cloned request body should match.'); | 509 assert_equals(text, 'Test Blob', 'Cloned request body should match.'); |
502 return Promise.all([req.text(), req2.text()]); | |
503 }).then(function(texts) { | |
504 assert_equals(texts[0], '', 'The body is consumed.'); | |
505 assert_equals(texts[1], '', 'The body is consumed.'); | |
506 return req.clone().text(); | |
507 }).then(function(text) { | |
508 assert_equals(text, '', 'The body was consumed before cloned.'); | |
509 }); | 510 }); |
510 }, 'Test clone behavior with loading content from Request.'); | 511 }, 'Test clone behavior with loading content from Request.'); |
511 | 512 |
512 async_test(function(t) { | 513 async_test(function(t) { |
513 var request = | 514 var request = |
514 new Request(URL, | 515 new Request(URL, |
515 { | 516 { |
516 method: 'POST', | 517 method: 'POST', |
517 body: new Blob(['Test Blob'], {type: 'test/type'}) | 518 body: new Blob(['Test Blob'], {type: 'test/type'}) |
518 }); | 519 }); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 }, 'MIME type for Blob'); | 656 }, 'MIME type for Blob'); |
656 | 657 |
657 promise_test(function(t) { | 658 promise_test(function(t) { |
658 var req = new Request('http://localhost/', | 659 var req = new Request('http://localhost/', |
659 {method: 'POST', | 660 {method: 'POST', |
660 body: new Blob([''], {type: 'Text/Plain'})}); | 661 body: new Blob([''], {type: 'Text/Plain'})}); |
661 return req.blob() | 662 return req.blob() |
662 .then(function(blob) { | 663 .then(function(blob) { |
663 assert_equals(blob.type, 'text/plain'); | 664 assert_equals(blob.type, 'text/plain'); |
664 assert_equals(req.headers.get('Content-Type'), 'text/plain'); | 665 assert_equals(req.headers.get('Content-Type'), 'text/plain'); |
665 return new Request(req).blob(); | |
666 }).then(function(blob) { | |
667 assert_equals(blob.type, 'text/plain'); | |
668 }); | 666 }); |
669 }, 'MIME type for Blob with non-empty type'); | 667 }, 'MIME type for Blob with non-empty type'); |
670 | 668 |
671 promise_test(function(t) { | 669 promise_test(function(t) { |
672 var req = new Request('http://localhost/', | 670 var req = new Request('http://localhost/', |
673 {method: 'POST', body: new FormData()}); | 671 {method: 'POST', body: new FormData()}); |
674 return req.blob() | 672 return req.blob() |
675 .then(function(blob) { | 673 .then(function(blob) { |
676 assert_equals(blob.type.indexOf('multipart/form-data; boundary='), | 674 assert_equals(blob.type.indexOf('multipart/form-data; boundary='), |
677 0); | 675 0); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
725 {method: 'POST', | 723 {method: 'POST', |
726 body: new Blob([''], {type: 'Text/Plain'}), | 724 body: new Blob([''], {type: 'Text/Plain'}), |
727 headers: [['Content-Type', 'Text/Html']]}); | 725 headers: [['Content-Type', 'Text/Html']]}); |
728 return req.blob() | 726 return req.blob() |
729 .then(function(blob) { | 727 .then(function(blob) { |
730 assert_equals(blob.type, 'text/html'); | 728 assert_equals(blob.type, 'text/html'); |
731 assert_equals(req.headers.get('Content-Type'), 'Text/Html'); | 729 assert_equals(req.headers.get('Content-Type'), 'Text/Html'); |
732 }); | 730 }); |
733 }, 'Extract a MIME type (1)'); | 731 }, 'Extract a MIME type (1)'); |
734 | 732 |
735 promise_test(function(t) { | |
736 var req = new Request('http://localhost/', {method: 'POST', body: 'hello'}); | |
737 return req.text().then(function(text) { | |
738 assert_equals(text, 'hello'); | |
739 var req2 = new Request(req); | |
740 assert_true(req.bodyUsed); | |
741 assert_false(req2.bodyUsed); | |
742 return req2.text(); | |
743 }).then(function(text) { | |
744 assert_equals(text, ''); | |
745 }); | |
746 }, 'Consume and pass'); | |
747 | |
748 done(); | 733 done(); |
OLD | NEW |