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

Side by Side Diff: test/runner/browser/content_shell_test.dart

Issue 1080193002: Add content shell support. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « lib/src/runner/browser/static/host.dart.js.map ('k') | test/runner/browser/runner_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 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 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 @TestOn("vm") 5 @TestOn("vm")
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:shelf/shelf.dart' as shelf; 10 import 'package:shelf/shelf.dart' as shelf;
11 import 'package:shelf/shelf_io.dart' as shelf_io; 11 import 'package:shelf/shelf_io.dart' as shelf_io;
12 import 'package:shelf_web_socket/shelf_web_socket.dart'; 12 import 'package:shelf_web_socket/shelf_web_socket.dart';
13 import 'package:test/src/runner/browser/dartium.dart'; 13 import 'package:test/src/runner/browser/content_shell.dart';
14 import 'package:test/src/util/io.dart'; 14 import 'package:test/src/util/io.dart';
15 import 'package:test/src/utils.dart'; 15 import 'package:test/src/utils.dart';
16 import 'package:test/test.dart'; 16 import 'package:test/test.dart';
17 17
18 void main() { 18 void main() {
19 group("running Dart", () { 19 group("running Dart", () {
20 // The Dart to serve in the server. 20 // The Dart to serve in the server.
21 var dart; 21 var dart;
22 22
23 var servePage = (request) { 23 var servePage = (request) {
24 var path = shelfUrl(request).path; 24 var path = shelfUrl(request).path;
25 25
26 if (path.isEmpty) { 26 if (path.isEmpty) {
27 return new shelf.Response.ok(""" 27 return new shelf.Response.ok("""
28 <!doctype html> 28 <!doctype html>
29 <html> 29 <html>
30 <head> 30 <head>
31 <script type="application/dart" src="index.dart"></script> 31 <script type="application/dart" src="index.dart"></script>
32 </head> 32 </head>
33 </html> 33 </html>
34 """, headers: {'content-type': 'text/html'}); 34 """, headers: {'content-type': 'text/html'});
35 } else if (path == "index.dart") { 35 } else if (path == "index.dart") {
36 return new shelf.Response.ok(''' 36 return new shelf.Response.ok('''
37 import "dart:js" as js;
37 import "dart:html"; 38 import "dart:html";
38 39
39 void main() { 40 void main() {
41 js.context['testRunner'].callMethod('waitUntilDone', []);
42
40 $dart 43 $dart
41 } 44 }
42 ''', headers: {'content-type': 'application/dart'}); 45 ''', headers: {'content-type': 'application/dart'});
43 } else { 46 } else {
44 return new shelf.Response.notFound(null); 47 return new shelf.Response.notFound(null);
45 } 48 }
46 }; 49 };
47 50
48 var server; 51 var server;
49 var webSockets; 52 var webSockets;
(...skipping 11 matching lines...) Expand all
61 }); 64 });
62 65
63 tearDown(() { 66 tearDown(() {
64 if (server != null) server.close(); 67 if (server != null) server.close();
65 68
66 dart = null; 69 dart = null;
67 server = null; 70 server = null;
68 webSockets = null; 71 webSockets = null;
69 }); 72 });
70 73
71 test("starts Dartium with the given URL", () { 74 test("starts content shell with the given URL", () {
72 dart = ''' 75 dart = '''
73 var webSocket = new WebSocket( 76 var webSocket = new WebSocket(
74 window.location.href.replaceFirst("http://", "ws://")); 77 window.location.href.replaceFirst("http://", "ws://"));
75 webSocket.onOpen.first.then((_) => webSocket.send("loaded!")); 78 webSocket.onOpen.first.then((_) => webSocket.send("loaded!"));
76 '''; 79 ''';
77 var dartium = new Dartium(baseUrlForAddress(server.address, server.port)); 80 var contentShell = new ContentShell(
81 baseUrlForAddress(server.address, server.port));
78 82
79 return webSockets.first.then((webSocket) { 83 return webSockets.first.then((webSocket) {
80 return webSocket.first.then( 84 return webSocket.first.then(
81 (message) => expect(message, equals("loaded!"))); 85 (message) => expect(message, equals("loaded!")));
82 }).whenComplete(dartium.close); 86 }).whenComplete(contentShell.close);
83 }); 87 });
84 88
85 test("doesn't preserve state across runs", () { 89 test("doesn't preserve state across runs", () {
86 dart = ''' 90 dart = '''
87 window.localStorage["data"] = "value"; 91 window.localStorage["data"] = "value";
88 92
89 var webSocket = new WebSocket( 93 var webSocket = new WebSocket(
90 window.location.href.replaceFirst("http://", "ws://")); 94 window.location.href.replaceFirst("http://", "ws://"));
91 webSocket.onOpen.first.then((_) => webSocket.send("done")); 95 webSocket.onOpen.first.then((_) => webSocket.send("done"));
92 '''; 96 ''';
93 var dartium = new Dartium(baseUrlForAddress(server.address, server.port)); 97 var contentShell = new ContentShell(
98 baseUrlForAddress(server.address, server.port));
94 99
95 var first = true; 100 var first = true;
96 webSockets.listen(expectAsync((webSocket) { 101 webSockets.listen(expectAsync((webSocket) {
97 if (first) { 102 if (first) {
98 // The first request will set local storage data. We can't kill the 103 // The first request will set local storage data. We can't kill the
99 // old Dartium and start a new one until we're sure that that has 104 // old content shell and start a new one until we're sure that that
100 // finished. 105 // has finished.
101 webSocket.first.then((_) { 106 webSocket.first.then((_) {
102 dartium.close(); 107 contentShell.close();
103 108
104 dart = ''' 109 dart = '''
105 var webSocket = new WebSocket( 110 var webSocket = new WebSocket(
106 window.location.href.replaceFirst("http://", "ws://")); 111 window.location.href.replaceFirst("http://", "ws://"));
107 webSocket.onOpen.first.then((_) => 112 webSocket.onOpen.first.then((_) =>
108 webSocket.send(window.localStorage["data"].toString())); 113 webSocket.send(window.localStorage["data"].toString()));
109 '''; 114 ''';
110 dartium = new Dartium( 115 contentShell = new ContentShell(
111 baseUrlForAddress(server.address, server.port)); 116 baseUrlForAddress(server.address, server.port));
112 first = false; 117 first = false;
113 }); 118 });
114 } else { 119 } else {
115 // The second request will return the local storage data. This should 120 // The second request will return the local storage data. This should
116 // be null, indicating that no data was saved between runs. 121 // be null, indicating that no data was saved between runs.
117 expect( 122 expect(
118 webSocket.first 123 webSocket.first
119 .then((message) => expect(message, equals('null'))) 124 .then((message) => expect(message, equals('null')))
120 .whenComplete(dartium.close), 125 .whenComplete(contentShell.close),
121 completes); 126 completes);
122 } 127 }
123 }, count: 2)); 128 }, count: 2));
124 }); 129 });
125 }); 130 });
126 131
127 test("a process can be killed synchronously after it's started", () { 132 test("a process can be killed synchronously after it's started", () {
128 return shelf_io.serve(expectAsync((_) {}, count: 0), 'localhost', 0) 133 return shelf_io.serve(expectAsync((_) {}, count: 0), 'localhost', 0)
129 .then((server) { 134 .then((server) {
130 var dartium = new Dartium(baseUrlForAddress(server.address, server.port)); 135 var contentShell = new ContentShell(
131 return dartium.close().whenComplete(server.close); 136 baseUrlForAddress(server.address, server.port));
137 return contentShell.close().whenComplete(server.close);
132 }); 138 });
133 }); 139 });
134 140
135 test("reports an error in onExit", () { 141 test("reports an error in onExit", () {
136 var dartium = new Dartium("http://dart-lang.org", 142 var contentShell = new ContentShell("http://dart-lang.org",
137 executable: "_does_not_exist"); 143 executable: "_does_not_exist");
138 expect(dartium.onExit, throwsA(new isInstanceOf<ProcessException>())); 144 expect(contentShell.onExit, throwsA(new isInstanceOf<ProcessException>()));
139 }); 145 });
140 } 146 }
OLDNEW
« no previous file with comments | « lib/src/runner/browser/static/host.dart.js.map ('k') | test/runner/browser/runner_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698