Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6e8aaf3

Browse files
committed
Add tests
1 parent 5ac74b5 commit 6e8aaf3

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
import android.content.res.AssetManager;
55
import android.provider.Settings;
66
import android.util.SparseIntArray;
7+
import android.view.KeyEvent;
78
import android.view.View;
9+
import android.view.inputmethod.EditorInfo;
10+
import android.view.inputmethod.InputConnection;
811
import android.view.inputmethod.InputMethodManager;
912
import android.view.inputmethod.InputMethodSubtype;
1013

1114
import java.nio.ByteBuffer;
15+
import java.util.Arrays;
1216

1317
import org.junit.Test;
1418
import org.junit.runner.RunWith;
@@ -21,6 +25,7 @@
2125
import org.robolectric.shadows.ShadowBuild;
2226
import org.robolectric.shadows.ShadowInputMethodManager;
2327

28+
import io.flutter.Log;
2429
import io.flutter.embedding.engine.FlutterJNI;
2530
import io.flutter.embedding.engine.dart.DartExecutor;
2631
import io.flutter.embedding.engine.systemchannels.TextInputChannel;
@@ -155,6 +160,33 @@ public void setTextInputEditingState_nullInputMethodSubtype() {
155160
assertEquals(1, testImm.getRestartCount(testView));
156161
}
157162

163+
@Test
164+
public void inputConnection_createsActionFromEnter() {
165+
Log.setLogLevel(android.util.Log.VERBOSE);
166+
TestImm testImm = Shadow.extract(RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE));
167+
FlutterJNI mockFlutterJni = mock(FlutterJNI.class);
168+
View testView = new View(RuntimeEnvironment.application);
169+
DartExecutor dartExecutor = spy(new DartExecutor(mockFlutterJni, mock(AssetManager.class)));
170+
TextInputPlugin textInputPlugin = new TextInputPlugin(testView, dartExecutor, mock(PlatformViewsController.class));
171+
textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, true, TextInputChannel.TextCapitalization.NONE, new TextInputChannel.InputType(TextInputChannel.TextInputType.TEXT, false, false), null, null));
172+
// There's a pending restart since we initialized the text input client. Flush that now.
173+
textInputPlugin.setTextInputEditingState(testView, new TextInputChannel.TextEditState("", 0, 0));
174+
175+
EditorInfo editorInfo = new EditorInfo();
176+
InputConnection connection = textInputPlugin.createInputConnection(testView, editorInfo);
177+
178+
ByteBuffer message = JSONMethodCodec.INSTANCE.encodeMethodCall(
179+
new MethodCall("TextInputClient.performAction", Arrays.asList(0, "TextInputAction.done")));
180+
connection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
181+
verify(dartExecutor, times(2)).send("flutter/textinput", message, null);
182+
connection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER));
183+
184+
connection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_NUMPAD_ENTER));
185+
verify(dartExecutor, times(3)).send("flutter/textinput", message, null);
186+
connection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_NUMPAD_ENTER));
187+
}
188+
189+
158190
@Implements(InputMethodManager.class)
159191
public static class TestImm extends ShadowInputMethodManager {
160192
private InputMethodSubtype currentInputMethodSubtype;

0 commit comments

Comments
 (0)