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

Side by Side 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: Created 5 years, 9 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 unified diff | Download patch
« lib/src/util/io.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, 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 import 'dart:async';
6
7 import 'package:unittest/unittest.dart';
8 import 'package:unittest/src/runner/browser/chrome.dart';
9 import 'package:unittest/src/util/io.dart';
10 import 'package:shelf/shelf.dart' as shelf;
11 import 'package:shelf/shelf_io.dart' as shelf_io;
12 import 'package:shelf_web_socket/shelf_web_socket.dart';
13
14 void main() {
15 group("running JavaScript", () {
16 // The JavaScript to serve in the server. We use actual JavaScript here to
17 // avoid the pain of compiling to JS in a test
18 var javaScript;
19
20 var server;
21 var webSockets;
22 setUp(() {
23 var webSocketsController = new StreamController();
24 webSockets = webSocketsController.stream;
25
26 return shelf_io.serve(new shelf.Cascade()
27 .add(webSocketHandler(webSocketsController.add))
28 .add((request) {
Bob Nystrom 2015/02/27 21:51:40 The nesting gets pretty deep below here. How about
nweiz 2015/02/28 00:42:05 It's only one level of nesting deeper than the bas
29 if (request.url.path == "/") {
30 return new shelf.Response.ok("""
31 <!doctype html>
32 <html>
33 <head>
34 <script src="index.js"></script>
35 </head>
36 </html>
37 """, headers: {'content-type': 'text/html'});
38 } else if (request.url.path == "/index.js") {
39 return new shelf.Response.ok(javaScript,
40 headers: {'content-type': 'application/javascript'});
41 } else {
42 return new shelf.Response.notFound(null);
43 }
44 }).handler, 'localhost', 0).then((server_) {
45 server = server_;
46 });
47 });
48
49 tearDown(() {
50 if (server != null) server.close();
51
52 javaScript = null;
53 server = null;
54 webSockets = null;
55 });
56
57 test("starts Chrome with the given URL", () {
58 javaScript = '''
59 var webSocket = new WebSocket(window.location.href.replace("http://", "ws://"));
60 webSocket.addEventListener("open", function() {
61 webSocket.send("loaded!");
62 });
63 ''';
64 var chrome = new Chrome(baseUrlForAddress(server.address, server.port));
65
66 return webSockets.first.then((webSocket) {
67 return webSocket.first.then(
68 (message) => expect(message, equals("loaded!")));
69 }).whenComplete(chrome.close);
70 });
71
72 test("doesn't preserve state across runs", () {
73 javaScript = '''
74 localStorage.setItem("data", "value");
75
76 var webSocket = new WebSocket(window.location.href.replace("http://", "ws://"));
77 webSocket.addEventListener("open", function() {
78 webSocket.send("done");
79 });
80 ''';
81 var chrome = new Chrome(baseUrlForAddress(server.address, server.port));
82
83 var first = true;
84 webSockets.listen(expectAsync((webSocket) {
85 if (first) {
86 // The first request will set local storage data. We can't kill the
87 // old chrome and start a new one until we're sure that that has
88 // finished.
89 webSocket.first.then((_) {
90 chrome.close();
91
92 javaScript = '''
93 var webSocket = new WebSocket(window.location.href.replace("http://", "ws://"));
94 webSocket.addEventListener("open", function() {
95 webSocket.send(localStorage.getItem("data"));
96 });
97 ''';
98 chrome = new Chrome(baseUrlForAddress(server.address, server.port));
99 first = false;
100 });
101 } else {
102 // The second request will return the local storage data. This should
103 // be null, indicating that no data was saved between runs.
104 expect(
105 webSocket.first
106 .then((message) => expect(message, equals('null')))
107 .whenComplete(chrome.close),
108 completes);
109 }
110 }, count: 2));
111 });
112 });
113
114 test("a process can be killed synchronously after it's started", () {
115 return shelf_io.serve(expectAsync((_) {}, count: 0), 'localhost', 8080)
116 .then((server) {
117 var chrome = new Chrome(baseUrlForAddress(server.address, server.port));
118 return chrome.close().whenComplete(server.close);
119 });
120 });
121
122 test("reports an error in onExit", () {
123 var chrome = new Chrome("http://dart-lang.org",
124 executable: "_does_not_exist");
125 expect(chrome.onExit, throwsA(new isInstanceOf<ProcessException>()));
126 });
127 }
OLDNEW
« lib/src/util/io.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698