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

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

Issue 10907047: Use onClosed instead of onError in the WebSocket classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Review update. Created 8 years, 3 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
« no previous file with comments | « runtime/bin/websocket_impl.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7
8 void testRequestResponseClientCloses( 8 void testRequestResponseClientCloses(
9 int totalConnections, int closeStatus, String closeReason) { 9 int totalConnections, int closeStatus, String closeReason) {
10 HttpServer server = new HttpServer(); 10 HttpServer server = new HttpServer();
11 HttpClient client = new HttpClient(); 11 HttpClient client = new HttpClient();
12 12
13 server.listen("127.0.0.1", 0, totalConnections); 13 server.listen("127.0.0.1", 0, totalConnections);
14 14
15 // Create a web socket handler and set is as the HTTP server default 15 // Create a web socket handler and set is as the HTTP server default
16 // handler. 16 // handler.
17 WebSocketHandler wsHandler = new WebSocketHandler(); 17 WebSocketHandler wsHandler = new WebSocketHandler();
18 wsHandler.onOpen = (WebSocketConnection conn) { 18 wsHandler.onOpen = (WebSocketConnection conn) {
19 var count = 0; 19 var count = 0;
20 conn.onMessage = (Object message) => conn.send(message); 20 conn.onMessage = (Object message) => conn.send(message);
21 conn.onClosed = (status, reason) { 21 conn.onClosed = (status, reason) {
22 Expect.equals(closeStatus, status); 22 Expect.equals(closeStatus === null ? 1005 : closeStatus, status);
23 Expect.equals(closeReason, reason); 23 Expect.equals(closeReason === null ? "" : closeReason, reason);
24 }; 24 };
25 }; 25 };
26 server.defaultRequestHandler = wsHandler.onRequest; 26 server.defaultRequestHandler = wsHandler.onRequest;
27 27
28 int closeCount = 0; 28 int closeCount = 0;
29 String messageText = "Hello, world!"; 29 String messageText = "Hello, world!";
30 for (int i = 0; i < totalConnections; i++) { 30 for (int i = 0; i < totalConnections; i++) {
31 int messageCount = 0; 31 int messageCount = 0;
32 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/"); 32 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
33 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn); 33 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn);
34 wsconn.onOpen = () => wsconn.send(messageText); 34 wsconn.onOpen = () => wsconn.send(messageText);
35 wsconn.onMessage = (message) { 35 wsconn.onMessage = (message) {
36 messageCount++; 36 messageCount++;
37 if (messageCount < 10) { 37 if (messageCount < 10) {
38 Expect.equals(messageText, message); 38 Expect.equals(messageText, message);
39 wsconn.send(message); 39 wsconn.send(message);
40 } else { 40 } else {
41 wsconn.close(closeStatus, closeReason); 41 wsconn.close(closeStatus, closeReason);
42 } 42 }
43 }; 43 };
44 wsconn.onClosed = (status, reason) { 44 wsconn.onClosed = (status, reason) {
45 Expect.equals(closeStatus, status); 45 Expect.equals(closeStatus === null ? 1005 : closeStatus, status);
46 Expect.isNull(reason); 46 Expect.equals("", reason);
47 closeCount++; 47 closeCount++;
48 if (closeCount == totalConnections) { 48 if (closeCount == totalConnections) {
49 client.shutdown(); 49 client.shutdown();
50 server.close(); 50 server.close();
51 } 51 }
52 }; 52 };
53 } 53 }
54 } 54 }
55 55
56 56
(...skipping 14 matching lines...) Expand all
71 conn.onMessage = (Object message) { 71 conn.onMessage = (Object message) {
72 messageCount++; 72 messageCount++;
73 if (messageCount < 10) { 73 if (messageCount < 10) {
74 Expect.equals(messageText, message); 74 Expect.equals(messageText, message);
75 conn.send(message); 75 conn.send(message);
76 } else { 76 } else {
77 conn.close(closeStatus, closeReason); 77 conn.close(closeStatus, closeReason);
78 } 78 }
79 }; 79 };
80 conn.onClosed = (status, reason) { 80 conn.onClosed = (status, reason) {
81 Expect.equals(closeStatus, status); 81 Expect.equals(closeStatus === null ? 1005 : closeStatus, status);
82 Expect.isNull(reason); 82 Expect.equals("", reason);
83 closeCount++; 83 closeCount++;
84 if (closeCount == totalConnections) { 84 if (closeCount == totalConnections) {
85 client.shutdown(); 85 client.shutdown();
86 server.close(); 86 server.close();
87 } 87 }
88 }; 88 };
89 conn.send(messageText); 89 conn.send(messageText);
90 }; 90 };
91 server.defaultRequestHandler = wsHandler.onRequest; 91 server.defaultRequestHandler = wsHandler.onRequest;
92 92
93 for (int i = 0; i < totalConnections; i++) { 93 for (int i = 0; i < totalConnections; i++) {
94 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/"); 94 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/");
95 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn); 95 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn);
96 wsconn.onMessage = (message) => wsconn.send(message); 96 wsconn.onMessage = (message) => wsconn.send(message);
97 wsconn.onClosed = (status, reason) { 97 wsconn.onClosed = (status, reason) {
98 Expect.equals(closeStatus, status); 98 Expect.equals(closeStatus === null ? 1005 : closeStatus, status);
99 Expect.equals(closeReason, reason); 99 Expect.equals(closeReason === null ? "" : closeReason, reason);
100 }; 100 };
101 } 101 }
102 } 102 }
103 103
104 104
105 void testMessageLength(int messageLength) { 105 void testMessageLength(int messageLength) {
106 HttpServer server = new HttpServer(); 106 HttpServer server = new HttpServer();
107 HttpClient client = new HttpClient(); 107 HttpClient client = new HttpClient();
108 108
109 server.listen("127.0.0.1", 0, 1); 109 server.listen("127.0.0.1", 0, 1);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 messageCount++; 256 messageCount++;
257 if (messageCount < 10) { 257 if (messageCount < 10) {
258 Expect.equals(messageText, message); 258 Expect.equals(messageText, message);
259 conn.send(message); 259 conn.send(message);
260 } else { 260 } else {
261 conn.close(closeStatus, closeReason); 261 conn.close(closeStatus, closeReason);
262 } 262 }
263 }; 263 };
264 conn.onClosed = (status, reason) { 264 conn.onClosed = (status, reason) {
265 Expect.equals(closeStatus, status); 265 Expect.equals(closeStatus, status);
266 Expect.isNull(reason); 266 Expect.equals("", reason);
267 closeCount++; 267 closeCount++;
268 if (closeCount == totalConnections) { 268 if (closeCount == totalConnections) {
269 server.close(); 269 server.close();
270 } 270 }
271 }; 271 };
272 conn.send(messageText); 272 conn.send(messageText);
273 }; 273 };
274 server.defaultRequestHandler = wsHandler.onRequest; 274 server.defaultRequestHandler = wsHandler.onRequest;
275 275
276 void webSocketConnection() { 276 void webSocketConnection() {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 testMessageLength(126); 323 testMessageLength(126);
324 testMessageLength(127); 324 testMessageLength(127);
325 testMessageLength(65535); 325 testMessageLength(65535);
326 testMessageLength(65536); 326 testMessageLength(65536);
327 testNoUpgrade(); 327 testNoUpgrade();
328 testUsePOST(); 328 testUsePOST();
329 testHashCode(2); 329 testHashCode(2);
330 330
331 testW3CInterface(2, 3002, "Got tired"); 331 testW3CInterface(2, 3002, "Got tired");
332 } 332 }
OLDNEW
« no previous file with comments | « runtime/bin/websocket_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698