| 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 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 import 'package:http/http.dart' as http; | 10 import 'package:http/http.dart' as http; |
| 11 import 'package:http/src/utils.dart'; | 11 import 'package:http/src/utils.dart'; |
| 12 import 'utils.dart'; | 12 import 'utils.dart'; |
| 13 | 13 |
| 14 void main() { | 14 void main() { |
| 15 test('.send', () { | 15 test('.send', () { |
| 16 startServer(); | 16 startServer(); |
| 17 | 17 |
| 18 var request = new http.Request('POST', serverUrl); | 18 var request = new http.Request('POST', serverUrl); |
| 19 request.body = "hello"; | 19 request.body = "hello"; |
| 20 var future = request.send().then((response) { | 20 |
| 21 expect(request.send().then((response) { |
| 21 expect(response.statusCode, equals(200)); | 22 expect(response.statusCode, equals(200)); |
| 22 return consumeInputStream(response.stream); | 23 return response.stream.bytesToString(); |
| 23 }).then((bytes) => new String.fromCharCodes(bytes)); | 24 }).whenComplete(stopServer), completion(parse(equals({ |
| 24 future.catchError((_) {}).then(expectAsync1((_) { | |
| 25 stopServer(); | |
| 26 })); | |
| 27 | |
| 28 expect(future, completion(parse(equals({ | |
| 29 'method': 'POST', | 25 'method': 'POST', |
| 30 'path': '/', | 26 'path': '/', |
| 31 'headers': { | 27 'headers': { |
| 32 'content-type': ['text/plain; charset=UTF-8'], | 28 'content-type': ['text/plain; charset=UTF-8'], |
| 33 'content-length': ['5'] | 29 'content-length': ['5'] |
| 34 }, | 30 }, |
| 35 'body': 'hello' | 31 'body': 'hello' |
| 36 })))); | 32 })))); |
| 37 }); | 33 }); |
| 38 | 34 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 request.body = '{"hello": "world"}'; | 305 request.body = '{"hello": "world"}'; |
| 310 expect(request.headers[HttpHeaders.CONTENT_TYPE], | 306 expect(request.headers[HttpHeaders.CONTENT_TYPE], |
| 311 equals('application/json; charset=iso-8859-1')); | 307 equals('application/json; charset=iso-8859-1')); |
| 312 }); | 308 }); |
| 313 }); | 309 }); |
| 314 | 310 |
| 315 group('#finalize', () { | 311 group('#finalize', () { |
| 316 test('returns a stream that emits the request body', () { | 312 test('returns a stream that emits the request body', () { |
| 317 var request = new http.Request('POST', dummyUrl); | 313 var request = new http.Request('POST', dummyUrl); |
| 318 request.body = "Hello, world!"; | 314 request.body = "Hello, world!"; |
| 319 expect( | 315 expect(request.finalize().bytesToString(), |
| 320 consumeInputStream(request.finalize()) | |
| 321 .then((bytes) => new String.fromCharCodes(bytes)), | |
| 322 completion(equals("Hello, world!"))); | 316 completion(equals("Hello, world!"))); |
| 323 }); | 317 }); |
| 324 | 318 |
| 325 test('freezes #persistentConnection', () { | 319 test('freezes #persistentConnection', () { |
| 326 var request = new http.Request('POST', dummyUrl); | 320 var request = new http.Request('POST', dummyUrl); |
| 327 request.finalize(); | 321 request.finalize(); |
| 328 | 322 |
| 329 expect(request.persistentConnection, isTrue); | 323 expect(request.persistentConnection, isTrue); |
| 330 expect(() => request.persistentConnection = false, throwsStateError); | 324 expect(() => request.persistentConnection = false, throwsStateError); |
| 331 }); | 325 }); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 }); | 383 }); |
| 390 | 384 |
| 391 group('#toString()', () { | 385 group('#toString()', () { |
| 392 test('includes the method and URL', () { | 386 test('includes the method and URL', () { |
| 393 var request = new http.Request('POST', dummyUrl); | 387 var request = new http.Request('POST', dummyUrl); |
| 394 expect(request.toString(), 'POST $dummyUrl'); | 388 expect(request.toString(), 'POST $dummyUrl'); |
| 395 }); | 389 }); |
| 396 }); | 390 }); |
| 397 } | 391 } |
| 398 | 392 |
| OLD | NEW |