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

Side by Side Diff: pkg/http/test/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/request_test.dart ('k') | pkg/http/test/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) 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'; 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', () { 16 test('defaults to null', () {
17 var request = new http.StreamedRequest('POST', dummyUrl); 17 var request = new http.StreamedRequest('POST', dummyUrl);
18 expect(request.contentLength, isNull); 18 expect(request.contentLength, isNull);
19 }); 19 });
20 20
21 test('disallows negative values', () { 21 test('disallows negative values', () {
22 var request = new http.StreamedRequest('POST', dummyUrl); 22 var request = new http.StreamedRequest('POST', dummyUrl);
23 expect(() => request.contentLength = -1, throwsArgumentError); 23 expect(() => request.contentLength = -1, throwsArgumentError);
24 }); 24 });
25 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()', () { 26 test('is frozen by finalize()', () {
56 var request = new http.StreamedRequest('POST', dummyUrl); 27 var request = new http.StreamedRequest('POST', dummyUrl);
57 request.finalize(); 28 request.finalize();
58 expect(() => request.contentLength = 10, throwsStateError); 29 expect(() => request.contentLength = 10, throwsStateError);
59 }); 30 });
60 }); 31 });
61
62 // Regression test.
63 test('.send() with a response with no content length', () {
64 return startServer().then((_) {
65 var request = new http.StreamedRequest(
66 'GET', serverUrl.resolve('/no-content-length'));
67 request.sink.close();
68 return request.send();
69 }).then((response) {
70 expect(UTF8.decodeStream(response.stream), completion(equals('body')));
71 }).whenComplete(stopServer);
72 });
73
74 } 32 }
OLDNEW
« no previous file with comments | « pkg/http/test/request_test.dart ('k') | pkg/http/test/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698