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

Side by Side Diff: pkg/http/test/io/streamed_request_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, 7 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/io/request_test.dart ('k') | pkg/http/test/io/utils.dart » ('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) 2014, 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 http.test.io.streamed_request_test;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 8
9 import 'package:http/http.dart' as http; 9 import 'package:http/http.dart' as http;
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
11 11
12 import 'utils.dart'; 12 import 'utils.dart';
13 13
14 void main() { 14 void main() {
15 group('contentLength', () { 15 group('contentLength', () {
16 test('defaults to null', () {
17 var request = new http.StreamedRequest('POST', dummyUrl);
18 expect(request.contentLength, isNull);
19 });
20
21 test('disallows negative values', () {
22 var request = new http.StreamedRequest('POST', dummyUrl);
23 expect(() => request.contentLength = -1, throwsArgumentError);
24 });
25
26 test('controls the Content-Length header', () { 16 test('controls the Content-Length header', () {
27 return startServer().then((_) { 17 return startServer().then((_) {
28 var request = new http.StreamedRequest('POST', serverUrl); 18 var request = new http.StreamedRequest('POST', serverUrl);
29 request.contentLength = 10; 19 request.contentLength = 10;
30 request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); 20 request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
31 request.sink.close(); 21 request.sink.close();
32 22
33 return request.send(); 23 return request.send();
34 }).then((response) { 24 }).then((response) {
35 expect(UTF8.decodeStream(response.stream), 25 expect(UTF8.decodeStream(response.stream),
36 completion(parse(containsPair('headers', 26 completion(parse(containsPair('headers',
37 containsPair('content-length', ['10']))))); 27 containsPair('content-length', ['10'])))));
38 }).whenComplete(stopServer); 28 }).whenComplete(stopServer);
39 }); 29 });
40 30
41 test('defaults to sending no Content-Length', () { 31 test('defaults to sending no Content-Length', () {
42 return startServer().then((_) { 32 return startServer().then((_) {
43 var request = new http.StreamedRequest('POST', serverUrl); 33 var request = new http.StreamedRequest('POST', serverUrl);
44 request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); 34 request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
45 request.sink.close(); 35 request.sink.close();
46 36
47 return request.send(); 37 return request.send();
48 }).then((response) { 38 }).then((response) {
49 expect(UTF8.decodeStream(response.stream), 39 expect(UTF8.decodeStream(response.stream),
50 completion(parse(containsPair('headers', 40 completion(parse(containsPair('headers',
51 isNot(contains('content-length')))))); 41 isNot(contains('content-length'))))));
52 }).whenComplete(stopServer); 42 }).whenComplete(stopServer);
53 }); 43 });
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 });
60 }); 44 });
61 45
62 // Regression test. 46 // Regression test.
63 test('.send() with a response with no content length', () { 47 test('.send() with a response with no content length', () {
64 return startServer().then((_) { 48 return startServer().then((_) {
65 var request = new http.StreamedRequest( 49 var request = new http.StreamedRequest(
66 'GET', serverUrl.resolve('/no-content-length')); 50 'GET', serverUrl.resolve('/no-content-length'));
67 request.sink.close(); 51 request.sink.close();
68 return request.send(); 52 return request.send();
69 }).then((response) { 53 }).then((response) {
70 expect(UTF8.decodeStream(response.stream), completion(equals('body'))); 54 expect(UTF8.decodeStream(response.stream), completion(equals('body')));
71 }).whenComplete(stopServer); 55 }).whenComplete(stopServer);
72 }); 56 });
73 57
74 } 58 }
OLDNEW
« no previous file with comments | « pkg/http/test/io/request_test.dart ('k') | pkg/http/test/io/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698