OLD | NEW |
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:test/test.dart'; | 10 import 'package:test/test.dart'; |
11 import 'package:test/src/runner/browser/firefox.dart'; | 11 import 'package:test/src/runner/browser/phantom_js.dart'; |
12 import 'package:test/src/util/io.dart'; | 12 import 'package:test/src/util/io.dart'; |
13 import 'package:shelf/shelf.dart' as shelf; | 13 import 'package:shelf/shelf.dart' as shelf; |
14 import 'package:shelf/shelf_io.dart' as shelf_io; | 14 import 'package:shelf/shelf_io.dart' as shelf_io; |
15 import 'package:shelf_web_socket/shelf_web_socket.dart'; | 15 import 'package:shelf_web_socket/shelf_web_socket.dart'; |
16 | 16 |
17 void main() { | 17 void main() { |
18 group("running JavaScript", () { | 18 group("running JavaScript", () { |
19 // The JavaScript to serve in the server. We use actual JavaScript here to | 19 // The JavaScript to serve in the server. We use actual JavaScript here to |
20 // avoid the pain of compiling to JS in a test | 20 // avoid the pain of compiling to JS in a test |
21 var javaScript; | 21 var javaScript; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 }); | 60 }); |
61 | 61 |
62 tearDown(() { | 62 tearDown(() { |
63 if (server != null) server.close(); | 63 if (server != null) server.close(); |
64 | 64 |
65 javaScript = null; | 65 javaScript = null; |
66 server = null; | 66 server = null; |
67 webSockets = null; | 67 webSockets = null; |
68 }); | 68 }); |
69 | 69 |
70 test("starts Firefox with the given URL", () { | 70 test("starts PhantomJs with the given URL", () { |
71 javaScript = ''' | 71 javaScript = ''' |
72 var webSocket = new WebSocket(window.location.href.replace("http://", "ws://")); | 72 var webSocket = new WebSocket(window.location.href.replace("http://", "ws://")); |
73 webSocket.addEventListener("open", function() { | 73 webSocket.addEventListener("open", function() { |
74 webSocket.send("loaded!"); | 74 webSocket.send("loaded!"); |
75 }); | 75 }); |
76 '''; | 76 '''; |
77 var firefox = new Firefox(baseUrlForAddress(server.address, server.port)); | 77 var phantomJS = new PhantomJS( |
| 78 baseUrlForAddress(server.address, server.port)); |
78 | 79 |
79 return webSockets.first.then((webSocket) { | 80 return webSockets.first.then((webSocket) { |
80 return webSocket.first.then( | 81 return webSocket.first.then( |
81 (message) => expect(message, equals("loaded!"))); | 82 (message) => expect(message, equals("loaded!"))); |
82 }).whenComplete(firefox.close); | 83 }).whenComplete(phantomJS.close); |
83 }); | 84 }); |
84 | 85 |
85 test("doesn't preserve state across runs", () { | 86 test("doesn't preserve state across runs", () { |
86 javaScript = ''' | 87 javaScript = ''' |
87 localStorage.setItem("data", "value"); | 88 localStorage.setItem("data", "value"); |
88 | 89 |
89 var webSocket = new WebSocket(window.location.href.replace("http://", "ws://")); | 90 var webSocket = new WebSocket(window.location.href.replace("http://", "ws://")); |
90 webSocket.addEventListener("open", function() { | 91 webSocket.addEventListener("open", function() { |
91 webSocket.send("done"); | 92 webSocket.send("done"); |
92 }); | 93 }); |
93 '''; | 94 '''; |
94 var firefox = new Firefox(baseUrlForAddress(server.address, server.port)); | 95 var phantomJS = new PhantomJS( |
| 96 baseUrlForAddress(server.address, server.port)); |
95 | 97 |
96 var first = true; | 98 var first = true; |
97 webSockets.listen(expectAsync((webSocket) { | 99 webSockets.listen(expectAsync((webSocket) { |
98 if (first) { | 100 if (first) { |
99 // The first request will set local storage data. We can't kill the | 101 // The first request will set local storage data. We can't kill the |
100 // old firefox and start a new one until we're sure that that has | 102 // old PhantomJS and start a new one until we're sure that that has |
101 // finished. | 103 // finished. |
102 webSocket.first.then((_) { | 104 webSocket.first.then((_) { |
103 firefox.close(); | 105 phantomJS.close(); |
104 | 106 |
105 javaScript = ''' | 107 javaScript = ''' |
106 var webSocket = new WebSocket(window.location.href.replace("http://", "ws://")); | 108 var webSocket = new WebSocket(window.location.href.replace("http://", "ws://")); |
107 webSocket.addEventListener("open", function() { | 109 webSocket.addEventListener("open", function() { |
108 webSocket.send(localStorage.getItem("data")); | 110 webSocket.send(localStorage.getItem("data")); |
109 }); | 111 }); |
110 '''; | 112 '''; |
111 firefox = new Firefox(baseUrlForAddress(server.address, server.port)
); | 113 phantomJS = new PhantomJS( |
| 114 baseUrlForAddress(server.address, server.port)); |
112 first = false; | 115 first = false; |
113 }); | 116 }); |
114 } else { | 117 } else { |
115 // The second request will return the local storage data. This should | 118 // The second request will return the local storage data. This should |
116 // be null, indicating that no data was saved between runs. | 119 // be null, indicating that no data was saved between runs. |
117 expect( | 120 expect( |
118 webSocket.first | 121 webSocket.first |
119 .then((message) => expect(message, equals('null'))) | 122 .then((message) => expect(message, equals('null'))) |
120 .whenComplete(firefox.close), | 123 .whenComplete(phantomJS.close), |
121 completes); | 124 completes); |
122 } | 125 } |
123 }, count: 2)); | 126 }, count: 2)); |
124 }); | 127 }); |
125 }); | 128 }); |
126 | 129 |
127 test("a process can be killed synchronously after it's started", () { | 130 test("a process can be killed synchronously after it's started", () { |
128 return shelf_io.serve(expectAsync((_) {}, count: 0), 'localhost', 0) | 131 return shelf_io.serve(expectAsync((_) {}, count: 0), 'localhost', 0) |
129 .then((server) { | 132 .then((server) { |
130 var firefox = new Firefox(baseUrlForAddress(server.address, server.port)); | 133 var phantomJS = new PhantomJS( |
131 return firefox.close().whenComplete(server.close); | 134 baseUrlForAddress(server.address, server.port)); |
| 135 return phantomJS.close().whenComplete(server.close); |
132 }); | 136 }); |
133 }); | 137 }); |
134 | 138 |
135 test("reports an error in onExit", () { | 139 test("reports an error in onExit", () { |
136 var firefox = new Firefox("http://dart-lang.org", | 140 var phantomJS = new PhantomJS("http://dart-lang.org", |
137 executable: "_does_not_exist"); | 141 executable: "_does_not_exist"); |
138 expect(firefox.onExit, throwsA(new isInstanceOf<ProcessException>())); | 142 expect(phantomJS.onExit, throwsA(new isInstanceOf<ProcessException>())); |
139 }); | 143 }); |
140 } | 144 } |
OLD | NEW |