| 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:io'; | 7 import 'dart:io'; |
| 8 import 'dart:utf'; | 8 import 'dart:utf'; |
| 9 | 9 |
| 10 // TODO(nweiz): get rid of this import before packaging this | 10 // TODO(nweiz): get rid of this import before packaging this |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 Matcher bodyMatches(String pattern) => new _BodyMatches(pattern); | 22 Matcher bodyMatches(String pattern) => new _BodyMatches(pattern); |
| 23 | 23 |
| 24 class _BodyMatches extends BaseMatcher { | 24 class _BodyMatches extends BaseMatcher { |
| 25 final String _pattern; | 25 final String _pattern; |
| 26 | 26 |
| 27 _BodyMatches(this._pattern); | 27 _BodyMatches(this._pattern); |
| 28 | 28 |
| 29 bool matches(item, MatchState matchState) { | 29 bool matches(item, MatchState matchState) { |
| 30 if (item is! http.MultipartRequest) return false; | 30 if (item is! http.MultipartRequest) return false; |
| 31 | 31 |
| 32 var future = consumeInputStream(item.finalize()).transform((bodyBytes) { | 32 var future = consumeInputStream(item.finalize()).then((bodyBytes) { |
| 33 var body = decodeUtf8(bodyBytes); | 33 var body = decodeUtf8(bodyBytes); |
| 34 var contentType = new ContentType.fromString( | 34 var contentType = new ContentType.fromString( |
| 35 item.headers['content-type']); | 35 item.headers['content-type']); |
| 36 var boundary = contentType.parameters['boundary']; | 36 var boundary = contentType.parameters['boundary']; |
| 37 var expected = cleanUpLiteral(_pattern) | 37 var expected = cleanUpLiteral(_pattern) |
| 38 .replaceAll("\n", "\r\n") | 38 .replaceAll("\n", "\r\n") |
| 39 .replaceAll("{{boundary}}", boundary); | 39 .replaceAll("{{boundary}}", boundary); |
| 40 | 40 |
| 41 expect(body, equals(expected)); | 41 expect(body, equals(expected)); |
| 42 expect(item.contentLength, equals(bodyBytes.length)); | 42 expect(item.contentLength, equals(bodyBytes.length)); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 expect(request, bodyMatches(''' | 196 expect(request, bodyMatches(''' |
| 197 --{{boundary}} | 197 --{{boundary}} |
| 198 content-type: application/octet-stream | 198 content-type: application/octet-stream |
| 199 content-disposition: form-data; name="file" | 199 content-disposition: form-data; name="file" |
| 200 | 200 |
| 201 hello | 201 hello |
| 202 --{{boundary}}-- | 202 --{{boundary}}-- |
| 203 ''')); | 203 ''')); |
| 204 }); | 204 }); |
| 205 } | 205 } |
| OLD | NEW |