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

Side by Side Diff: pkg/http/test/response_test.dart

Issue 23450003: Add encoding tests to pkg/http. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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') | no next file » | 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 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';
11 11
12 void main() { 12 void main() {
13 group('()', () { 13 group('()', () {
14 test('sets body', () { 14 test('sets body', () {
15 var response = new http.Response("Hello, world!", 200); 15 var response = new http.Response("Hello, world!", 200);
16 expect(response.body, equals("Hello, world!")); 16 expect(response.body, equals("Hello, world!"));
17 }); 17 });
18 18
19 test('sets bodyBytes', () { 19 test('sets bodyBytes', () {
20 var response = new http.Response("Hello, world!", 200); 20 var response = new http.Response("Hello, world!", 200);
21 expect(response.bodyBytes, equals( 21 expect(response.bodyBytes, equals(
22 [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33])); 22 [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]));
23 }); 23 });
24 24
25 // TODO(nweiz): test that this respects the inferred encoding when issue 25 test('respects the inferred encoding', () {
26 // 6284 is fixed. 26 var response = new http.Response("föøbãr", 200,
27 headers: {'content-type': 'text/plain; charset=iso-8859-1'});
28 expect(response.bodyBytes, equals(
29 [102, 246, 248, 98, 227, 114]));
30 });
27 }); 31 });
28 32
29 group('.bytes()', () { 33 group('.bytes()', () {
30 test('sets body', () { 34 test('sets body', () {
31 var response = new http.Response.bytes([104, 101, 108, 108, 111], 200); 35 var response = new http.Response.bytes([104, 101, 108, 108, 111], 200);
32 expect(response.body, equals("hello")); 36 expect(response.body, equals("hello"));
33 }); 37 });
34 38
35 test('sets bodyBytes', () { 39 test('sets bodyBytes', () {
36 var response = new http.Response.bytes([104, 101, 108, 108, 111], 200); 40 var response = new http.Response.bytes([104, 101, 108, 108, 111], 200);
37 expect(response.bodyBytes, equals([104, 101, 108, 108, 111])); 41 expect(response.bodyBytes, equals([104, 101, 108, 108, 111]));
38 }); 42 });
39 43
40 // TODO(nweiz): test that this respects the inferred encoding when issue 44 test('respects the inferred encoding', () {
41 // 6284 is fixed. 45 var response = new http.Response.bytes([102, 246, 248, 98, 227, 114], 200,
46 headers: {'content-type': 'text/plain; charset=iso-8859-1'});
47 expect(response.body, equals("föøbãr"));
48 });
42 }); 49 });
43 50
44 group('.fromStream()', () { 51 group('.fromStream()', () {
45 test('sets body', () { 52 test('sets body', () {
46 var controller = new StreamController(sync: true); 53 var controller = new StreamController(sync: true);
47 var streamResponse = new http.StreamedResponse( 54 var streamResponse = new http.StreamedResponse(
48 controller.stream, 200, 13); 55 controller.stream, 200, 13);
49 var future = http.Response.fromStream(streamResponse) 56 var future = http.Response.fromStream(streamResponse)
50 .then((response) => response.body); 57 .then((response) => response.body);
51 expect(future, completion(equals("Hello, world!"))); 58 expect(future, completion(equals("Hello, world!")));
52 59
53 controller.add([72, 101, 108, 108, 111, 44, 32]); 60 controller.add([72, 101, 108, 108, 111, 44, 32]);
54 controller.add([119, 111, 114, 108, 100, 33]); 61 controller.add([119, 111, 114, 108, 100, 33]);
55 controller.close(); 62 controller.close();
56 }); 63 });
57 64
58 test('sets bodyBytes', () { 65 test('sets bodyBytes', () {
59 var controller = new StreamController(sync: true); 66 var controller = new StreamController(sync: true);
60 var streamResponse = new http.StreamedResponse(controller.stream, 200, 5); 67 var streamResponse = new http.StreamedResponse(controller.stream, 200, 5);
61 var future = http.Response.fromStream(streamResponse) 68 var future = http.Response.fromStream(streamResponse)
62 .then((response) => response.bodyBytes); 69 .then((response) => response.bodyBytes);
63 expect(future, completion(equals([104, 101, 108, 108, 111]))); 70 expect(future, completion(equals([104, 101, 108, 108, 111])));
64 71
65 controller.add([104, 101, 108, 108, 111]); 72 controller.add([104, 101, 108, 108, 111]);
66 controller.close(); 73 controller.close();
67 }); 74 });
68 }); 75 });
69 } 76 }
OLDNEW
« no previous file with comments | « pkg/http/test/request_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698