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

Unified Diff: tests/standalone/io/http_server_response_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_server_response_test.dart
diff --git a/tests/standalone/io/http_server_response_test.dart b/tests/standalone/io/http_server_response_test.dart
index a6c06aff34072797b1870cf7106bf97b8285071b..c231c4af9630ec31e8f207d8f8c8fdb0c6a04e14 100644
--- a/tests/standalone/io/http_server_response_test.dart
+++ b/tests/standalone/io/http_server_response_test.dart
@@ -19,8 +19,7 @@ File scriptSource = new File(
Platform.script.resolve("http_server_response_test.dart").toFilePath());
void testServerRequest(void handler(server, request),
- {int bytes,
- bool closeClient}) {
+ {int bytes, bool closeClient}) {
HttpServer.bind("127.0.0.1", 0).then((server) {
server.defaultResponseHeaders.clear();
server.listen((request) {
@@ -31,35 +30,31 @@ void testServerRequest(void handler(server, request),
// We only close the client on either
// - Bad response headers
// - Response done (with optional errors in between).
- client.get("127.0.0.1", server.port, "/")
- .then((request) => request.close())
- .then((response) {
- int received = 0;
- var subscription;
- subscription = response.listen(
- (data) {
- if (closeClient == true) {
- subscription.cancel();
- client.close();
- } else {
- received += data.length;
- }
- },
- onDone: () {
- if (bytes != null) Expect.equals(received, bytes);
- client.close();
- },
- onError: (error) {
- Expect.isTrue(error is HttpException);
- });
- })
- .catchError((error) {
- client.close();
- }, test: (e) => e is HttpException);
+ client
+ .get("127.0.0.1", server.port, "/")
+ .then((request) => request.close())
+ .then((response) {
+ int received = 0;
+ var subscription;
+ subscription = response.listen((data) {
+ if (closeClient == true) {
+ subscription.cancel();
+ client.close();
+ } else {
+ received += data.length;
+ }
+ }, onDone: () {
+ if (bytes != null) Expect.equals(received, bytes);
+ client.close();
+ }, onError: (error) {
+ Expect.isTrue(error is HttpException);
+ });
+ }).catchError((error) {
+ client.close();
+ }, test: (e) => e is HttpException);
});
}
-
void testResponseDone() {
testServerRequest((server, request) {
request.response.close();
@@ -70,10 +65,12 @@ void testResponseDone() {
});
testServerRequest((server, request) {
- new File("__nonexistent_file_").openRead().pipe(request.response)
+ new File("__nonexistent_file_")
+ .openRead()
+ .pipe(request.response)
.catchError((e) {
- server.close();
- });
+ server.close();
+ });
});
testServerRequest((server, request) {
@@ -85,86 +82,81 @@ void testResponseDone() {
});
}
-
void testResponseAddStream() {
File file = scriptSource;
int bytes = file.lengthSync();
testServerRequest((server, request) {
- request.response.addStream(file.openRead())
- .then((response) {
- response.close();
- response.done.then((_) => server.close());
- });
+ request.response.addStream(file.openRead()).then((response) {
+ response.close();
+ response.done.then((_) => server.close());
+ });
}, bytes: bytes);
testServerRequest((server, request) {
- request.response.addStream(file.openRead())
- .then((response) {
- request.response.addStream(file.openRead())
- .then((response) {
- response.close();
- response.done.then((_) => server.close());
- });
- });
+ request.response.addStream(file.openRead()).then((response) {
+ request.response.addStream(file.openRead()).then((response) {
+ response.close();
+ response.done.then((_) => server.close());
+ });
+ });
}, bytes: bytes * 2);
testServerRequest((server, request) {
var controller = new StreamController(sync: true);
- request.response.addStream(controller.stream)
- .then((response) {
- response.close();
- response.done.then((_) => server.close());
- });
+ request.response.addStream(controller.stream).then((response) {
+ response.close();
+ response.done.then((_) => server.close());
+ });
controller.close();
}, bytes: 0);
testServerRequest((server, request) {
- request.response.addStream(new File("__nonexistent_file_").openRead())
+ request.response
+ .addStream(new File("__nonexistent_file_").openRead())
.catchError((e) {
- server.close();
- });
+ server.close();
+ });
});
testServerRequest((server, request) {
- new File("__nonexistent_file_").openRead().pipe(request.response)
+ new File("__nonexistent_file_")
+ .openRead()
+ .pipe(request.response)
.catchError((e) {
- server.close();
- });
+ server.close();
+ });
});
}
-
void testResponseAddStreamClosed() {
File file = scriptSource;
testServerRequest((server, request) {
- request.response.addStream(file.openRead())
- .then((response) {
- response.close();
- response.done.then((_) => server.close());
- });
+ request.response.addStream(file.openRead()).then((response) {
+ response.close();
+ response.done.then((_) => server.close());
+ });
}, closeClient: true);
testServerRequest((server, request) {
int count = 0;
write() {
- request.response.addStream(file.openRead())
- .then((response) {
- request.response.write("sync data");
- count++;
- if (count < 1000) {
- write();
- } else {
- response.close();
- response.done.then((_) => server.close());
- }
- });
+ request.response.addStream(file.openRead()).then((response) {
+ request.response.write("sync data");
+ count++;
+ if (count < 1000) {
+ write();
+ } else {
+ response.close();
+ response.done.then((_) => server.close());
+ }
+ });
}
+
write();
}, closeClient: true);
}
-
void testResponseAddClosed() {
File file = scriptSource;
testServerRequest((server, request) {
@@ -191,15 +183,15 @@ void testResponseAddClosed() {
write();
} else {
request.response.close();
- request. response.done.then((_) => server.close());
+ request.response.done.then((_) => server.close());
}
});
}
+
write();
}, closeClient: true);
}
-
void testBadResponseAdd() {
testServerRequest((server, request) {
request.response.contentLength = 0;
@@ -232,7 +224,6 @@ void testBadResponseAdd() {
});
}
-
void testBadResponseClose() {
testServerRequest((server, request) {
request.response.contentLength = 5;
@@ -252,35 +243,28 @@ void testBadResponseClose() {
});
}
-
void testIgnoreRequestData() {
- HttpServer.bind("127.0.0.1", 0)
- .then((server) {
- server.listen((request) {
- // Ignore request data.
- request.response.write("all-okay");
- request.response.close();
- });
+ HttpServer.bind("127.0.0.1", 0).then((server) {
+ server.listen((request) {
+ // Ignore request data.
+ request.response.write("all-okay");
+ request.response.close();
+ });
- var client = new HttpClient();
- client.get("127.0.0.1", server.port, "/")
- .then((request) {
- request.contentLength = 1024 * 1024;
- request.add(new Uint8List(1024 * 1024));
- return request.close();
- })
- .then((response) {
- response
- .fold(0, (s, b) => s + b.length)
- .then((bytes) {
- Expect.equals(8, bytes);
- server.close();
- });
- });
+ var client = new HttpClient();
+ client.get("127.0.0.1", server.port, "/").then((request) {
+ request.contentLength = 1024 * 1024;
+ request.add(new Uint8List(1024 * 1024));
+ return request.close();
+ }).then((response) {
+ response.fold(0, (s, b) => s + b.length).then((bytes) {
+ Expect.equals(8, bytes);
+ server.close();
});
+ });
+ });
}
-
void testWriteCharCode() {
testServerRequest((server, request) {
// Test that default is latin-1 (only 2 bytes).
@@ -292,7 +276,6 @@ void testWriteCharCode() {
}, bytes: 2);
}
-
void main() {
testResponseDone();
testResponseAddStream();

Powered by Google App Engine
This is Rietveld 408576698