Fix a bug with double-space-to-period

Bug: 13778001
Change-Id: I3ebd57950cdfacbbcdc64ed214c0590519a0665c
This commit is contained in:
Jean Chalard 2014-04-03 16:25:05 +09:00
parent 23431879da
commit 28a59dd049
3 changed files with 82 additions and 10 deletions

View file

@ -823,14 +823,12 @@ public final class InputLogic {
}
if (Constants.CODE_SPACE == codePoint) {
if (inputTransaction.mSettingsValues.isSuggestionsRequested()) {
if (maybeDoubleSpacePeriod(inputTransaction)) {
inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW);
mSpaceState = SpaceState.DOUBLE;
} else if (!mSuggestedWords.isPunctuationSuggestions()) {
mSpaceState = SpaceState.WEAK;
}
}
startDoubleSpacePeriodCountdown(inputTransaction);
inputTransaction.setRequiresUpdateSuggestions();

View file

@ -16,7 +16,10 @@
package com.android.inputmethod.latin;
import com.android.inputmethod.latin.settings.Settings;
import android.test.suitebuilder.annotation.LargeTest;
import android.text.TextUtils;
import android.view.inputmethod.BaseInputConnection;
@LargeTest
@ -179,6 +182,8 @@ public class InputLogicTests extends InputTestsBase {
}
public void testDoubleSpace() {
// Set default pref just in case
setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true);
// U+1F607 is an emoji
final String[] STRINGS_TO_TYPE =
new String[] { "this ", "a+ ", "\u1F607 ", ".. ", ") ", "( ", "% " };
@ -200,6 +205,76 @@ public class InputLogicTests extends InputTestsBase {
assertEquals("double space make a period", EXPECTED_RESULT, mEditText.getText().toString());
}
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);
}
public void testBackspaceAtStartAfterAutocorrect() {
final String STRING_TO_TYPE = "tgis ";
final int typedLength = STRING_TO_TYPE.length();

View file

@ -65,7 +65,6 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
protected MyEditText mEditText;
protected View mInputView;
protected InputConnection mInputConnection;
private boolean mPreviousDebugSetting;
private boolean mPreviousBigramPredictionSettings;
private String mPreviousAutoCorrectSetting;
@ -185,7 +184,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
mEditText.setEnabled(true);
setupService();
mLatinIME = getService();
mPreviousDebugSetting = setDebugMode(true);
setDebugMode(true);
mPreviousBigramPredictionSettings = setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS,
true, true /* defaultValue */);
mPreviousAutoCorrectSetting = setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD,
@ -219,7 +218,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
true /* defaultValue */);
setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, mPreviousAutoCorrectSetting,
DEFAULT_AUTO_CORRECTION_THRESHOLD);
setDebugMode(mPreviousDebugSetting);
setDebugMode(false);
super.tearDown();
}