Moved the default BinaryMessenger instance to ServicesBinding (#38464)

* Moved the default BinaryMessenger instance to ServicesBinding

This reverts commit 821602aef3.

* Added assertion in defaultBinaryMessenger. Also fixed the devicelab tests.
This commit is contained in:
adazh
2019-08-21 16:47:42 -07:00
committed by GitHub
parent ddb10dd9d1
commit 93c32c4ff6
32 changed files with 251 additions and 158 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
@@ -812,7 +812,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
/// platform messages.
SystemChannels.navigation.setMockMethodCallHandler((MethodCall methodCall) async {});
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(