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 http_test; | 5 library http_test; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import '../../unittest/lib/unittest.dart'; | 9 import '../../unittest/lib/unittest.dart'; |
10 import '../lib/http.dart' as http; | 10 import '../lib/http.dart' as http; |
(...skipping 14 matching lines...) Expand all Loading... |
25 test('get', () { | 25 test('get', () { |
26 expect(http.get(serverUrl, headers: { | 26 expect(http.get(serverUrl, headers: { |
27 'X-Random-Header': 'Value', | 27 'X-Random-Header': 'Value', |
28 'X-Other-Header': 'Other Value' | 28 'X-Other-Header': 'Other Value' |
29 }).transform((response) { | 29 }).transform((response) { |
30 expect(response.statusCode, equals(200)); | 30 expect(response.statusCode, equals(200)); |
31 expect(response.body, parse(equals({ | 31 expect(response.body, parse(equals({ |
32 'method': 'GET', | 32 'method': 'GET', |
33 'path': '/', | 33 'path': '/', |
34 'headers': { | 34 'headers': { |
| 35 'content-length': ['0'], |
35 'x-random-header': ['Value'], | 36 'x-random-header': ['Value'], |
36 'x-other-header': ['Other Value'] | 37 'x-other-header': ['Other Value'] |
37 }, | 38 }, |
38 }))); | 39 }))); |
39 }), completes); | 40 }), completes); |
40 }); | 41 }); |
41 | 42 |
42 test('post', () { | 43 test('post', () { |
43 expect(http.post(serverUrl, headers: { | 44 expect(http.post(serverUrl, headers: { |
44 'X-Random-Header': 'Value', | 45 'X-Random-Header': 'Value', |
(...skipping 23 matching lines...) Expand all Loading... |
68 expect(http.post(serverUrl, headers: { | 69 expect(http.post(serverUrl, headers: { |
69 'X-Random-Header': 'Value', | 70 'X-Random-Header': 'Value', |
70 'X-Other-Header': 'Other Value', | 71 'X-Other-Header': 'Other Value', |
71 'Content-Type': 'text/plain' | 72 'Content-Type': 'text/plain' |
72 }).transform((response) { | 73 }).transform((response) { |
73 expect(response.statusCode, equals(200)); | 74 expect(response.statusCode, equals(200)); |
74 expect(response.body, parse(equals({ | 75 expect(response.body, parse(equals({ |
75 'method': 'POST', | 76 'method': 'POST', |
76 'path': '/', | 77 'path': '/', |
77 'headers': { | 78 'headers': { |
| 79 'content-length': ['0'], |
78 'content-type': ['text/plain'], | 80 'content-type': ['text/plain'], |
79 'x-random-header': ['Value'], | 81 'x-random-header': ['Value'], |
80 'x-other-header': ['Other Value'] | 82 'x-other-header': ['Other Value'] |
81 } | 83 } |
82 }))); | 84 }))); |
83 }), completes); | 85 }), completes); |
84 }); | 86 }); |
85 | 87 |
86 test('put', () { | 88 test('put', () { |
87 expect(http.put(serverUrl, headers: { | 89 expect(http.put(serverUrl, headers: { |
(...skipping 24 matching lines...) Expand all Loading... |
112 expect(http.put(serverUrl, headers: { | 114 expect(http.put(serverUrl, headers: { |
113 'X-Random-Header': 'Value', | 115 'X-Random-Header': 'Value', |
114 'X-Other-Header': 'Other Value', | 116 'X-Other-Header': 'Other Value', |
115 'Content-Type': 'text/plain' | 117 'Content-Type': 'text/plain' |
116 }).transform((response) { | 118 }).transform((response) { |
117 expect(response.statusCode, equals(200)); | 119 expect(response.statusCode, equals(200)); |
118 expect(response.body, parse(equals({ | 120 expect(response.body, parse(equals({ |
119 'method': 'PUT', | 121 'method': 'PUT', |
120 'path': '/', | 122 'path': '/', |
121 'headers': { | 123 'headers': { |
| 124 'content-length': ['0'], |
122 'content-type': ['text/plain'], | 125 'content-type': ['text/plain'], |
123 'x-random-header': ['Value'], | 126 'x-random-header': ['Value'], |
124 'x-other-header': ['Other Value'] | 127 'x-other-header': ['Other Value'] |
125 } | 128 } |
126 }))); | 129 }))); |
127 }), completes); | 130 }), completes); |
128 }); | 131 }); |
129 | 132 |
130 test('delete', () { | 133 test('delete', () { |
131 expect(http.delete(serverUrl, headers: { | 134 expect(http.delete(serverUrl, headers: { |
132 'X-Random-Header': 'Value', | 135 'X-Random-Header': 'Value', |
133 'X-Other-Header': 'Other Value' | 136 'X-Other-Header': 'Other Value' |
134 }).transform((response) { | 137 }).transform((response) { |
135 expect(response.statusCode, equals(200)); | 138 expect(response.statusCode, equals(200)); |
136 expect(response.body, parse(equals({ | 139 expect(response.body, parse(equals({ |
137 'method': 'DELETE', | 140 'method': 'DELETE', |
138 'path': '/', | 141 'path': '/', |
139 'headers': { | 142 'headers': { |
| 143 'content-length': ['0'], |
140 'x-random-header': ['Value'], | 144 'x-random-header': ['Value'], |
141 'x-other-header': ['Other Value'] | 145 'x-other-header': ['Other Value'] |
142 } | 146 } |
143 }))); | 147 }))); |
144 }), completes); | 148 }), completes); |
145 }); | 149 }); |
146 | 150 |
147 test('read', () { | 151 test('read', () { |
148 expect(http.read(serverUrl, headers: { | 152 expect(http.read(serverUrl, headers: { |
149 'X-Random-Header': 'Value', | 153 'X-Random-Header': 'Value', |
150 'X-Other-Header': 'Other Value' | 154 'X-Other-Header': 'Other Value' |
151 }), completion(parse(equals({ | 155 }), completion(parse(equals({ |
152 'method': 'GET', | 156 'method': 'GET', |
153 'path': '/', | 157 'path': '/', |
154 'headers': { | 158 'headers': { |
| 159 'content-length': ['0'], |
155 'x-random-header': ['Value'], | 160 'x-random-header': ['Value'], |
156 'x-other-header': ['Other Value'] | 161 'x-other-header': ['Other Value'] |
157 }, | 162 }, |
158 })))); | 163 })))); |
159 }); | 164 }); |
160 | 165 |
161 test('read throws an error for a 4** status code', () { | 166 test('read throws an error for a 4** status code', () { |
162 expect(http.read(serverUrl.resolve('/error')), throwsHttpException); | 167 expect(http.read(serverUrl.resolve('/error')), throwsHttpException); |
163 }); | 168 }); |
164 | 169 |
165 test('readBytes', () { | 170 test('readBytes', () { |
166 var future = http.readBytes(serverUrl, headers: { | 171 var future = http.readBytes(serverUrl, headers: { |
167 'X-Random-Header': 'Value', | 172 'X-Random-Header': 'Value', |
168 'X-Other-Header': 'Other Value' | 173 'X-Other-Header': 'Other Value' |
169 }).transform((bytes) => new String.fromCharCodes(bytes)); | 174 }).transform((bytes) => new String.fromCharCodes(bytes)); |
170 | 175 |
171 expect(future, completion(parse(equals({ | 176 expect(future, completion(parse(equals({ |
172 'method': 'GET', | 177 'method': 'GET', |
173 'path': '/', | 178 'path': '/', |
174 'headers': { | 179 'headers': { |
| 180 'content-length': ['0'], |
175 'x-random-header': ['Value'], | 181 'x-random-header': ['Value'], |
176 'x-other-header': ['Other Value'] | 182 'x-other-header': ['Other Value'] |
177 }, | 183 }, |
178 })))); | 184 })))); |
179 }); | 185 }); |
180 | 186 |
181 test('readBytes throws an error for a 4** status code', () { | 187 test('readBytes throws an error for a 4** status code', () { |
182 expect(http.readBytes(serverUrl.resolve('/error')), throwsHttpException); | 188 expect(http.readBytes(serverUrl.resolve('/error')), throwsHttpException); |
183 }); | 189 }); |
184 }); | 190 }); |
185 } | 191 } |
OLD | NEW |