Chromium Code Reviews| 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 request_test; | 5 library request_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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 'application/x-www-form-urlencoded'; | 184 'application/x-www-form-urlencoded'; |
| 185 request.body = 'key%201=value&key+2=other%2bvalue'; | 185 request.body = 'key%201=value&key+2=other%2bvalue'; |
| 186 expect(request.bodyFields, | 186 expect(request.bodyFields, |
| 187 equals({'key 1': 'value', 'key 2': 'other+value'})); | 187 equals({'key 1': 'value', 'key 2': 'other+value'})); |
| 188 }); | 188 }); |
| 189 | 189 |
| 190 // TODO(nweiz): test that both the getter and the setter respect #encoding | 190 // TODO(nweiz): test that both the getter and the setter respect #encoding |
| 191 // when issue 6284 is fixed. | 191 // when issue 6284 is fixed. |
| 192 }); | 192 }); |
| 193 | 193 |
| 194 test('#followRedirects', () { | |
| 195 print("This test is known to be flaky, please ignore " | |
| 196 "(debug prints below added by sgjesse@)"); | |
| 197 print("#followRedirects test starting server..."); | |
| 198 startServer(); | |
| 199 print("#followRedirects test server running"); | |
| 200 | |
| 201 var request = new http.Request('POST', serverUrl.resolve('/redirect')) | |
| 202 ..followRedirects = false; | |
|
Bob Nystrom
2012/11/28 01:50:18
How about not using a cascade here. Or, if you mus
| |
| 203 var future = request.send().transform((response) { | |
| 204 print("#followRedirects test response received"); | |
| 205 expect(response.statusCode, equals(302)); | |
| 206 }); | |
| 207 future.onComplete((_) { | |
| 208 print("#followRedirects test stopping server..."); | |
| 209 stopServer(); | |
| 210 print("#followRedirects test server stopped"); | |
| 211 }); | |
| 212 | |
| 213 expect(future, completes); | |
| 214 print("#followRedirects test started"); | |
| 215 }); | |
| 216 | |
| 217 test('#maxRedirects', () { | |
| 218 print("This test is known to be flaky, please ignore " | |
| 219 "(debug prints below added by sgjesse@)"); | |
| 220 print("#maxRedirects test starting server..."); | |
| 221 startServer(); | |
| 222 print("#maxRedirects test server running"); | |
| 223 | |
| 224 var request = new http.Request('POST', serverUrl.resolve('/loop?1')) | |
| 225 ..maxRedirects = 2; | |
| 226 var future = request.send().transformException((e) { | |
| 227 print("#maxRedirects test exception received"); | |
| 228 expect(e, isRedirectLimitExceededException); | |
| 229 expect(e.redirects.length, equals(2)); | |
| 230 }); | |
| 231 future.onComplete((_) { | |
| 232 print("#maxRedirects test stopping server..."); | |
| 233 stopServer(); | |
| 234 print("#maxRedirects test server stopped"); | |
| 235 }); | |
| 236 | |
| 237 expect(future, completes); | |
| 238 print("#maxRedirects test started"); | |
| 239 }); | |
| 240 | |
| 194 group('content-type header', () { | 241 group('content-type header', () { |
| 195 test('defaults to empty', () { | 242 test('defaults to empty', () { |
| 196 var request = new http.Request('POST', dummyUrl); | 243 var request = new http.Request('POST', dummyUrl); |
| 197 expect(request.headers[HttpHeaders.CONTENT_TYPE], isNull); | 244 expect(request.headers[HttpHeaders.CONTENT_TYPE], isNull); |
| 198 }); | 245 }); |
| 199 | 246 |
| 200 test('defaults to empty if only encoding is set', () { | 247 test('defaults to empty if only encoding is set', () { |
| 201 var request = new http.Request('POST', dummyUrl); | 248 var request = new http.Request('POST', dummyUrl); |
| 202 request.encoding = Encoding.ISO_8859_1; | 249 request.encoding = Encoding.ISO_8859_1; |
| 203 expect(request.headers[HttpHeaders.CONTENT_TYPE], isNull); | 250 expect(request.headers[HttpHeaders.CONTENT_TYPE], isNull); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 }); | 390 }); |
| 344 | 391 |
| 345 test("can't be called twice", () { | 392 test("can't be called twice", () { |
| 346 var request = new http.Request('POST', dummyUrl); | 393 var request = new http.Request('POST', dummyUrl); |
| 347 request.finalize(); | 394 request.finalize(); |
| 348 expect(request.finalize, throwsStateError); | 395 expect(request.finalize, throwsStateError); |
| 349 }); | 396 }); |
| 350 }); | 397 }); |
| 351 } | 398 } |
| 352 | 399 |
| OLD | NEW |