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

Unified Diff: samples/tests/samples/src/chat/ChatServerTest.dart

Issue 9495007: Prepare the HTTP library for inclusion in the standalone VM (step 2) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 8 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 | « samples/chat/http_impl.dart ('k') | samples/tests/samples/src/chat/HttpTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/tests/samples/src/chat/ChatServerTest.dart
diff --git a/samples/tests/samples/src/chat/ChatServerTest.dart b/samples/tests/samples/src/chat/ChatServerTest.dart
index abf29439612441857128a4d8debbaff31a69e114..a00adf3d63ceb412dbba0d62bcbf56c9323baced 100644
--- a/samples/tests/samples/src/chat/ChatServerTest.dart
+++ b/samples/tests/samples/src/chat/ChatServerTest.dart
@@ -9,6 +9,7 @@
#library("chat_server_test.dart");
+#import("dart:io");
#import("dart:json");
#import("dart:isolate");
#import("../../../../chat/http.dart");
@@ -73,7 +74,10 @@ class ChatTestClient extends Isolate {
};
conn.responseHandler = (HTTPClientResponse r) {
response = r;
- response.dataEnd = leaveResponseHandler;
+ StringInputStream stream = new StringInputStream(response.inputStream);
+ StringBuffer body = new StringBuffer();
+ stream.dataHandler = () => body.add(stream.read());
+ stream.closeHandler = () => leaveResponseHandler(body.toString());
};
}
@@ -131,7 +135,10 @@ class ChatTestClient extends Isolate {
};
conn.responseHandler = (HTTPClientResponse r) {
response = r;
- response.dataEnd = receiveResponseHandler;
+ StringInputStream stream = new StringInputStream(response.inputStream);
+ StringBuffer body = new StringBuffer();
+ stream.dataHandler = () => body.add(stream.read());
+ stream.closeHandler = () => receiveResponseHandler(body.toString());
};
}
@@ -163,7 +170,10 @@ class ChatTestClient extends Isolate {
};
conn.responseHandler = (HTTPClientResponse r) {
response = r;
- response.dataEnd = sendResponseHandler;
+ StringInputStream stream = new StringInputStream(response.inputStream);
+ StringBuffer body = new StringBuffer();
+ stream.dataHandler = () => body.add(stream.read());
+ stream.closeHandler = () => sendResponseHandler(body.toString());
};
}
@@ -195,24 +205,26 @@ class ChatTestClient extends Isolate {
};
conn.responseHandler = (HTTPClientResponse r) {
response = r;
- response.dataEnd = joinResponseHandler;
+ StringInputStream stream = new StringInputStream(response.inputStream);
+ StringBuffer body = new StringBuffer();
+ stream.dataHandler = () => body.add(stream.read());
+ stream.closeHandler = () => joinResponseHandler(body.toString());
};
}
- this.port.receive(
- void _(var message, SendPort replyTo) {
- totalClients = message.totalClients;
- messagesToSend = message.messagesToSend;
- messagesToReceive = message.messagesToReceive;
- port = message.port;
- statusPort = replyTo;
+ this.port.receive((var message, SendPort replyTo) {
+ totalClients = message.totalClients;
+ messagesToSend = message.messagesToSend;
+ messagesToReceive = message.messagesToReceive;
+ port = message.port;
+ statusPort = replyTo;
- // Create a HTTP client factory.
- httpClient = new HTTPClient();
+ // Create a HTTP client factory.
+ httpClient = new HTTPClient();
- // Start the client by joining the chat topic.
- join();
- });
+ // Start the client by joining the chat topic.
+ join();
+ });
}
}
@@ -222,7 +234,7 @@ class TestMain {
: serverStatusPort = new ReceivePort(),
serverPort = null,
finishedClients = 0 {
- new ChatServer().spawn().then(void _(SendPort port) {
+ new ChatServer().spawn().then((SendPort port) {
serverPort = port;
start();
});
@@ -254,24 +266,23 @@ class TestMain {
clientStatusPorts = new List<ReceivePort>(clientCount);
for (int i = 0; i < clientCount; i++) {
ReceivePort statusPort = new ReceivePort();
- statusPort.receive(
- void _(var message, SendPort replyTo) {
- // First and only message from the client indicates that
- // the test is done.
- Expect.equals("Test succeeded", message);
- statusPort.close();
- finishedClients++;
-
- // If all clients are finished shutdown the server.
- if (finishedClients == clientCount) {
- // Send server stop message to the server.
- serverPort.send(new ChatServerCommand.stop(),
- serverStatusPort.toSendPort());
-
- // Close the last port to terminate the test.
- serverStatusPort.close();
- }
- });
+ statusPort.receive((var message, SendPort replyTo) {
+ // First and only message from the client indicates that
+ // the test is done.
+ Expect.equals("Test succeeded", message);
+ statusPort.close();
+ finishedClients++;
+
+ // If all clients are finished shutdown the server.
+ if (finishedClients == clientCount) {
+ // Send server stop message to the server.
+ serverPort.send(new ChatServerCommand.stop(),
+ serverStatusPort.toSendPort());
+
+ // Close the last port to terminate the test.
+ serverStatusPort.close();
+ }
+ });
clientStatusPorts[i] = statusPort;
new ChatTestClient().spawn().then((SendPort p) {
« no previous file with comments | « samples/chat/http_impl.dart ('k') | samples/tests/samples/src/chat/HttpTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698