Unverified Commit 58287ace authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Convert services tests to NNBD (#62694)

This converts the packages/flutter/test/services directory to NNBD, now that the services package is converted.

I changed the signature of checkMessageHandler and checkMockMessageHandler on BinaryMessenger to take a nullable handler, since the tests wanted to check to make sure a handler wasn't set, and that functionality no longer works if the handler is non-nullable.
parent ddab09f5
......@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
# The tests to run on Firebase Test Lab.
# Currently, the test consists on building an Android App Bundle and ensuring
# that the app doesn't crash upon startup.
......@@ -26,8 +28,6 @@ devices=(
"model=griffin,version=24"
)
set -e
GIT_REVISION=$(git rev-parse HEAD)
DEVICE_FLAG=""
......@@ -35,6 +35,12 @@ for device in ${devices[*]}; do
DEVICE_FLAG+="--device $device "
done
# If running tests locally, the key env var needs to be set.
if [[ -z $GCLOUD_FIREBASE_TESTLAB_KEY ]]; then
echo "Not running firebase test lab tests because GCLOUD_FIREBASE_TESTLAB_KEY isn't set."
exit 0
fi
# New contributors will not have permissions to run this test - they won't be
# able to access the service account information. We should just mark the test
# as passed - it will run fine on post submit, where it will still catch
......
......@@ -48,6 +48,9 @@ abstract class BinaryMessenger {
///
/// This method is useful for tests or test harnesses that want to assert the
/// handler for the specified channel has not been altered by a previous test.
///
/// Passing null for the `handler` returns true if the handler for the
/// `channel` is not set.
bool checkMessageHandler(String channel, MessageHandler? handler);
/// Set a mock callback for intercepting messages from the [send] method on
......@@ -69,6 +72,9 @@ abstract class BinaryMessenger {
/// This method is useful for tests or test harnesses that want to assert the
/// mock handler for the specified channel has not been altered by a previous
/// test.
///
/// Passing null for the `handler` returns true if the handler for the
/// `channel` is not set.
bool checkMockMessageHandler(String channel, MessageHandler? handler);
}
......
......@@ -389,6 +389,9 @@ class MethodChannel {
///
/// This method is useful for tests or test harnesses that want to assert the
/// handler for the specified channel has not been altered by a previous test.
///
/// Passing null for the `handler` returns true if the handler for the channel
/// is not set.
bool checkMethodCallHandler(Future<dynamic> Function(MethodCall call)? handler) => _methodChannelHandlers[this] == handler;
/// Sets a mock callback for intercepting method invocations on this channel.
......@@ -422,6 +425,9 @@ class MethodChannel {
///
/// This method is useful for tests or test harnesses that want to assert the
/// handler for the specified channel has not been altered by a previous test.
///
/// Passing null for the `handler` returns true if the handler for the channel
/// is not set.
bool checkMockMethodCallHandler(Future<dynamic> Function(MethodCall call)? handler) => _methodChannelMockHandlers[this] == handler;
Future<ByteData?> _handleAsMethodCall(ByteData? message, Future<dynamic> handler(MethodCall call)) async {
......
......@@ -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:convert';
import 'dart:typed_data';
......@@ -41,7 +39,7 @@ void main() {
expect(bundle.loadCallCount['one'], 1);
Object loadException;
late Object loadException;
try {
await bundle.loadString('foo');
} catch (e) {
......@@ -61,7 +59,7 @@ void main() {
test('NetworkAssetBundle control test', () async {
final Uri uri = Uri.http('example.org', '/path');
final NetworkAssetBundle bundle = NetworkAssetBundle(uri);
FlutterError error;
late FlutterError error;
try {
await bundle.load('key');
} on FlutterError catch (e) {
......
......@@ -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:convert' show utf8;
import 'package:flutter/services.dart';
......@@ -13,13 +11,12 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('TextInput message channels', () {
FakeTextChannel fakeTextChannel;
FakeAutofillScope scope;
late FakeTextChannel fakeTextChannel;
final FakeAutofillScope scope = FakeAutofillScope();
setUp(() {
fakeTextChannel = FakeTextChannel((MethodCall call) async {});
TextInput.setChannel(fakeTextChannel);
scope ??= FakeAutofillScope();
scope.clients.clear();
});
......@@ -28,35 +25,8 @@ void main() {
TextInput.setChannel(SystemChannels.textInput);
});
test('mandatory fields are mandatory', () async {
AutofillConfiguration config;
try {
config = AutofillConfiguration(
uniqueIdentifier: null,
autofillHints: const <String>['test'],
currentEditingValue: const TextEditingValue(),
);
} catch (e) {
expect(e.toString(), contains('uniqueIdentifier != null'));
}
expect(config, isNull);
try {
config = AutofillConfiguration(
uniqueIdentifier: 'id',
autofillHints: null,
currentEditingValue: const TextEditingValue(),
);
} catch (e) {
expect(e.toString(), contains('autofillHints != null'));
}
expect(config, isNull);
});
test('throws if the hint list is empty', () async {
Map<String, dynamic> json;
Map<String, dynamic>? json;
try {
const AutofillConfiguration config = AutofillConfiguration(
uniqueIdentifier: 'id',
......@@ -113,7 +83,7 @@ void main() {
]);
const TextEditingValue text2 = TextEditingValue(text: 'Text 2');
fakeTextChannel.incoming(MethodCall(
fakeTextChannel.incoming?.call(MethodCall(
'TextInputClient.updateEditingStateWithTag',
<dynamic>[0, <String, dynamic>{ client2.autofillId : text2.toJSON() }],
));
......@@ -130,7 +100,7 @@ class FakeAutofillClient implements TextInputClient, AutofillClient {
String get autofillId => hashCode.toString();
@override
TextInputConfiguration textInputConfiguration;
late TextInputConfiguration textInputConfiguration;
@override
void updateEditingValue(TextEditingValue newEditingValue) {
......@@ -139,7 +109,7 @@ class FakeAutofillClient implements TextInputClient, AutofillClient {
}
@override
AutofillScope currentAutofillScope;
AutofillScope? currentAutofillScope;
String latestMethodCall = '';
......@@ -179,7 +149,7 @@ class FakeAutofillScope with AutofillScopeMixin implements AutofillScope {
Iterable<AutofillClient> get autofillClients => clients.values;
@override
AutofillClient getAutofillClient(String autofillId) => clients[autofillId];
AutofillClient getAutofillClient(String autofillId) => clients[autofillId]!;
void register(AutofillClient client) {
clients.putIfAbsent(client.autofillId, () => client);
......@@ -190,7 +160,7 @@ class FakeTextChannel implements MethodChannel {
FakeTextChannel(this.outgoing) : assert(outgoing != null);
Future<dynamic> Function(MethodCall) outgoing;
Future<void> Function(MethodCall) incoming;
Future<void> Function(MethodCall)? incoming;
List<MethodCall> outgoingCalls = <MethodCall>[];
......@@ -217,18 +187,18 @@ class FakeTextChannel implements MethodChannel {
String get name => 'flutter/textinput';
@override
void setMethodCallHandler(Future<void> Function(MethodCall call) handler) {
void setMethodCallHandler(Future<void> Function(MethodCall call)? handler) {
incoming = handler;
}
@override
bool checkMethodCallHandler(Future<void> Function(MethodCall call) handler) => throw UnimplementedError();
bool checkMethodCallHandler(Future<void> Function(MethodCall call)? handler) => throw UnimplementedError();
@override
void setMockMethodCallHandler(Future<void> Function(MethodCall call) handler) => throw UnimplementedError();
void setMockMethodCallHandler(Future<void> Function(MethodCall call)? handler) => throw UnimplementedError();
@override
bool checkMockMethodCallHandler(Future<void> Function(MethodCall call) handler) => throw UnimplementedError();
bool checkMockMethodCallHandler(Future<void> Function(MethodCall call)? handler) => throw UnimplementedError();
void validateOutgoingMethodCalls(List<MethodCall> calls) {
expect(outgoingCalls.length, calls.length);
......
......@@ -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:typed_data';
import 'package:flutter/foundation.dart';
......@@ -45,7 +43,7 @@ class TestBinding extends BindingBase with SchedulerBinding, ServicesBinding {
@override
BinaryMessenger createBinaryMessenger() {
return super.createBinaryMessenger()
..setMockMessageHandler('flutter/assets', (ByteData message) async {
..setMockMessageHandler('flutter/assets', (ByteData? message) async {
if (const StringCodec().decodeMessage(message) == 'NOTICES') {
return const StringCodec().encodeMessage(licenses);
}
......
......@@ -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
// TODO(yjbanov): enable Web when https://github.com/flutter/engine/pull/12747 rolls into the framework.
@TestOn('!chrome')
......@@ -35,15 +33,15 @@ void main() {
final TestChannelBuffersFlutterBinding binding = TestChannelBuffersFlutterBinding();
expect(binding.defaultBinaryMessenger, isNotNull);
bool didCallCallback = false;
final ui.PlatformMessageResponseCallback callback = (ByteData responseData) {
final ui.PlatformMessageResponseCallback callback = (ByteData? responseData) {
didCallCallback = true;
};
const String payload = 'bar';
final ByteData data = _makeByteData(payload);
ui.channelBuffers.push(channel, data, callback);
bool didDrainData = false;
binding.defaultBinaryMessenger.setMessageHandler(channel, (ByteData message) async {
expect(_getString(message), payload);
binding.defaultBinaryMessenger.setMessageHandler(channel, (ByteData? message) async {
expect(_getString(message!), payload);
didDrainData = true;
return null;
});
......
......@@ -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:convert';
import 'dart:typed_data';
import 'dart:ui' as ui;
......@@ -23,22 +21,21 @@ void main() {
test('default binary messenger calls callback once', () async {
int count = 0;
const String channel = 'foo';
ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
channel, _makeByteData('bar'), (ByteData message) async {
ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage(
channel, _makeByteData('bar'), (ByteData? message) async {
count += 1;
});
expect(count, equals(0));
await ui.channelBuffers.drain(channel,
(ByteData data, ui.PlatformMessageResponseCallback callback) {
(ByteData? data, ui.PlatformMessageResponseCallback callback) async {
callback(null);
return null;
});
expect(count, equals(1));
});
test('can check the handler', () {
Future<ByteData> handler(ByteData call) => Future<ByteData>.value(null);
final BinaryMessenger messenger = ServicesBinding.instance.defaultBinaryMessenger;
Future<ByteData> handler(ByteData? call) => Future<ByteData>.value(null);
final BinaryMessenger messenger = ServicesBinding.instance!.defaultBinaryMessenger;
expect(messenger.checkMessageHandler('test_channel', null), true);
expect(messenger.checkMessageHandler('test_channel', handler), false);
......@@ -48,8 +45,8 @@ void main() {
});
test('can check the mock handler', () {
Future<ByteData> handler(ByteData call) => Future<ByteData>.value(null);
final BinaryMessenger messenger = ServicesBinding.instance.defaultBinaryMessenger;
Future<ByteData> handler(ByteData? call) => Future<ByteData>.value(null);
final BinaryMessenger messenger = ServicesBinding.instance!.defaultBinaryMessenger;
expect(messenger.checkMockMessageHandler('test_channel', null), true);
expect(messenger.checkMockMessageHandler('test_channel', handler), false);
......
......@@ -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:async';
import 'dart:typed_data';
......@@ -14,10 +12,7 @@ import 'package:flutter/widgets.dart';
/// Used in internal testing.
class FakePlatformViewController extends PlatformViewController {
FakePlatformViewController(int id) {
_id = id;
}
FakePlatformViewController(this.viewId);
bool disposed = false;
bool focusCleared = false;
......@@ -25,10 +20,8 @@ class FakePlatformViewController extends PlatformViewController {
/// Events that are dispatched.
List<PointerEvent> dispatchedPointerEvents = <PointerEvent>[];
int _id;
@override
int get viewId => _id;
final int viewId;
@override
Future<void> dispatchPointerEvent(PointerEvent event) async {
......@@ -66,7 +59,7 @@ class FakeAndroidViewController implements AndroidViewController {
final int viewId;
@override
Offset Function(Offset position) pointTransformer;
Offset Function(Offset position)? pointTransformer;
@override
Future<void> dispatchPointerEvent(PointerEvent event) async {
......@@ -98,7 +91,7 @@ class FakeAndroidViewController implements AndroidViewController {
int get textureId => throw UnimplementedError();
@override
bool isCreated;
bool get isCreated => throw UnimplementedError();
@override
void addOnPlatformViewCreatedListener(PlatformViewCreatedCallback listener) =>
......@@ -133,7 +126,6 @@ class FakeAndroidPlatformViewsController {
SystemChannels.platform_views.setMockMethodCallHandler(_onMethodCall);
}
Iterable<FakeAndroidPlatformView> get views => _views.values;
final Map<int, FakeAndroidPlatformView> _views = <int, FakeAndroidPlatformView>{};
......@@ -143,11 +135,11 @@ class FakeAndroidPlatformViewsController {
int _textureCounter = 0;
Completer<void> resizeCompleter;
Completer<void>? resizeCompleter;
Completer<void> createCompleter;
Completer<void>? createCompleter;
int lastClearedFocusViewId;
int? lastClearedFocusViewId;
void registerViewType(String viewType) {
_registeredViewTypes.add(viewType);
......@@ -156,7 +148,8 @@ class FakeAndroidPlatformViewsController {
void invokeViewFocused(int viewId) {
final MethodCodec codec = SystemChannels.platform_views.codec;
final ByteData data = codec.encodeMethodCall(MethodCall('viewFocused', viewId));
ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(SystemChannels.platform_views.name, data, (ByteData data) {});
ServicesBinding.instance!.defaultBinaryMessenger
.handlePlatformMessage(SystemChannels.platform_views.name, data, (ByteData? data) {});
}
Future<dynamic> _onMethodCall(MethodCall call) {
......@@ -200,7 +193,7 @@ class FakeAndroidPlatformViewsController {
);
if (createCompleter != null) {
await createCompleter.future;
await createCompleter!.future;
}
_views[id] = FakeAndroidPlatformView(id, viewType,
......@@ -219,9 +212,9 @@ class FakeAndroidPlatformViewsController {
final int id = call.arguments['id'] as int;
final bool hybrid = call.arguments['hybrid'] as bool;
if (hybrid && !_views[id].hybrid) {
if (hybrid && !_views[id]!.hybrid!) {
throw ArgumentError('An $AndroidViewController using hybrid composition must pass `hybrid: true`');
} else if (!hybrid && _views[id].hybrid != null && _views[id].hybrid) {
} else if (!hybrid && (_views[id]!.hybrid ?? false)) {
throw ArgumentError('An $AndroidViewController not using hybrid composition must pass `hybrid: false`');
}
......@@ -248,9 +241,9 @@ class FakeAndroidPlatformViewsController {
);
if (resizeCompleter != null) {
await resizeCompleter.future;
await resizeCompleter!.future;
}
_views[id] = _views[id].copyWith(size: Size(width, height));
_views[id] = _views[id]!.copyWith(size: Size(width, height));
return Future<dynamic>.sync(() => null);
}
......@@ -273,7 +266,7 @@ class FakeAndroidPlatformViewsController {
if (!motionEvents.containsKey(id))
motionEvents[id] = <FakeAndroidMotionEvent> [];
motionEvents[id].add(FakeAndroidMotionEvent(action, pointerIds, pointerOffsets));
motionEvents[id]!.add(FakeAndroidMotionEvent(action, pointerIds, pointerOffsets));
return Future<dynamic>.sync(() => null);
}
......@@ -288,7 +281,7 @@ class FakeAndroidPlatformViewsController {
message: 'Trying to resize a platform view with unknown id: $id',
);
_views[id] = _views[id].copyWith(layoutDirection: layoutDirection);
_views[id] = _views[id]!.copyWith(layoutDirection: layoutDirection);
return Future<dynamic>.sync(() => null);
}
......@@ -312,7 +305,6 @@ class FakeIosPlatformViewsController {
SystemChannels.platform_views.setMockMethodCallHandler(_onMethodCall);
}
Iterable<FakeUiKitView> get views => _views.values;
final Map<int, FakeUiKitView> _views = <int, FakeUiKitView>{};
......@@ -320,7 +312,7 @@ class FakeIosPlatformViewsController {
// When this completer is non null, the 'create' method channel call will be
// delayed until it completes.
Completer<void> creationDelay;
Completer<void>? creationDelay;
// Maps a view id to the number of gestures it accepted so far.
final Map<int, int> gesturesAccepted = <int, int>{};
......@@ -348,7 +340,7 @@ class FakeIosPlatformViewsController {
Future<dynamic> _create(MethodCall call) async {
if (creationDelay != null)
await creationDelay.future;
await creationDelay!.future;
final Map<dynamic, dynamic> args = call.arguments as Map<dynamic, dynamic>;
final int id = args['id'] as int;
final String viewType = args['viewType'] as String;
......@@ -371,21 +363,21 @@ class FakeIosPlatformViewsController {
_views[id] = FakeUiKitView(id, viewType, creationParams);
gesturesAccepted[id] = 0;
gesturesRejected[id] = 0;
return Future<int>.sync(() => null);
return Future<int?>.sync(() => null);
}
Future<dynamic> _acceptGesture(MethodCall call) async {
final Map<dynamic, dynamic> args = call.arguments as Map<dynamic, dynamic>;
final int id = args['id'] as int;
gesturesAccepted[id] += 1;
return Future<int>.sync(() => null);
gesturesAccepted[id] = gesturesAccepted[id]! + 1;
return Future<int?>.sync(() => null);
}
Future<dynamic> _rejectGesture(MethodCall call) async {
final Map<dynamic, dynamic> args = call.arguments as Map<dynamic, dynamic>;
final int id = args['id'] as int;
gesturesRejected[id] += 1;
return Future<int>.sync(() => null);
gesturesRejected[id] = gesturesRejected[id]! + 1;
return Future<int?>.sync(() => null);
}
Future<dynamic> _dispose(MethodCall call) {
......@@ -413,9 +405,9 @@ class FakeHtmlPlatformViewsController {
final Set<String> _registeredViewTypes = <String>{};
Completer<void> resizeCompleter;
late Completer<void> resizeCompleter;
Completer<void> createCompleter;
Completer<void>? createCompleter;
void registerViewType(String viewType) {
_registeredViewTypes.add(viewType);
......@@ -449,11 +441,11 @@ class FakeHtmlPlatformViewsController {
);
if (createCompleter != null) {
await createCompleter.future;
await createCompleter!.future;
}
_views[id] = FakeHtmlPlatformView(id, viewType);
return Future<int>.sync(() => null);
return Future<int?>.sync(() => null);
}
Future<dynamic> _dispose(MethodCall call) {
......@@ -476,12 +468,12 @@ class FakeAndroidPlatformView {
final int id;
final String type;
final Uint8List creationParams;
final Size size;
final Uint8List? creationParams;
final Size? size;
final int layoutDirection;
final bool hybrid;
final bool? hybrid;
FakeAndroidPlatformView copyWith({Size size, int layoutDirection}) => FakeAndroidPlatformView(
FakeAndroidPlatformView copyWith({Size? size, int? layoutDirection}) => FakeAndroidPlatformView(
id,
type,
size ?? this.size,
......@@ -544,7 +536,7 @@ class FakeUiKitView {
final int id;
final String type;
final Uint8List creationParams;
final Uint8List? creationParams;
@override
bool operator ==(Object other) {
......
......@@ -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:typed_data';
import 'package:flutter/services.dart';
......
......@@ -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 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
......
......@@ -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 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
......
......@@ -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 'package:flutter_test/flutter_test.dart';
import 'package:flutter/services.dart';
......@@ -11,7 +9,7 @@ void main() {
testWidgets('initialLifecycleState is used to init state paused', (WidgetTester tester) async {
// The lifecycleState is null initially in tests as there is no
// initialLifecycleState.
expect(ServicesBinding.instance.lifecycleState, equals(null));
expect(ServicesBinding.instance!.lifecycleState, equals(null));
// Mock the Window to provide paused as the AppLifecycleState
final TestWidgetsFlutterBinding binding = tester.binding;
// Use paused as the initial state.
......@@ -20,6 +18,6 @@ void main() {
// The lifecycleState should now be the state we passed above,
// even though no lifecycle event was fired from the platform.
expect(ServicesBinding.instance.lifecycleState.toString(), equals('AppLifecycleState.paused'));
expect(ServicesBinding.instance!.lifecycleState.toString(), equals('AppLifecycleState.paused'));
});
}
......@@ -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
// This files contains message codec tests that are supported both on the Web
// and in the VM. For VM-only tests see message_codecs_vm_test.dart.
......@@ -18,26 +16,25 @@ import 'message_codecs_testing.dart';
void main() {
group('Binary codec', () {
const MessageCodec<ByteData> binary = BinaryCodec();
const MessageCodec<ByteData?> binary = BinaryCodec();
test('should encode and decode simple messages', () {
checkEncodeDecode<ByteData>(binary, null);
checkEncodeDecode<ByteData>(binary, ByteData(0));
checkEncodeDecode<ByteData>(binary, ByteData(4)..setInt32(0, -7));
checkEncodeDecode<ByteData?>(binary, null);
checkEncodeDecode<ByteData?>(binary, ByteData(0));
checkEncodeDecode<ByteData?>(binary, ByteData(4)..setInt32(0, -7));
});
});
group('String codec', () {
const MessageCodec<String> string = StringCodec();
const MessageCodec<String?> string = StringCodec();
test('should encode and decode simple messages', () {
checkEncodeDecode<String>(string, null);
checkEncodeDecode<String>(string, '');
checkEncodeDecode<String>(string, 'hello');
checkEncodeDecode<String>(string, 'special chars >\u263A\u{1F602}<');
checkEncodeDecode<String?>(string, null);
checkEncodeDecode<String?>(string, '');
checkEncodeDecode<String?>(string, 'hello');
checkEncodeDecode<String?>(string, 'special chars >\u263A\u{1F602}<');
});
test('ByteData with offset', () {
const MessageCodec<String> string = StringCodec();
final ByteData helloWorldByteData = string.encodeMessage('hello world');
final ByteData helloByteData = string.encodeMessage('hello');
const MessageCodec<String?> string = StringCodec();
final ByteData helloWorldByteData = string.encodeMessage('hello world')!;
final ByteData helloByteData = string.encodeMessage('hello')!;
final ByteData offsetByteData = ByteData.view(
helloWorldByteData.buffer,
helloByteData.lengthInBytes,
......@@ -97,7 +94,7 @@ void main() {
e.details == 'errorDetails')));
});
test('should decode error envelope with native stacktrace.', () {
final ByteData errorData = stringCodec.encodeMessage(json
final ByteData? errorData = stringCodec.encodeMessage(json
.encode(<dynamic>[
'errorCode',
'errorMessage',
......@@ -105,7 +102,7 @@ void main() {
'errorStacktrace'
]));
expect(
() => jsonMethodCodec.decodeEnvelope(errorData),
() => jsonMethodCodec.decodeEnvelope(errorData!),
throwsA(predicate((PlatformException e) =>
e is PlatformException && e.stacktrace == 'errorStacktrace')));
});
......
......@@ -23,9 +23,9 @@ void checkEncodeDecode<T>(MessageCodec<T> codec, T message) {
expect(decoded, isNull);
} else {
expect(deepEquals(message, decoded), isTrue);
final ByteData encodedAgain = codec.encodeMessage(decoded)!;
final ByteData? encodedAgain = codec.encodeMessage(decoded);
expect(
encodedAgain.buffer.asUint8List(),
encodedAgain!.buffer.asUint8List(),
orderedEquals(encoded!.buffer.asUint8List()),
);
}
......
......@@ -2,7 +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
// This file contains tests that are only supported by the Dart VM. For
// example, on the Web there's no way to express large integers.
......
......@@ -2,7 +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') // missing web infrastructure for plugins.
......@@ -16,20 +15,20 @@ void main() {
// Initialize all bindings because defaultBinaryMessenger.send() needs a window.
TestWidgetsFlutterBinding.ensureInitialized();
final List<ByteData> log = <ByteData>[];
final List<ByteData?> log = <ByteData>[];
ServicesBinding.instance.defaultBinaryMessenger.setMockMessageHandler('test1', (ByteData message) async {
ServicesBinding.instance!.defaultBinaryMessenger.setMockMessageHandler('test1', (ByteData? message) async {
log.add(message);
return null;
});
final ByteData message = ByteData(2)..setUint16(0, 0xABCD);
await ServicesBinding.instance.defaultBinaryMessenger.send('test1', message);
await ServicesBinding.instance!.defaultBinaryMessenger.send('test1', message);
expect(log, equals(<ByteData>[message]));
log.clear();
ServicesBinding.instance.defaultBinaryMessenger.setMockMessageHandler('test1', null);
await ServicesBinding.instance.defaultBinaryMessenger.send('test1', message);
ServicesBinding.instance!.defaultBinaryMessenger.setMockMessageHandler('test1', null);
await ServicesBinding.instance!.defaultBinaryMessenger.send('test1', message);
expect(log, isEmpty);
});
}
......@@ -2,7 +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 'package:flutter/painting.dart';
import 'package:flutter/services.dart';
......@@ -15,7 +14,7 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('Android', () {
FakeAndroidPlatformViewsController viewsController;
late FakeAndroidPlatformViewsController viewsController;
setUp(() {
viewsController = FakeAndroidPlatformViewsController();
});
......@@ -202,7 +201,7 @@ void main() {
});
group('iOS', () {
FakeIosPlatformViewsController viewsController;
late FakeIosPlatformViewsController viewsController;
setUp(() {
viewsController = FakeIosPlatformViewsController();
});
......
......@@ -2,7 +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 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
......@@ -54,7 +53,7 @@ void main() {
expect(manager.updateScheduled, isFalse);
// Can store null.
bucket.write<bool>('value4', null);
bucket.write<bool?>('value4', null);
expect(manager.updateScheduled, isTrue);
expect(bucket.read<int>('value4'), null);
manager.doSerialization();
......@@ -111,7 +110,7 @@ void main() {
expect(manager.updateScheduled, isFalse);
// Can store null.
child.write<bool>('value4', null);
child.write<bool?>('value4', null);
expect(manager.updateScheduled, isTrue);
expect(child.read<int>('value4'), null);
manager.doSerialization();
......@@ -327,7 +326,7 @@ void main() {
final RestorationBucket root = RestorationBucket.root(manager: manager, rawData: rawData);
final RestorationBucket child = root.claimChild('child1', debugOwner: 'owner1');
final Object rawChildData = rawData[childrenMapKey]['child1'];
final Object rawChildData = rawData[childrenMapKey]['child1'] as Object;
expect(rawChildData, isNotNull);
expect(manager.updateScheduled, isFalse);
......@@ -370,9 +369,9 @@ void main() {
final RestorationBucket child2 = root.claimChild('child2', debugOwner: 'owner1');
manager.doSerialization();
final Object rawChild1Data = rawData[childrenMapKey]['child1'];
final Object rawChild1Data = rawData[childrenMapKey]['child1'] as Object;
expect(rawChild1Data, isNotNull);
final Object rawChild2Data = rawData[childrenMapKey]['child2'];
final Object rawChild2Data = rawData[childrenMapKey]['child2'] as Object;
expect(rawChild2Data, isNotNull);
expect(child1.restorationId, 'child1');
......@@ -396,7 +395,7 @@ void main() {
final Map<String, dynamic> rawData = _createRawDataSet();
final RestorationBucket root = RestorationBucket.root(manager: manager, rawData: rawData);
final Object rawChild1Data = rawData[childrenMapKey]['child1'];
final Object rawChild1Data = rawData[childrenMapKey]['child1'] as Object;
expect(rawChild1Data, isNotNull);
final RestorationBucket child1 = root.claimChild('child1', debugOwner: 'owner1');
......@@ -462,7 +461,7 @@ void main() {
manager.doSerialization();
expect(manager.updateScheduled, isFalse);
final Object childOfChildData = rawData[childrenMapKey]['child1'][childrenMapKey]['childOfChild'];
final Object childOfChildData = rawData[childrenMapKey]['child1'][childrenMapKey]['childOfChild'] as Object;
expect(childOfChildData, isNotEmpty);
root.adoptChild(childOfChild);
......@@ -497,7 +496,7 @@ void main() {
final RestorationBucket childOfChild = child.claimChild('child1', debugOwner: 'owner2');
childOfChild.write<String>('foo', 'bar');
final Object childOfChildData = rawData[childrenMapKey]['child1'][childrenMapKey]['child1'];
final Object childOfChildData = rawData[childrenMapKey]['child1'][childrenMapKey]['child1'] as Object;
expect(childOfChildData, isNotEmpty);
expect(manager.updateScheduled, isTrue);
......
......@@ -2,7 +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:typed_data';
......@@ -61,11 +60,10 @@ void main() {
});
test('setApplicationSwitcherDescription missing plugin', () async {
final List<ByteData> log = <ByteData>[];
final List<ByteData?> log = <ByteData>[];
ServicesBinding.instance.defaultBinaryMessenger.setMockMessageHandler('flutter/platform', (ByteData message) {
ServicesBinding.instance!.defaultBinaryMessenger.setMockMessageHandler('flutter/platform', (ByteData? message) async {
log.add(message);
return null;
});
await SystemChrome.setApplicationSwitcherDescription(
......
......@@ -2,7 +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 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
......
......@@ -2,7 +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 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
......
......@@ -2,27 +2,25 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
TextEditingValue testOldValue;
TextEditingValue testNewValue;
TextEditingValue testOldValue = TextEditingValue.empty;
TextEditingValue testNewValue = TextEditingValue.empty;
test('withFunction wraps formatting function', () {
testOldValue = const TextEditingValue();
testNewValue = const TextEditingValue();
TextEditingValue calledOldValue;
TextEditingValue calledNewValue;
late TextEditingValue calledOldValue;
late TextEditingValue calledNewValue;
final TextInputFormatter formatterUnderTest = TextInputFormatter.withFunction(
(TextEditingValue oldValue, TextEditingValue newValue) {
calledOldValue = oldValue;
calledNewValue = newValue;
return null;
return TextEditingValue.empty;
}
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment