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

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

Issue 8776001: Fix HTTP sample implementation to actually wait for connections before attempting to write. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 9 years, 1 month 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/tests/samples/src/chat/ChatServerTest.dart ('k') | tests/standalone/src/SocketExceptionTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/tests/samples/src/chat/HttpTest.dart
diff --git a/samples/tests/samples/src/chat/HttpTest.dart b/samples/tests/samples/src/chat/HttpTest.dart
index b41cc4e72c419f0b0e80804e09b8bf38843c495f..72ee136fb4470bb427d42ea77eb22efa63aea52f 100644
--- a/samples/tests/samples/src/chat/HttpTest.dart
+++ b/samples/tests/samples/src/chat/HttpTest.dart
@@ -184,25 +184,22 @@ void testStartStop() {
void testGET() {
TestServerMain testServerMain = new TestServerMain();
- testServerMain.setServerStartedHandler(
- void _(int port) {
- HTTPClient httpClient = new HTTPClient();
- HTTPClientRequest request = httpClient.open("GET",
- "127.0.0.1",
- port,
- "/0123456789");
- request.responseReceived =
- void _(HTTPClientResponse response) {
- Expect.equals(HTTPStatus.OK, response.statusCode);
- response.dataEnd =
- void _(String body) {
- Expect.equals("01234567890", body);
- httpClient.shutdown();
- testServerMain.shutdown();
- };
- };
- request.writeDone();
- });
+ testServerMain.setServerStartedHandler((int port) {
+ HTTPClient httpClient = new HTTPClient();
+ httpClient.openHandler = (HTTPClientRequest request) {
+ request.responseReceived = (HTTPClientResponse response) {
+ Expect.equals(HTTPStatus.OK, response.statusCode);
+ response.dataEnd =
+ void _(String body) {
+ Expect.equals("01234567890", body);
+ httpClient.shutdown();
+ testServerMain.shutdown();
+ };
+ };
+ request.writeDone();
+ };
+ httpClient.open("GET", "127.0.0.1", port, "/0123456789");
+ });
testServerMain.start();
}
@@ -217,34 +214,31 @@ void testPOST(bool chunkedEncoding) {
int count = 0;
HTTPClient httpClient = new HTTPClient();
void sendRequest() {
- HTTPClientRequest request = httpClient.open("POST",
- "127.0.0.1",
- port,
- "/echo");
-
- request.responseReceived =
- void _(HTTPClientResponse response) {
- Expect.equals(HTTPStatus.OK, response.statusCode);
- response.dataEnd =
- void _(String body) {
- Expect.equals(data, body);
- count++;
- if (count < kMessageCount) {
- sendRequest();
- } else {
- httpClient.shutdown();
- testServerMain.shutdown();
- }
- };
- };
- if (chunkedEncoding) {
- request.writeString(data);
- } else {
- request.contentLength = data.length;
- request.writeList(data.charCodes(), 0, data.length);
- }
- request.writeDone();
+ httpClient.openHandler = (HTTPClientRequest request) {
+ request.responseReceived = (HTTPClientResponse response) {
+ Expect.equals(HTTPStatus.OK, response.statusCode);
+ response.dataEnd =
+ void _(String body) {
+ Expect.equals(data, body);
+ count++;
+ if (count < kMessageCount) {
+ sendRequest();
+ } else {
+ httpClient.shutdown();
+ testServerMain.shutdown();
+ }
+ };
+ };
+ if (chunkedEncoding) {
+ request.writeString(data);
+ } else {
+ request.contentLength = data.length;
+ request.writeList(data.charCodes(), 0, data.length);
+ }
+ request.writeDone();
+ };
+ httpClient.open("POST", "127.0.0.1", port, "/echo");
}
sendRequest();
@@ -260,22 +254,19 @@ void testPOST(bool chunkedEncoding) {
void test404() {
TestServerMain testServerMain = new TestServerMain();
- testServerMain.setServerStartedHandler(
- void _(int port) {
- HTTPClient httpClient = new HTTPClient();
- HTTPClientRequest request = httpClient.open("GET",
- "127.0.0.1",
- port,
- "/thisisnotfound");
- request.writeDone();
- request.keepAlive = false;
- request.responseReceived =
- void _(HTTPClientResponse response) {
- Expect.equals(HTTPStatus.NOT_FOUND, response.statusCode);
- httpClient.shutdown();
- testServerMain.shutdown();
- };
- });
+ testServerMain.setServerStartedHandler((int port) {
+ HTTPClient httpClient = new HTTPClient();
+ httpClient.openHandler = (HTTPClientRequest request) {
+ request.writeDone();
+ request.keepAlive = false;
+ request.responseReceived = (HTTPClientResponse response) {
+ Expect.equals(HTTPStatus.NOT_FOUND, response.statusCode);
+ httpClient.shutdown();
+ testServerMain.shutdown();
+ };
+ };
+ httpClient.open("GET", "127.0.0.1", port, "/thisisnotfound");
+ });
testServerMain.start();
}
« no previous file with comments | « samples/tests/samples/src/chat/ChatServerTest.dart ('k') | tests/standalone/src/SocketExceptionTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698