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

Unified Diff: tests/standalone/src/io/HttpContentLengthTest.dart

Issue 10232006: Check the state of the HTTP request and response when handling headers (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Reverted unintentional edit Created 8 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/src/io/HttpContentLengthTest.dart
diff --git a/tests/standalone/src/io/HttpContentLengthTest.dart b/tests/standalone/src/io/HttpContentLengthTest.dart
new file mode 100644
index 0000000000000000000000000000000000000000..cf2614588f647c6def0d187187f3c253d8ca7087
--- /dev/null
+++ b/tests/standalone/src/io/HttpContentLengthTest.dart
@@ -0,0 +1,85 @@
+// Copyright (c) 2012, 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.
+//
+
+#import("dart:isolate");
+#import("dart:io");
+
+void testNoBody(int totalConnections) {
+ HttpServer server = new HttpServer();
+ server.onError = (e) => Expect.fail("Unexpected error $e");
+ server.listen("127.0.0.1", 0, totalConnections);
+ server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
+ response.contentLength = 0;
+ OutputStream stream = response.outputStream;
+ Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
+ stream.close();
+ Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
+ };
+
+ int count = 0;
+ HttpClient client = new HttpClient();
+ for (int i = 0; i < totalConnections; i++) {
+ HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
+ conn.onError = (e) => Expect.fail("Unexpected error $e");
+ conn.onRequest = (HttpClientRequest request) {
+ OutputStream stream = request.outputStream;
+ Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
+ stream.close();
+ Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
+ };
+ conn.onResponse = (HttpClientResponse response) {
+ count++;
+ if (count == totalConnections) {
+ client.shutdown();
+ server.close();
+ }
+ };
+ }
+}
+
+void testBody(int totalConnections) {
+ HttpServer server = new HttpServer();
+ server.onError = (e) => Expect.fail("Unexpected error $e");
+ server.listen("127.0.0.1", 0, totalConnections);
+ server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
+ response.contentLength = 2;
+ OutputStream stream = response.outputStream;
+ stream.writeString("x");
+ Expect.throws(() => response.contentLength = 3, (e) => e is HttpException);
+ stream.writeString("x");
+ Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
+ stream.close();
+ Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
+ };
+
+ int count = 0;
+ HttpClient client = new HttpClient();
+ for (int i = 0; i < totalConnections; i++) {
+ HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
+ conn.onError = (e) => Expect.fail("Unexpected error $e");
+ conn.onRequest = (HttpClientRequest request) {
+ request.contentLength = 2;
+ OutputStream stream = request.outputStream;
+ stream.writeString("x");
+ Expect.throws(() => request.contentLength = 3, (e) => e is HttpException);
+ stream.writeString("x");
+ Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
+ stream.close();
+ Expect.throws(() => stream.writeString("x"), (e) => e is HttpException);
+ };
+ conn.onResponse = (HttpClientResponse response) {
+ count++;
+ if (count == totalConnections) {
+ client.shutdown();
+ server.close();
+ }
+ };
+ }
+}
+
+void main() {
+ testNoBody(5);
+ testBody(5);
+}

Powered by Google App Engine
This is Rietveld 408576698