Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit fbc0a34

Browse files
authored
Update to the latest package:test (#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 dart-lang/test#2065 - Use `Runtime.edge` for the edge browser. We may deprecate or remove the constant. Edge is a more appropriate value for this usage.
1 parent 1ac3086 commit fbc0a34

6 files changed

Lines changed: 51 additions & 27 deletions

File tree

lib/web_ui/dev/edge.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class EdgeEnvironment implements BrowserEnvironment {
2424
}
2525

2626
@override
27-
Runtime get packageTestRuntime => Runtime.internetExplorer;
27+
Runtime get packageTestRuntime => Runtime.edge;
2828

2929
@override
3030
Future<void> prepare() async {

lib/web_ui/lib/src/engine/dom.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,6 +3027,31 @@ extension DomMessageEventExtension on DomMessageEvent {
30273027
@JS('origin')
30283028
external JSString get _origin;
30293029
String get origin => _origin.toDart;
3030+
3031+
/// The source may be a `WindowProxy`, a `MessagePort`, or a `ServiceWorker`.
3032+
///
3033+
/// When a message is sent from an iframe through `window.parent.postMessage`
3034+
/// the source will be a `WindowProxy` which has the same methods as [Window].
3035+
DomMessageEventSource get source => js_util.getProperty(this, 'source');
3036+
3037+
List<DomMessagePort> get ports =>
3038+
js_util.getProperty<List<Object?>>(this, 'ports').cast<DomMessagePort>();
3039+
}
3040+
3041+
@JS()
3042+
@staticInterop
3043+
class DomMessageEventSource {}
3044+
3045+
extension DomMEssageEventSourceExtension on DomMessageEventSource {
3046+
external DomMessageEventLocation? get location;
3047+
}
3048+
3049+
@JS()
3050+
@staticInterop
3051+
class DomMessageEventLocation {}
3052+
3053+
extension DomMessageEventSourceExtension on DomMessageEventLocation {
3054+
external String? get href;
30303055
}
30313056

30323057
@JS()

lib/web_ui/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ dev_dependencies:
2727
http: 1.1.0
2828
http_multi_server: any
2929
image: 3.0.1
30-
matcher: 0.12.14
30+
matcher: 0.12.16
3131
package_config: any
3232
path: 1.8.0
3333
pool: any
@@ -38,7 +38,7 @@ dev_dependencies:
3838
shelf_web_socket: any
3939
stack_trace: any
4040
stream_channel: 2.1.1
41-
test: 1.22.1
41+
test: 1.24.8
4242
test_api: any
4343
test_core: any
4444
typed_data: any

web_sdk/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dev_dependencies:
1313
# up-to-date instead of a version from pub, which may not have the latest
1414
# language features enabled.
1515
analyzer: any
16-
test: 1.22.1
16+
test: 1.24.8
1717

1818
dependency_overrides: # Must include all transitive dependencies from the "any" packages above.
1919
_fe_analyzer_shared:

web_sdk/web_engine_tester/lib/static/host.dart

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,8 @@ StreamChannel<dynamic> _connectToIframe(String url, int id) {
207207
..height = '1000';
208208
domDocument.body!.appendChild(iframe);
209209

210-
// Use this to communicate securely with the iframe.
211-
final DomMessageChannel channel = createDomMessageChannel();
212210
final StreamChannelController<dynamic> controller = StreamChannelController<dynamic>(sync: true);
213211

214-
// Use this to avoid sending a message to the iframe before it's sent a
215-
// message to us. This ensures that no messages get dropped on the floor.
216-
final Completer<dynamic> readyCompleter = Completer<dynamic>();
217-
218212
final List<DomSubscription> domSubscriptions = <DomSubscription>[];
219213
final List<StreamSubscription<dynamic>> streamSubscriptions = <StreamSubscription<dynamic>>[];
220214
_domSubscriptions[id] = domSubscriptions;
@@ -229,37 +223,42 @@ StreamChannel<dynamic> _connectToIframe(String url, int id) {
229223
if (message.origin != domWindow.location.origin) {
230224
return;
231225
}
232-
233-
if (message.data['href'] != iframe.src) {
226+
if (message.source.location?.href != iframe.src) {
234227
return;
235228
}
236229

237230
message.stopPropagation();
238231

239-
if (message.data['ready'] == true) {
232+
if (message.data == 'port') {
233+
final DomMessagePort port = message.ports.first;
234+
domSubscriptions.add(
235+
DomSubscription(port, 'message',(DomEvent event) {
236+
controller.local.sink.add((event as DomMessageEvent).data);
237+
}));
238+
port.start();
239+
streamSubscriptions.add(controller.local.stream.listen(port.postMessage));
240+
} else if (message.data['ready'] == true) {
240241
// This message indicates that the iframe is actively listening for
241242
// events, so the message channel's second port can now be transferred.
243+
final DomMessageChannel channel = createDomMessageChannel();
244+
channel.port1.start();
242245
channel.port2.start();
243-
iframe.contentWindow.postMessage('port', domWindow.location.origin,
244-
<DomMessagePort>[channel.port2]);
245-
readyCompleter.complete();
246+
iframe.contentWindow.postMessage(
247+
'port', domWindow.location.origin, <DomMessagePort>[channel.port2]);
248+
domSubscriptions
249+
.add(DomSubscription(channel.port1, 'message', (DomEvent message) {
250+
controller.local.sink.add((message as DomMessageEvent).data['data']);
251+
}));
252+
253+
streamSubscriptions
254+
.add(controller.local.stream.listen(channel.port1.postMessage));
246255
} else if (message.data['exception'] == true) {
247256
// This message from `dart.js` indicates that an exception occurred
248257
// loading the test.
249258
controller.local.sink.add(message.data['data']);
250259
}
251260
}));
252261

253-
channel.port1.start();
254-
domSubscriptions.add(DomSubscription(channel.port1, 'message',
255-
(DomEvent message) {
256-
controller.local.sink.add((message as DomMessageEvent).data['data']);
257-
}));
258-
259-
streamSubscriptions.add(controller.local.stream.listen((dynamic message) async {
260-
await readyCompleter.future;
261-
channel.port1.postMessage(message);
262-
}));
263262

264263
return controller.foreign;
265264
}

web_sdk/web_engine_tester/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ environment:
77
dependencies:
88
js: 0.6.4
99
stream_channel: 2.1.1
10-
test: 1.22.1
10+
test: 1.24.8
1111
webkit_inspection_protocol: 1.0.0
1212
stack_trace: 1.10.0
1313
ui:

0 commit comments

Comments
 (0)