flutter_web_plugins cleanup and documentation (#67164)

This commit is contained in:
Ian Hickson
2020-10-06 16:52:02 -07:00
committed by GitHub
parent d411242468
commit 8d923bf9a7
4 changed files with 204 additions and 56 deletions

View File

@@ -23,7 +23,7 @@ void main() {
webPluginRegistry.registerMessageHandler();
});
test('can send events to an $EventChannel', () async {
test('can send events to an $EventChannel (deprecated API)', () async {
const EventChannel listeningChannel = EventChannel('test');
const PluginEventChannel<String> sendingChannel =
PluginEventChannel<String>('test');
@@ -39,7 +39,23 @@ void main() {
await controller.close();
});
test('can send errors to an $EventChannel', () async {
test('can send events to an $EventChannel', () async {
const EventChannel listeningChannel = EventChannel('test');
const PluginEventChannel<String> sendingChannel =
PluginEventChannel<String>('test');
final StreamController<String> controller = StreamController<String>();
sendingChannel.setController(controller);
expect(listeningChannel.receiveBroadcastStream(),
emitsInOrder(<String>['hello', 'world']));
controller.add('hello');
controller.add('world');
await controller.close();
});
test('can send errors to an $EventChannel (deprecated API)', () async {
const EventChannel listeningChannel = EventChannel('test2');
const PluginEventChannel<String> sendingChannel =
PluginEventChannel<String>('test2');
@@ -56,7 +72,24 @@ void main() {
await controller.close();
});
test('receives a listen event', () async {
test('can send errors to an $EventChannel', () async {
const EventChannel listeningChannel = EventChannel('test2');
const PluginEventChannel<String> sendingChannel =
PluginEventChannel<String>('test2');
final StreamController<String> controller = StreamController<String>();
sendingChannel.setController(controller);
expect(
listeningChannel.receiveBroadcastStream(),
emitsError(predicate<dynamic>((dynamic e) =>
e is PlatformException && e.message == 'Test error')));
controller.addError('Test error');
await controller.close();
});
test('receives a listen event (deprecated API)', () async {
const EventChannel listeningChannel = EventChannel('test3');
const PluginEventChannel<String> sendingChannel =
PluginEventChannel<String>('test3');
@@ -72,7 +105,23 @@ void main() {
await controller.close();
});
test('receives a cancel event', () async {
test('receives a listen event', () async {
const EventChannel listeningChannel = EventChannel('test3');
const PluginEventChannel<String> sendingChannel =
PluginEventChannel<String>('test3');
final StreamController<String> controller = StreamController<String>(
onListen: expectAsync0<void>(() {}, count: 1));
sendingChannel.setController(controller);
expect(listeningChannel.receiveBroadcastStream(),
emitsInOrder(<String>['hello']));
controller.add('hello');
await controller.close();
});
test('receives a cancel event (deprecated API)', () async {
const EventChannel listeningChannel = EventChannel('test4');
const PluginEventChannel<String> sendingChannel =
PluginEventChannel<String>('test4');
@@ -92,5 +141,26 @@ void main() {
controller.add('hello');
});
test('receives a cancel event', () async {
const EventChannel listeningChannel = EventChannel('test4');
const PluginEventChannel<String> sendingChannel =
PluginEventChannel<String>('test4');
final StreamController<String> controller =
StreamController<String>(onCancel: expectAsync0<void>(() {}));
sendingChannel.setController(controller);
final Stream<dynamic> eventStream =
listeningChannel.receiveBroadcastStream();
StreamSubscription<dynamic> subscription;
subscription =
eventStream.listen(expectAsync1<void, dynamic>((dynamic x) {
expect(x, equals('hello'));
subscription.cancel();
}));
controller.add('hello');
});
});
}