b1d4b29faf
js_interop_1_test awaits the completer itself instead of the future which is triggered when the completer completes. Change-Id: I6a784ced7caaade457cd444823e8cd21d338b9b7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213025 Reviewed-by: Nicholas Shahan <nshahan@google.com> Commit-Queue: Srujan Gaddam <srujzs@google.com>
33 lines
857 B
Dart
33 lines
857 B
Dart
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file
|
|
|
|
library JsInterop1Test;
|
|
|
|
import 'package:async_helper/async_helper.dart';
|
|
import 'dart:async';
|
|
import 'dart:html';
|
|
|
|
injectSource(code) {
|
|
final script = new ScriptElement();
|
|
script.type = 'text/javascript';
|
|
script.innerHtml = code;
|
|
document.body!.append(script);
|
|
}
|
|
|
|
main() {
|
|
asyncTest(() async {
|
|
var subscription;
|
|
var completer = Completer<void>();
|
|
subscription = window.onMessage.listen((e) {
|
|
if (!completer.isCompleted && e.data == 'hello') {
|
|
completer.complete();
|
|
subscription.cancel();
|
|
}
|
|
});
|
|
injectSource("window.postMessage('hello', '*');");
|
|
|
|
await completer.future;
|
|
});
|
|
}
|