Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 // | |
| 5 // VMOptions= | |
| 6 // VMOptions=--short_socket_read | |
| 7 // VMOptions=--short_socket_write | |
| 8 // VMOptions=--short_socket_read --short_socket_write | |
| 9 | |
| 10 import "package:expect/expect.dart"; | |
| 11 import "dart:async"; | |
| 12 import "dart:io"; | |
| 13 | |
| 14 class IdentityTransformer extends StreamEventTransformer { | |
| 15 void handleData(data, sink) => sink.add(data); | |
| 16 } | |
| 17 | |
| 18 class ReverseStringTransformer extends StreamEventTransformer { | |
| 19 void handleData(String data, sink) { | |
| 20 var sb = new StringBuffer(); | |
| 21 for (int i = data.length - 1; i >= 0; i--) sb.write(data[i]); | |
| 22 sink.add(sb.toString()); | |
| 23 } | |
| 24 } | |
| 25 | |
| 26 testPipe({int messages, bool transform}) { | |
| 27 HttpServer.bind("127.0.0.1", 0).then((server) { | |
| 28 server.listen((request) { | |
| 29 WebSocketTransformer.upgrade(request).then((websocket) { | |
| 30 Future done; | |
|
Bill Hesse
2013/09/02 08:38:10
Indentation, and why not:
(transform ? websocket.
| |
| 31 if (transform) { | |
| 32 done = websocket | |
| 33 .transform(new ReverseStringTransformer()) | |
| 34 .pipe(websocket); | |
| 35 } else { | |
| 36 done = websocket.pipe(websocket); | |
| 37 } | |
| 38 done.then((_) => server.close()); | |
| 39 }); | |
| 40 }); | |
| 41 WebSocket.connect("ws://localhost:${server.port}/").then((client) { | |
| 42 var count = 0; | |
| 43 next() { | |
| 44 if (count < messages) { | |
| 45 client.add("Hello"); | |
| 46 } else { | |
| 47 client.close(); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 next(); | |
| 52 client.listen((data) { | |
| 53 count++; | |
|
Bill Hesse
2013/09/02 08:38:10
Indentation should be 2.
| |
| 54 if (transform) { | |
| 55 Expect.equals("olleH", data); | |
| 56 } else { | |
| 57 Expect.equals("Hello", data); | |
| 58 } | |
| 59 next(); | |
| 60 }, | |
| 61 onDone: () => print("Client received close")); | |
| 62 }); | |
| 63 }); | |
| 64 } | |
| 65 | |
| 66 void main() { | |
| 67 testPipe(messages: 0, transform: false); | |
| 68 testPipe(messages: 0, transform: true); | |
| 69 testPipe(messages: 1, transform: false); | |
| 70 testPipe(messages: 1, transform: true); | |
| 71 testPipe(messages: 10, transform: false); | |
| 72 testPipe(messages: 10, transform: true); | |
| 73 } | |
| OLD | NEW |