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

Unified Diff: tests/standalone/io/web_socket_pipe_test.dart

Issue 23507003: Fix piping to a WebSocket (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/websocket_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/web_socket_pipe_test.dart
diff --git a/tests/standalone/io/web_socket_pipe_test.dart b/tests/standalone/io/web_socket_pipe_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9c1bbac914abbbaa41e1d360cab4040a69830ac8
--- /dev/null
+++ b/tests/standalone/io/web_socket_pipe_test.dart
@@ -0,0 +1,73 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// 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.
+//
+// VMOptions=
+// VMOptions=--short_socket_read
+// VMOptions=--short_socket_write
+// VMOptions=--short_socket_read --short_socket_write
+
+import "package:expect/expect.dart";
+import "dart:async";
+import "dart:io";
+
+class IdentityTransformer extends StreamEventTransformer {
+ void handleData(data, sink) => sink.add(data);
+}
+
+class ReverseStringTransformer extends StreamEventTransformer {
+ void handleData(String data, sink) {
+ var sb = new StringBuffer();
+ for (int i = data.length - 1; i >= 0; i--) sb.write(data[i]);
+ sink.add(sb.toString());
+ }
+}
+
+testPipe({int messages, bool transform}) {
+ HttpServer.bind("127.0.0.1", 0).then((server) {
+ server.listen((request) {
+ WebSocketTransformer.upgrade(request).then((websocket) {
+ Future done;
Bill Hesse 2013/09/02 08:38:10 Indentation, and why not: (transform ? websocket.
+ if (transform) {
+ done = websocket
+ .transform(new ReverseStringTransformer())
+ .pipe(websocket);
+ } else {
+ done = websocket.pipe(websocket);
+ }
+ done.then((_) => server.close());
+ });
+ });
+ WebSocket.connect("ws://localhost:${server.port}/").then((client) {
+ var count = 0;
+ next() {
+ if (count < messages) {
+ client.add("Hello");
+ } else {
+ client.close();
+ }
+ }
+
+ next();
+ client.listen((data) {
+ count++;
Bill Hesse 2013/09/02 08:38:10 Indentation should be 2.
+ if (transform) {
+ Expect.equals("olleH", data);
+ } else {
+ Expect.equals("Hello", data);
+ }
+ next();
+ },
+ onDone: () => print("Client received close"));
+ });
+ });
+}
+
+void main() {
+ testPipe(messages: 0, transform: false);
+ testPipe(messages: 0, transform: true);
+ testPipe(messages: 1, transform: false);
+ testPipe(messages: 1, transform: true);
+ testPipe(messages: 10, transform: false);
+ testPipe(messages: 10, transform: true);
+}
« no previous file with comments | « sdk/lib/io/websocket_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698