Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Unified Diff: tests/standalone/io/http_client_test.dart

Issue 12316036: Merge IO v2 branch to bleeding edge (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to r18818 Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/standalone/io/http_basic_test.dart ('k') | tests/standalone/io/http_connection_close_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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() {
« no previous file with comments | « tests/standalone/io/http_basic_test.dart ('k') | tests/standalone/io/http_connection_close_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698