| 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 promise_test(function() { | 4 promise_test(function() { |
| 5 var response = new Response('test string'); | 5 var response = new Response('test string'); |
| 6 assert_equals( | 6 assert_equals( |
| 7 response.headers.get('Content-Type'), | 7 response.headers.get('Content-Type'), |
| 8 'text/plain;charset=UTF-8', | 8 'text/plain;charset=UTF-8', |
| 9 'A Response constructed with a string should have a Content-Type.'); | 9 'A Response constructed with a string should have a Content-Type.'); |
| 10 return response.text() | 10 return response.text() |
| 11 .then(function(text) { | 11 .then(function(text) { |
| 12 assert_equals(text, 'test string', | 12 assert_equals(text, 'test string', |
| 13 'Response body text should match the string on construction.'); | 13 'Response body text should match the string on ' + |
| 14 'construction.'); |
| 14 }); | 15 }); |
| 15 }, 'Behavior of Response with string content.'); | 16 }, 'Behavior of Response with string content.'); |
| 16 | 17 |
| 17 promise_test(function() { | 18 promise_test(function() { |
| 18 var intView = new Int32Array([0, 1, 2, 3, 4, 55, 6, 7, 8, 9]); | 19 var intView = new Int32Array([0, 1, 2, 3, 4, 55, 6, 7, 8, 9]); |
| 19 var buffer = intView.buffer; | 20 var buffer = intView.buffer; |
| 20 | 21 |
| 21 var response = new Response(buffer); | 22 var response = new Response(buffer); |
| 22 assert_false(response.headers.has('Content-Type'), | 23 assert_false(response.headers.has('Content-Type'), |
| 23 'A Response constructed with ArrayBuffer should not have a content type.')
; | 24 'A Response constructed with ArrayBuffer should not have a ' + |
| 25 'content type.'); |
| 24 return response.arrayBuffer() | 26 return response.arrayBuffer() |
| 25 .then(function(buffer) { | 27 .then(function(buffer) { |
| 26 var resultIntView = new Int32Array(buffer); | 28 var resultIntView = new Int32Array(buffer); |
| 27 assert_array_equals( | 29 assert_array_equals( |
| 28 resultIntView, [0, 1, 2, 3, 4, 55, 6, 7, 8, 9], | 30 resultIntView, [0, 1, 2, 3, 4, 55, 6, 7, 8, 9], |
| 29 'Response body ArrayBuffer should match ArrayBuffer ' + | 31 'Response body ArrayBuffer should match ArrayBuffer ' + |
| 30 'it was constructed with.'); | 32 'it was constructed with.'); |
| 31 }); | 33 }); |
| 32 }, 'Behavior of Response with ArrayBuffer content.'); | 34 }, 'Behavior of Response with ArrayBuffer content.'); |
| 33 | 35 |
| 34 promise_test(function() { | 36 promise_test(function() { |
| 35 var intView = new Int32Array([0, 1, 2, 3, 4, 55, 6, 7, 8, 9]); | 37 var intView = new Int32Array([0, 1, 2, 3, 4, 55, 6, 7, 8, 9]); |
| 36 | 38 |
| 37 var response = new Response(intView); | 39 var response = new Response(intView); |
| 38 assert_false(response.headers.has('Content-Type'), | 40 assert_false(response.headers.has('Content-Type'), |
| 39 'A Response constructed with ArrayBufferView ' + | 41 'A Response constructed with ArrayBufferView ' + |
| 40 'should not have a content type.'); | 42 'should not have a content type.'); |
| 41 return response.arrayBuffer() | 43 return response.arrayBuffer() |
| 42 .then(function(buffer) { | 44 .then(function(buffer) { |
| 43 var resultIntView = new Int32Array(buffer); | 45 var resultIntView = new Int32Array(buffer); |
| 44 assert_array_equals( | 46 assert_array_equals( |
| 45 resultIntView, [0, 1, 2, 3, 4, 55, 6, 7, 8, 9], | 47 resultIntView, [0, 1, 2, 3, 4, 55, 6, 7, 8, 9], |
| 46 'Response body ArrayBuffer should match ArrayBufferView ' + | 48 'Response body ArrayBuffer should match ArrayBufferView ' + |
| 47 'it was constructed with.'); | 49 'it was constructed with.'); |
| 48 }); | 50 }); |
| 49 }, 'Behavior of Response with ArrayBufferView content without a slice.'); | 51 }, 'Behavior of Response with ArrayBufferView content without a slice.'); |
| 50 | 52 |
| 51 promise_test(function() { | 53 promise_test(function() { |
| 52 var intView = new Int32Array([0, 1, 2, 3, 4, 55, 6, 7, 8, 9]); | 54 var intView = new Int32Array([0, 1, 2, 3, 4, 55, 6, 7, 8, 9]); |
| 53 var slice = intView.subarray(1, 4); // Should be [1, 2, 3] | 55 var slice = intView.subarray(1, 4); // Should be [1, 2, 3] |
| 54 var response = new Response(slice); | 56 var response = new Response(slice); |
| 55 assert_false(response.headers.has('Content-Type'), | 57 assert_false(response.headers.has('Content-Type'), |
| 56 'A Response constructed with ArrayBufferView ' + | 58 'A Response constructed with ArrayBufferView ' + |
| 57 'should not have a content type.'); | 59 'should not have a content type.'); |
| 58 return response.arrayBuffer() | 60 return response.arrayBuffer() |
| 59 .then(function(buffer) { | 61 .then(function(buffer) { |
| 60 var resultIntView = new Int32Array(buffer); | 62 var resultIntView = new Int32Array(buffer); |
| 61 assert_array_equals( | 63 assert_array_equals( |
| 62 resultIntView, [1, 2, 3], | 64 resultIntView, [1, 2, 3], |
| 63 'Response body ArrayBuffer should match ArrayBufferView ' + | 65 'Response body ArrayBuffer should match ArrayBufferView ' + |
| 64 'slice it was constructed with.'); | 66 'slice it was constructed with.'); |
| 65 }); | 67 }); |
| 66 }, 'Behavior of Response with ArrayBufferView content with a slice.'); | 68 }, 'Behavior of Response with ArrayBufferView content with a slice.'); |
| 67 | 69 |
| 68 promise_test(function() { | 70 promise_test(function() { |
| 69 var headers = new Headers; | 71 var headers = new Headers; |
| 70 headers.set('Content-Language', 'ja'); | 72 headers.set('Content-Language', 'ja'); |
| 71 var response = new Response( | 73 var response = new Response( |
| 72 'test string', {method: 'GET', headers: headers}); | 74 'test string', {method: 'GET', headers: headers}); |
| 73 assert_false(response.bodyUsed, | 75 assert_false(response.bodyUsed, |
| 74 "bodyUsed is not set until Response is consumed."); | 76 'bodyUsed is not set until Response is consumed.'); |
| 75 var response2 = response.clone(); | 77 var response2 = response.clone(); |
| 76 response.headers.set('Content-Language', 'en'); | 78 response.headers.set('Content-Language', 'en'); |
| 77 var response3; | 79 var response3; |
| 78 assert_false(response2.bodyUsed, | 80 assert_false(response2.bodyUsed, |
| 79 "bodyUsed should be false in clone of non-consumed Response."); | 81 'bodyUsed should be false in clone of non-consumed Response.'); |
| 80 assert_equals( | 82 assert_equals( |
| 81 response2.headers.get('Content-Language'), 'ja', 'Headers of cloned ' + | 83 response2.headers.get('Content-Language'), 'ja', 'Headers of cloned ' + |
| 82 'response should not change when original response headers are changed.'); | 84 'response should not change when original response headers are changed.'); |
| 83 | 85 |
| 84 return response.text() | 86 return response.text() |
| 85 .then(function(text) { | 87 .then(function(text) { |
| 86 assert_true( | 88 assert_true( |
| 87 response.bodyUsed, | 89 response.bodyUsed, |
| 88 "bodyUsed should be true after a response is consumed."); | 90 'bodyUsed should be true after a response is consumed.'); |
| 89 assert_false( | 91 assert_false( |
| 90 response2.bodyUsed, "bodyUsed should be false in Response cloned " + | 92 response2.bodyUsed, 'bodyUsed should be false in Response cloned ' + |
| 91 "before the original response was consumed."); | 93 'before the original response was consumed.'); |
| 92 response3 = response.clone(); | 94 response3 = response.clone(); |
| 93 assert_true(response3.bodyUsed, | 95 assert_true(response3.bodyUsed, |
| 94 "bodyUsed should be true in clone of consumed response."); | 96 'bodyUsed should be true in clone of consumed response.'); |
| 95 return response2.text(); | 97 return response2.text(); |
| 96 }) | 98 }) |
| 97 .then(function(text) { | 99 .then(function(text) { |
| 98 assert_equals(text, 'test string', | 100 assert_equals(text, 'test string', |
| 99 'Response clone response body text should match.'); | 101 'Response clone response body text should match.'); |
| 100 }); | 102 }); |
| 101 }, 'Behavior of bodyUsed in Response and clone behavior.'); | 103 }, 'Behavior of bodyUsed in Response and clone behavior.'); |
| OLD | NEW |