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

Unified Diff: tests/standalone/io/http_server_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_server_socket_test.dart ('k') | tests/standalone/io/http_session_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/http_server_test.dart
diff --git a/tests/standalone/io/http_server_test.dart b/tests/standalone/io/http_server_test.dart
index 8e7424e5349679676b2759509800fbdee2abaaae..dd6eeace72b6db75013afb23ef3a40064513b865 100644
--- a/tests/standalone/io/http_server_test.dart
+++ b/tests/standalone/io/http_server_test.dart
@@ -1,4 +1,4 @@
-// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2013, 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.
@@ -6,56 +6,53 @@ import "dart:io";
import "dart:isolate";
void testListenOn() {
- ServerSocket socket = new ServerSocket("127.0.0.1", 0, 5);
-
- socket.onError = (Exception e) {
- Expect.fail("ServerSocket closed unexpected");
- };
+ ServerSocket socket;
+ HttpServer server;
void test(void onDone()) {
- HttpServer server = new HttpServer();
- Expect.throws(() => server.port);
-
- ReceivePort serverPort = new ReceivePort();
- server.defaultRequestHandler =
- (HttpRequest request, HttpResponse response) {
- request.inputStream.onClosed = () {
- response.outputStream.close();
- serverPort.close();
- };
- };
-
- server.onError = (Exception e) {
- Expect.fail("Unexpected error in Http Server: $e");
- };
- server.listenOn(socket);
Expect.equals(socket.port, server.port);
- HttpClient client = new HttpClient();
- HttpClientConnection conn = client.get("127.0.0.1", socket.port, "/");
- conn.onRequest = (HttpClientRequest request) {
- request.outputStream.close();
- };
ReceivePort clientPort = new ReceivePort();
- conn.onResponse = (HttpClientResponse response) {
- response.inputStream.onClosed = () {
- client.shutdown();
- clientPort.close();
- server.close();
- Expect.throws(() => server.port);
- onDone();
- };
- };
- conn.onError = (Exception e) {
- Expect.fail("Unexpected error in Http Client: $e");
- };
- };
+ HttpClient client = new HttpClient();
+ client.get("127.0.0.1", socket.port, "/")
+ .then((request) {
+ return request.close();
+ })
+ .then((response) {
+ response.listen(
+ (_) {},
+ onDone: () {
+ client.close();
+ clientPort.close();
+ onDone();
+ });
+ })
+ .catchError((error) {
+ Expect.fail("Unexpected error in Http Client: $error");
+ });
+ }
// Test two connection after each other.
- test(() {
+ ServerSocket.bind().then((s) {
+ socket = s;
+ server = new HttpServer.listenOn(socket);
+ ReceivePort serverPort = new ReceivePort();
+ server.listen((HttpRequest request) {
+ request.listen(
+ (_) {},
+ onDone: () {
+ request.response.close();
+ serverPort.close();
+ });
+ });
+
test(() {
- socket.close();
+ test(() {
+ server.close();
+ Expect.throws(() => server.port);
+ socket.close();
+ });
});
});
}
« no previous file with comments | « tests/standalone/io/http_server_socket_test.dart ('k') | tests/standalone/io/http_session_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698