| 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(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, status); |
| 99 Expect.equals(closeReason, reason); | 99 Expect.equals(closeReason, reason); |
| 100 }; | 100 }; |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 | 104 |
| 105 void testMessageLength(int messageLength) { |
| 106 HttpServer server = new HttpServer(); |
| 107 HttpClient client = new HttpClient(); |
| 108 |
| 109 server.listen("127.0.0.1", 0, 1); |
| 110 |
| 111 // Create a web socket handler and set is as the HTTP server default |
| 112 // handler. |
| 113 String originalMessage = ""; |
| 114 for (int i = 0; i < messageLength; i++) originalMessage += "${i % 10}"; |
| 115 WebSocketHandler wsHandler = new WebSocketHandler(); |
| 116 wsHandler.onOpen = (WebSocketConnection conn) { |
| 117 conn.onMessage = (Object message) { |
| 118 Expect.equals(originalMessage, message); |
| 119 conn.send(message); |
| 120 }; |
| 121 conn.onClosed = (status, reason) { |
| 122 }; |
| 123 }; |
| 124 server.defaultRequestHandler = wsHandler.onRequest; |
| 125 |
| 126 HttpClientConnection conn = client.get("127.0.0.1", server.port, "/"); |
| 127 WebSocketClientConnection wsconn = new WebSocketClientConnection(conn); |
| 128 wsconn.onMessage = (message) { |
| 129 Expect.equals(originalMessage, message); |
| 130 wsconn.close(); |
| 131 }; |
| 132 wsconn.onClosed = (status, reason) { |
| 133 server.close(); |
| 134 }; |
| 135 wsconn.onOpen = () { |
| 136 wsconn.send(originalMessage); |
| 137 }; |
| 138 } |
| 139 |
| 140 |
| 105 void testNoUpgrade() { | 141 void testNoUpgrade() { |
| 106 HttpServer server = new HttpServer(); | 142 HttpServer server = new HttpServer(); |
| 107 HttpClient client = new HttpClient(); | 143 HttpClient client = new HttpClient(); |
| 108 | 144 |
| 109 server.listen("127.0.0.1", 0, 5); | 145 server.listen("127.0.0.1", 0, 5); |
| 110 | 146 |
| 111 // Create a server which always responds with a redirect. | 147 // Create a server which always responds with a redirect. |
| 112 server.defaultRequestHandler = (request, response) { | 148 server.defaultRequestHandler = (request, response) { |
| 113 response.statusCode = HttpStatus.MOVED_PERMANENTLY; | 149 response.statusCode = HttpStatus.MOVED_PERMANENTLY; |
| 114 response.outputStream.close(); | 150 response.outputStream.close(); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 } | 313 } |
| 278 | 314 |
| 279 | 315 |
| 280 main() { | 316 main() { |
| 281 testRequestResponseClientCloses(2, null, null); | 317 testRequestResponseClientCloses(2, null, null); |
| 282 testRequestResponseClientCloses(2, 3001, null); | 318 testRequestResponseClientCloses(2, 3001, null); |
| 283 testRequestResponseClientCloses(2, 3002, "Got tired"); | 319 testRequestResponseClientCloses(2, 3002, "Got tired"); |
| 284 testRequestResponseServerCloses(2, null, null); | 320 testRequestResponseServerCloses(2, null, null); |
| 285 testRequestResponseServerCloses(2, 3001, null); | 321 testRequestResponseServerCloses(2, 3001, null); |
| 286 testRequestResponseServerCloses(2, 3002, "Got tired"); | 322 testRequestResponseServerCloses(2, 3002, "Got tired"); |
| 323 testMessageLength(125); |
| 324 testMessageLength(126); |
| 325 testMessageLength(127); |
| 326 testMessageLength(65535); |
| 327 testMessageLength(65536); |
| 287 testNoUpgrade(); | 328 testNoUpgrade(); |
| 288 testUsePOST(); | 329 testUsePOST(); |
| 289 testHashCode(2); | 330 testHashCode(2); |
| 290 | 331 |
| 291 testW3CInterface(2, 3002, "Got tired"); | 332 testW3CInterface(2, 3002, "Got tired"); |
| 292 } | 333 } |
| OLD | NEW |