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

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

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 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
Index: tests/standalone/io/http_content_length_test.dart
diff --git a/tests/standalone/io/http_content_length_test.dart b/tests/standalone/io/http_content_length_test.dart
index 5094c43b2fdac9a022f9a94d768c125463ecbec2..f65f4052623de76a9bd10d2d1fab40d47d7b9918 100644
--- a/tests/standalone/io/http_content_length_test.dart
+++ b/tests/standalone/io/http_content_length_test.dart
@@ -15,56 +15,49 @@ import "dart:io";
void testNoBody(int totalConnections, bool explicitContentLength) {
int count = 0;
HttpServer.bind("127.0.0.1", 0, backlog: totalConnections).then((server) {
- server.listen(
- (HttpRequest request) {
- Expect.equals("0", request.headers.value('content-length'));
- Expect.equals(0, request.contentLength);
- var response = request.response;
- response.contentLength = 0;
- response.done
- .then((_) {
- Expect.fail("Unexpected successful response completion");
- })
- .catchError((error) {
- Expect.isTrue(error is HttpException);
- if (++count == totalConnections) {
- server.close();
- }
- });
- // write with content length 0 closes the connection and
- // reports an error.
- response.write("x");
- // Subsequent write are ignored as there is already an
- // error.
- response.write("x");
- // After an explicit close, write becomes a state error
- // because we have said we will not add more.
- response.close();
- response.write("x");
- },
- onError: (e, trace) {
- String msg = "Unexpected server error $e";
- if (trace != null) msg += "\nStackTrace: $trace";
- Expect.fail(msg);
- });
+ server.listen((HttpRequest request) {
+ Expect.equals("0", request.headers.value('content-length'));
+ Expect.equals(0, request.contentLength);
+ var response = request.response;
+ response.contentLength = 0;
+ response.done.then((_) {
+ Expect.fail("Unexpected successful response completion");
+ }).catchError((error) {
+ Expect.isTrue(error is HttpException);
+ if (++count == totalConnections) {
+ server.close();
+ }
+ });
+ // write with content length 0 closes the connection and
+ // reports an error.
+ response.write("x");
+ // Subsequent write are ignored as there is already an
+ // error.
+ response.write("x");
+ // After an explicit close, write becomes a state error
+ // because we have said we will not add more.
+ response.close();
+ response.write("x");
+ }, onError: (e, trace) {
+ String msg = "Unexpected server error $e";
+ if (trace != null) msg += "\nStackTrace: $trace";
+ Expect.fail(msg);
+ });
HttpClient client = new HttpClient();
for (int i = 0; i < totalConnections; i++) {
- client.get("127.0.0.1", server.port, "/")
- .then((request) {
- if (explicitContentLength) {
- request.contentLength = 0;
- }
- return request.close();
- })
- .then((response) {
- Expect.equals("0", response.headers.value('content-length'));
- Expect.equals(0, response.contentLength);
- response.drain();
- })
- .catchError((e, trace) {
- // It's also okay to fail, as headers may not be written.
- });
+ client.get("127.0.0.1", server.port, "/").then((request) {
+ if (explicitContentLength) {
+ request.contentLength = 0;
+ }
+ return request.close();
+ }).then((response) {
+ Expect.equals("0", response.headers.value('content-length'));
+ Expect.equals(0, response.contentLength);
+ response.drain();
+ }).catchError((e, trace) {
+ // It's also okay to fail, as headers may not be written.
+ });
}
});
}
@@ -72,180 +65,156 @@ void testNoBody(int totalConnections, bool explicitContentLength) {
void testBody(int totalConnections, bool useHeader) {
HttpServer.bind("127.0.0.1", 0, backlog: totalConnections).then((server) {
int serverCount = 0;
- server.listen(
- (HttpRequest request) {
- Expect.equals("2", request.headers.value('content-length'));
- Expect.equals(2, request.contentLength);
- var response = request.response;
- if (useHeader) {
- response.contentLength = 2;
- } else {
- response.headers.set("content-length", 2);
+ server.listen((HttpRequest request) {
+ Expect.equals("2", request.headers.value('content-length'));
+ Expect.equals(2, request.contentLength);
+ var response = request.response;
+ if (useHeader) {
+ response.contentLength = 2;
+ } else {
+ response.headers.set("content-length", 2);
+ }
+ request.listen((d) {}, onDone: () {
+ response.write("x");
+ Expect.throws(
+ () => response.contentLength = 3, (e) => e is HttpException);
+ response.write("x");
+ response.write("x");
+ response.done.then((_) {
+ Expect.fail("Unexpected successful response completion");
+ }).catchError((error) {
+ Expect.isTrue(error is HttpException, "[$error]");
+ if (++serverCount == totalConnections) {
+ server.close();
}
- request.listen(
- (d) {},
- onDone: () {
- response.write("x");
- Expect.throws(() => response.contentLength = 3,
- (e) => e is HttpException);
- response.write("x");
- response.write("x");
- response.done
- .then((_) {
- Expect.fail("Unexpected successful response completion");
- })
- .catchError((error) {
- Expect.isTrue(error is HttpException, "[$error]");
- if (++serverCount == totalConnections) {
- server.close();
- }
- });
- response.close();
- response.write("x");
- });
- },
- onError: (e, trace) {
- String msg = "Unexpected error $e";
- if (trace != null) msg += "\nStackTrace: $trace";
- Expect.fail(msg);
});
+ response.close();
+ response.write("x");
+ });
+ }, onError: (e, trace) {
+ String msg = "Unexpected error $e";
+ if (trace != null) msg += "\nStackTrace: $trace";
+ Expect.fail(msg);
+ });
int clientCount = 0;
HttpClient client = new HttpClient();
for (int i = 0; i < totalConnections; i++) {
- client.get("127.0.0.1", server.port, "/")
- .then((request) {
- if (useHeader) {
- request.contentLength = 2;
- } else {
- request.headers.add(HttpHeaders.CONTENT_LENGTH, "7");
- request.headers.add(HttpHeaders.CONTENT_LENGTH, "2");
- }
- request.write("x");
- Expect.throws(() => request.contentLength = 3,
- (e) => e is HttpException);
- request.write("x");
- return request.close();
- })
- .then((response) {
- Expect.equals("2", response.headers.value('content-length'));
- Expect.equals(2, response.contentLength);
- response.listen(
- (d) {},
- onDone: () {
- if (++clientCount == totalConnections) {
- client.close();
- }
- },
- onError: (error, trace) {
- // Undefined what server response sends.
- });
- })
- .catchError((error) {
- // It's also okay to fail, as headers may not be written.
- });
+ client.get("127.0.0.1", server.port, "/").then((request) {
+ if (useHeader) {
+ request.contentLength = 2;
+ } else {
+ request.headers.add(HttpHeaders.CONTENT_LENGTH, "7");
+ request.headers.add(HttpHeaders.CONTENT_LENGTH, "2");
+ }
+ request.write("x");
+ Expect.throws(
+ () => request.contentLength = 3, (e) => e is HttpException);
+ request.write("x");
+ return request.close();
+ }).then((response) {
+ Expect.equals("2", response.headers.value('content-length'));
+ Expect.equals(2, response.contentLength);
+ response.listen((d) {}, onDone: () {
+ if (++clientCount == totalConnections) {
+ client.close();
+ }
+ }, onError: (error, trace) {
+ // Undefined what server response sends.
+ });
+ }).catchError((error) {
+ // It's also okay to fail, as headers may not be written.
+ });
}
});
}
void testBodyChunked(int totalConnections, bool useHeader) {
HttpServer.bind("127.0.0.1", 0, backlog: totalConnections).then((server) {
- server.listen(
- (HttpRequest request) {
- Expect.isNull(request.headers.value('content-length'));
- Expect.equals(-1, request.contentLength);
- var response = request.response;
- if (useHeader) {
- response.contentLength = 2;
- response.headers.chunkedTransferEncoding = true;
- } else {
- response.headers.set("content-length", 2);
- response.headers.set("transfer-encoding", "chunked");
- }
- request.listen(
- (d) {},
- onDone: () {
- response.write("x");
- Expect.throws(
- () => response.headers.chunkedTransferEncoding = false,
- (e) => e is HttpException);
- response.write("x");
- response.write("x");
- response.close();
- response.write("x");
- });
- },
- onError: (e, trace) {
- String msg = "Unexpected error $e";
- if (trace != null) msg += "\nStackTrace: $trace";
- Expect.fail(msg);
- });
+ server.listen((HttpRequest request) {
+ Expect.isNull(request.headers.value('content-length'));
+ Expect.equals(-1, request.contentLength);
+ var response = request.response;
+ if (useHeader) {
+ response.contentLength = 2;
+ response.headers.chunkedTransferEncoding = true;
+ } else {
+ response.headers.set("content-length", 2);
+ response.headers.set("transfer-encoding", "chunked");
+ }
+ request.listen((d) {}, onDone: () {
+ response.write("x");
+ Expect.throws(() => response.headers.chunkedTransferEncoding = false,
+ (e) => e is HttpException);
+ response.write("x");
+ response.write("x");
+ response.close();
+ response.write("x");
+ });
+ }, onError: (e, trace) {
+ String msg = "Unexpected error $e";
+ if (trace != null) msg += "\nStackTrace: $trace";
+ Expect.fail(msg);
+ });
int count = 0;
HttpClient client = new HttpClient();
for (int i = 0; i < totalConnections; i++) {
- client.get("127.0.0.1", server.port, "/")
- .then((request) {
- if (useHeader) {
- request.contentLength = 2;
- request.headers.chunkedTransferEncoding = true;
- } else {
- request.headers.add(HttpHeaders.CONTENT_LENGTH, "2");
- request.headers.set(HttpHeaders.TRANSFER_ENCODING, "chunked");
- }
- request.write("x");
- Expect.throws(() => request.headers.chunkedTransferEncoding = false,
- (e) => e is HttpException);
- request.write("x");
- request.write("x");
- return request.close();
- })
- .then((response) {
- Expect.isNull(response.headers.value('content-length'));
- Expect.equals(-1, response.contentLength);
- response.listen(
- (d) {},
- onDone: () {
- if (++count == totalConnections) {
- client.close();
- server.close();
- }
- });
- })
- .catchError((e, trace) {
- String msg = "Unexpected error $e";
- if (trace != null) msg += "\nStackTrace: $trace";
- Expect.fail(msg);
- });
+ client.get("127.0.0.1", server.port, "/").then((request) {
+ if (useHeader) {
+ request.contentLength = 2;
+ request.headers.chunkedTransferEncoding = true;
+ } else {
+ request.headers.add(HttpHeaders.CONTENT_LENGTH, "2");
+ request.headers.set(HttpHeaders.TRANSFER_ENCODING, "chunked");
+ }
+ request.write("x");
+ Expect.throws(() => request.headers.chunkedTransferEncoding = false,
+ (e) => e is HttpException);
+ request.write("x");
+ request.write("x");
+ return request.close();
+ }).then((response) {
+ Expect.isNull(response.headers.value('content-length'));
+ Expect.equals(-1, response.contentLength);
+ response.listen((d) {}, onDone: () {
+ if (++count == totalConnections) {
+ client.close();
+ server.close();
+ }
+ });
+ }).catchError((e, trace) {
+ String msg = "Unexpected error $e";
+ if (trace != null) msg += "\nStackTrace: $trace";
+ Expect.fail(msg);
+ });
}
});
}
void testSetContentLength() {
HttpServer.bind("127.0.0.1", 0).then((server) {
- server.listen(
- (HttpRequest request) {
- var response = request.response;
- Expect.isNull(response.headers.value('content-length'));
- Expect.equals(-1, response.contentLength);
- response.headers.set("content-length", 3);
- Expect.equals("3", response.headers.value('content-length'));
- Expect.equals(3, response.contentLength);
- response.write("xxx");
- response.close();
- });
+ server.listen((HttpRequest request) {
+ var response = request.response;
+ Expect.isNull(response.headers.value('content-length'));
+ Expect.equals(-1, response.contentLength);
+ response.headers.set("content-length", 3);
+ Expect.equals("3", response.headers.value('content-length'));
+ Expect.equals(3, response.contentLength);
+ response.write("xxx");
+ response.close();
+ });
var client = new HttpClient();
- client.get("127.0.0.1", server.port, "/")
+ client
+ .get("127.0.0.1", server.port, "/")
.then((request) => request.close())
.then((response) {
- response.listen(
- (_) { },
- onDone: () {
- client.close();
- server.close();
- });
- });
+ response.listen((_) {}, onDone: () {
+ client.close();
+ server.close();
+ });
+ });
});
}

Powered by Google App Engine
This is Rietveld 408576698