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

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

Issue 11338054: Add an HTTP library that wraps dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library http_test;
6
7 import 'dart:io';
8
9 import '../../unittest/unittest.dart';
10 import '../lib/http.dart' as http;
11 import 'utils.dart';
12
13 main() {
14 group('http.', () {
Bob Nystrom 2012/10/31 01:17:44 These tests are great, but how about some failure
nweiz 2012/10/31 18:20:59 I've added some tests for the HttpException that w
15 setUp(startServer);
16 tearDown(stopServer);
17
18 test('head', () {
19 expect(http.head(serverUrl).transform((response) {
20 expect(response.statusCode, equals(200));
21 expect(response.body, equals(''));
22 }), completes);
23 });
24
25 test('get', () {
26 expect(http.get(serverUrl, headers: {
27 'X-Random-Header': 'Value',
28 'X-Other-Header': 'Other Value'
29 }).transform((response) {
30 expect(response.statusCode, equals(200));
31 expect(response.body, parse(equals({
32 'method': 'GET',
33 'path': '/',
34 'headers': {
35 'x-random-header': ['Value'],
36 'x-other-header': ['Other Value']
37 },
38 })));
39 }), completes);
40 });
41
42 test('post', () {
43 expect(http.post(serverUrl, headers: {
44 'X-Random-Header': 'Value',
45 'X-Other-Header': 'Other Value'
46 }, fields: {
47 'some-field': 'value',
48 'other-field': 'other value'
49 }).transform((response) {
50 expect(response.statusCode, equals(200));
51 expect(response.body, parse(equals({
52 'method': 'POST',
53 'path': '/',
54 'headers': {
55 'content-type': ['application/x-www-form-urlencoded; charset=UTF-8'] ,
Bob Nystrom 2012/10/31 01:17:44 Long line.
nweiz 2012/10/31 18:20:59 Done.
56 'content-length': ['42'],
57 'x-random-header': ['Value'],
58 'x-other-header': ['Other Value']
59 },
60 'body': 'some-field=value&other-field=other%20value'
61 })));
62 }), completes);
63 });
64
65 test('post without fields', () {
66 expect(http.post(serverUrl, headers: {
67 'X-Random-Header': 'Value',
68 'X-Other-Header': 'Other Value',
69 'Content-Type': 'text/plain'
70 }).transform((response) {
71 expect(response.statusCode, equals(200));
72 expect(response.body, parse(equals({
73 'method': 'POST',
74 'path': '/',
75 'headers': {
76 'content-type': ['text/plain'],
77 'x-random-header': ['Value'],
78 'x-other-header': ['Other Value']
79 }
80 })));
81 }), completes);
82 });
83
84 test('put', () {
85 expect(http.put(serverUrl, headers: {
86 'X-Random-Header': 'Value',
87 'X-Other-Header': 'Other Value'
88 }, fields: {
89 'some-field': 'value',
90 'other-field': 'other value'
91 }).transform((response) {
92 expect(response.statusCode, equals(200));
93 expect(response.body, parse(equals({
94 'method': 'PUT',
95 'path': '/',
96 'headers': {
97 'content-type': ['application/x-www-form-urlencoded; charset=UTF-8'] ,
98 'content-length': ['42'],
99 'x-random-header': ['Value'],
100 'x-other-header': ['Other Value']
101 },
102 'body': 'some-field=value&other-field=other%20value'
103 })));
104 }), completes);
105 });
106
107 test('put without fields', () {
108 expect(http.put(serverUrl, headers: {
109 'X-Random-Header': 'Value',
110 'X-Other-Header': 'Other Value',
111 'Content-Type': 'text/plain'
112 }).transform((response) {
113 expect(response.statusCode, equals(200));
114 expect(response.body, parse(equals({
115 'method': 'PUT',
116 'path': '/',
117 'headers': {
118 'content-type': ['text/plain'],
119 'x-random-header': ['Value'],
120 'x-other-header': ['Other Value']
121 }
122 })));
123 }), completes);
124 });
125
126 test('delete', () {
127 expect(http.delete(serverUrl, headers: {
128 'X-Random-Header': 'Value',
129 'X-Other-Header': 'Other Value'
130 }).transform((response) {
131 expect(response.statusCode, equals(200));
132 expect(response.body, parse(equals({
133 'method': 'DELETE',
134 'path': '/',
135 'headers': {
136 'x-random-header': ['Value'],
137 'x-other-header': ['Other Value']
138 }
139 })));
140 }), completes);
141 });
142
143 test('read', () {
144 expect(http.read(serverUrl, headers: {
145 'X-Random-Header': 'Value',
146 'X-Other-Header': 'Other Value'
147 }), completion(parse(equals({
148 'method': 'GET',
149 'path': '/',
150 'headers': {
151 'x-random-header': ['Value'],
152 'x-other-header': ['Other Value']
153 },
154 }))));
155 });
156
157 test('readBytes', () {
Bob Nystrom 2012/10/31 01:17:44 Add a test that this completes to an HttpException
nweiz 2012/10/31 18:20:59 Done.
158 var future = http.readBytes(serverUrl, headers: {
159 'X-Random-Header': 'Value',
160 'X-Other-Header': 'Other Value'
161 }).transform((bytes) => new String.fromCharCodes(bytes));
162
163 expect(future, completion(parse(equals({
164 'method': 'GET',
165 'path': '/',
166 'headers': {
167 'x-random-header': ['Value'],
168 'x-other-header': ['Other Value']
169 },
170 }))));
171 });
172 });
173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698