[flutter_web_plugins] Migrate to null safety. (#69844)

This commit is contained in:
David Iglesias
2020-11-06 15:34:10 -08:00
committed by GitHub
parent 2b512781a0
commit e148bf8785
11 changed files with 79 additions and 103 deletions

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:html';
@TestOn('chrome') // Uses web-only Flutter SDK
@@ -13,16 +11,12 @@ import 'package:flutter_web_plugins/flutter_web_plugins.dart';
void main() {
group('$HashUrlStrategy', () {
TestPlatformLocation location;
late TestPlatformLocation location;
setUp(() {
location = TestPlatformLocation();
});
tearDown(() {
location = null;
});
test('leading slash is optional', () {
final HashUrlStrategy strategy = HashUrlStrategy(location);
@@ -48,16 +42,12 @@ void main() {
});
group('$PathUrlStrategy', () {
TestPlatformLocation location;
late TestPlatformLocation location;
setUp(() {
location = TestPlatformLocation();
});
tearDown(() {
location = null;
});
test('validates base href', () {
location.baseHref = '/';
expect(
@@ -153,7 +143,7 @@ class TestPlatformLocation extends PlatformLocation {
String hash = '';
@override
dynamic state;
Object? Function() state = () => null;
/// Mocks the base href of the document.
String baseHref = '';

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
@TestOn('browser') // Uses web-only Flutter SDK
import 'package:flutter_test/flutter_test.dart';

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
@TestOn('chrome') // Uses web-only Flutter SDK
import 'dart:async';
@@ -29,7 +27,7 @@ void main() {
PluginEventChannel<String>('test');
final StreamController<String> controller = StreamController<String>();
sendingChannel.controller = controller;
sendingChannel.setController(controller);
expect(listeningChannel.receiveBroadcastStream(),
emitsInOrder(<String>['hello', 'world']));
@@ -61,7 +59,7 @@ void main() {
PluginEventChannel<String>('test2');
final StreamController<String> controller = StreamController<String>();
sendingChannel.controller = controller;
sendingChannel.setController(controller);
expect(
listeningChannel.receiveBroadcastStream(),
@@ -96,7 +94,7 @@ void main() {
final StreamController<String> controller = StreamController<String>(
onListen: expectAsync0<void>(() {}, count: 1));
sendingChannel.controller = controller;
sendingChannel.setController(controller);
expect(listeningChannel.receiveBroadcastStream(),
emitsInOrder(<String>['hello']));
@@ -128,11 +126,11 @@ void main() {
final StreamController<String> controller =
StreamController<String>(onCancel: expectAsync0<void>(() {}));
sendingChannel.controller = controller;
sendingChannel.setController(controller);
final Stream<dynamic> eventStream =
listeningChannel.receiveBroadcastStream();
StreamSubscription<dynamic> subscription;
late StreamSubscription<dynamic> subscription;
subscription =
eventStream.listen(expectAsync1<void, dynamic>((dynamic x) {
expect(x, equals('hello'));
@@ -153,7 +151,7 @@ void main() {
final Stream<dynamic> eventStream =
listeningChannel.receiveBroadcastStream();
StreamSubscription<dynamic> subscription;
late StreamSubscription<dynamic> subscription;
subscription =
eventStream.listen(expectAsync1<void, dynamic>((dynamic x) {
expect(x, equals('hello'));

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
@TestOn('chrome') // Uses web-only Flutter SDK
import 'dart:ui' as ui; // ignore: unused_import, it looks unused as web-only elements are the only elements used.
@@ -56,8 +54,8 @@ void main() {
const StandardMessageCodec codec = StandardMessageCodec();
final List<String> loggedMessages = <String>[];
ServicesBinding.instance.defaultBinaryMessenger
.setMessageHandler('test_send', (ByteData data) {
ServicesBinding.instance!.defaultBinaryMessenger
.setMessageHandler('test_send', (ByteData? data) {
loggedMessages.add(codec.decodeMessage(data) as String);
return null;
});
@@ -70,14 +68,14 @@ void main() {
'test_send', codec.encodeMessage('world'));
expect(loggedMessages, equals(<String>['hello', 'world']));
ServicesBinding.instance.defaultBinaryMessenger
ServicesBinding.instance!.defaultBinaryMessenger
.setMessageHandler('test_send', null);
});
test('throws when trying to set a mock handler', () {
expect(
() => pluginBinaryMessenger.setMockMessageHandler(
'test', (ByteData data) async => ByteData(0)),
'test', (ByteData? data) async => ByteData(0)),
throwsFlutterError);
});
});