OLD | NEW |
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 response_test; | 5 library response_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
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'; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 var response = new http.Response.bytes([102, 246, 248, 98, 227, 114], 200, | 45 var response = new http.Response.bytes([102, 246, 248, 98, 227, 114], 200, |
46 headers: {'content-type': 'text/plain; charset=iso-8859-1'}); | 46 headers: {'content-type': 'text/plain; charset=iso-8859-1'}); |
47 expect(response.body, equals("föøbãr")); | 47 expect(response.body, equals("föøbãr")); |
48 }); | 48 }); |
49 }); | 49 }); |
50 | 50 |
51 group('.fromStream()', () { | 51 group('.fromStream()', () { |
52 test('sets body', () { | 52 test('sets body', () { |
53 var controller = new StreamController(sync: true); | 53 var controller = new StreamController(sync: true); |
54 var streamResponse = new http.StreamedResponse( | 54 var streamResponse = new http.StreamedResponse( |
55 controller.stream, 200, 13); | 55 controller.stream, 200, contentLength: 13); |
56 var future = http.Response.fromStream(streamResponse) | 56 var future = http.Response.fromStream(streamResponse) |
57 .then((response) => response.body); | 57 .then((response) => response.body); |
58 expect(future, completion(equals("Hello, world!"))); | 58 expect(future, completion(equals("Hello, world!"))); |
59 | 59 |
60 controller.add([72, 101, 108, 108, 111, 44, 32]); | 60 controller.add([72, 101, 108, 108, 111, 44, 32]); |
61 controller.add([119, 111, 114, 108, 100, 33]); | 61 controller.add([119, 111, 114, 108, 100, 33]); |
62 controller.close(); | 62 controller.close(); |
63 }); | 63 }); |
64 | 64 |
65 test('sets bodyBytes', () { | 65 test('sets bodyBytes', () { |
66 var controller = new StreamController(sync: true); | 66 var controller = new StreamController(sync: true); |
67 var streamResponse = new http.StreamedResponse(controller.stream, 200, 5); | 67 var streamResponse = new http.StreamedResponse( |
| 68 controller.stream, 200, contentLength: 5); |
68 var future = http.Response.fromStream(streamResponse) | 69 var future = http.Response.fromStream(streamResponse) |
69 .then((response) => response.bodyBytes); | 70 .then((response) => response.bodyBytes); |
70 expect(future, completion(equals([104, 101, 108, 108, 111]))); | 71 expect(future, completion(equals([104, 101, 108, 108, 111]))); |
71 | 72 |
72 controller.add([104, 101, 108, 108, 111]); | 73 controller.add([104, 101, 108, 108, 111]); |
73 controller.close(); | 74 controller.close(); |
74 }); | 75 }); |
75 }); | 76 }); |
76 } | 77 } |
OLD | NEW |