| OLD | NEW |
| 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 === null ? 1005 : closeStatus, status); | 22 Expect.equals(closeStatus === null |
| 23 ? WebSocketStatus.NO_STATUS_RECEIVED |
| 24 : closeStatus, status); |
| 23 Expect.equals(closeReason === null ? "" : closeReason, reason); | 25 Expect.equals(closeReason === null ? "" : closeReason, reason); |
| 24 }; | 26 }; |
| 25 }; | 27 }; |
| 26 server.defaultRequestHandler = wsHandler.onRequest; | 28 server.defaultRequestHandler = wsHandler.onRequest; |
| 27 | 29 |
| 28 int closeCount = 0; | 30 int closeCount = 0; |
| 29 String messageText = "Hello, world!"; | 31 String messageText = "Hello, world!"; |
| 30 for (int i = 0; i < totalConnections; i++) { | 32 for (int i = 0; i < totalConnections; i++) { |
| 31 int messageCount = 0; | 33 int messageCount = 0; |
| 32 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/"); | 34 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/"); |
| 33 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn); | 35 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn); |
| 34 wsconn.onOpen = () => wsconn.send(messageText); | 36 wsconn.onOpen = () => wsconn.send(messageText); |
| 35 wsconn.onMessage = (message) { | 37 wsconn.onMessage = (message) { |
| 36 messageCount++; | 38 messageCount++; |
| 37 if (messageCount < 10) { | 39 if (messageCount < 10) { |
| 38 Expect.equals(messageText, message); | 40 Expect.equals(messageText, message); |
| 39 wsconn.send(message); | 41 wsconn.send(message); |
| 40 } else { | 42 } else { |
| 41 wsconn.close(closeStatus, closeReason); | 43 wsconn.close(closeStatus, closeReason); |
| 42 } | 44 } |
| 43 }; | 45 }; |
| 44 wsconn.onClosed = (status, reason) { | 46 wsconn.onClosed = (status, reason) { |
| 45 Expect.equals(closeStatus === null ? 1005 : closeStatus, status); | 47 Expect.equals(closeStatus === null |
| 48 ? WebSocketStatus.NO_STATUS_RECEIVED |
| 49 : closeStatus, status); |
| 46 Expect.equals("", reason); | 50 Expect.equals("", reason); |
| 47 closeCount++; | 51 closeCount++; |
| 48 if (closeCount == totalConnections) { | 52 if (closeCount == totalConnections) { |
| 49 client.shutdown(); | 53 client.shutdown(); |
| 50 server.close(); | 54 server.close(); |
| 51 } | 55 } |
| 52 }; | 56 }; |
| 53 } | 57 } |
| 54 } | 58 } |
| 55 | 59 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 71 conn.onMessage = (Object message) { | 75 conn.onMessage = (Object message) { |
| 72 messageCount++; | 76 messageCount++; |
| 73 if (messageCount < 10) { | 77 if (messageCount < 10) { |
| 74 Expect.equals(messageText, message); | 78 Expect.equals(messageText, message); |
| 75 conn.send(message); | 79 conn.send(message); |
| 76 } else { | 80 } else { |
| 77 conn.close(closeStatus, closeReason); | 81 conn.close(closeStatus, closeReason); |
| 78 } | 82 } |
| 79 }; | 83 }; |
| 80 conn.onClosed = (status, reason) { | 84 conn.onClosed = (status, reason) { |
| 81 Expect.equals(closeStatus === null ? 1005 : closeStatus, status); | 85 Expect.equals(closeStatus === null |
| 86 ? WebSocketStatus.NO_STATUS_RECEIVED |
| 87 : closeStatus, status); |
| 82 Expect.equals("", reason); | 88 Expect.equals("", reason); |
| 83 closeCount++; | 89 closeCount++; |
| 84 if (closeCount == totalConnections) { | 90 if (closeCount == totalConnections) { |
| 85 client.shutdown(); | 91 client.shutdown(); |
| 86 server.close(); | 92 server.close(); |
| 87 } | 93 } |
| 88 }; | 94 }; |
| 89 conn.send(messageText); | 95 conn.send(messageText); |
| 90 }; | 96 }; |
| 91 server.defaultRequestHandler = wsHandler.onRequest; | 97 server.defaultRequestHandler = wsHandler.onRequest; |
| 92 | 98 |
| 93 for (int i = 0; i < totalConnections; i++) { | 99 for (int i = 0; i < totalConnections; i++) { |
| 94 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/"); | 100 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/"); |
| 95 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn); | 101 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn); |
| 96 wsconn.onMessage = (message) => wsconn.send(message); | 102 wsconn.onMessage = (message) => wsconn.send(message); |
| 97 wsconn.onClosed = (status, reason) { | 103 wsconn.onClosed = (status, reason) { |
| 98 Expect.equals(closeStatus === null ? 1005 : closeStatus, status); | 104 Expect.equals(closeStatus === null |
| 105 ? WebSocketStatus.NO_STATUS_RECEIVED |
| 106 : closeStatus, status); |
| 99 Expect.equals(closeReason === null ? "" : closeReason, reason); | 107 Expect.equals(closeReason === null ? "" : closeReason, reason); |
| 100 }; | 108 }; |
| 101 } | 109 } |
| 102 } | 110 } |
| 103 | 111 |
| 104 | 112 |
| 105 void testMessageLength(int messageLength) { | 113 void testMessageLength(int messageLength) { |
| 106 HttpServer server = new HttpServer(); | 114 HttpServer server = new HttpServer(); |
| 107 HttpClient client = new HttpClient(); | 115 HttpClient client = new HttpClient(); |
| 108 | 116 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 testMessageLength(126); | 331 testMessageLength(126); |
| 324 testMessageLength(127); | 332 testMessageLength(127); |
| 325 testMessageLength(65535); | 333 testMessageLength(65535); |
| 326 testMessageLength(65536); | 334 testMessageLength(65536); |
| 327 testNoUpgrade(); | 335 testNoUpgrade(); |
| 328 testUsePOST(); | 336 testUsePOST(); |
| 329 testHashCode(2); | 337 testHashCode(2); |
| 330 | 338 |
| 331 testW3CInterface(2, 3002, "Got tired"); | 339 testW3CInterface(2, 3002, "Got tired"); |
| 332 } | 340 } |
| OLD | NEW |