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

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

Issue 196423017: Make BaseRequest.contentType use null rather than -1 as a flag value. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 9 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/response_test.dart ('k') | pkg/oauth2/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http/test/streamed_request_test.dart
diff --git a/pkg/http/test/streamed_request_test.dart b/pkg/http/test/streamed_request_test.dart
index 56c92527c33a4e2599b3e4d766fcb092c6bd8e38..761102c8aa464ed18517cfd7fb1499425b574bb0 100644
--- a/pkg/http/test/streamed_request_test.dart
+++ b/pkg/http/test/streamed_request_test.dart
@@ -4,17 +4,58 @@
library streamed_request_test;
+import 'dart:convert';
+
import 'package:http/http.dart' as http;
import 'package:unittest/unittest.dart';
import 'utils.dart';
void main() {
- test('#finalize freezes contentLength', () {
- var request = new http.StreamedRequest('POST', dummyUrl);
- request.finalize();
+ group('contentLength', () {
+ test('defaults to null', () {
+ var request = new http.StreamedRequest('POST', dummyUrl);
+ expect(request.contentLength, isNull);
+ });
+
+ test('disallows negative values', () {
+ var request = new http.StreamedRequest('POST', dummyUrl);
+ expect(() => request.contentLength = -1, throwsArgumentError);
+ });
+
+ test('controls the Content-Length header', () {
+ return startServer().then((_) {
+ var request = new http.StreamedRequest('POST', serverUrl);
+ request.contentLength = 10;
+ request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
+ request.sink.close();
+
+ return request.send();
+ }).then((response) {
+ expect(UTF8.decodeStream(response.stream),
+ completion(parse(containsPair('headers',
+ containsPair('content-length', ['10'])))));
+ }).whenComplete(stopServer);
+ });
+
+ test('defaults to sending no Content-Length', () {
+ return startServer().then((_) {
+ var request = new http.StreamedRequest('POST', serverUrl);
+ request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
+ request.sink.close();
+
+ return request.send();
+ }).then((response) {
+ expect(UTF8.decodeStream(response.stream),
+ completion(parse(containsPair('headers',
+ isNot(contains('content-length'))))));
+ }).whenComplete(stopServer);
+ });
- expect(request.contentLength, equals(-1));
- expect(() => request.contentLength = 10, throwsStateError);
+ test('is frozen by finalize()', () {
+ var request = new http.StreamedRequest('POST', dummyUrl);
+ request.finalize();
+ expect(() => request.contentLength = 10, throwsStateError);
+ });
});
}
« no previous file with comments | « pkg/http/test/response_test.dart ('k') | pkg/oauth2/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698