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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:convert'; | 6 import 'dart:convert'; |
7 import 'dart:html'; | 7 import 'dart:html'; |
8 import 'dart:js' as js; | 8 import 'dart:js' as js; |
9 | 9 |
10 import 'package:stack_trace/stack_trace.dart'; | 10 import 'package:stack_trace/stack_trace.dart'; |
11 import 'package:test/src/util/multi_channel.dart'; | 11 import 'package:stream_channel/stream_channel.dart'; |
12 import 'package:test/src/util/stream_channel.dart'; | |
13 | 12 |
14 /// The iframes created for each loaded test suite, indexed by the suite id. | 13 /// The iframes created for each loaded test suite, indexed by the suite id. |
15 final _iframes = new Map<int, IFrameElement>(); | 14 final _iframes = new Map<int, IFrameElement>(); |
16 | 15 |
17 // TODO(nweiz): test this once we can run browser tests. | 16 // TODO(nweiz): test this once we can run browser tests. |
18 /// Code that runs in the browser and loads test suites at the server's behest. | 17 /// Code that runs in the browser and loads test suites at the server's behest. |
19 /// | 18 /// |
20 /// One instance of this runs for each browser. When the server tells it to load | 19 /// One instance of this runs for each browser. When the server tells it to load |
21 /// a test, it starts an iframe pointing at that test's code; from then on, it | 20 /// a test, it starts an iframe pointing at that test's code; from then on, it |
22 /// just relays messages between the two. | 21 /// just relays messages between the two. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 108 |
110 var inputController = new StreamController(sync: true); | 109 var inputController = new StreamController(sync: true); |
111 webSocket.onMessage.listen((message) { | 110 webSocket.onMessage.listen((message) { |
112 inputController.add(JSON.decode(message.data)); | 111 inputController.add(JSON.decode(message.data)); |
113 }); | 112 }); |
114 | 113 |
115 var outputController = new StreamController(sync: true); | 114 var outputController = new StreamController(sync: true); |
116 outputController.stream.listen( | 115 outputController.stream.listen( |
117 (message) => webSocket.send(JSON.encode(message))); | 116 (message) => webSocket.send(JSON.encode(message))); |
118 | 117 |
119 return new MultiChannel(inputController.stream, outputController.sink); | 118 return new MultiChannel( |
| 119 new StreamChannel(inputController.stream, outputController.sink)); |
120 } | 120 } |
121 | 121 |
122 /// Creates an iframe with `src` [url] and establishes a connection to it using | 122 /// Creates an iframe with `src` [url] and establishes a connection to it using |
123 /// `postMessage`. | 123 /// `postMessage`. |
124 /// | 124 /// |
125 /// [id] identifies the suite loaded in this iframe. | 125 /// [id] identifies the suite loaded in this iframe. |
126 StreamChannel _connectToIframe(String url, int id) { | 126 StreamChannel _connectToIframe(String url, int id) { |
127 var iframe = new IFrameElement(); | 127 var iframe = new IFrameElement(); |
128 _iframes[id] = iframe; | 128 _iframes[id] = iframe; |
129 iframe.src = url; | 129 iframe.src = url; |
(...skipping 24 matching lines...) Expand all Loading... |
154 if (!readyCompleter.isCompleted) readyCompleter.complete(); | 154 if (!readyCompleter.isCompleted) readyCompleter.complete(); |
155 }); | 155 }); |
156 | 156 |
157 outputController.stream.listen((message) async { | 157 outputController.stream.listen((message) async { |
158 await readyCompleter.future; | 158 await readyCompleter.future; |
159 iframe.contentWindow.postMessage(message, window.location.origin); | 159 iframe.contentWindow.postMessage(message, window.location.origin); |
160 }); | 160 }); |
161 | 161 |
162 return new StreamChannel(inputController.stream, outputController.sink); | 162 return new StreamChannel(inputController.stream, outputController.sink); |
163 } | 163 } |
OLD | NEW |