Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1066)

Unified Diff: pkg/http/test/multipart_test.dart

Issue 261763002: Rip out the last dart:io dependency from pkg/http. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/http/test/io/utils.dart ('k') | pkg/http/test/request_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http/test/multipart_test.dart
diff --git a/pkg/http/test/multipart_test.dart b/pkg/http/test/multipart_test.dart
index a3f0f8e92997da44a287c691aa0840ad51213c1f..e2494d5f0d97922c32bd4108b60dcc6f7ae183c5 100644
--- a/pkg/http/test/multipart_test.dart
+++ b/pkg/http/test/multipart_test.dart
@@ -5,50 +5,13 @@
library multipart_test;
import 'dart:async';
-import 'dart:convert';
-import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:http_parser/http_parser.dart';
-import 'package:path/path.dart' as path;
import 'package:unittest/unittest.dart';
import 'utils.dart';
-/// A matcher that validates the body of a multipart request after finalization.
-/// The string "{{boundary}}" in [pattern] will be replaced by the boundary
-/// string for the request, and LF newlines will be replaced with CRLF.
-/// Indentation will be normalized.
-Matcher bodyMatches(String pattern) => new _BodyMatches(pattern);
-
-class _BodyMatches extends Matcher {
- final String _pattern;
-
- _BodyMatches(this._pattern);
-
- bool matches(item, Map matchState) {
- if (item is! http.MultipartRequest) return false;
-
- var future = item.finalize().toBytes().then((bodyBytes) {
- var body = UTF8.decode(bodyBytes);
- var contentType = new MediaType.parse(item.headers['content-type']);
- var boundary = contentType.parameters['boundary'];
- var expected = cleanUpLiteral(_pattern)
- .replaceAll("\n", "\r\n")
- .replaceAll("{{boundary}}", boundary);
-
- expect(body, equals(expected));
- expect(item.contentLength, equals(bodyBytes.length));
- });
-
- return completes.matches(future, matchState);
- }
-
- Description describe(Description description) {
- return description.add('has a body that matches "$_pattern"');
- }
-}
-
void main() {
test('empty', () {
var request = new http.MultipartRequest('POST', dummyUrl);
@@ -269,33 +232,4 @@ void main() {
--{{boundary}}--
'''));
});
-
- group('in a temp directory', () {
- var tempDir;
- setUp(() {
- tempDir = Directory.systemTemp.createTempSync('http_test_');
- });
-
- tearDown(() => tempDir.deleteSync(recursive: true));
-
- test('with a file from disk', () {
- expect(new Future.sync(() {
- var filePath = path.join(tempDir.path, 'test-file');
- new File(filePath).writeAsStringSync('hello');
- return http.MultipartFile.fromPath('file', filePath);
- }).then((file) {
- var request = new http.MultipartRequest('POST', dummyUrl);
- request.files.add(file);
-
- expect(request, bodyMatches('''
- --{{boundary}}
- content-type: application/octet-stream
- content-disposition: form-data; name="file"; filename="test-file"
-
- hello
- --{{boundary}}--
- '''));
- }), completes);
- });
- });
}
« no previous file with comments | « pkg/http/test/io/utils.dart ('k') | pkg/http/test/request_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698