2012-01-19 02:58:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
|
|
|
*
|
2013-02-12 07:15:47 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2012-01-19 02:58:54 +00:00
|
|
|
*
|
2013-02-12 07:15:47 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-01-19 02:58:54 +00:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-02-12 07:15:47 +00:00
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2012-01-19 02:58:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.latin;
|
|
|
|
|
2014-04-03 07:25:05 +00:00
|
|
|
import com.android.inputmethod.latin.settings.Settings;
|
|
|
|
|
2013-02-04 23:25:24 +00:00
|
|
|
import android.test.suitebuilder.annotation.LargeTest;
|
2014-04-03 07:25:05 +00:00
|
|
|
import android.text.TextUtils;
|
2013-08-15 07:31:29 +00:00
|
|
|
import android.view.inputmethod.BaseInputConnection;
|
2013-02-04 23:25:24 +00:00
|
|
|
|
|
|
|
@LargeTest
|
2012-03-23 04:12:19 +00:00
|
|
|
public class InputLogicTests extends InputTestsBase {
|
2012-03-01 10:04:44 +00:00
|
|
|
|
2012-01-19 02:58:54 +00:00
|
|
|
public void testTypeWord() {
|
2012-01-24 08:15:06 +00:00
|
|
|
final String WORD_TO_TYPE = "abcd";
|
|
|
|
type(WORD_TO_TYPE);
|
2013-05-01 04:33:39 +00:00
|
|
|
assertEquals("type word", WORD_TO_TYPE, mEditText.getText().toString());
|
2012-01-19 02:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testPickSuggestionThenBackspace() {
|
2012-02-03 07:05:48 +00:00
|
|
|
final String WORD_TO_TYPE = "this";
|
2012-05-18 10:10:48 +00:00
|
|
|
final String EXPECTED_RESULT = "thi";
|
2012-01-24 08:15:06 +00:00
|
|
|
type(WORD_TO_TYPE);
|
2012-04-12 04:42:22 +00:00
|
|
|
pickSuggestionManually(0, WORD_TO_TYPE);
|
2012-02-03 07:05:48 +00:00
|
|
|
mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
|
2012-10-29 05:46:34 +00:00
|
|
|
type(Constants.CODE_DELETE);
|
2012-02-03 07:05:48 +00:00
|
|
|
assertEquals("press suggestion then backspace", EXPECTED_RESULT,
|
2013-05-01 04:33:39 +00:00
|
|
|
mEditText.getText().toString());
|
2012-02-03 07:05:48 +00:00
|
|
|
}
|
|
|
|
|
2012-02-22 09:17:26 +00:00
|
|
|
public void testPickAutoCorrectionThenBackspace() {
|
|
|
|
final String WORD_TO_TYPE = "tgis";
|
|
|
|
final String WORD_TO_PICK = "this";
|
2012-05-18 10:10:48 +00:00
|
|
|
final String EXPECTED_RESULT = "thi";
|
2012-02-22 09:17:26 +00:00
|
|
|
type(WORD_TO_TYPE);
|
|
|
|
// Choose the auto-correction, which is always in position 0. For "tgis", the
|
|
|
|
// auto-correction should be "this".
|
2012-04-12 04:42:22 +00:00
|
|
|
pickSuggestionManually(0, WORD_TO_PICK);
|
2012-02-22 09:17:26 +00:00
|
|
|
mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
|
|
|
|
assertEquals("pick typed word over auto-correction then backspace", WORD_TO_PICK,
|
2013-05-01 04:33:39 +00:00
|
|
|
mEditText.getText().toString());
|
2012-10-29 05:46:34 +00:00
|
|
|
type(Constants.CODE_DELETE);
|
2012-02-22 09:17:26 +00:00
|
|
|
assertEquals("pick typed word over auto-correction then backspace", EXPECTED_RESULT,
|
2013-05-01 04:33:39 +00:00
|
|
|
mEditText.getText().toString());
|
2012-02-22 09:17:26 +00:00
|
|
|
}
|
|
|
|
|
2012-02-03 07:05:48 +00:00
|
|
|
public void testPickTypedWordOverAutoCorrectionThenBackspace() {
|
|
|
|
final String WORD_TO_TYPE = "tgis";
|
2012-05-18 10:10:48 +00:00
|
|
|
final String EXPECTED_RESULT = "tgi";
|
2012-02-03 07:05:48 +00:00
|
|
|
type(WORD_TO_TYPE);
|
|
|
|
// Choose the typed word, which should be in position 1 (because position 0 should
|
|
|
|
// be occupied by the "this" auto-correction, as checked by testAutoCorrect())
|
2012-04-12 04:42:22 +00:00
|
|
|
pickSuggestionManually(1, WORD_TO_TYPE);
|
2012-02-03 07:05:48 +00:00
|
|
|
mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
|
2012-02-22 09:17:26 +00:00
|
|
|
assertEquals("pick typed word over auto-correction then backspace", WORD_TO_TYPE,
|
2013-05-01 04:33:39 +00:00
|
|
|
mEditText.getText().toString());
|
2012-10-29 05:46:34 +00:00
|
|
|
type(Constants.CODE_DELETE);
|
2012-02-03 07:05:48 +00:00
|
|
|
assertEquals("pick typed word over auto-correction then backspace", EXPECTED_RESULT,
|
2013-05-01 04:33:39 +00:00
|
|
|
mEditText.getText().toString());
|
2012-01-19 02:58:54 +00:00
|
|
|
}
|
|
|
|
|
2012-02-22 09:17:26 +00:00
|
|
|
public void testPickDifferentSuggestionThenBackspace() {
|
|
|
|
final String WORD_TO_TYPE = "tgis";
|
|
|
|
final String WORD_TO_PICK = "thus";
|
2012-05-18 10:10:48 +00:00
|
|
|
final String EXPECTED_RESULT = "thu";
|
2012-02-22 09:17:26 +00:00
|
|
|
type(WORD_TO_TYPE);
|
|
|
|
// Choose the second suggestion, which should be in position 2 and should be "thus"
|
|
|
|
// when "tgis is typed.
|
2012-04-12 04:42:22 +00:00
|
|
|
pickSuggestionManually(2, WORD_TO_PICK);
|
2012-02-22 09:17:26 +00:00
|
|
|
mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1);
|
|
|
|
assertEquals("pick different suggestion then backspace", WORD_TO_PICK,
|
2013-05-01 04:33:39 +00:00
|
|
|
mEditText.getText().toString());
|
2012-10-29 05:46:34 +00:00
|
|
|
type(Constants.CODE_DELETE);
|
2012-02-22 09:17:26 +00:00
|
|
|
assertEquals("pick different suggestion then backspace", EXPECTED_RESULT,
|
2013-05-01 04:33:39 +00:00
|
|
|
mEditText.getText().toString());
|
2012-02-22 09:17:26 +00:00
|
|
|
}
|
|
|
|
|
2012-01-24 08:15:06 +00:00
|
|
|
public void testDeleteSelection() {
|
|
|
|
final String STRING_TO_TYPE = "some text delete me some text";
|
2012-10-10 09:57:47 +00:00
|
|
|
final int typedLength = STRING_TO_TYPE.length();
|
2012-01-24 08:15:06 +00:00
|
|
|
final int SELECTION_START = 10;
|
|
|
|
final int SELECTION_END = 19;
|
|
|
|
final String EXPECTED_RESULT = "some text some text";
|
|
|
|
type(STRING_TO_TYPE);
|
|
|
|
// There is no IMF to call onUpdateSelection for us so we must do it by hand.
|
|
|
|
// Send once to simulate the cursor actually responding to the move caused by typing.
|
|
|
|
// This is necessary because LatinIME is bookkeeping to avoid confusing a real cursor
|
|
|
|
// move with a move triggered by LatinIME inputting stuff.
|
2012-10-10 09:57:47 +00:00
|
|
|
mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
|
2012-01-24 08:15:06 +00:00
|
|
|
mInputConnection.setSelection(SELECTION_START, SELECTION_END);
|
|
|
|
// And now we simulate the user actually selecting some text.
|
2012-10-10 09:57:47 +00:00
|
|
|
mLatinIME.onUpdateSelection(typedLength, typedLength,
|
|
|
|
SELECTION_START, SELECTION_END, -1, -1);
|
2012-10-29 05:46:34 +00:00
|
|
|
type(Constants.CODE_DELETE);
|
2013-05-01 04:33:39 +00:00
|
|
|
assertEquals("delete selection", EXPECTED_RESULT, mEditText.getText().toString());
|
2013-01-09 09:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testDeleteSelectionTwice() {
|
|
|
|
final String STRING_TO_TYPE = "some text delete me some text";
|
|
|
|
final int typedLength = STRING_TO_TYPE.length();
|
|
|
|
final int SELECTION_START = 10;
|
|
|
|
final int SELECTION_END = 19;
|
|
|
|
final String EXPECTED_RESULT = "some text some text";
|
|
|
|
type(STRING_TO_TYPE);
|
|
|
|
// There is no IMF to call onUpdateSelection for us so we must do it by hand.
|
|
|
|
// Send once to simulate the cursor actually responding to the move caused by typing.
|
|
|
|
// This is necessary because LatinIME is bookkeeping to avoid confusing a real cursor
|
|
|
|
// move with a move triggered by LatinIME inputting stuff.
|
|
|
|
mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
|
|
|
|
mInputConnection.setSelection(SELECTION_START, SELECTION_END);
|
|
|
|
// And now we simulate the user actually selecting some text.
|
|
|
|
mLatinIME.onUpdateSelection(typedLength, typedLength,
|
|
|
|
SELECTION_START, SELECTION_END, -1, -1);
|
|
|
|
type(Constants.CODE_DELETE);
|
|
|
|
type(Constants.CODE_DELETE);
|
2013-05-01 04:33:39 +00:00
|
|
|
assertEquals("delete selection twice", EXPECTED_RESULT, mEditText.getText().toString());
|
2012-01-24 08:15:06 +00:00
|
|
|
}
|
2012-01-25 09:11:26 +00:00
|
|
|
|
|
|
|
public void testAutoCorrect() {
|
|
|
|
final String STRING_TO_TYPE = "tgis ";
|
|
|
|
final String EXPECTED_RESULT = "this ";
|
|
|
|
type(STRING_TO_TYPE);
|
2013-05-01 04:33:39 +00:00
|
|
|
assertEquals("simple auto-correct", EXPECTED_RESULT, mEditText.getText().toString());
|
2012-02-22 09:17:26 +00:00
|
|
|
}
|
|
|
|
|
2013-09-17 10:43:22 +00:00
|
|
|
public void testAutoCorrectWithQuote() {
|
|
|
|
final String STRING_TO_TYPE = "didn' ";
|
|
|
|
final String EXPECTED_RESULT = "didn't ";
|
|
|
|
type(STRING_TO_TYPE);
|
|
|
|
assertEquals("auto-correct with quote", EXPECTED_RESULT, mEditText.getText().toString());
|
|
|
|
}
|
|
|
|
|
2012-02-22 09:17:26 +00:00
|
|
|
public void testAutoCorrectWithPeriod() {
|
|
|
|
final String STRING_TO_TYPE = "tgis.";
|
|
|
|
final String EXPECTED_RESULT = "this.";
|
|
|
|
type(STRING_TO_TYPE);
|
2013-05-01 04:33:39 +00:00
|
|
|
assertEquals("auto-correct with period", EXPECTED_RESULT, mEditText.getText().toString());
|
2012-02-22 09:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testAutoCorrectWithPeriodThenRevert() {
|
|
|
|
final String STRING_TO_TYPE = "tgis.";
|
|
|
|
final String EXPECTED_RESULT = "tgis.";
|
|
|
|
type(STRING_TO_TYPE);
|
|
|
|
mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
|
2012-10-29 05:46:34 +00:00
|
|
|
type(Constants.CODE_DELETE);
|
2012-02-22 09:17:26 +00:00
|
|
|
assertEquals("auto-correct with period then revert", EXPECTED_RESULT,
|
2013-05-01 04:33:39 +00:00
|
|
|
mEditText.getText().toString());
|
2012-01-25 09:11:26 +00:00
|
|
|
}
|
2012-01-26 01:10:38 +00:00
|
|
|
|
2012-07-05 02:43:03 +00:00
|
|
|
public void testAutoCorrectWithSpaceThenRevert() {
|
|
|
|
final String STRING_TO_TYPE = "tgis ";
|
|
|
|
final String EXPECTED_RESULT = "tgis ";
|
|
|
|
type(STRING_TO_TYPE);
|
|
|
|
mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
|
2012-10-29 05:46:34 +00:00
|
|
|
type(Constants.CODE_DELETE);
|
2012-07-05 02:43:03 +00:00
|
|
|
assertEquals("auto-correct with space then revert", EXPECTED_RESULT,
|
2013-05-01 04:33:39 +00:00
|
|
|
mEditText.getText().toString());
|
2012-07-05 02:43:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testAutoCorrectToSelfDoesNotRevert() {
|
|
|
|
final String STRING_TO_TYPE = "this ";
|
|
|
|
final String EXPECTED_RESULT = "this";
|
|
|
|
type(STRING_TO_TYPE);
|
|
|
|
mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1);
|
2012-10-29 05:46:34 +00:00
|
|
|
type(Constants.CODE_DELETE);
|
2012-07-05 02:43:03 +00:00
|
|
|
assertEquals("auto-correct with space does not revert", EXPECTED_RESULT,
|
2013-05-01 04:33:39 +00:00
|
|
|
mEditText.getText().toString());
|
2012-07-05 02:43:03 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 01:10:38 +00:00
|
|
|
public void testDoubleSpace() {
|
2014-04-03 07:25:05 +00:00
|
|
|
// Set default pref just in case
|
|
|
|
setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true);
|
2013-10-04 12:29:20 +00:00
|
|
|
// U+1F607 is an emoji
|
|
|
|
final String[] STRINGS_TO_TYPE =
|
|
|
|
new String[] { "this ", "a+ ", "\u1F607 ", ".. ", ") ", "( ", "% " };
|
|
|
|
final String[] EXPECTED_RESULTS =
|
2013-10-11 07:52:12 +00:00
|
|
|
new String[] { "this. ", "a+. ", "\u1F607. ", ".. ", "). ", "( ", "%. " };
|
2013-10-04 12:29:20 +00:00
|
|
|
for (int i = 0; i < STRINGS_TO_TYPE.length; ++i) {
|
|
|
|
mEditText.setText("");
|
|
|
|
type(STRINGS_TO_TYPE[i]);
|
|
|
|
assertEquals("double space processing", EXPECTED_RESULTS[i],
|
|
|
|
mEditText.getText().toString());
|
|
|
|
}
|
2012-01-26 01:10:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCancelDoubleSpace() {
|
2012-02-02 08:18:03 +00:00
|
|
|
final String STRING_TO_TYPE = "this ";
|
2013-08-08 03:51:37 +00:00
|
|
|
final String EXPECTED_RESULT = "this ";
|
2012-01-26 01:10:38 +00:00
|
|
|
type(STRING_TO_TYPE);
|
2012-10-29 05:46:34 +00:00
|
|
|
type(Constants.CODE_DELETE);
|
2013-05-01 04:33:39 +00:00
|
|
|
assertEquals("double space make a period", EXPECTED_RESULT, mEditText.getText().toString());
|
2012-01-26 07:08:53 +00:00
|
|
|
}
|
2012-01-26 01:02:33 +00:00
|
|
|
|
2014-04-03 07:25:05 +00:00
|
|
|
private void testDoubleSpacePeriodWithSettings(final boolean expectsPeriod,
|
|
|
|
final Object... settingsKeysValues) {
|
|
|
|
final Object[] oldSettings = new Object[settingsKeysValues.length / 2];
|
|
|
|
final String STRING_WITHOUT_PERIOD = "this ";
|
|
|
|
final String STRING_WITH_PERIOD = "this. ";
|
|
|
|
final String EXPECTED_RESULT = expectsPeriod ? STRING_WITH_PERIOD : STRING_WITHOUT_PERIOD;
|
|
|
|
try {
|
|
|
|
for (int i = 0; i < settingsKeysValues.length; i += 2) {
|
|
|
|
if (settingsKeysValues[i + 1] instanceof String) {
|
|
|
|
oldSettings[i / 2] = setStringPreference((String)settingsKeysValues[i],
|
|
|
|
(String)settingsKeysValues[i + 1], "0");
|
|
|
|
} else {
|
|
|
|
oldSettings[i / 2] = setBooleanPreference((String)settingsKeysValues[i],
|
|
|
|
(Boolean)settingsKeysValues[i + 1], false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mLatinIME.loadSettings();
|
|
|
|
mEditText.setText("");
|
|
|
|
type(STRING_WITHOUT_PERIOD);
|
|
|
|
assertEquals("double-space-to-period with specific settings "
|
|
|
|
+ TextUtils.join(" ", settingsKeysValues),
|
|
|
|
EXPECTED_RESULT, mEditText.getText().toString());
|
|
|
|
} finally {
|
|
|
|
// Restore old settings
|
|
|
|
for (int i = 0; i < settingsKeysValues.length; i += 2) {
|
|
|
|
if (null == oldSettings[i / 2]) {
|
|
|
|
break;
|
|
|
|
} if (oldSettings[i / 2] instanceof String) {
|
|
|
|
setStringPreference((String)settingsKeysValues[i], (String)oldSettings[i / 2],
|
|
|
|
"");
|
|
|
|
} else {
|
|
|
|
setBooleanPreference((String)settingsKeysValues[i], (Boolean)oldSettings[i / 2],
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testDoubleSpacePeriod() {
|
|
|
|
// Reset settings to default, else these tests will go flaky.
|
|
|
|
setStringPreference(Settings.PREF_SHOW_SUGGESTIONS_SETTING, "0", "0");
|
|
|
|
setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, "1", "1");
|
|
|
|
setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true);
|
|
|
|
testDoubleSpacePeriodWithSettings(true /* expectsPeriod */);
|
|
|
|
// "Suggestion visibility" to "always hide"
|
|
|
|
testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "2");
|
|
|
|
// "Suggestion visibility" to "portrait only"
|
|
|
|
testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "1");
|
|
|
|
// "Suggestion visibility" to "always show"
|
|
|
|
testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "0");
|
|
|
|
|
|
|
|
// "Double-space period" to "off"
|
|
|
|
testDoubleSpacePeriodWithSettings(false, Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, false);
|
|
|
|
|
|
|
|
// "Auto-correction" to "off"
|
|
|
|
testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0");
|
|
|
|
// "Auto-correction" to "modest"
|
|
|
|
testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION_THRESHOLD, "1");
|
|
|
|
// "Auto-correction" to "very aggressive"
|
|
|
|
testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION_THRESHOLD, "3");
|
|
|
|
|
|
|
|
// "Suggestion visibility" to "always hide" and "Auto-correction" to "off"
|
|
|
|
testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "0",
|
|
|
|
Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0");
|
|
|
|
// "Suggestion visibility" to "always hide" and "Auto-correction" to "off"
|
|
|
|
testDoubleSpacePeriodWithSettings(false, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "0",
|
|
|
|
Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0",
|
|
|
|
Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, false);
|
|
|
|
}
|
|
|
|
|
2012-01-26 01:02:33 +00:00
|
|
|
public void testBackspaceAtStartAfterAutocorrect() {
|
|
|
|
final String STRING_TO_TYPE = "tgis ";
|
2012-10-10 09:57:47 +00:00
|
|
|
final int typedLength = STRING_TO_TYPE.length();
|
2012-01-26 01:02:33 +00:00
|
|
|
final String EXPECTED_RESULT = "this ";
|
|
|
|
final int NEW_CURSOR_POSITION = 0;
|
|
|
|
type(STRING_TO_TYPE);
|
2012-10-10 09:57:47 +00:00
|
|
|
mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
|
2012-01-26 01:02:33 +00:00
|
|
|
mInputConnection.setSelection(NEW_CURSOR_POSITION, NEW_CURSOR_POSITION);
|
2012-10-10 09:57:47 +00:00
|
|
|
mLatinIME.onUpdateSelection(typedLength, typedLength,
|
|
|
|
NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
|
2012-10-29 05:46:34 +00:00
|
|
|
type(Constants.CODE_DELETE);
|
2012-02-02 08:18:03 +00:00
|
|
|
assertEquals("auto correct then move cursor to start of line then backspace",
|
2013-05-01 04:33:39 +00:00
|
|
|
EXPECTED_RESULT, mEditText.getText().toString());
|
2012-01-26 01:10:38 +00:00
|
|
|
}
|
2012-01-26 00:59:28 +00:00
|
|
|
|
|
|
|
public void testAutoCorrectThenMoveCursorThenBackspace() {
|
|
|
|
final String STRING_TO_TYPE = "and tgis ";
|
2012-10-10 09:57:47 +00:00
|
|
|
final int typedLength = STRING_TO_TYPE.length();
|
2012-01-26 00:59:28 +00:00
|
|
|
final String EXPECTED_RESULT = "andthis ";
|
|
|
|
final int NEW_CURSOR_POSITION = STRING_TO_TYPE.indexOf('t');
|
|
|
|
type(STRING_TO_TYPE);
|
2012-10-10 09:57:47 +00:00
|
|
|
mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
|
2012-01-26 00:59:28 +00:00
|
|
|
mInputConnection.setSelection(NEW_CURSOR_POSITION, NEW_CURSOR_POSITION);
|
2012-10-10 09:57:47 +00:00
|
|
|
mLatinIME.onUpdateSelection(typedLength, typedLength,
|
|
|
|
NEW_CURSOR_POSITION, NEW_CURSOR_POSITION, -1, -1);
|
2012-10-29 05:46:34 +00:00
|
|
|
type(Constants.CODE_DELETE);
|
2012-02-02 08:18:03 +00:00
|
|
|
assertEquals("auto correct then move cursor then backspace",
|
2013-05-01 04:33:39 +00:00
|
|
|
EXPECTED_RESULT, mEditText.getText().toString());
|
2012-01-26 00:59:28 +00:00
|
|
|
}
|
2012-02-02 08:53:00 +00:00
|
|
|
|
|
|
|
public void testNoSpaceAfterManualPick() {
|
|
|
|
final String WORD_TO_TYPE = "this";
|
|
|
|
final String EXPECTED_RESULT = WORD_TO_TYPE;
|
|
|
|
type(WORD_TO_TYPE);
|
2012-04-12 04:42:22 +00:00
|
|
|
pickSuggestionManually(0, WORD_TO_TYPE);
|
2012-02-02 08:53:00 +00:00
|
|
|
assertEquals("no space after manual pick", EXPECTED_RESULT,
|
2013-05-01 04:33:39 +00:00
|
|
|
mEditText.getText().toString());
|
2012-02-02 08:53:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testManualPickThenType() {
|
|
|
|
final String WORD1_TO_TYPE = "this";
|
|
|
|
final String WORD2_TO_TYPE = "is";
|
|
|
|
final String EXPECTED_RESULT = "this is";
|
|
|
|
type(WORD1_TO_TYPE);
|
2012-04-12 04:42:22 +00:00
|
|
|
pickSuggestionManually(0, WORD1_TO_TYPE);
|
2012-02-02 08:53:00 +00:00
|
|
|
type(WORD2_TO_TYPE);
|
2013-05-01 04:33:39 +00:00
|
|
|
assertEquals("manual pick then type", EXPECTED_RESULT, mEditText.getText().toString());
|
2012-02-02 08:53:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testManualPickThenSeparator() {
|
|
|
|
final String WORD1_TO_TYPE = "this";
|
|
|
|
final String WORD2_TO_TYPE = "!";
|
|
|
|
final String EXPECTED_RESULT = "this!";
|
|
|
|
type(WORD1_TO_TYPE);
|
2012-04-12 04:42:22 +00:00
|
|
|
pickSuggestionManually(0, WORD1_TO_TYPE);
|
2012-02-02 08:53:00 +00:00
|
|
|
type(WORD2_TO_TYPE);
|
2013-05-01 04:33:39 +00:00
|
|
|
assertEquals("manual pick then separator", EXPECTED_RESULT, mEditText.getText().toString());
|
2014-05-01 03:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This test matches the one in InputLogicTestsNonEnglish. In some non-English languages,
|
|
|
|
// ! and ? are clustering punctuation signs.
|
|
|
|
public void testClusteringPunctuation() {
|
|
|
|
final String WORD1_TO_TYPE = "test";
|
|
|
|
final String WORD2_TO_TYPE = "!!?!:!";
|
|
|
|
final String EXPECTED_RESULT = "test!!?!:!";
|
|
|
|
type(WORD1_TO_TYPE);
|
|
|
|
pickSuggestionManually(0, WORD1_TO_TYPE);
|
|
|
|
type(WORD2_TO_TYPE);
|
|
|
|
assertEquals("clustering punctuation", EXPECTED_RESULT, mEditText.getText().toString());
|
2012-02-02 08:53:00 +00:00
|
|
|
}
|
|
|
|
|
2012-07-27 15:49:43 +00:00
|
|
|
public void testManualPickThenStripperThenPick() {
|
|
|
|
final String WORD_TO_TYPE = "this";
|
|
|
|
final String STRIPPER = "\n";
|
|
|
|
final String EXPECTED_RESULT = "this\nthis";
|
|
|
|
type(WORD_TO_TYPE);
|
|
|
|
pickSuggestionManually(0, WORD_TO_TYPE);
|
|
|
|
type(STRIPPER);
|
|
|
|
type(WORD_TO_TYPE);
|
|
|
|
pickSuggestionManually(0, WORD_TO_TYPE);
|
|
|
|
assertEquals("manual pick then \\n then manual pick", EXPECTED_RESULT,
|
2013-05-01 04:33:39 +00:00
|
|
|
mEditText.getText().toString());
|
2012-07-27 15:49:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 08:53:00 +00:00
|
|
|
public void testManualPickThenSpaceThenType() {
|
|
|
|
final String WORD1_TO_TYPE = "this";
|
|
|
|
final String WORD2_TO_TYPE = " is";
|
|
|
|
final String EXPECTED_RESULT = "this is";
|
|
|
|
type(WORD1_TO_TYPE);
|
2012-04-12 04:42:22 +00:00
|
|
|
pickSuggestionManually(0, WORD1_TO_TYPE);
|
2012-02-02 08:53:00 +00:00
|
|
|
type(WORD2_TO_TYPE);
|
2012-03-07 06:59:53 +00:00
|
|
|
assertEquals("manual pick then space then type", EXPECTED_RESULT,
|
2013-05-01 04:33:39 +00:00
|
|
|
mEditText.getText().toString());
|
2012-03-07 06:59:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testManualPickThenManualPick() {
|
|
|
|
final String WORD1_TO_TYPE = "this";
|
|
|
|
final String WORD2_TO_PICK = "is";
|
|
|
|
final String EXPECTED_RESULT = "this is";
|
|
|
|
type(WORD1_TO_TYPE);
|
2012-04-12 04:42:22 +00:00
|
|
|
pickSuggestionManually(0, WORD1_TO_TYPE);
|
2012-03-07 06:59:53 +00:00
|
|
|
// Here we fake picking a word through bigram prediction. This test is taking
|
|
|
|
// advantage of the fact that Latin IME blindly trusts the caller of #pickSuggestionManually
|
|
|
|
// to actually pass the right string.
|
2012-04-12 04:42:22 +00:00
|
|
|
pickSuggestionManually(1, WORD2_TO_PICK);
|
2012-03-07 06:59:53 +00:00
|
|
|
assertEquals("manual pick then manual pick", EXPECTED_RESULT,
|
2013-05-01 04:33:39 +00:00
|
|
|
mEditText.getText().toString());
|
2012-03-07 06:59:53 +00:00
|
|
|
}
|
|
|
|
|
2012-02-03 03:22:02 +00:00
|
|
|
public void testDeleteWholeComposingWord() {
|
|
|
|
final String WORD_TO_TYPE = "this";
|
|
|
|
type(WORD_TO_TYPE);
|
|
|
|
for (int i = 0; i < WORD_TO_TYPE.length(); ++i) {
|
2012-10-29 05:46:34 +00:00
|
|
|
type(Constants.CODE_DELETE);
|
2012-02-03 03:22:02 +00:00
|
|
|
}
|
2013-05-01 04:33:39 +00:00
|
|
|
assertEquals("delete whole composing word", "", mEditText.getText().toString());
|
2012-02-03 03:22:02 +00:00
|
|
|
}
|
2013-08-15 07:31:29 +00:00
|
|
|
|
|
|
|
public void testResumeSuggestionOnBackspace() {
|
2013-12-25 12:43:23 +00:00
|
|
|
final String STRING_TO_TYPE = "and this ";
|
|
|
|
final int typedLength = STRING_TO_TYPE.length();
|
|
|
|
type(STRING_TO_TYPE);
|
2013-08-15 07:31:29 +00:00
|
|
|
assertEquals("resume suggestion on backspace", -1,
|
|
|
|
BaseInputConnection.getComposingSpanStart(mEditText.getText()));
|
|
|
|
assertEquals("resume suggestion on backspace", -1,
|
|
|
|
BaseInputConnection.getComposingSpanEnd(mEditText.getText()));
|
2013-12-25 12:43:23 +00:00
|
|
|
mLatinIME.onUpdateSelection(0, 0, typedLength, typedLength, -1, -1);
|
2013-08-15 07:31:29 +00:00
|
|
|
type(Constants.CODE_DELETE);
|
|
|
|
assertEquals("resume suggestion on backspace", 4,
|
|
|
|
BaseInputConnection.getComposingSpanStart(mEditText.getText()));
|
|
|
|
assertEquals("resume suggestion on backspace", 8,
|
|
|
|
BaseInputConnection.getComposingSpanEnd(mEditText.getText()));
|
|
|
|
}
|
2013-08-21 06:52:33 +00:00
|
|
|
|
|
|
|
private void helperTestComposing(final String wordToType, final boolean shouldBeComposing) {
|
|
|
|
mEditText.setText("");
|
|
|
|
type(wordToType);
|
|
|
|
assertEquals("start composing inside text", shouldBeComposing ? 0 : -1,
|
|
|
|
BaseInputConnection.getComposingSpanStart(mEditText.getText()));
|
|
|
|
assertEquals("start composing inside text", shouldBeComposing ? wordToType.length() : -1,
|
|
|
|
BaseInputConnection.getComposingSpanEnd(mEditText.getText()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testStartComposing() {
|
|
|
|
// Should start composing on a letter
|
|
|
|
helperTestComposing("a", true);
|
|
|
|
type(" "); // To reset the composing state
|
|
|
|
// Should not start composing on quote
|
|
|
|
helperTestComposing("'", false);
|
|
|
|
type(" ");
|
|
|
|
helperTestComposing("'-", false);
|
|
|
|
type(" ");
|
|
|
|
// Should not start composing on dash
|
|
|
|
helperTestComposing("-", false);
|
|
|
|
type(" ");
|
|
|
|
helperTestComposing("-'", false);
|
|
|
|
type(" ");
|
|
|
|
helperTestComposing("a-", true);
|
|
|
|
type(" ");
|
|
|
|
helperTestComposing("a'", true);
|
|
|
|
}
|
2012-02-03 07:05:48 +00:00
|
|
|
// TODO: Add some tests for non-BMP characters
|
2013-12-26 14:13:58 +00:00
|
|
|
|
2014-02-21 04:12:26 +00:00
|
|
|
public void testAutoCorrectByUserHistory() {
|
|
|
|
final String WORD_TO_BE_CORRECTED = "qpmx";
|
|
|
|
final String NOT_CORRECTED_RESULT = "qpmx ";
|
|
|
|
final String DESIRED_WORD = "qpmz";
|
|
|
|
final String CORRECTED_RESULT = "qpmz ";
|
2014-03-14 03:23:24 +00:00
|
|
|
final int typeCountNotToAutocorrect = 1;
|
2014-02-21 04:12:26 +00:00
|
|
|
final int typeCountToAutoCorrect = 16;
|
|
|
|
int startIndex = 0;
|
|
|
|
int endIndex = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < typeCountNotToAutocorrect; i++) {
|
|
|
|
type(DESIRED_WORD);
|
|
|
|
type(Constants.CODE_SPACE);
|
|
|
|
}
|
|
|
|
startIndex = mEditText.getText().length();
|
|
|
|
type(WORD_TO_BE_CORRECTED);
|
|
|
|
type(Constants.CODE_SPACE);
|
|
|
|
endIndex = mEditText.getText().length();
|
|
|
|
assertEquals("not auto-corrected by user history", NOT_CORRECTED_RESULT,
|
|
|
|
mEditText.getText().subSequence(startIndex, endIndex).toString());
|
|
|
|
for (int i = typeCountNotToAutocorrect; i < typeCountToAutoCorrect; i++) {
|
|
|
|
type(DESIRED_WORD);
|
|
|
|
type(Constants.CODE_SPACE);
|
|
|
|
}
|
|
|
|
startIndex = mEditText.getText().length();
|
|
|
|
type(WORD_TO_BE_CORRECTED);
|
|
|
|
type(Constants.CODE_SPACE);
|
|
|
|
endIndex = mEditText.getText().length();
|
|
|
|
assertEquals("auto-corrected by user history",
|
|
|
|
CORRECTED_RESULT, mEditText.getText().subSequence(startIndex, endIndex).toString());
|
|
|
|
}
|
|
|
|
|
2013-12-26 14:13:58 +00:00
|
|
|
public void testPredictionsAfterSpace() {
|
|
|
|
final String WORD_TO_TYPE = "Barack ";
|
|
|
|
type(WORD_TO_TYPE);
|
|
|
|
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
|
|
|
|
runMessages();
|
|
|
|
// Test the first prediction is displayed
|
2014-02-18 08:07:46 +00:00
|
|
|
final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
|
2013-12-26 14:13:58 +00:00
|
|
|
assertEquals("predictions after space", "Obama",
|
|
|
|
suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testPredictionsAfterManualPick() {
|
|
|
|
final String WORD_TO_TYPE = "Barack";
|
|
|
|
type(WORD_TO_TYPE);
|
|
|
|
// Choose the auto-correction, which is always in position 0. For "Barack", the
|
|
|
|
// auto-correction should be "Barack".
|
|
|
|
pickSuggestionManually(0, WORD_TO_TYPE);
|
|
|
|
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
|
2014-01-09 07:23:43 +00:00
|
|
|
runMessages();
|
2013-12-26 14:13:58 +00:00
|
|
|
// Test the first prediction is displayed
|
2014-02-18 08:07:46 +00:00
|
|
|
final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
|
2013-12-26 14:13:58 +00:00
|
|
|
assertEquals("predictions after manual pick", "Obama",
|
|
|
|
suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testNoPredictionsAfterPeriod() {
|
|
|
|
final String WORD_TO_TYPE = "Barack. ";
|
|
|
|
type(WORD_TO_TYPE);
|
|
|
|
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
|
|
|
|
runMessages();
|
2014-01-10 12:39:02 +00:00
|
|
|
// Test the first prediction is not displayed
|
2014-02-18 08:07:46 +00:00
|
|
|
final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
|
2013-12-26 14:13:58 +00:00
|
|
|
assertEquals("no prediction after period", 0, suggestedWords.size());
|
|
|
|
}
|
2014-02-18 07:58:04 +00:00
|
|
|
|
|
|
|
public void testPredictionsAfterRecorrection() {
|
|
|
|
final String PREFIX = "A ";
|
|
|
|
final String WORD_TO_TYPE = "Barack";
|
|
|
|
final String FIRST_NON_TYPED_SUGGESTION = "Barrack";
|
|
|
|
final int endOfPrefix = PREFIX.length();
|
|
|
|
final int endOfWord = endOfPrefix + WORD_TO_TYPE.length();
|
|
|
|
final int endOfSuggestion = endOfPrefix + FIRST_NON_TYPED_SUGGESTION.length();
|
|
|
|
final int indexForManualCursor = endOfPrefix + 3; // +3 because it's after "Bar" in "Barack"
|
|
|
|
type(PREFIX);
|
|
|
|
mLatinIME.onUpdateSelection(0, 0, endOfPrefix, endOfPrefix, -1, -1);
|
|
|
|
type(WORD_TO_TYPE);
|
|
|
|
pickSuggestionManually(1, FIRST_NON_TYPED_SUGGESTION);
|
|
|
|
mLatinIME.onUpdateSelection(endOfPrefix, endOfPrefix, endOfSuggestion, endOfSuggestion,
|
|
|
|
-1, -1);
|
|
|
|
runMessages();
|
|
|
|
type(" ");
|
|
|
|
mLatinIME.onUpdateSelection(endOfSuggestion, endOfSuggestion,
|
|
|
|
endOfSuggestion + 1, endOfSuggestion + 1, -1, -1);
|
|
|
|
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
|
|
|
|
runMessages();
|
|
|
|
// Simulate a manual cursor move
|
|
|
|
mInputConnection.setSelection(indexForManualCursor, indexForManualCursor);
|
|
|
|
mLatinIME.onUpdateSelection(endOfSuggestion + 1, endOfSuggestion + 1,
|
|
|
|
indexForManualCursor, indexForManualCursor, -1, -1);
|
|
|
|
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
|
|
|
|
runMessages();
|
|
|
|
pickSuggestionManually(0, WORD_TO_TYPE);
|
|
|
|
mLatinIME.onUpdateSelection(indexForManualCursor, indexForManualCursor,
|
|
|
|
endOfWord, endOfWord, -1, -1);
|
|
|
|
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
|
|
|
|
runMessages();
|
|
|
|
// Test the first prediction is displayed
|
2014-02-18 11:08:53 +00:00
|
|
|
final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
|
2014-02-18 07:58:04 +00:00
|
|
|
assertEquals("predictions after recorrection", "Obama",
|
|
|
|
suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
|
|
|
|
}
|
2014-03-25 06:57:47 +00:00
|
|
|
|
|
|
|
public void testComposingMultipleBackspace() {
|
|
|
|
final String WORD_TO_TYPE = "radklro";
|
|
|
|
final int TIMES_TO_TYPE = 3;
|
|
|
|
final int TIMES_TO_BACKSPACE = 8;
|
|
|
|
type(WORD_TO_TYPE);
|
|
|
|
type(Constants.CODE_DELETE);
|
|
|
|
type(Constants.CODE_DELETE);
|
|
|
|
type(Constants.CODE_DELETE);
|
|
|
|
type(WORD_TO_TYPE);
|
|
|
|
type(Constants.CODE_DELETE);
|
|
|
|
type(Constants.CODE_DELETE);
|
|
|
|
type(WORD_TO_TYPE);
|
|
|
|
type(Constants.CODE_DELETE);
|
|
|
|
type(Constants.CODE_DELETE);
|
|
|
|
type(Constants.CODE_DELETE);
|
|
|
|
assertEquals("composing with multiple backspace",
|
|
|
|
WORD_TO_TYPE.length() * TIMES_TO_TYPE - TIMES_TO_BACKSPACE,
|
|
|
|
mEditText.getText().length());
|
|
|
|
}
|
2014-03-28 04:25:04 +00:00
|
|
|
|
|
|
|
public void testManySingleQuotes() {
|
|
|
|
final String WORD_TO_AUTOCORRECT = "i";
|
|
|
|
final String WORD_AUTOCORRECTED = "I";
|
|
|
|
final String QUOTES = "''''''''''''''''''''";
|
|
|
|
final String WORD_TO_TYPE = WORD_TO_AUTOCORRECT + QUOTES + " ";
|
|
|
|
final String EXPECTED_RESULT = WORD_AUTOCORRECTED + QUOTES + " ";
|
|
|
|
type(WORD_TO_TYPE);
|
|
|
|
assertEquals("auto-correct with many trailing single quotes", EXPECTED_RESULT,
|
|
|
|
mEditText.getText().toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testManySingleQuotesOneByOne() {
|
|
|
|
final String WORD_TO_AUTOCORRECT = "i";
|
|
|
|
final String WORD_AUTOCORRECTED = "I";
|
|
|
|
final String QUOTES = "''''''''''''''''''''";
|
|
|
|
final String WORD_TO_TYPE = WORD_TO_AUTOCORRECT + QUOTES + " ";
|
|
|
|
final String EXPECTED_RESULT = WORD_AUTOCORRECTED + QUOTES + " ";
|
|
|
|
|
|
|
|
for (int i = 0; i < WORD_TO_TYPE.length(); ++i) {
|
|
|
|
type(WORD_TO_TYPE.substring(i, i+1));
|
|
|
|
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
|
|
|
|
runMessages();
|
|
|
|
}
|
|
|
|
assertEquals("type many trailing single quotes one by one", EXPECTED_RESULT,
|
|
|
|
mEditText.getText().toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testTypingSingleQuotesOneByOne() {
|
|
|
|
final String WORD_TO_TYPE = "it's ";
|
|
|
|
final String EXPECTED_RESULT = WORD_TO_TYPE;
|
|
|
|
for (int i = 0; i < WORD_TO_TYPE.length(); ++i) {
|
|
|
|
type(WORD_TO_TYPE.substring(i, i+1));
|
|
|
|
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
|
|
|
|
runMessages();
|
|
|
|
}
|
|
|
|
assertEquals("type words letter by letter", EXPECTED_RESULT,
|
|
|
|
mEditText.getText().toString());
|
|
|
|
}
|
2014-05-14 11:19:16 +00:00
|
|
|
|
|
|
|
public void testSwitchLanguages() {
|
|
|
|
final String WORD_TO_TYPE_FIRST_PART = "com";
|
|
|
|
final String WORD_TO_TYPE_SECOND_PART = "md ";
|
|
|
|
final String EXPECTED_RESULT = "comme ";
|
|
|
|
changeLanguage("en");
|
|
|
|
type(WORD_TO_TYPE_FIRST_PART);
|
|
|
|
changeLanguage("fr");
|
|
|
|
type(WORD_TO_TYPE_SECOND_PART);
|
|
|
|
assertEquals("Composing continues after switching languages", EXPECTED_RESULT,
|
|
|
|
mEditText.getText().toString());
|
|
|
|
}
|
2012-01-19 02:58:54 +00:00
|
|
|
}
|