Update to the latest package:test (flutter/engine#46592)
- Update the pinned version of `test` to the latest published. - Add support for reading the `source.location` of messages to the JS interop library. - Update `host.dart` to support the new communication pattern with the test frame. See https://github.com/dart-lang/test/issues/2065 - Use `Runtime.edge` for the edge browser. We may deprecate or remove the constant. Edge is a more appropriate value for this usage.
This commit is contained in:
@@ -24,7 +24,7 @@ class EdgeEnvironment implements BrowserEnvironment {
|
||||
}
|
||||
|
||||
@override
|
||||
Runtime get packageTestRuntime => Runtime.internetExplorer;
|
||||
Runtime get packageTestRuntime => Runtime.edge;
|
||||
|
||||
@override
|
||||
Future<void> prepare() async {
|
||||
|
||||
@@ -3027,6 +3027,31 @@ extension DomMessageEventExtension on DomMessageEvent {
|
||||
@JS('origin')
|
||||
external JSString get _origin;
|
||||
String get origin => _origin.toDart;
|
||||
|
||||
/// The source may be a `WindowProxy`, a `MessagePort`, or a `ServiceWorker`.
|
||||
///
|
||||
/// When a message is sent from an iframe through `window.parent.postMessage`
|
||||
/// the source will be a `WindowProxy` which has the same methods as [Window].
|
||||
DomMessageEventSource get source => js_util.getProperty(this, 'source');
|
||||
|
||||
List<DomMessagePort> get ports =>
|
||||
js_util.getProperty<List<Object?>>(this, 'ports').cast<DomMessagePort>();
|
||||
}
|
||||
|
||||
@JS()
|
||||
@staticInterop
|
||||
class DomMessageEventSource {}
|
||||
|
||||
extension DomMEssageEventSourceExtension on DomMessageEventSource {
|
||||
external DomMessageEventLocation? get location;
|
||||
}
|
||||
|
||||
@JS()
|
||||
@staticInterop
|
||||
class DomMessageEventLocation {}
|
||||
|
||||
extension DomMessageEventSourceExtension on DomMessageEventLocation {
|
||||
external String? get href;
|
||||
}
|
||||
|
||||
@JS()
|
||||
|
||||
@@ -27,7 +27,7 @@ dev_dependencies:
|
||||
http: 1.1.0
|
||||
http_multi_server: any
|
||||
image: 3.0.1
|
||||
matcher: 0.12.14
|
||||
matcher: 0.12.16
|
||||
package_config: any
|
||||
path: 1.8.0
|
||||
pool: any
|
||||
@@ -38,7 +38,7 @@ dev_dependencies:
|
||||
shelf_web_socket: any
|
||||
stack_trace: any
|
||||
stream_channel: 2.1.1
|
||||
test: 1.22.1
|
||||
test: 1.24.8
|
||||
test_api: any
|
||||
test_core: any
|
||||
typed_data: any
|
||||
|
||||
@@ -13,7 +13,7 @@ dev_dependencies:
|
||||
# up-to-date instead of a version from pub, which may not have the latest
|
||||
# language features enabled.
|
||||
analyzer: any
|
||||
test: 1.22.1
|
||||
test: 1.24.8
|
||||
|
||||
dependency_overrides: # Must include all transitive dependencies from the "any" packages above.
|
||||
_fe_analyzer_shared:
|
||||
|
||||
@@ -207,14 +207,8 @@ StreamChannel<dynamic> _connectToIframe(String url, int id) {
|
||||
..height = '1000';
|
||||
domDocument.body!.appendChild(iframe);
|
||||
|
||||
// Use this to communicate securely with the iframe.
|
||||
final DomMessageChannel channel = createDomMessageChannel();
|
||||
final StreamChannelController<dynamic> controller = StreamChannelController<dynamic>(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.
|
||||
final Completer<dynamic> readyCompleter = Completer<dynamic>();
|
||||
|
||||
final List<DomSubscription> domSubscriptions = <DomSubscription>[];
|
||||
final List<StreamSubscription<dynamic>> streamSubscriptions = <StreamSubscription<dynamic>>[];
|
||||
_domSubscriptions[id] = domSubscriptions;
|
||||
@@ -229,20 +223,35 @@ StreamChannel<dynamic> _connectToIframe(String url, int id) {
|
||||
if (message.origin != domWindow.location.origin) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.data['href'] != iframe.src) {
|
||||
if (message.source.location?.href != iframe.src) {
|
||||
return;
|
||||
}
|
||||
|
||||
message.stopPropagation();
|
||||
|
||||
if (message.data['ready'] == true) {
|
||||
if (message.data == 'port') {
|
||||
final DomMessagePort port = message.ports.first;
|
||||
domSubscriptions.add(
|
||||
DomSubscription(port, 'message',(DomEvent event) {
|
||||
controller.local.sink.add((event as DomMessageEvent).data);
|
||||
}));
|
||||
port.start();
|
||||
streamSubscriptions.add(controller.local.stream.listen(port.postMessage));
|
||||
} else if (message.data['ready'] == true) {
|
||||
// This message indicates that the iframe is actively listening for
|
||||
// events, so the message channel's second port can now be transferred.
|
||||
final DomMessageChannel channel = createDomMessageChannel();
|
||||
channel.port1.start();
|
||||
channel.port2.start();
|
||||
iframe.contentWindow.postMessage('port', domWindow.location.origin,
|
||||
<DomMessagePort>[channel.port2]);
|
||||
readyCompleter.complete();
|
||||
iframe.contentWindow.postMessage(
|
||||
'port', domWindow.location.origin, <DomMessagePort>[channel.port2]);
|
||||
domSubscriptions
|
||||
.add(DomSubscription(channel.port1, 'message', (DomEvent message) {
|
||||
controller.local.sink.add((message as DomMessageEvent).data['data']);
|
||||
}));
|
||||
|
||||
streamSubscriptions
|
||||
.add(controller.local.stream.listen(channel.port1.postMessage));
|
||||
} else if (message.data['exception'] == true) {
|
||||
// This message from `dart.js` indicates that an exception occurred
|
||||
// loading the test.
|
||||
@@ -250,16 +259,6 @@ StreamChannel<dynamic> _connectToIframe(String url, int id) {
|
||||
}
|
||||
}));
|
||||
|
||||
channel.port1.start();
|
||||
domSubscriptions.add(DomSubscription(channel.port1, 'message',
|
||||
(DomEvent message) {
|
||||
controller.local.sink.add((message as DomMessageEvent).data['data']);
|
||||
}));
|
||||
|
||||
streamSubscriptions.add(controller.local.stream.listen((dynamic message) async {
|
||||
await readyCompleter.future;
|
||||
channel.port1.postMessage(message);
|
||||
}));
|
||||
|
||||
return controller.foreign;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ environment:
|
||||
dependencies:
|
||||
js: 0.6.4
|
||||
stream_channel: 2.1.1
|
||||
test: 1.22.1
|
||||
test: 1.24.8
|
||||
webkit_inspection_protocol: 1.0.0
|
||||
stack_trace: 1.10.0
|
||||
ui:
|
||||
|
||||
Reference in New Issue
Block a user