Chromium Code Reviews| Index: pkg/mime/test/mime_multipart_transformer_test.dart |
| diff --git a/tests/standalone/io/mime_multipart_parser_test.dart b/pkg/mime/test/mime_multipart_transformer_test.dart |
| similarity index 88% |
| rename from tests/standalone/io/mime_multipart_parser_test.dart |
| rename to pkg/mime/test/mime_multipart_transformer_test.dart |
| index 49e5b6a7459e8b86b82e00bcca4b251fae202875..efd14d491a51f98f75ed0f3d3964a2342b8c9658 100644 |
| --- a/tests/standalone/io/mime_multipart_parser_test.dart |
| +++ b/pkg/mime/test/mime_multipart_transformer_test.dart |
| @@ -2,44 +2,48 @@ |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| -import "package:expect/expect.dart"; |
| +import "package:unittest/unittest.dart"; |
| +import "package:mime/mime.dart"; |
| import 'dart:async'; |
| import 'dart:math'; |
| -import 'dart:io'; |
| import 'dart:isolate'; |
| void testParse(String message, |
| String boundary, |
| [List<Map> expectedHeaders, |
| - List expectedParts, |
| - bool expectError = false]) { |
| - void testWrite(List<int> data, [int chunkSize = -1]) { |
| + List expectedParts, |
| + bool expectError = false]) { |
| + Future testWrite(List<int> data, [int chunkSize = -1]) { |
| StreamController controller = new StreamController(sync: true); |
| var stream = controller.stream.transform( |
| new MimeMultipartTransformer(boundary)); |
| int i = 0; |
| - var port = new ReceivePort(); |
| + var completer = new Completer(); |
| + var futures = []; |
| stream.listen((multipart) { |
| int part = i++; |
| if (expectedHeaders != null) { |
| - Expect.mapEquals(expectedHeaders[part], multipart.headers); |
| + expect(multipart.headers, equals(expectedHeaders[part])); |
| } |
| - var partPort = new ReceivePort(); |
| + var partCompleter = new Completer(); |
| + futures.add(partCompleter.future); |
|
Bill Hesse
2013/07/03 11:30:27
Why not
futures.add(multipart.fold( ... ).then((da
Anders Johnsen
2013/07/12 10:45:57
Done.
|
| multipart.fold([], (buffer, data) => buffer..addAll(data)) |
| .then((data) { |
| if (expectedParts[part] != null) { |
| - Expect.listEquals(expectedParts[part].codeUnits, data); |
| + expect(data, equals(expectedParts[part].codeUnits)); |
| } |
| - partPort.close(); |
| + partCompleter.complete(true); |
| }); |
| }, onError: (error) { |
| if (!expectError) throw error; |
| }, onDone: () { |
| if (expectedParts != null) { |
| - Expect.equals(expectedParts.length, i); |
| + expect(i, equals(expectedParts.length)); |
| } |
| - port.close(); |
| + Future.wait(futures) |
| + .then((values) => !values.any((b) => !b)) |
|
Bill Hesse
2013/07/03 11:30:27
Is this stray code? All the values are true by co
Anders Johnsen
2013/07/12 10:45:57
Done.
|
| + .then(completer.complete); |
| }); |
| if (chunkSize == -1) chunkSize = data.length; |
| @@ -52,15 +56,20 @@ void testParse(String message, |
| written += writeLength; |
| } |
| controller.close(); |
| + |
| + return completer.future; |
| } |
| // Test parsing the data three times delivering the data in |
| // different chunks. |
| List<int> data = message.codeUnits; |
| - testWrite(data); |
| - testWrite(data, 10); |
| - testWrite(data, 2); |
| - testWrite(data, 1); |
| + expect(Future.wait([ |
| + testWrite(data), |
| + testWrite(data, 10), |
| + testWrite(data, 2), |
| + testWrite(data, 1)]) |
| + .then((values) => !values.any((b) => !b)), |
|
Bill Hesse
2013/07/03 11:30:27
All the values are true anyway.
completion(anythi
Anders Johnsen
2013/07/12 10:45:57
Done.
|
| + completion(equals(true))); |
| } |
| void testParseValid() { |
| @@ -75,7 +84,6 @@ void testParseValid() { |
| String body3; |
| String body4; |
| - // Sample from Wikipedia. |
| message = """ |
| This is a message with multiple parts in MIME format.\r |
| --frontier\r |
| @@ -91,14 +99,13 @@ Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg=\r |
| --frontier--\r\n"""; |
| headers1 = <String, String>{"content-type": "text/plain"}; |
| headers2 = <String, String>{"content-type": "application/octet-stream", |
| - "content-transfer-encoding": "base64"}; |
| + "content-transfer-encoding": "base64"}; |
|
Bill Hesse
2013/07/03 11:30:27
Indentation
Anders Johnsen
2013/07/12 10:45:57
Done.
|
| body1 = "This is the body of the message."; |
| body2 = """ |
| PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg |
| Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg="""; |
| testParse(message, "frontier", [headers1, headers2], [body1, body2]); |
| - // Sample from HTML 4.01 Specification. |
| message = """ |
| \r\n--AaB03x\r |
| Content-Disposition: form-data; name=\"submit-name\"\r |