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

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

Issue 12328037: Add missing files from previous commit (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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
Index: tests/standalone/io/http_detach_socket_test.dart
diff --git a/tests/standalone/io/http_detach_socket_test.dart b/tests/standalone/io/http_detach_socket_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..e3a5ad533345ff848880b4212a340d25072537db
--- /dev/null
+++ b/tests/standalone/io/http_detach_socket_test.dart
@@ -0,0 +1,113 @@
+// Copyright (c) 2013, 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.
+//
+// VMOptions=
+// VMOptions=--short_socket_read
+// VMOptions=--short_socket_write
+// VMOptions=--short_socket_read --short_socket_write
+
+import "dart:io";
+import "dart:isolate";
+
+void testServerDetachSocket() {
+ HttpServer.bind().then((server) {
+ server.listen((request) {
+ var response = request.response;
+ response.contentLength = 0;
+ response.detachSocket().then((socket) {
+ Expect.isNotNull(socket);
+ var body = new StringBuffer();
+ socket.listen(
+ (data) => body.add(new String.fromCharCodes(data)),
+ onDone: () => Expect.equals("Some data", body.toString()));
+ socket.addString("Test!");
+ socket.close();
+ });
+ server.close();
+ });
+
+ Socket.connect("127.0.0.1", server.port).then((socket) {
+ socket.addString("GET / HTTP/1.1\r\n"
+ "content-length: 0\r\n\r\n"
+ "Some data");
+ var body = new StringBuffer();
+ socket.listen(
+ (data) => body.add(new String.fromCharCodes(data)),
+ onDone: () {
+ Expect.equals("HTTP/1.1 200 OK\r\n"
+ "content-length: 0\r\n"
+ "\r\n"
+ "Test!",
+ body.toString());
+ socket.close();
+ });
+ });
+ });
+}
+
+void testBadServerDetachSocket() {
+ HttpServer.bind().then((server) {
+ server.listen((request) {
+ var response = request.response;
+ response.contentLength = 0;
+ response.close();
+ Expect.throws(response.detachSocket);
+ server.close();
+ });
+
+ Socket.connect("127.0.0.1", server.port).then((socket) {
+ socket.addString("GET / HTTP/1.1\r\n"
+ "content-length: 0\r\n\r\n");
+ socket.listen((_) {}, onDone: () {
+ socket.close();
+ });
+ });
+ });
+}
+
+void testClientDetachSocket() {
+ ServerSocket.bind().then((server) {
+ server.listen((socket) {
+ socket.addString("HTTP/1.1 200 OK\r\n"
+ "\r\n"
+ "Test!");
+ var body = new StringBuffer();
+ socket.listen(
+ (data) => body.add(new String.fromCharCodes(data)),
+ onDone: () {
+ Expect.equals("GET / HTTP/1.1\r\n"
+ "content-length: 0\r\n"
+ "host: 127.0.0.1:${server.port}\r\n\r\n"
+ "Some data",
+ body.toString());
+ socket.close();
+ });
+ server.close();
+ });
+
+ var client = new HttpClient();
+ client.get("127.0.0.1", server.port, "/")
+ .then((request) => request.close())
+ .then((response) {
+ response.detachSocket().then((socket) {
+ var body = new StringBuffer();
+ socket.listen(
+ (data) => body.add(new String.fromCharCodes(data)),
+ onDone: () {
+ Expect.equals("Test!",
+ body.toString());
+ client.close();
+ });
+ socket.addString("Some data");
+ socket.close();
+ });
+ });
+ });
+}
+
+void main() {
+ testServerDetachSocket();
+ testBadServerDetachSocket();
+ testClientDetachSocket();
+}
« no previous file with comments | « tests/standalone/io/http_client_socket_reuse_test.dart ('k') | tests/standalone/io/http_server_response_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698