| 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 promise_test(function() { | 5 promise_test(function() { |
| 6 var response = new Response; | 6 var response = new Response; |
| 7 return response.text() | 7 return response.text() |
| 8 .then(function(text) { | 8 .then(function(text) { |
| 9 assert_equals(text, '', | 9 assert_equals(text, '', |
| 10 'response.text() must return an empty string' + | 10 'response.text() must return an empty string' + |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 return response.arrayBuffer() | 71 return response.arrayBuffer() |
| 72 .then(function(buffer) { | 72 .then(function(buffer) { |
| 73 var resultIntView = new Int32Array(buffer); | 73 var resultIntView = new Int32Array(buffer); |
| 74 assert_array_equals( | 74 assert_array_equals( |
| 75 resultIntView, [1, 2, 3], | 75 resultIntView, [1, 2, 3], |
| 76 'Response body ArrayBuffer should match ArrayBufferView ' + | 76 'Response body ArrayBuffer should match ArrayBufferView ' + |
| 77 'slice it was constructed with.'); | 77 'slice it was constructed with.'); |
| 78 }); | 78 }); |
| 79 }, 'Behavior of Response with ArrayBufferView content with a slice.'); | 79 }, 'Behavior of Response with ArrayBufferView content with a slice.'); |
| 80 | 80 |
| 81 promise_test(function() { | 81 promise_test(function(t) { |
| 82 var formData = new FormData(); | 82 var formData = new FormData(); |
| 83 formData.append('sample string', '1234567890'); | 83 formData.append('sample string', '1234567890'); |
| 84 formData.append('sample blob', new Blob(['blob content'])); | 84 formData.append('sample blob', new Blob(['blob content'])); |
| 85 formData.append('sample file', | 85 formData.append('sample file', |
| 86 new File(['file content'], 'file.dat')); | 86 new File(['file content'], 'file.dat')); |
| 87 var response = new Response(formData); | 87 var response = new Response(formData); |
| 88 return response.text() | 88 return response.text() |
| 89 .then(function(result) { | 89 .then(function(result) { |
| 90 var reg = new RegExp('multipart\/form-data; boundary=(.*)'); | 90 var reg = new RegExp('multipart\/form-data; boundary=(.*)'); |
| 91 var regResult = reg.exec(getContentType(response.headers)); | 91 var regResult = reg.exec(getContentType(response.headers)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 104 '--' + boundary + '\r\n' + | 104 '--' + boundary + '\r\n' + |
| 105 'Content-Disposition: form-data; name="sample file"; ' + | 105 'Content-Disposition: form-data; name="sample file"; ' + |
| 106 'filename="file.dat"\r\n' + | 106 'filename="file.dat"\r\n' + |
| 107 'Content-Type: application/octet-stream\r\n' + | 107 'Content-Type: application/octet-stream\r\n' + |
| 108 '\r\n' + | 108 '\r\n' + |
| 109 'file content\r\n' + | 109 'file content\r\n' + |
| 110 '--' + boundary + '--\r\n'; | 110 '--' + boundary + '--\r\n'; |
| 111 assert_equals( | 111 assert_equals( |
| 112 result, expected_body, | 112 result, expected_body, |
| 113 'Creating a Response with FormData body must succeed.'); | 113 'Creating a Response with FormData body must succeed.'); |
| 114 response = new Response( |
| 115 expected_body, {headers: [['Content-Type', regResult[0]]]}); |
| 116 return response.formData(); |
| 117 }) |
| 118 .then(function(result) { |
| 119 assert_equals(result.get('sample string'), |
| 120 formData.get('sample string')); |
| 121 assert_equals(result.get('sample blob').name, |
| 122 formData.get('sample blob').name); |
| 123 assert_equals(result.get('sample blob').size, |
| 124 formData.get('sample blob').size); |
| 125 assert_equals(result.get('sample blob').type, |
| 126 'application/octet-stream'); |
| 127 assert_equals(result.get('sample file').name, |
| 128 formData.get('sample file').name); |
| 129 assert_equals(result.get('sample file').size, |
| 130 formData.get('sample file').size); |
| 131 assert_equals(result.get('sample file').type, |
| 132 'application/octet-stream'); |
| 114 }); | 133 }); |
| 115 }, 'Behavior of Response with FormData content'); | 134 }, 'Behavior of Response with FormData content'); |
| 116 | 135 |
| 117 promise_test(function() { | 136 promise_test(function() { |
| 118 const urlSearchParams = new URLSearchParams(); | 137 const urlSearchParams = new URLSearchParams(); |
| 119 urlSearchParams.append('sample string', '1234567890'); | 138 urlSearchParams.append('sample string', '1234567890'); |
| 120 urlSearchParams.append('sample string 2', '1234567890 & 2'); | 139 urlSearchParams.append('sample string 2', '1234567890 & 2'); |
| 121 var response = new Response(urlSearchParams); | 140 var response = new Response(urlSearchParams); |
| 122 assert_equals( | 141 assert_equals( |
| 123 response.headers.get('Content-Type'), | 142 response.headers.get('Content-Type'), |
| 124 'application/x-www-form-urlencoded;charset=UTF-8', | 143 'application/x-www-form-urlencoded;charset=UTF-8', |
| 125 'A Response constructed with a URLSearchParams should have a Content-Type.
'); | 144 'A Response constructed with a URLSearchParams should have a Content-Type.
'); |
| 126 return response.text() | 145 return response.text() |
| 127 .then(function(result) { | 146 .then(function(result) { |
| 147 const expected_body = |
| 148 'sample+string=1234567890&sample+string+2=1234567890+%26+2'; |
| 128 assert_equals( | 149 assert_equals( |
| 129 result, 'sample+string=1234567890&sample+string+2=1234567890+%26+2', | 150 result, expected_body, |
| 130 'Creating a Response with URLSearchParams body must succeed.'); | 151 'Creating a Response with URLSearchParams body must succeed.'); |
| 152 response = new Response( |
| 153 expected_body, {headers: [ |
| 154 ['Content-Type', |
| 155 'application/x-www-form-urlencoded; charset=UTF-8']]}); |
| 156 return response.formData(); |
| 157 }) |
| 158 .then(function(result) { |
| 159 assert_equals(result.get('sample string'), |
| 160 urlSearchParams.get('sample string')); |
| 161 assert_equals(result.get('sample string 2'), |
| 162 urlSearchParams.get('sample string 2')); |
| 131 }); | 163 }); |
| 132 }, 'Behavior of Response with URLSearchParams content'); | 164 }, 'Behavior of Response with URLSearchParams content'); |
| 133 | 165 |
| 134 promise_test(function() { | 166 promise_test(function() { |
| 135 var headers = new Headers; | 167 var headers = new Headers; |
| 136 headers.set('Content-Language', 'ja'); | 168 headers.set('Content-Language', 'ja'); |
| 137 var response = new Response( | 169 var response = new Response( |
| 138 'test string', {method: 'GET', headers: headers}); | 170 'test string', {method: 'GET', headers: headers}); |
| 139 assert_false(response.bodyUsed); | 171 assert_false(response.bodyUsed); |
| 140 var response2 = response.clone(); | 172 var response2 = response.clone(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 'A Response constructed with no body should have no Content-Type.'); | 217 'A Response constructed with no body should have no Content-Type.'); |
| 186 return response.text() | 218 return response.text() |
| 187 .then(function(text) { | 219 .then(function(text) { |
| 188 assert_equals(text, '', | 220 assert_equals(text, '', |
| 189 'Response with no body accessed as text should ' + | 221 'Response with no body accessed as text should ' + |
| 190 'resolve to the empty string.'); | 222 'resolve to the empty string.'); |
| 191 }); | 223 }); |
| 192 }, 'Behavior of Response with no body.'); | 224 }, 'Behavior of Response with no body.'); |
| 193 | 225 |
| 194 done(); | 226 done(); |
| OLD | NEW |