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

Unified Diff: lib/src/runner/browser/static/host.dart

Issue 1704773002: Load web tests using the plugin infrastructure. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 4 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
Index: lib/src/runner/browser/static/host.dart
diff --git a/lib/src/runner/browser/static/host.dart b/lib/src/runner/browser/static/host.dart
index 3a72b2150b495a14ab533e0be268efb741638999..fcb33a0311f4dbd8689da33e4d0dac8bb11d4ee9 100644
--- a/lib/src/runner/browser/static/host.dart
+++ b/lib/src/runner/browser/static/host.dart
@@ -88,6 +88,11 @@ void main() {
}
});
+ // Send periodic pings to the test runner so it can know when the browser is
+ // paused for debugging.
+ new Timer.periodic(new Duration(seconds: 1),
kevmoo 2016/02/17 16:22:48 const Duration?
+ (_) => serverChannel.sink.add({"command": "ping"}));
+
var play = document.querySelector("#play");
play.onClick.listen((_) {
document.body.classes.remove('paused');
@@ -106,17 +111,15 @@ MultiChannel _connectToServer() {
var currentUrl = Uri.parse(window.location.href);
var webSocket = new WebSocket(currentUrl.queryParameters['managerUrl']);
- var inputController = new StreamController(sync: true);
+ var controller = new StreamChannelController(sync: true);
webSocket.onMessage.listen((message) {
- inputController.add(JSON.decode(message.data));
+ controller.local.sink.add(JSON.decode(message.data));
});
- var outputController = new StreamController(sync: true);
- outputController.stream.listen(
+ controller.local.stream.listen(
(message) => webSocket.send(JSON.encode(message)));
- return new MultiChannel(
- new StreamChannel(inputController.stream, outputController.sink));
+ return new MultiChannel(controller.foreign);
}
/// Creates an iframe with `src` [url] and establishes a connection to it using
@@ -129,8 +132,7 @@ StreamChannel _connectToIframe(String url, int id) {
iframe.src = url;
document.body.children.add(iframe);
- var inputController = new StreamController(sync: true);
- var outputController = new StreamController(sync: true);
+ var controller = new StreamChannelController(sync: true);
// Use this to avoid sending a message to the iframe before it's sent a
// message to us. This ensures that no messages get dropped on the floor.
@@ -150,14 +152,24 @@ StreamChannel _connectToIframe(String url, int id) {
if (message.data["href"] != iframe.src) return;
message.stopPropagation();
- inputController.add(message.data["data"]);
- if (!readyCompleter.isCompleted) readyCompleter.complete();
+
+ // This message indicates that the iframe is actively listening for events.
+ if (message.data["ready"] == true) {
+ readyCompleter.complete();
+ } else {
+ controller.local.sink.add(message.data["data"]);
+ }
});
- outputController.stream.listen((message) async {
+ controller.local.stream.listen((message) async {
await readyCompleter.future;
- iframe.contentWindow.postMessage(message, window.location.origin);
+
+ // JSON-encode the message to work around sdk#25636, which caused the
+ // structured clone algorithm to be broken with Window.postMessage in
+ // 1.14.{0,1,2}. Once we no longer care about these Dartiums, stop encoding.
+ iframe.contentWindow.postMessage(
+ JSON.encode(message), window.location.origin);
});
- return new StreamChannel(inputController.stream, outputController.sink);
+ return controller.foreign;
}

Powered by Google App Engine
This is Rietveld 408576698