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 library test.runner.browser.host; | 5 library test.runner.browser.host; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:html'; | 9 import 'dart:html'; |
10 import 'dart:js' as js; | 10 import 'dart:js' as js; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 var testRunner = js.context['testRunner']; | 74 var testRunner = js.context['testRunner']; |
75 if (testRunner != null) testRunner.callMethod('waitUntilDone', []); | 75 if (testRunner != null) testRunner.callMethod('waitUntilDone', []); |
76 | 76 |
77 runZoned(() { | 77 runZoned(() { |
78 var serverChannel = _connectToServer(); | 78 var serverChannel = _connectToServer(); |
79 serverChannel.stream.listen((message) { | 79 serverChannel.stream.listen((message) { |
80 if (message['command'] == 'loadSuite') { | 80 if (message['command'] == 'loadSuite') { |
81 var suiteChannel = serverChannel.virtualChannel(message['channel']); | 81 var suiteChannel = serverChannel.virtualChannel(message['channel']); |
82 var iframeChannel = _connectToIframe(message['url'], message['id']); | 82 var iframeChannel = _connectToIframe(message['url'], message['id']); |
83 suiteChannel.pipe(iframeChannel); | 83 suiteChannel.pipe(iframeChannel); |
| 84 } else if (message['command'] == 'displayPause') { |
| 85 document.body.classes.add('paused'); |
| 86 } else if (message['command'] == 'resume') { |
| 87 document.body.classes.remove('paused'); |
84 } else { | 88 } else { |
85 assert(message['command'] == 'closeSuite'); | 89 assert(message['command'] == 'closeSuite'); |
86 _iframes[message['id']].remove(); | 90 _iframes[message['id']].remove(); |
87 } | 91 } |
88 }); | 92 }); |
| 93 |
| 94 var play = document.querySelector("#play"); |
| 95 play.onClick.listen((_) { |
| 96 document.body.classes.remove('paused'); |
| 97 serverChannel.sink.add({"command": "resume"}); |
| 98 }); |
89 }, onError: (error, stackTrace) { | 99 }, onError: (error, stackTrace) { |
90 print("$error\n${new Trace.from(stackTrace).terse}"); | 100 print("$error\n${new Trace.from(stackTrace).terse}"); |
91 }); | 101 }); |
92 } | 102 } |
93 | 103 |
94 /// Creates a [MultiChannel] connection to the server, using a [WebSocket] as | 104 /// Creates a [MultiChannel] connection to the server, using a [WebSocket] as |
95 /// the underlying protocol. | 105 /// the underlying protocol. |
96 MultiChannel _connectToServer() { | 106 MultiChannel _connectToServer() { |
97 // The `managerUrl` query parameter contains the WebSocket URL of the remote | 107 // The `managerUrl` query parameter contains the WebSocket URL of the remote |
98 // [BrowserManager] with which this communicates. | 108 // [BrowserManager] with which this communicates. |
99 var currentUrl = Uri.parse(window.location.href); | 109 var currentUrl = Uri.parse(window.location.href); |
100 var webSocket = new WebSocket(currentUrl.queryParameters['managerUrl']); | 110 var webSocket = new WebSocket(currentUrl.queryParameters['managerUrl']); |
101 | 111 |
102 var inputController = new StreamController(sync: true); | 112 var inputController = new StreamController(sync: true); |
103 webSocket.onMessage.listen( | 113 webSocket.onMessage.listen((message) { |
104 (message) => inputController.add(JSON.decode(message.data))); | 114 inputController.add(JSON.decode(message.data)); |
| 115 }); |
105 | 116 |
106 var outputController = new StreamController(sync: true); | 117 var outputController = new StreamController(sync: true); |
107 outputController.stream.listen( | 118 outputController.stream.listen( |
108 (message) => webSocket.send(JSON.encode(message))); | 119 (message) => webSocket.send(JSON.encode(message))); |
109 | 120 |
110 return new MultiChannel(inputController.stream, outputController.sink); | 121 return new MultiChannel(inputController.stream, outputController.sink); |
111 } | 122 } |
112 | 123 |
113 /// Creates an iframe with `src` [url] and establishes a connection to it using | 124 /// Creates an iframe with `src` [url] and establishes a connection to it using |
114 /// `postMessage`. | 125 /// `postMessage`. |
(...skipping 30 matching lines...) Expand all Loading... |
145 if (!readyCompleter.isCompleted) readyCompleter.complete(); | 156 if (!readyCompleter.isCompleted) readyCompleter.complete(); |
146 }); | 157 }); |
147 | 158 |
148 outputController.stream.listen((message) async { | 159 outputController.stream.listen((message) async { |
149 await readyCompleter.future; | 160 await readyCompleter.future; |
150 iframe.contentWindow.postMessage(message, window.location.origin); | 161 iframe.contentWindow.postMessage(message, window.location.origin); |
151 }); | 162 }); |
152 | 163 |
153 return new StreamChannel(inputController.stream, outputController.sink); | 164 return new StreamChannel(inputController.stream, outputController.sink); |
154 } | 165 } |
OLD | NEW |