| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 testrunner_test; | 5 library testrunner_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 | 10 |
| 11 main() { | 11 main() { |
| 12 var get = (String what, int code, String text) { | 12 var get = (String what, int code, String text) { |
| 13 var c = new Completer(); | 13 var c = new Completer(); |
| 14 HttpClient client = new HttpClient(); | 14 HttpClient client = new HttpClient(); |
| 15 client.getUrl(Uri.parse("http://127.0.0.1:3456/$what")) | 15 client |
| 16 .then((HttpClientRequest request) { | 16 .getUrl(Uri.parse("http://127.0.0.1:3456/$what")) |
| 17 .then((HttpClientRequest request) { |
| 17 // Prepare the request then call close on it to send it. | 18 // Prepare the request then call close on it to send it. |
| 18 return request.close(); | 19 return request.close(); |
| 19 }) | 20 }).then((HttpClientResponse response) { |
| 20 .then((HttpClientResponse response) { | |
| 21 // Process the response. | 21 // Process the response. |
| 22 expect(response.statusCode, code); | 22 expect(response.statusCode, code); |
| 23 var sb = new StringBuffer(); | 23 var sb = new StringBuffer(); |
| 24 response.transform(UTF8.decoder) | 24 response.transform(UTF8.decoder).listen((data) { |
| 25 .listen((data) { | 25 sb.write(data); |
| 26 sb.write(data); | |
| 27 }, onDone: () { | 26 }, onDone: () { |
| 28 expect(sb.toString(), text); | 27 expect(sb.toString(), text); |
| 29 c.complete(); | 28 c.complete(); |
| 30 }); | 29 }); |
| 31 }); | 30 }); |
| 32 return c.future; | 31 return c.future; |
| 33 }; | 32 }; |
| 34 test('test1', () { | 33 test('test1', () { |
| 35 return get('test.txt', 200, "Hello world!\n"); | 34 return get('test.txt', 200, "Hello world!\n"); |
| 36 }); | 35 }); |
| 37 test('test2', () { | 36 test('test2', () { |
| 38 return get('fail.txt', 404, ""); | 37 return get('fail.txt', 404, ""); |
| 39 }); | 38 }); |
| 40 } | 39 } |
| 41 | |
| OLD | NEW |