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

Unified Diff: mojo/public/dart/third_party/http_parser/test/web_socket_test.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
Index: mojo/public/dart/third_party/http_parser/test/web_socket_test.dart
diff --git a/mojo/public/dart/third_party/http_parser/test/web_socket_test.dart b/mojo/public/dart/third_party/http_parser/test/web_socket_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..61bf0cc8214c40f6df0510ed22790c826ca2e846
--- /dev/null
+++ b/mojo/public/dart/third_party/http_parser/test/web_socket_test.dart
@@ -0,0 +1,99 @@
+// Copyright (c) 2014, 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('vm')
+
+library http_parser.web_socket_test;
+
+import 'dart:io';
+
+import 'package:http_parser/http_parser.dart';
+import 'package:test/test.dart';
+
+void main() {
+ test("a client can communicate with a WebSocket server", () {
+ return HttpServer.bind("localhost", 0).then((server) {
+ server.transform(new WebSocketTransformer()).listen((webSocket) {
+ webSocket.add("hello!");
+ webSocket.listen((request) {
+ expect(request, equals("ping"));
+ webSocket.add("pong");
+ webSocket.close();
+ });
+ });
+
+ var client = new HttpClient();
+ return client
+ .openUrl("GET", Uri.parse("http://localhost:${server.port}"))
+ .then((request) {
+ request.headers
+ ..set("Connection", "Upgrade")
+ ..set("Upgrade", "websocket")
+ ..set("Sec-WebSocket-Key", "x3JJHMbDL1EzLkh9GBhXDw==")
+ ..set("Sec-WebSocket-Version", "13");
+ return request.close();
+ }).then((response) => response.detachSocket()).then((socket) {
+ var webSocket = new CompatibleWebSocket(socket, serverSide: false);
+
+ var n = 0;
+ return webSocket.listen((message) {
+ if (n == 0) {
+ expect(message, equals("hello!"));
+ webSocket.add("ping");
+ } else if (n == 1) {
+ expect(message, equals("pong"));
+ webSocket.close();
+ server.close();
+ } else {
+ fail("Only expected two messages.");
+ }
+ n++;
+ }).asFuture();
+ });
+ });
+ });
+
+ test("a server can communicate with a WebSocket client", () {
+ return HttpServer.bind("localhost", 0).then((server) {
+ server.listen((request) {
+ var response = request.response;
+ response.statusCode = 101;
+ response.headers
+ ..set("Connection", "Upgrade")
+ ..set("Upgrade", "websocket")
+ ..set("Sec-WebSocket-Accept", CompatibleWebSocket
+ .signKey(request.headers.value('Sec-WebSocket-Key')));
+ response.contentLength = 0;
+ response.detachSocket().then((socket) {
+ var webSocket = new CompatibleWebSocket(socket);
+ webSocket.add("hello!");
+ webSocket.first.then((request) {
+ expect(request, equals("ping"));
+ webSocket.add("pong");
+ webSocket.close();
+ });
+ });
+ });
+
+ return WebSocket
+ .connect('ws://localhost:${server.port}')
+ .then((webSocket) {
+ var n = 0;
+ return webSocket.listen((message) {
+ if (n == 0) {
+ expect(message, equals("hello!"));
+ webSocket.add("ping");
+ } else if (n == 1) {
+ expect(message, equals("pong"));
+ webSocket.close();
+ server.close();
+ } else {
+ fail("Only expected two messages.");
+ }
+ n++;
+ }).asFuture();
+ });
+ });
+ });
+}
« no previous file with comments | « mojo/public/dart/third_party/http_parser/test/media_type_test.dart ('k') | mojo/public/dart/third_party/logging/.gitignore » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698