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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/http/test/response_test.dart ('k') | pkg/oauth2/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 streamed_request_test; 5 library streamed_request_test;
6 6
7 import 'dart:convert';
8
7 import 'package:http/http.dart' as http; 9 import 'package:http/http.dart' as http;
8 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
9 11
10 import 'utils.dart'; 12 import 'utils.dart';
11 13
12 void main() { 14 void main() {
13 test('#finalize freezes contentLength', () { 15 group('contentLength', () {
14 var request = new http.StreamedRequest('POST', dummyUrl); 16 test('defaults to null', () {
15 request.finalize(); 17 var request = new http.StreamedRequest('POST', dummyUrl);
18 expect(request.contentLength, isNull);
19 });
16 20
17 expect(request.contentLength, equals(-1)); 21 test('disallows negative values', () {
18 expect(() => request.contentLength = 10, throwsStateError); 22 var request = new http.StreamedRequest('POST', dummyUrl);
23 expect(() => request.contentLength = -1, throwsArgumentError);
24 });
25
26 test('controls the Content-Length header', () {
27 return startServer().then((_) {
28 var request = new http.StreamedRequest('POST', serverUrl);
29 request.contentLength = 10;
30 request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
31 request.sink.close();
32
33 return request.send();
34 }).then((response) {
35 expect(UTF8.decodeStream(response.stream),
36 completion(parse(containsPair('headers',
37 containsPair('content-length', ['10'])))));
38 }).whenComplete(stopServer);
39 });
40
41 test('defaults to sending no Content-Length', () {
42 return startServer().then((_) {
43 var request = new http.StreamedRequest('POST', serverUrl);
44 request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
45 request.sink.close();
46
47 return request.send();
48 }).then((response) {
49 expect(UTF8.decodeStream(response.stream),
50 completion(parse(containsPair('headers',
51 isNot(contains('content-length'))))));
52 }).whenComplete(stopServer);
53 });
54
55 test('is frozen by finalize()', () {
56 var request = new http.StreamedRequest('POST', dummyUrl);
57 request.finalize();
58 expect(() => request.contentLength = 10, throwsStateError);
59 });
19 }); 60 });
20 } 61 }
OLDNEW
« 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