| 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; |
| 11 import '../lib/src/utils.dart'; | 11 import '../lib/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 print("This test is known to be flaky, please ignore " |
| 17 "(debug prints below added by sgjesse@)"); |
| 18 print(".send test starting server..."); |
| 16 startServer(); | 19 startServer(); |
| 20 print(".send test server running"); |
| 17 | 21 |
| 18 var request = new http.Request('POST', serverUrl); | 22 var request = new http.Request('POST', serverUrl); |
| 19 request.body = "hello"; | 23 request.body = "hello"; |
| 20 var future = request.send().chain((response) { | 24 var future = request.send().chain((response) { |
| 25 print(".send test response received"); |
| 21 expect(response.statusCode, equals(200)); | 26 expect(response.statusCode, equals(200)); |
| 22 return consumeInputStream(response.stream); | 27 return consumeInputStream(response.stream); |
| 23 }).transform((bytes) => new String.fromCharCodes(bytes)); | 28 }).transform((bytes) => new String.fromCharCodes(bytes)); |
| 24 future.onComplete((_) => stopServer()); | 29 future.onComplete((_) { |
| 30 print(".send test stopping server..."); |
| 31 stopServer(); |
| 32 print(".send test server stopped"); |
| 33 }); |
| 25 | 34 |
| 26 expect(future, completion(parse(equals({ | 35 expect(future, completion(parse(equals({ |
| 27 'method': 'POST', | 36 'method': 'POST', |
| 28 'path': '/', | 37 'path': '/', |
| 29 'headers': { | 38 'headers': { |
| 30 'content-type': ['text/plain; charset=UTF-8'], | 39 'content-type': ['text/plain; charset=UTF-8'], |
| 31 'content-length': ['5'] | 40 'content-length': ['5'] |
| 32 }, | 41 }, |
| 33 'body': 'hello' | 42 'body': 'hello' |
| 34 })))); | 43 })))); |
| 44 print(".send test started"); |
| 35 }); | 45 }); |
| 36 | 46 |
| 37 group('#contentLength', () { | 47 group('#contentLength', () { |
| 38 test('is computed from bodyBytes', () { | 48 test('is computed from bodyBytes', () { |
| 39 var request = new http.Request('POST', dummyUrl); | 49 var request = new http.Request('POST', dummyUrl); |
| 40 request.bodyBytes = [1, 2, 3, 4, 5]; | 50 request.bodyBytes = [1, 2, 3, 4, 5]; |
| 41 expect(request.contentLength, equals(5)); | 51 expect(request.contentLength, equals(5)); |
| 42 request.bodyBytes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | 52 request.bodyBytes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
| 43 expect(request.contentLength, equals(10)); | 53 expect(request.contentLength, equals(10)); |
| 44 }); | 54 }); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 }); | 343 }); |
| 334 | 344 |
| 335 test("can't be called twice", () { | 345 test("can't be called twice", () { |
| 336 var request = new http.Request('POST', dummyUrl); | 346 var request = new http.Request('POST', dummyUrl); |
| 337 request.finalize(); | 347 request.finalize(); |
| 338 expect(request.finalize, throwsStateError); | 348 expect(request.finalize, throwsStateError); |
| 339 }); | 349 }); |
| 340 }); | 350 }); |
| 341 } | 351 } |
| 342 | 352 |
| OLD | NEW |