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

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

Issue 11194025: Second round of cleanups for new optional parameter semantics. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 5
6 #import("dart:io"); 6 #import("dart:io");
7 #import("dart:scalarlist"); 7 #import("dart:scalarlist");
8 8
9 void testRequestResponseClientCloses( 9 void testRequestResponseClientCloses(
10 int totalConnections, int closeStatus, String closeReason) { 10 int totalConnections, int closeStatus, String closeReason) {
11 HttpServer server = new HttpServer(); 11 HttpServer server = new HttpServer();
12 HttpClient client = new HttpClient(); 12 HttpClient client = new HttpClient();
13 13
14 server.listen("127.0.0.1", 0, totalConnections); 14 server.listen("127.0.0.1", 0, backlog: totalConnections);
15 15
16 // Create a web socket handler and set is as the HTTP server default 16 // Create a web socket handler and set is as the HTTP server default
17 // handler. 17 // handler.
18 WebSocketHandler wsHandler = new WebSocketHandler(); 18 WebSocketHandler wsHandler = new WebSocketHandler();
19 wsHandler.onOpen = (WebSocketConnection conn) { 19 wsHandler.onOpen = (WebSocketConnection conn) {
20 var count = 0; 20 var count = 0;
21 conn.onMessage = (Object message) => conn.send(message); 21 conn.onMessage = (Object message) => conn.send(message);
22 conn.onClosed = (status, reason) { 22 conn.onClosed = (status, reason) {
23 Expect.equals(closeStatus === null 23 Expect.equals(closeStatus === null
24 ? WebSocketStatus.NO_STATUS_RECEIVED 24 ? WebSocketStatus.NO_STATUS_RECEIVED
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 }; 57 };
58 } 58 }
59 } 59 }
60 60
61 61
62 void testRequestResponseServerCloses( 62 void testRequestResponseServerCloses(
63 int totalConnections, int closeStatus, String closeReason) { 63 int totalConnections, int closeStatus, String closeReason) {
64 HttpServer server = new HttpServer(); 64 HttpServer server = new HttpServer();
65 HttpClient client = new HttpClient(); 65 HttpClient client = new HttpClient();
66 66
67 server.listen("127.0.0.1", 0, totalConnections); 67 server.listen("127.0.0.1", 0, backlog: totalConnections);
68 68
69 // Create a web socket handler and set is as the HTTP server default 69 // Create a web socket handler and set is as the HTTP server default
70 // handler. 70 // handler.
71 int closeCount = 0; 71 int closeCount = 0;
72 WebSocketHandler wsHandler = new WebSocketHandler(); 72 WebSocketHandler wsHandler = new WebSocketHandler();
73 wsHandler.onOpen = (WebSocketConnection conn) { 73 wsHandler.onOpen = (WebSocketConnection conn) {
74 String messageText = "Hello, world!"; 74 String messageText = "Hello, world!";
75 int messageCount = 0; 75 int messageCount = 0;
76 conn.onMessage = (Object message) { 76 conn.onMessage = (Object message) {
77 messageCount++; 77 messageCount++;
(...skipping 30 matching lines...) Expand all
108 Expect.equals(closeReason === null ? "" : closeReason, reason); 108 Expect.equals(closeReason === null ? "" : closeReason, reason);
109 }; 109 };
110 } 110 }
111 } 111 }
112 112
113 113
114 void testMessageLength(int messageLength) { 114 void testMessageLength(int messageLength) {
115 HttpServer server = new HttpServer(); 115 HttpServer server = new HttpServer();
116 HttpClient client = new HttpClient(); 116 HttpClient client = new HttpClient();
117 117
118 server.listen("127.0.0.1", 0, 1); 118 server.listen("127.0.0.1", 0, backlog: 1);
119 119
120 // Create a web socket handler and set is as the HTTP server default 120 // Create a web socket handler and set is as the HTTP server default
121 // handler. 121 // handler.
122 Uint8List originalMessage = new Uint8List(messageLength); 122 Uint8List originalMessage = new Uint8List(messageLength);
123 WebSocketHandler wsHandler = new WebSocketHandler(); 123 WebSocketHandler wsHandler = new WebSocketHandler();
124 wsHandler.onOpen = (WebSocketConnection conn) { 124 wsHandler.onOpen = (WebSocketConnection conn) {
125 conn.onMessage = (Object message) { 125 conn.onMessage = (Object message) {
126 Expect.listEquals(originalMessage, message); 126 Expect.listEquals(originalMessage, message);
127 conn.send(message); 127 conn.send(message);
128 }; 128 };
(...skipping 14 matching lines...) Expand all
143 wsconn.onOpen = () { 143 wsconn.onOpen = () {
144 wsconn.send(originalMessage); 144 wsconn.send(originalMessage);
145 }; 145 };
146 } 146 }
147 147
148 148
149 void testNoUpgrade() { 149 void testNoUpgrade() {
150 HttpServer server = new HttpServer(); 150 HttpServer server = new HttpServer();
151 HttpClient client = new HttpClient(); 151 HttpClient client = new HttpClient();
152 152
153 server.listen("127.0.0.1", 0, 5); 153 server.listen("127.0.0.1", 0, backlog: 5);
154 154
155 // Create a server which always responds with a redirect. 155 // Create a server which always responds with a redirect.
156 server.defaultRequestHandler = (request, response) { 156 server.defaultRequestHandler = (request, response) {
157 response.statusCode = HttpStatus.MOVED_PERMANENTLY; 157 response.statusCode = HttpStatus.MOVED_PERMANENTLY;
158 response.outputStream.close(); 158 response.outputStream.close();
159 }; 159 };
160 160
161 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/"); 161 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
162 conn.followRedirects = false; 162 conn.followRedirects = false;
163 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn); 163 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn);
164 wsconn.onNoUpgrade = (response) { 164 wsconn.onNoUpgrade = (response) {
165 Expect.equals(HttpStatus.MOVED_PERMANENTLY, response.statusCode); 165 Expect.equals(HttpStatus.MOVED_PERMANENTLY, response.statusCode);
166 client.shutdown(); 166 client.shutdown();
167 server.close(); 167 server.close();
168 }; 168 };
169 } 169 }
170 170
171 171
172 void testUsePOST() { 172 void testUsePOST() {
173 HttpServer server = new HttpServer(); 173 HttpServer server = new HttpServer();
174 HttpClient client = new HttpClient(); 174 HttpClient client = new HttpClient();
175 175
176 server.listen("127.0.0.1", 0, 5); 176 server.listen("127.0.0.1", 0, backlog: 5);
177 177
178 // Create a web socket handler and set is as the HTTP server default 178 // Create a web socket handler and set is as the HTTP server default
179 // handler. 179 // handler.
180 int closeCount = 0; 180 int closeCount = 0;
181 WebSocketHandler wsHandler = new WebSocketHandler(); 181 WebSocketHandler wsHandler = new WebSocketHandler();
182 wsHandler.onOpen = (WebSocketConnection conn) { 182 wsHandler.onOpen = (WebSocketConnection conn) {
183 Expect.fail("No connection expected"); 183 Expect.fail("No connection expected");
184 }; 184 };
185 server.defaultRequestHandler = wsHandler.onRequest; 185 server.defaultRequestHandler = wsHandler.onRequest;
186 186
(...skipping 10 matching lines...) Expand all
197 class WebSocketInfo { 197 class WebSocketInfo {
198 int messageCount = 0; 198 int messageCount = 0;
199 } 199 }
200 200
201 201
202 void testHashCode(int totalConnections) { 202 void testHashCode(int totalConnections) {
203 HttpServer server = new HttpServer(); 203 HttpServer server = new HttpServer();
204 HttpClient client = new HttpClient(); 204 HttpClient client = new HttpClient();
205 Map connections = new Map(); 205 Map connections = new Map();
206 206
207 server.listen("127.0.0.1", 0, totalConnections); 207 server.listen("127.0.0.1", 0, backlog: totalConnections);
208 208
209 void handleMessage(conn, message) { 209 void handleMessage(conn, message) {
210 var info = connections[conn]; 210 var info = connections[conn];
211 Expect.isNotNull(info); 211 Expect.isNotNull(info);
212 info.messageCount++; 212 info.messageCount++;
213 if (info.messageCount < 10) { 213 if (info.messageCount < 10) {
214 conn.send(message); 214 conn.send(message);
215 } else { 215 } else {
216 conn.close(); 216 conn.close();
217 } 217 }
(...skipping 27 matching lines...) Expand all
245 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn); 245 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn);
246 wsconn.onMessage = (message) => wsconn.send(message); 246 wsconn.onMessage = (message) => wsconn.send(message);
247 } 247 }
248 } 248 }
249 249
250 250
251 void testW3CInterface( 251 void testW3CInterface(
252 int totalConnections, int closeStatus, String closeReason) { 252 int totalConnections, int closeStatus, String closeReason) {
253 HttpServer server = new HttpServer(); 253 HttpServer server = new HttpServer();
254 254
255 server.listen("127.0.0.1", 0, totalConnections); 255 server.listen("127.0.0.1", 0, backlog: totalConnections);
256 256
257 // Create a web socket handler and set is as the HTTP server default 257 // Create a web socket handler and set is as the HTTP server default
258 // handler. 258 // handler.
259 int closeCount = 0; 259 int closeCount = 0;
260 WebSocketHandler wsHandler = new WebSocketHandler(); 260 WebSocketHandler wsHandler = new WebSocketHandler();
261 wsHandler.onOpen = (WebSocketConnection conn) { 261 wsHandler.onOpen = (WebSocketConnection conn) {
262 String messageText = "Hello, world!"; 262 String messageText = "Hello, world!";
263 int messageCount = 0; 263 int messageCount = 0;
264 conn.onMessage = (Object message) { 264 conn.onMessage = (Object message) {
265 messageCount++; 265 messageCount++;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 testMessageLength(126); 332 testMessageLength(126);
333 testMessageLength(127); 333 testMessageLength(127);
334 testMessageLength(65535); 334 testMessageLength(65535);
335 testMessageLength(65536); 335 testMessageLength(65536);
336 testNoUpgrade(); 336 testNoUpgrade();
337 testUsePOST(); 337 testUsePOST();
338 testHashCode(2); 338 testHashCode(2);
339 339
340 testW3CInterface(2, 3002, "Got tired"); 340 testW3CInterface(2, 3002, "Got tired");
341 } 341 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698