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

Unified Diff: test/browser/chrome_test.dart

Issue 958423002: Add a class to start and stop a Chrome process. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Code review changes Created 5 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 | « pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/browser/chrome_test.dart
diff --git a/test/browser/chrome_test.dart b/test/browser/chrome_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9393d9194115ace58486af6e6603c8f73ac68a30
--- /dev/null
+++ b/test/browser/chrome_test.dart
@@ -0,0 +1,131 @@
+// Copyright (c) 2015, 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.
+
+import 'dart:async';
+
+import 'package:unittest/unittest.dart';
+import 'package:unittest/src/runner/browser/chrome.dart';
+import 'package:unittest/src/util/io.dart';
+import 'package:shelf/shelf.dart' as shelf;
+import 'package:shelf/shelf_io.dart' as shelf_io;
+import 'package:shelf_web_socket/shelf_web_socket.dart';
+
+void main() {
+ group("running JavaScript", () {
+ // The JavaScript to serve in the server. We use actual JavaScript here to
+ // avoid the pain of compiling to JS in a test
+ var javaScript;
+
+ var servePage = (request) {
Bob Nystrom 2015/02/28 01:02:44 servePage(request) { ... Does this close over any
nweiz 2015/03/02 22:31:18 It closes over [javaScript].
+ if (request.url.path == "/") {
+ return new shelf.Response.ok("""
+<!doctype html>
+<html>
+<head>
+ <script src="index.js"></script>
+</head>
+</html>
+""", headers: {'content-type': 'text/html'});
+ } else if (request.url.path == "/index.js") {
+ return new shelf.Response.ok(javaScript,
+ headers: {'content-type': 'application/javascript'});
+ } else {
+ return new shelf.Response.notFound(null);
+ }
+ };
+
+ var server;
+ var webSockets;
+ setUp(() {
+ var webSocketsController = new StreamController();
+ webSockets = webSocketsController.stream;
+
+ return shelf_io.serve(
+ new shelf.Cascade()
+ .add(webSocketHandler(webSocketsController.add))
+ .add(servePage).handler,
+ 'localhost', 0).then((server_) {
+ server = server_;
+ });
+ });
+
+ tearDown(() {
+ if (server != null) server.close();
+
+ javaScript = null;
+ server = null;
+ webSockets = null;
+ });
+
+ test("starts Chrome with the given URL", () {
+ javaScript = '''
+var webSocket = new WebSocket(window.location.href.replace("http://", "ws://"));
+webSocket.addEventListener("open", function() {
+ webSocket.send("loaded!");
+});
+''';
+ var chrome = new Chrome(baseUrlForAddress(server.address, server.port));
+
+ return webSockets.first.then((webSocket) {
+ return webSocket.first.then(
+ (message) => expect(message, equals("loaded!")));
+ }).whenComplete(chrome.close);
+ });
+
+ test("doesn't preserve state across runs", () {
+ javaScript = '''
+localStorage.setItem("data", "value");
+
+var webSocket = new WebSocket(window.location.href.replace("http://", "ws://"));
+webSocket.addEventListener("open", function() {
+ webSocket.send("done");
+});
+''';
+ var chrome = new Chrome(baseUrlForAddress(server.address, server.port));
+
+ var first = true;
+ webSockets.listen(expectAsync((webSocket) {
+ if (first) {
+ // The first request will set local storage data. We can't kill the
+ // old chrome and start a new one until we're sure that that has
+ // finished.
+ webSocket.first.then((_) {
+ chrome.close();
+
+ javaScript = '''
+var webSocket = new WebSocket(window.location.href.replace("http://", "ws://"));
+webSocket.addEventListener("open", function() {
+ webSocket.send(localStorage.getItem("data"));
+});
+''';
+ chrome = new Chrome(baseUrlForAddress(server.address, server.port));
+ first = false;
+ });
+ } else {
+ // The second request will return the local storage data. This should
+ // be null, indicating that no data was saved between runs.
+ expect(
+ webSocket.first
+ .then((message) => expect(message, equals('null')))
+ .whenComplete(chrome.close),
+ completes);
+ }
+ }, count: 2));
+ });
+ });
+
+ test("a process can be killed synchronously after it's started", () {
+ return shelf_io.serve(expectAsync((_) {}, count: 0), 'localhost', 8080)
+ .then((server) {
+ var chrome = new Chrome(baseUrlForAddress(server.address, server.port));
+ return chrome.close().whenComplete(server.close);
+ });
+ });
+
+ test("reports an error in onExit", () {
+ var chrome = new Chrome("http://dart-lang.org",
+ executable: "_does_not_exist");
+ expect(chrome.onExit, throwsA(new isInstanceOf<ProcessException>()));
+ });
+}
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698