Moved the default BinaryMessenger instance to ServicesBinding (#37489)

This commit is contained in:
adazh
2019-08-09 10:13:40 -07:00
committed by GitHub
parent 20ecae0e92
commit 92ef2b9ce1
30 changed files with 243 additions and 161 deletions

View File

@@ -207,10 +207,10 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
@override
void initInstances() {
super.initInstances();
timeDilation = 1.0; // just in case the developer has artificially changed it for development
HttpOverrides.global = _MockHttpOverrides();
_testTextInput = TestTextInput(onCleared: _resetFocusedEditable)..register();
super.initInstances();
}
@override
@@ -808,7 +808,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
final String assetFolderPath = Platform.environment['UNIT_TEST_ASSETS'];
final String prefix = 'packages/${Platform.environment['APP_NAME']}/';
defaultBinaryMessenger.setMockMessageHandler('flutter/assets', (ByteData message) {
ServicesBinding.instance.defaultBinaryMessenger.setMockMessageHandler('flutter/assets', (ByteData message) {
String key = utf8.decode(message.buffer.asUint8List());
File asset = File(path.join(assetFolderPath, key));

View File

@@ -36,6 +36,9 @@ class TestTextInput {
/// first be requested, e.g. using [WidgetTester.showKeyboard].
final VoidCallback onCleared;
/// The messenger which sends the bytes for this channel, not null.
BinaryMessenger get _binaryMessenger => ServicesBinding.instance.defaultBinaryMessenger;
/// Installs this object as a mock handler for [SystemChannels.textInput].
void register() {
SystemChannels.textInput.setMockMethodCallHandler(_handleTextInputCall);
@@ -108,7 +111,7 @@ class TestTextInput {
// test this code does not run in a package:test test zone.
if (_client == 0)
throw TestFailure('Tried to use TestTextInput with no keyboard attached. You must use WidgetTester.showKeyboard() first.');
defaultBinaryMessenger.handlePlatformMessage(
_binaryMessenger.handlePlatformMessage(
SystemChannels.textInput.name,
SystemChannels.textInput.codec.encodeMethodCall(
MethodCall(
@@ -140,7 +143,7 @@ class TestTextInput {
final Completer<void> completer = Completer<void>();
defaultBinaryMessenger.handlePlatformMessage(
_binaryMessenger.handlePlatformMessage(
SystemChannels.textInput.name,
SystemChannels.textInput.codec.encodeMethodCall(
MethodCall(