Unverified Commit d23fb23d authored by Nate Bosch's avatar Nate Bosch Committed by GitHub

Send test message channel from the test frame (#131881)

Towards https://github.com/dart-lang/test/issues/2065

The flutter test runner uses the copy of `host.dart.js` from the copy of
`package:test` that surfaces in the pub solve for `flutter_tool`. This
copy has been updated to allow either the old pattern of communication,
or this new pattern. The new pattern removes an extra hop and use of the
frame `window.onMessage` messages.
parent fff08248
...@@ -247,25 +247,16 @@ String generateTestEntrypoint({ ...@@ -247,25 +247,16 @@ String generateTestEntrypoint({
StreamChannel serializeSuite(Function getMain(), {bool hidePrints = true}) => RemoteListener.start(getMain, hidePrints: hidePrints); StreamChannel serializeSuite(Function getMain(), {bool hidePrints = true}) => RemoteListener.start(getMain, hidePrints: hidePrints);
StreamChannel postMessageChannel() { StreamChannel postMessageChannel() {
var controller = StreamChannelController(sync: true); var controller = StreamChannelController<Object?>(sync: true);
window.onMessage.firstWhere((message) { var channel = MessageChannel();
return message.origin == window.location.origin && message.data == "port"; window.parent!.postMessage('port', window.location.origin, [channel.port2]);
}).then((message) {
var port = message.ports.first; var portSubscription = channel.port1.onMessage.listen((message) {
var portSubscription = port.onMessage.listen((message) {
controller.local.sink.add(message.data); controller.local.sink.add(message.data);
}); });
controller.local.stream.listen((data) { controller.local.stream
port.postMessage({"data": data}); .listen(channel.port1.postMessage, onDone: portSubscription.cancel);
}, onDone: () {
port.postMessage({"event": "done"});
portSubscription.cancel();
});
});
context['parent'].callMethod('postMessage', [
JsObject.jsify({"href": window.location.href, "ready": true}),
window.location.origin,
]);
return controller.foreign; return controller.foreign;
} }
'''; ''';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment