Chromium Code Reviews| Index: tests/standalone/src/io/WebSocketTest.dart |
| diff --git a/tests/standalone/src/io/WebSocketTest.dart b/tests/standalone/src/io/WebSocketTest.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b5c394fe164675d6a27b1048b423402c0b07161c |
| --- /dev/null |
| +++ b/tests/standalone/src/io/WebSocketTest.dart |
| @@ -0,0 +1,58 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
|
Mads Ager (google)
2012/04/25 10:41:55
Since this test is not finished yet, maybe you sho
Søren Gjesse
2012/04/25 13:57:14
I will do that.
|
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| +// |
| + |
| +#import("dart:io"); |
| + |
| +class Server { |
| + Server() { |
| + server = new HttpServer(); |
| + server.listen("0.0.0.0", 1234); |
|
Anders Johnsen
2012/04/24 12:20:47
Could you use '0' for port, so we don't conflict w
Søren Gjesse
2012/04/25 13:57:14
Sure - I had the fixed port for testing with Chrom
|
| + port = server.port; |
| + server.onError = (e) { |
| + Expect.fail("No server errors expected: $e"); |
| + }; |
| + } |
| + |
| + void addHandler(Function matcher, handler) { |
| + server.addRequestHandler(matcher, handler); |
| + } |
| + |
| + void set defaultHandler(handler) { |
| + server.defaultRequestHandler = handler; |
| + } |
| + |
| + void close() { |
| + server.close(); |
| + } |
| + |
| + int port; |
| + HttpServer server; |
| +} |
| + |
| +void test() { |
| + Server server = new Server(); |
| + |
| + // Create a web socket handler and set is as the HTTP server default |
| + // handler. |
| + WebSocketHandler wsHandler = new WebSocketHandler(); |
| + wsHandler.onConnection = (WebSocketConnection conn) { |
| + var count = 0; |
| + print("New web socket connection"); |
| + conn.onMessage = (Object message) { |
| + print("Web socket message: [$message]"); |
| + conn.send(message); |
| + count++; |
| + if (count == 4) conn.close(3000, "Bye!"); |
| + }; |
| + conn.onClosed = |
| + (int status, String reason) => print("Closing $status $reason"); |
| + conn.onError = (e) => print("Web socket error $e"); |
| + }; |
| + server.defaultHandler = wsHandler.onRequest; |
| +} |
| + |
| +main() { |
| + test(); |
| +} |