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({
StreamChannel serializeSuite(Function getMain(), {bool hidePrints = true}) => RemoteListener.start(getMain, hidePrints: hidePrints);
StreamChannel postMessageChannel() {
var controller = StreamChannelController(sync: true);
window.onMessage.firstWhere((message) {
return message.origin == window.location.origin && message.data == "port";
}).then((message) {
var port = message.ports.first;
var portSubscription = port.onMessage.listen((message) {
controller.local.sink.add(message.data);
});
controller.local.stream.listen((data) {
port.postMessage({"data": data});
}, onDone: () {
port.postMessage({"event": "done"});
portSubscription.cancel();
});
var controller = StreamChannelController<Object?>(sync: true);
var channel = MessageChannel();
window.parent!.postMessage('port', window.location.origin, [channel.port2]);
var portSubscription = channel.port1.onMessage.listen((message) {
controller.local.sink.add(message.data);
});
context['parent'].callMethod('postMessage', [
JsObject.jsify({"href": window.location.href, "ready": true}),
window.location.origin,
]);
controller.local.stream
.listen(channel.port1.postMessage, onDone: portSubscription.cancel);
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