1package io.flutter.plugin.editing;
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertTrue;
6import static org.mockito.Mockito.mock;
12import android.view.inputmethod.BaseInputConnection;
13import android.view.inputmethod.EditorInfo;
14import androidx.test.core.app.ApplicationProvider;
15import androidx.test.ext.junit.runners.AndroidJUnit4;
16import io.flutter.embedding.android.KeyboardManager;
17import io.flutter.embedding.engine.systemchannels.TextInputChannel;
18import java.util.ArrayList;
19import org.junit.Before;
21import org.junit.runner.RunWith;
22import org.mockito.Mock;
23import org.mockito.MockitoAnnotations;
24import org.robolectric.annotation.Config;
27@RunWith(AndroidJUnit4.class)
29 private final Context ctx = ApplicationProvider.getApplicationContext();
32 private BaseInputConnection getTestInputConnection(View view, Editable mEditable) {
34 return new BaseInputConnection(view,
true) {
36 public Editable getEditable() {
44 MockitoAnnotations.openMocks(
this);
59 final View testView =
new View(ctx);
60 final BaseInputConnection inputConnection = getTestInputConnection(testView, editingState);
64 editingState.
replace(0, editingState.length(),
"update");
77 editingState.
replace(0, editingState.length(),
"update1");
81 editingState.
replace(0, editingState.length(),
"update2");
82 inputConnection.setComposingRegion(0, editingState.length());
91 inputConnection.setSelection(0, 0);
98 inputConnection.finishComposingText();
118 editingState.
replace(0, editingState.length(),
"text");
125 editingState.
replace(0, editingState.length(),
"more text");
138 editingState.
replace(0, editingState.length(),
"update");
149 editingState.
replace(0, editingState.length(),
"more updates");
158 editingState.
replace(0, editingState.length(),
"update");
172 editingState.
replace(0, editingState.length(),
"update");
186 public void didChangeEditingState(
187 boolean textChanged,
boolean selectionChanged,
boolean composingRegionChanged) {
190 0, editingState.length(),
"one does not simply replace the text in the listener");
196 editingState.
replace(0, editingState.length(),
"update");
201 assertEquals(
"one does not simply replace the text in the listener", editingState.
toString());
208 editingState.
replace(0, editingState.length(),
"text");
237 editingState.
replace(0, editingState.length(),
"text");
238 editingState.delete(0, 1);
239 editingState.insert(0,
"This is t");
249 editingState.
replace(0, editingState.length(),
"test");
250 editingState.delete(0, 1);
251 editingState.insert(0,
"This is a t");
254 assertEquals(3, batchDeltas.size());
260 final ArrayList<String> batchMarkers =
new ArrayList<>();
264 public final void beginBatchEdit() {
266 batchMarkers.add(
"begin");
270 public void endBatchEdit() {
271 super.endBatchEdit();
272 batchMarkers.add(
"end");
277 final View testView =
new View(ctx);
290 assertEquals(1, batchMarkers.size());
291 assertEquals(
"begin", batchMarkers.get(0));
294 assertEquals(2, batchMarkers.size());
295 assertEquals(
"end", batchMarkers.get(1));
302 final View testView =
new View(ctx);
311 editingState.
replace(0, editingState.length(),
"initial text");
336 final View testView =
new View(ctx);
345 editingState.
replace(0, editingState.length(),
"initial text");
356 Selection.setSelection(editingState, 0, 0);
396 final View testView =
new View(ctx);
405 editingState.
replace(0, editingState.length(),
"initial text");
413 return timesCalled > 0;
417 boolean textChanged =
false;
418 boolean selectionChanged =
false;
419 boolean composingRegionChanged =
false;
423 boolean textChanged,
boolean selectionChanged,
boolean composingRegionChanged) {
425 this.textChanged = textChanged;
426 this.selectionChanged = selectionChanged;
427 this.composingRegionChanged = composingRegionChanged;
433 selectionChanged =
false;
434 composingRegionChanged =
false;
void didChangeEditingState(boolean textChanged, boolean selectionChanged, boolean composingRegionChanged)
boolean composingRegionChanged
void inputMethod_testSetSelection()
void testBatchingEditing_removeListenerDuringBatchEdit()
void testBatchingEditing_addListenerDuringBatchEdit()
void testBatchingEditing_listenerCallsReplaceWhenBatchEditEnds()
void inputMethod_testCommitText()
void testExtractBatchTextEditingDeltas()
void testSetComposingRegion()
void inputMethod_testSetComposition()
void inputMethod_batchEditingBeginAndEnd()
void testClearBatchDeltas()
KeyboardManager mockKeyboardManager
void testBatchingEditing_callEndBeforeBegin()
final int getSelectionStart()
ArrayList< TextEditingDelta > extractBatchTextEditingDeltas()
void removeEditingStateListener(EditingStateWatcher listener)
final int getComposingEnd()
SpannableStringBuilder replace(int start, int end, CharSequence tb, int tbstart, int tbend)
final int getSelectionEnd()
void addEditingStateListener(EditingStateWatcher listener)
final int getComposingStart()
void setComposingRange(int composingStart, int composingEnd)