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

Unified Diff: test/html_test.dart

Issue 1747113003: Add an HTML implementation of WebSocketChannel. (Closed) Base URL: git@github.com:dart-lang/web_socket_channel.git@master
Patch Set: Code review changes Created 4 years, 10 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 | « lib/html.dart ('k') | test/html_test_server.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/html_test.dart
diff --git a/test/html_test.dart b/test/html_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f5c355506ddf9d3e3fdd9fb424b212214e4720dd
--- /dev/null
+++ b/test/html_test.dart
@@ -0,0 +1,92 @@
+// Copyright (c) 2016, 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.
+
+@TestOn('browser')
+@Skip(
+ "This suite requires a WebSocket server, which is currently unsupported\n"
+ "by the test package (dart-lang/test#330). It's currently set up to talk\n"
+ "to a hard-coded server on localhost:1234 that is spawned in \n"
+ "html_test_server.dart.")
+
+import 'dart:async';
+import 'dart:html';
+import 'dart:typed_data';
+
+import 'package:async/async.dart';
+import 'package:test/test.dart';
+
+import 'package:web_socket_channel/html.dart';
+
+void main() {
+ var channel;
+ tearDown(() {
+ if (channel != null) channel.sink.close();
+ });
+
+ test("communicates using an existing WebSocket", () async {
+ var webSocket = new WebSocket("ws://localhost:1234");
+ channel = new HtmlWebSocketChannel(webSocket);
+
+ var queue = new StreamQueue(channel.stream);
+ channel.sink.add("foo");
+ expect(await queue.next, equals("foo"));
+
+ channel.sink.add(new Uint8List.fromList([1, 2, 3, 4, 5]));
+ expect(await _decodeBlob(await queue.next), equals([1, 2, 3, 4, 5]));
+
+ webSocket.binaryType = "arraybuffer";
+ channel.sink.add(new Uint8List.fromList([1, 2, 3, 4, 5]));
+ expect(await queue.next, equals([1, 2, 3, 4, 5]));
+ });
+
+ test("communicates using an existing open WebSocket", () async {
+ var webSocket = new WebSocket("ws://localhost:1234");
+ await webSocket.onOpen.first;
+
+ channel = new HtmlWebSocketChannel(webSocket);
+
+ var queue = new StreamQueue(channel.stream);
+ channel.sink.add("foo");
+ expect(await queue.next, equals("foo"));
+ });
+
+ test(".connect defaults to binary lists", () async {
+ channel = new HtmlWebSocketChannel.connect("ws://localhost:1234");
+
+ var queue = new StreamQueue(channel.stream);
+ channel.sink.add("foo");
+ expect(await queue.next, equals("foo"));
+
+ channel.sink.add(new Uint8List.fromList([1, 2, 3, 4, 5]));
+ expect(await queue.next, equals([1, 2, 3, 4, 5]));
+ });
+
+ test(".connect can use blobs", () async {
+ channel = new HtmlWebSocketChannel.connect(
+ "ws://localhost:1234", binaryType: BinaryType.blob);
+
+ var queue = new StreamQueue(channel.stream);
+ channel.sink.add("foo");
+ expect(await queue.next, equals("foo"));
+
+ channel.sink.add(new Uint8List.fromList([1, 2, 3, 4, 5]));
+ expect(await _decodeBlob(await queue.next), equals([1, 2, 3, 4, 5]));
+ });
+
+ test(".connect wraps a connection error in WebSocketChannelException",
+ () async {
+ // TODO(nweiz): Make this channel use a port number that's guaranteed to be
+ // invalid.
+ var channel = new HtmlWebSocketChannel.connect("ws://localhost:1235");
+ expect(channel.stream.toList(),
+ throwsA(new isInstanceOf<WebSocketChannelException>()));
+ });
+}
+
+Future<List<int>> _decodeBlob(Blob blob) async {
+ var reader = new FileReader();
+ reader.readAsArrayBuffer(blob);
+ await reader.onLoad.first;
+ return reader.result;
+}
« no previous file with comments | « lib/html.dart ('k') | test/html_test_server.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698