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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 //
5 // VMOptions=
6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write
9
10 import "dart:io";
11 import "dart:isolate";
12
13 void testServerDetachSocket() {
14 HttpServer.bind().then((server) {
15 server.listen((request) {
16 var response = request.response;
17 response.contentLength = 0;
18 response.detachSocket().then((socket) {
19 Expect.isNotNull(socket);
20 var body = new StringBuffer();
21 socket.listen(
22 (data) => body.add(new String.fromCharCodes(data)),
23 onDone: () => Expect.equals("Some data", body.toString()));
24 socket.addString("Test!");
25 socket.close();
26 });
27 server.close();
28 });
29
30 Socket.connect("127.0.0.1", server.port).then((socket) {
31 socket.addString("GET / HTTP/1.1\r\n"
32 "content-length: 0\r\n\r\n"
33 "Some data");
34 var body = new StringBuffer();
35 socket.listen(
36 (data) => body.add(new String.fromCharCodes(data)),
37 onDone: () {
38 Expect.equals("HTTP/1.1 200 OK\r\n"
39 "content-length: 0\r\n"
40 "\r\n"
41 "Test!",
42 body.toString());
43 socket.close();
44 });
45 });
46 });
47 }
48
49 void testBadServerDetachSocket() {
50 HttpServer.bind().then((server) {
51 server.listen((request) {
52 var response = request.response;
53 response.contentLength = 0;
54 response.close();
55 Expect.throws(response.detachSocket);
56 server.close();
57 });
58
59 Socket.connect("127.0.0.1", server.port).then((socket) {
60 socket.addString("GET / HTTP/1.1\r\n"
61 "content-length: 0\r\n\r\n");
62 socket.listen((_) {}, onDone: () {
63 socket.close();
64 });
65 });
66 });
67 }
68
69 void testClientDetachSocket() {
70 ServerSocket.bind().then((server) {
71 server.listen((socket) {
72 socket.addString("HTTP/1.1 200 OK\r\n"
73 "\r\n"
74 "Test!");
75 var body = new StringBuffer();
76 socket.listen(
77 (data) => body.add(new String.fromCharCodes(data)),
78 onDone: () {
79 Expect.equals("GET / HTTP/1.1\r\n"
80 "content-length: 0\r\n"
81 "host: 127.0.0.1:${server.port}\r\n\r\n"
82 "Some data",
83 body.toString());
84 socket.close();
85 });
86 server.close();
87 });
88
89 var client = new HttpClient();
90 client.get("127.0.0.1", server.port, "/")
91 .then((request) => request.close())
92 .then((response) {
93 response.detachSocket().then((socket) {
94 var body = new StringBuffer();
95 socket.listen(
96 (data) => body.add(new String.fromCharCodes(data)),
97 onDone: () {
98 Expect.equals("Test!",
99 body.toString());
100 client.close();
101 });
102 socket.addString("Some data");
103 socket.close();
104 });
105 });
106 });
107 }
108
109 void main() {
110 testServerDetachSocket();
111 testBadServerDetachSocket();
112 testClientDetachSocket();
113 }
OLDNEW
« 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