|
35 | 35 | import io.flutter.plugin.common.BinaryMessenger; |
36 | 36 | import io.flutter.plugin.common.JSONMethodCodec; |
37 | 37 | import io.flutter.plugin.common.MethodCall; |
| 38 | +import io.flutter.plugin.common.MethodChannel; |
38 | 39 | import io.flutter.plugin.platform.PlatformViewsController; |
39 | 40 | import java.nio.ByteBuffer; |
40 | 41 | import java.util.ArrayList; |
@@ -70,6 +71,12 @@ private void verifyMethodCall(ByteBuffer buffer, String methodName, String[] exp |
70 | 71 | } |
71 | 72 | } |
72 | 73 |
|
| 74 | + private static void sendToBinaryMessageHandler(BinaryMessenger.BinaryMessageHandler binaryMessageHandler, String method, Object args) { |
| 75 | + MethodCall methodCall = new MethodCall(method, args); |
| 76 | + ByteBuffer encodedMethodCall = JSONMethodCodec.INSTANCE.encodeMethodCall(methodCall).position(0); |
| 77 | + binaryMessageHandler.onMessage(encodedMethodCall, mock(BinaryMessenger.BinaryReply.class)); |
| 78 | + } |
| 79 | + |
73 | 80 | @Test |
74 | 81 | public void textInputPlugin_RequestsReattachOnCreation() throws JSONException { |
75 | 82 | // Initialize a general TextInputPlugin. |
@@ -531,6 +538,32 @@ public void autofill_onProvideVirtualViewStructure_single() { |
531 | 538 | verify(children[0]).setDimens(anyInt(), anyInt(), anyInt(), anyInt(), geq(0), geq(0)); |
532 | 539 | } |
533 | 540 |
|
| 541 | + @Test |
| 542 | + public void respondsToInputChannelMessages () { |
| 543 | + ArgumentCaptor<BinaryMessenger.BinaryMessageHandler> binaryMessageHandlerCaptor = ArgumentCaptor.forClass(BinaryMessenger.BinaryMessageHandler.class); |
| 544 | + DartExecutor mockBinaryMessenger = mock(DartExecutor.class); |
| 545 | + TextInputChannel.TextInputMethodHandler mockHandler = mock(TextInputChannel.TextInputMethodHandler.class); |
| 546 | + TextInputChannel textInputChannel = new TextInputChannel(mockBinaryMessenger); |
| 547 | + |
| 548 | + textInputChannel.setTextInputMethodHandler(mockHandler); |
| 549 | + |
| 550 | + verify(mockBinaryMessenger, times(1)) |
| 551 | + .setMessageHandler( |
| 552 | + any(String.class), |
| 553 | + binaryMessageHandlerCaptor.capture()); |
| 554 | + |
| 555 | + BinaryMessenger.BinaryMessageHandler binaryMessageHandler = binaryMessageHandlerCaptor.getValue(); |
| 556 | + |
| 557 | + sendToBinaryMessageHandler(binaryMessageHandler, "TextInput.requestAutofill", null); |
| 558 | + verify(mockHandler, times(1)).requestAutofill(); |
| 559 | + |
| 560 | + sendToBinaryMessageHandler(binaryMessageHandler, "TextInput.AutofillContext.commit", null); |
| 561 | + verify(mockHandler, times(1)).finishAutofillContext(true); |
| 562 | + |
| 563 | + sendToBinaryMessageHandler(binaryMessageHandler, "TextInput.AutofillContext.cancel", null); |
| 564 | + verify(mockHandler, times(1)).finishAutofillContext(false); |
| 565 | + } |
| 566 | + |
534 | 567 | @Implements(InputMethodManager.class) |
535 | 568 | public static class TestImm extends ShadowInputMethodManager { |
536 | 569 | private InputMethodSubtype currentInputMethodSubtype; |
|
0 commit comments