| 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import "dart:convert"; | 6 import "dart:convert"; |
| 7 import "dart:math"; | 7 import "dart:math"; |
| 8 import "dart:async"; | 8 import "dart:async"; |
| 9 import "dart:collection"; | 9 import "dart:collection"; |
| 10 import "dart:typed_data"; | 10 import "dart:typed_data"; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 Function onClosed; | 35 Function onClosed; |
| 36 | 36 |
| 37 WebSocketMessageCollector(Stream stream, | 37 WebSocketMessageCollector(Stream stream, |
| 38 [List<int> this.expectedMessage = null]) { | 38 [List<int> this.expectedMessage = null]) { |
| 39 stream.listen(onMessageData, onDone: onClosed, onError: onError); | 39 stream.listen(onMessageData, onDone: onClosed, onError: onError); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void onMessageData(buffer) { | 42 void onMessageData(buffer) { |
| 43 if (buffer is String) { | 43 if (buffer is String) { |
| 44 buffer = _encodeString(buffer); | 44 buffer = UTF8.encode(buffer); |
| 45 } | 45 } |
| 46 Expect.listEquals(expectedMessage, buffer); | 46 Expect.listEquals(expectedMessage, buffer); |
| 47 messageCount++; | 47 messageCount++; |
| 48 data = buffer; | 48 data = buffer; |
| 49 } | 49 } |
| 50 | 50 |
| 51 void onError(e) { | 51 void onError(e) { |
| 52 String msg = "Unexpected error $e"; | 52 String msg = "Unexpected error $e"; |
| 53 var trace = getAttachedStackTrace(e); | 53 var trace = getAttachedStackTrace(e); |
| 54 if (trace != null) msg += "\nStackTrace: $trace"; | 54 if (trace != null) msg += "\nStackTrace: $trace"; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 true, FRAME_OPCODE_BINARY, null, message, 0, message.length); | 241 true, FRAME_OPCODE_BINARY, null, message, 0, message.length); |
| 242 controller.add(frame); | 242 controller.add(frame); |
| 243 } | 243 } |
| 244 | 244 |
| 245 | 245 |
| 246 void main() { | 246 void main() { |
| 247 testFullMessages(); | 247 testFullMessages(); |
| 248 testFragmentedMessages(); | 248 testFragmentedMessages(); |
| 249 testUnmaskedMessage(); | 249 testUnmaskedMessage(); |
| 250 } | 250 } |
| OLD | NEW |