|
1 | 1 | package io.flutter.plugin.editing; |
2 | 2 |
|
3 | 3 | import android.content.Context; |
| 4 | +import android.content.res.AssetManager; |
4 | 5 | import android.provider.Settings; |
5 | 6 | import android.util.SparseIntArray; |
6 | 7 | import android.view.View; |
7 | 8 | import android.view.inputmethod.InputMethodManager; |
8 | 9 | import android.view.inputmethod.InputMethodSubtype; |
9 | 10 |
|
| 11 | +import java.nio.ByteBuffer; |
| 12 | + |
10 | 13 | import org.junit.Test; |
11 | 14 | import org.junit.runner.RunWith; |
12 | 15 | import org.robolectric.RobolectricTestRunner; |
|
18 | 21 | import org.robolectric.shadows.ShadowBuild; |
19 | 22 | import org.robolectric.shadows.ShadowInputMethodManager; |
20 | 23 |
|
| 24 | +import io.flutter.embedding.engine.FlutterJNI; |
21 | 25 | import io.flutter.embedding.engine.dart.DartExecutor; |
22 | 26 | import io.flutter.embedding.engine.systemchannels.TextInputChannel; |
| 27 | +import io.flutter.plugin.common.JSONMethodCodec; |
| 28 | +import io.flutter.plugin.common.MethodCall; |
23 | 29 | import io.flutter.plugin.platform.PlatformViewsController; |
24 | 30 |
|
25 | 31 | import static org.junit.Assert.assertEquals; |
26 | 32 | import static org.mockito.Mockito.mock; |
| 33 | +import static org.mockito.Mockito.spy; |
| 34 | +import static org.mockito.Mockito.times; |
| 35 | +import static org.mockito.Mockito.verify; |
27 | 36 |
|
28 | 37 | @Config(manifest = Config.NONE, shadows = TextInputPluginTest.TestImm.class, sdk = 27) |
29 | 38 | @RunWith(RobolectricTestRunner.class) |
30 | 39 | public class TextInputPluginTest { |
| 40 | + @Test |
| 41 | + public void textInputPlugin_RequestsReattachOnCreation() { |
| 42 | + // Initialize a general TextInputPlugin. |
| 43 | + InputMethodSubtype inputMethodSubtype = mock(InputMethodSubtype.class); |
| 44 | + TestImm testImm = Shadow.extract(RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE)); |
| 45 | + testImm.setCurrentInputMethodSubtype(inputMethodSubtype); |
| 46 | + View testView = new View(RuntimeEnvironment.application); |
| 47 | + |
| 48 | + FlutterJNI mockFlutterJni = mock(FlutterJNI.class); |
| 49 | + DartExecutor dartExecutor = spy(new DartExecutor(mockFlutterJni, mock(AssetManager.class))); |
| 50 | + TextInputPlugin textInputPlugin = new TextInputPlugin(testView, dartExecutor, mock(PlatformViewsController.class)); |
| 51 | + |
| 52 | + ByteBuffer message = JSONMethodCodec.INSTANCE.encodeMethodCall(new MethodCall("TextInputClient.requestExistingInputState", null)); |
| 53 | + verify(dartExecutor, times(1)).send("flutter/textinput", message, null); |
| 54 | + } |
| 55 | + |
31 | 56 | @Test |
32 | 57 | public void setTextInputEditingState_doesNotRestartWhenTextIsIdentical() { |
33 | 58 | // Initialize a general TextInputPlugin. |
|
0 commit comments