OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library multipart_test; | 5 library multipart_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 import 'dart:utf'; | 9 import 'dart:utf'; |
10 | 10 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 }); | 149 }); |
150 | 150 |
151 // TODO(nweiz): test creating a multipart file with a charset other than UTF-8 | 151 // TODO(nweiz): test creating a multipart file with a charset other than UTF-8 |
152 // once issue 6284 is fixed. | 152 // once issue 6284 is fixed. |
153 | 153 |
154 // TODO(nweiz): test creating a string with a unicode body once issue 6284 is | 154 // TODO(nweiz): test creating a string with a unicode body once issue 6284 is |
155 // fixed. | 155 // fixed. |
156 | 156 |
157 test('with a stream file', () { | 157 test('with a stream file', () { |
158 var request = new http.MultipartRequest('POST', dummyUrl); | 158 var request = new http.MultipartRequest('POST', dummyUrl); |
159 var stream = new StreamController(); | 159 var controller = new StreamController(); |
160 request.files.add(new http.MultipartFile('file', stream, 5)); | 160 request.files.add(new http.MultipartFile('file', controller.stream, 5)); |
161 | 161 |
162 expect(request, bodyMatches(''' | 162 expect(request, bodyMatches(''' |
163 --{{boundary}} | 163 --{{boundary}} |
164 content-type: application/octet-stream | 164 content-type: application/octet-stream |
165 content-disposition: form-data; name="file" | 165 content-disposition: form-data; name="file" |
166 | 166 |
167 hello | 167 hello |
168 --{{boundary}}-- | 168 --{{boundary}}-- |
169 ''')); | 169 ''')); |
170 | 170 |
171 stream.add([104, 101, 108, 108, 111]); | 171 controller.add([104, 101, 108, 108, 111]); |
172 stream.close(); | 172 controller.close(); |
173 }); | 173 }); |
174 | 174 |
175 test('with an empty stream file', () { | 175 test('with an empty stream file', () { |
176 var request = new http.MultipartRequest('POST', dummyUrl); | 176 var request = new http.MultipartRequest('POST', dummyUrl); |
177 var stream = new StreamController(); | 177 var controller = new StreamController(); |
178 request.files.add(new http.MultipartFile('file', stream, 0)); | 178 request.files.add(new http.MultipartFile('file', controller.stream, 0)); |
179 | 179 |
180 expect(request, bodyMatches(''' | 180 expect(request, bodyMatches(''' |
181 --{{boundary}} | 181 --{{boundary}} |
182 content-type: application/octet-stream | 182 content-type: application/octet-stream |
183 content-disposition: form-data; name="file" | 183 content-disposition: form-data; name="file" |
184 | 184 |
185 | 185 |
186 --{{boundary}}-- | 186 --{{boundary}}-- |
187 ''')); | 187 ''')); |
188 | 188 |
189 stream.close(); | 189 controller.close(); |
190 }); | 190 }); |
191 | 191 |
192 test('with a byte file', () { | 192 test('with a byte file', () { |
193 var request = new http.MultipartRequest('POST', dummyUrl); | 193 var request = new http.MultipartRequest('POST', dummyUrl); |
194 var file = new http.MultipartFile.fromBytes( | 194 var file = new http.MultipartFile.fromBytes( |
195 'file', [104, 101, 108, 108, 111]); | 195 'file', [104, 101, 108, 108, 111]); |
196 request.files.add(file); | 196 request.files.add(file); |
197 | 197 |
198 expect(request, bodyMatches(''' | 198 expect(request, bodyMatches(''' |
199 --{{boundary}} | 199 --{{boundary}} |
200 content-type: application/octet-stream | 200 content-type: application/octet-stream |
201 content-disposition: form-data; name="file" | 201 content-disposition: form-data; name="file" |
202 | 202 |
203 hello | 203 hello |
204 --{{boundary}}-- | 204 --{{boundary}}-- |
205 ''')); | 205 ''')); |
206 }); | 206 }); |
207 } | 207 } |
OLD | NEW |