| Index: tests/standalone/io/https_client_test.dart
|
| diff --git a/tests/standalone/io/https_client_test.dart b/tests/standalone/io/https_client_test.dart
|
| index 847249fc135b8b96a947df4f69d93047a689f36f..37b3d4f01779014606e65efb13d1f8a9f8238a51 100644
|
| --- a/tests/standalone/io/https_client_test.dart
|
| +++ b/tests/standalone/io/https_client_test.dart
|
| @@ -7,50 +7,46 @@ import "dart:uri";
|
| import "dart:isolate";
|
|
|
|
|
| -int testGoogleUrlCount = 0;
|
| void testGoogleUrl() {
|
| + int testsStarted = 0;
|
| + int testsFinished = 0;
|
| + bool allStarted = false;
|
| HttpClient client = new HttpClient();
|
|
|
| void testUrl(String url) {
|
| + testsStarted++;
|
| var requestUri = Uri.parse(url);
|
| - var conn = client.getUrl(requestUri);
|
| -
|
| - conn.onRequest = (HttpClientRequest request) {
|
| - request.outputStream.close();
|
| - };
|
| - conn.onResponse = (HttpClientResponse response) {
|
| - testGoogleUrlCount++;
|
| - Expect.isTrue(response.statusCode < 500);
|
| - if (requestUri.path.length == 0) {
|
| - Expect.isTrue(response.statusCode != 404);
|
| - }
|
| - response.inputStream.onData = () {
|
| - response.inputStream.read();
|
| - };
|
| - response.inputStream.onClosed = () {
|
| - if (testGoogleUrlCount == 4) client.shutdown();
|
| - };
|
| - };
|
| - conn.onError = (error) => Expect.fail("Unexpected IO error $error");
|
| + client.getUrl(requestUri)
|
| + .then((HttpClientRequest request) => request.close())
|
| + .then((HttpClientResponse response) {
|
| + Expect.isTrue(response.statusCode < 500);
|
| + if (requestUri.path.length == 0) {
|
| + Expect.isTrue(response.statusCode != 404);
|
| + }
|
| + response.listen((data) { }, onDone: () {
|
| + if (++testsFinished == testsStarted && allStarted) client.close();
|
| + });
|
| + })
|
| + .catchError((error) => Expect.fail("Unexpected IO error: $error"));
|
| }
|
|
|
| testUrl('https://www.google.dk');
|
| testUrl('https://www.google.dk');
|
| testUrl('https://www.google.dk/#q=foo');
|
| testUrl('https://www.google.dk/#hl=da&q=foo');
|
| + allStarted = true;
|
| }
|
|
|
| void testBadHostName() {
|
| HttpClient client = new HttpClient();
|
| - HttpClientConnection connection = client.getUrl(
|
| - Uri.parse("https://some.bad.host.name.7654321/"));
|
| - connection.onRequest = (HttpClientRequest request) {
|
| - Expect.fail("Should not open a request on bad hostname");
|
| - };
|
| ReceivePort port = new ReceivePort();
|
| - connection.onError = (Exception error) {
|
| - port.close(); // We expect onError to be called, due to bad host name.
|
| - };
|
| + client.getUrl(Uri.parse("https://some.bad.host.name.7654321/"))
|
| + .then((HttpClientRequest request) {
|
| + Expect.fail("Should not open a request on bad hostname");
|
| + })
|
| + .catchError((error) {
|
| + port.close(); // Should throw an error on bad hostname.
|
| + });
|
| }
|
|
|
| void InitializeSSL() {
|
|
|