| Index: tests/standalone/io/http_client_test.dart
|
| diff --git a/tests/standalone/io/http_client_test.dart b/tests/standalone/io/http_client_test.dart
|
| index 698090a8aa502be99c6ccf2aac0a3db47b961c9c..c3e7db1c7848f836591c4591e5a2ccd3386b2f67 100644
|
| --- a/tests/standalone/io/http_client_test.dart
|
| +++ b/tests/standalone/io/http_client_test.dart
|
| @@ -1,6 +1,11 @@
|
| // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
| +//
|
| +// VMOptions=
|
| +// VMOptions=--short_socket_read
|
| +// VMOptions=--short_socket_write
|
| +// VMOptions=--short_socket_read --short_socket_write
|
|
|
| import "dart:io";
|
| import "dart:uri";
|
| @@ -8,21 +13,13 @@ import "dart:isolate";
|
|
|
| void testGoogle() {
|
| HttpClient client = new HttpClient();
|
| - var conn = client.get('www.google.com', 80, '/');
|
| -
|
| - conn.onRequest = (HttpClientRequest request) {
|
| - request.outputStream.close();
|
| - };
|
| - conn.onResponse = (HttpClientResponse response) {
|
| - Expect.isTrue(response.statusCode < 500);
|
| - response.inputStream.onData = () {
|
| - response.inputStream.read();
|
| - };
|
| - response.inputStream.onClosed = () {
|
| - client.shutdown();
|
| - };
|
| - };
|
| - conn.onError = (error) => Expect.fail("Unexpected IO error $error");
|
| + client.get('www.google.com', 80, '/')
|
| + .then((request) => request.close())
|
| + .then((response) {
|
| + Expect.isTrue(response.statusCode < 500);
|
| + response.listen((data) {}, onDone: client.close);
|
| + })
|
| + .catchError((error) => Expect.fail("Unexpected IO error: $error"));
|
| }
|
|
|
| int testGoogleUrlCount = 0;
|
| @@ -31,25 +28,19 @@ void testGoogleUrl() {
|
|
|
| void testUrl(String url) {
|
| 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 == 5) client.shutdown();
|
| - };
|
| - };
|
| - conn.onError = (error) => Expect.fail("Unexpected IO error $error");
|
| + client.getUrl(requestUri)
|
| + .then((request) => request.close())
|
| + .then((response) {
|
| + testGoogleUrlCount++;
|
| + Expect.isTrue(response.statusCode < 500);
|
| + if (requestUri.path.length == 0) {
|
| + Expect.isTrue(response.statusCode != 404);
|
| + }
|
| + response.listen((data) {}, onDone: () {
|
| + if (testGoogleUrlCount == 5) client.close();
|
| + });
|
| + })
|
| + .catchError((error) => Expect.fail("Unexpected IO error: $error"));
|
| }
|
|
|
| testUrl('http://www.google.com');
|
| @@ -67,15 +58,13 @@ void testInvalidUrl() {
|
|
|
| void testBadHostName() {
|
| HttpClient client = new HttpClient();
|
| - HttpClientConnection connection =
|
| - client.get("some.bad.host.name.7654321", 0, "/");
|
| - 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.get("some.bad.host.name.7654321", 0, "/")
|
| + .then((request) {
|
| + Expect.fail("Should not open a request on bad hostname");
|
| + }).catchError((error) {
|
| + port.close(); // We expect onError to be called, due to bad host name.
|
| + }, test: (error) => error is! String);
|
| }
|
|
|
| void main() {
|
|
|