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

Side by Side Diff: tests/standalone/io/http_detach_socket_test.dart

Issue 12473003: Remove deprecated StringBuffer.add, addAll and addCharCode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 // 4 //
5 // VMOptions= 5 // VMOptions=
6 // VMOptions=--short_socket_read 6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write 7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write 8 // VMOptions=--short_socket_read --short_socket_write
9 9
10 import "dart:io"; 10 import "dart:io";
11 import "dart:isolate"; 11 import "dart:isolate";
12 12
13 void testServerDetachSocket() { 13 void testServerDetachSocket() {
14 HttpServer.bind().then((server) { 14 HttpServer.bind().then((server) {
15 server.listen((request) { 15 server.listen((request) {
16 var response = request.response; 16 var response = request.response;
17 response.contentLength = 0; 17 response.contentLength = 0;
18 response.detachSocket().then((socket) { 18 response.detachSocket().then((socket) {
19 Expect.isNotNull(socket); 19 Expect.isNotNull(socket);
20 var body = new StringBuffer(); 20 var body = new StringBuffer();
21 socket.listen( 21 socket.listen(
22 (data) => body.add(new String.fromCharCodes(data)), 22 (data) => body.write(new String.fromCharCodes(data)),
23 onDone: () => Expect.equals("Some data", body.toString())); 23 onDone: () => Expect.equals("Some data", body.toString()));
24 socket.addString("Test!"); 24 socket.addString("Test!");
25 socket.close(); 25 socket.close();
26 }); 26 });
27 server.close(); 27 server.close();
28 }); 28 });
29 29
30 Socket.connect("127.0.0.1", server.port).then((socket) { 30 Socket.connect("127.0.0.1", server.port).then((socket) {
31 socket.addString("GET / HTTP/1.1\r\n" 31 socket.addString("GET / HTTP/1.1\r\n"
32 "content-length: 0\r\n\r\n" 32 "content-length: 0\r\n\r\n"
33 "Some data"); 33 "Some data");
34 var body = new StringBuffer(); 34 var body = new StringBuffer();
35 socket.listen( 35 socket.listen(
36 (data) => body.add(new String.fromCharCodes(data)), 36 (data) => body.write(new String.fromCharCodes(data)),
37 onDone: () { 37 onDone: () {
38 Expect.equals("HTTP/1.1 200 OK\r\n" 38 Expect.equals("HTTP/1.1 200 OK\r\n"
39 "content-length: 0\r\n" 39 "content-length: 0\r\n"
40 "\r\n" 40 "\r\n"
41 "Test!", 41 "Test!",
42 body.toString()); 42 body.toString());
43 socket.close(); 43 socket.close();
44 }); 44 });
45 }); 45 });
46 }); 46 });
(...skipping 20 matching lines...) Expand all
67 } 67 }
68 68
69 void testClientDetachSocket() { 69 void testClientDetachSocket() {
70 ServerSocket.bind().then((server) { 70 ServerSocket.bind().then((server) {
71 server.listen((socket) { 71 server.listen((socket) {
72 socket.addString("HTTP/1.1 200 OK\r\n" 72 socket.addString("HTTP/1.1 200 OK\r\n"
73 "\r\n" 73 "\r\n"
74 "Test!"); 74 "Test!");
75 var body = new StringBuffer(); 75 var body = new StringBuffer();
76 socket.listen( 76 socket.listen(
77 (data) => body.add(new String.fromCharCodes(data)), 77 (data) => body.write(new String.fromCharCodes(data)),
78 onDone: () { 78 onDone: () {
79 Expect.equals("GET / HTTP/1.1\r\n" 79 Expect.equals("GET / HTTP/1.1\r\n"
80 "content-length: 0\r\n" 80 "content-length: 0\r\n"
81 "host: 127.0.0.1:${server.port}\r\n\r\n" 81 "host: 127.0.0.1:${server.port}\r\n\r\n"
82 "Some data", 82 "Some data",
83 body.toString()); 83 body.toString());
84 socket.close(); 84 socket.close();
85 }); 85 });
86 server.close(); 86 server.close();
87 }); 87 });
88 88
89 var client = new HttpClient(); 89 var client = new HttpClient();
90 client.get("127.0.0.1", server.port, "/") 90 client.get("127.0.0.1", server.port, "/")
91 .then((request) => request.close()) 91 .then((request) => request.close())
92 .then((response) { 92 .then((response) {
93 response.detachSocket().then((socket) { 93 response.detachSocket().then((socket) {
94 var body = new StringBuffer(); 94 var body = new StringBuffer();
95 socket.listen( 95 socket.listen(
96 (data) => body.add(new String.fromCharCodes(data)), 96 (data) => body.write(new String.fromCharCodes(data)),
97 onDone: () { 97 onDone: () {
98 Expect.equals("Test!", 98 Expect.equals("Test!",
99 body.toString()); 99 body.toString());
100 client.close(); 100 client.close();
101 }); 101 });
102 socket.addString("Some data"); 102 socket.addString("Some data");
103 socket.close(); 103 socket.close();
104 }); 104 });
105 }); 105 });
106 }); 106 });
107 } 107 }
108 108
109 void main() { 109 void main() {
110 testServerDetachSocket(); 110 testServerDetachSocket();
111 testBadServerDetachSocket(); 111 testBadServerDetachSocket();
112 testClientDetachSocket(); 112 testClientDetachSocket();
113 } 113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698