diff options
Diffstat (limited to 'tests')
5 files changed, 124 insertions, 70 deletions
diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java index 9da1e9470..89167f744 100644 --- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java @@ -24,7 +24,6 @@ import android.util.Pair; import com.android.inputmethod.latin.NgramContext.WordInfo; import com.android.inputmethod.latin.common.CodePointUtils; import com.android.inputmethod.latin.common.FileUtils; -import com.android.inputmethod.latin.define.DecoderSpecificConstants; import com.android.inputmethod.latin.makedict.DictionaryHeader; import com.android.inputmethod.latin.makedict.FormatSpec; import com.android.inputmethod.latin.makedict.WeightedString; @@ -44,7 +43,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { private static final String TEST_DICT_FILE_EXTENSION = ".testDict"; private static final String TEST_LOCALE = "test"; private static final int[] DICT_FORMAT_VERSIONS = - new int[] { FormatSpec.VERSION402, FormatSpec.VERSION403, FormatSpec.VERSION4_DEV }; + new int[] { FormatSpec.VERSION402, FormatSpec.VERSION403 }; private static final String DICTIONARY_ID = "TestBinaryDictionary"; private static boolean supportsNgram(final int formatVersion) { @@ -170,7 +169,7 @@ public class BinaryDictionaryTests extends AndroidTestCase { private void testAddTooLongWord(final int formatVersion) { final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(formatVersion); final StringBuffer stringBuilder = new StringBuffer(); - for (int i = 0; i < DecoderSpecificConstants.DICTIONARY_MAX_WORD_LENGTH; i++) { + for (int i = 0; i < BinaryDictionary.DICTIONARY_MAX_WORD_LENGTH; i++) { stringBuilder.append('a'); } final String validLongWord = stringBuilder.toString(); diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java index a6c9bbee0..b1b48135f 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java @@ -265,7 +265,7 @@ public class InputLogicTests extends InputTestsBase { public void testDoubleSpacePeriod() { // Reset settings to default, else these tests will go flaky. setBooleanPreference(Settings.PREF_SHOW_SUGGESTIONS, true, true); - setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, "1", "1"); + setBooleanPreference(Settings.PREF_AUTO_CORRECTION, true, true); setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true); testDoubleSpacePeriodWithSettings(true /* expectsPeriod */); // "Suggestion visibility" to off @@ -277,18 +277,16 @@ public class InputLogicTests extends InputTestsBase { 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"); + testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION, false); + // "Auto-correction" to "on" + testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION, true); // "Suggestion visibility" to "always hide" and "Auto-correction" to "off" testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS, false, - Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0"); + Settings.PREF_AUTO_CORRECTION, false); // "Suggestion visibility" to "always hide" and "Auto-correction" to "off" testDoubleSpacePeriodWithSettings(false, Settings.PREF_SHOW_SUGGESTIONS, false, - Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0", + Settings.PREF_AUTO_CORRECTION, false, Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, false); } @@ -504,11 +502,9 @@ public class InputLogicTests extends InputTestsBase { type(" "); sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); runMessages(); - // Corrections have been replaced with predictions. + // Test the predictions have been cleared SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest(); - String word = suggestedWords == null ? null : suggestedWords.getWord(0); - assertTrue("predictions after double-space-to-period is I or The", - "I".equals(word) || "The".equals(word)); + assertEquals("predictions cleared after double-space-to-period", suggestedWords.size(), 0); type(Constants.CODE_DELETE); sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); runMessages(); @@ -531,6 +527,23 @@ public class InputLogicTests extends InputTestsBase { suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null); } + public void testPredictionsAfterPeriod() { + mLatinIME.clearPersonalizedDictionariesForTest(); + final String WORD_TO_TYPE = "Barack. "; + type(WORD_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest(); + assertEquals("No prediction after period after inputting once.", 0, suggestedWords.size()); + + type(WORD_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + suggestedWords = mLatinIME.getSuggestedWordsForTest(); + assertEquals("Beginning-of-Sentence prediction after inputting 2 times.", "Barack", + suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null); + } + public void testPredictionsAfterRecorrection() { final String PREFIX = "A "; final String WORD_TO_TYPE = "Barack"; diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index ea7823c64..6ae38c615 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -58,7 +58,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { // Default value for auto-correction threshold. This is the string representation of the // index in the resources array of auto-correction threshold settings. - private static final String DEFAULT_AUTO_CORRECTION_THRESHOLD = "1"; + private static final boolean DEFAULT_AUTO_CORRECTION = true; // The message that sets the underline is posted with a 500 ms delay protected static final int DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS = 500; @@ -77,7 +77,8 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { protected MyEditText mEditText; protected View mInputView; protected InputConnection mInputConnection; - private String mPreviousAutoCorrectSetting; + private boolean mPreviousAutoCorrectSetting; + private boolean mPreviousBigramPredictionSettings; // A helper class to ease span tests public static class SpanGetter { @@ -200,8 +201,10 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { setupService(); mLatinIME = getService(); setDebugMode(true); - mPreviousAutoCorrectSetting = setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, - DEFAULT_AUTO_CORRECTION_THRESHOLD, DEFAULT_AUTO_CORRECTION_THRESHOLD); + mPreviousBigramPredictionSettings = setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, + true, true /* defaultValue */); + mPreviousAutoCorrectSetting = setBooleanPreference(Settings.PREF_AUTO_CORRECTION, + DEFAULT_AUTO_CORRECTION, DEFAULT_AUTO_CORRECTION); mLatinIME.onCreate(); EditorInfo ei = new EditorInfo(); final InputConnection ic = mEditText.onCreateInputConnection(ei); @@ -230,8 +233,10 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { mLatinIME.onFinishInput(); runMessages(); mLatinIME.mHandler.removeAllMessages(); - setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, mPreviousAutoCorrectSetting, - DEFAULT_AUTO_CORRECTION_THRESHOLD); + setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, mPreviousBigramPredictionSettings, + true /* defaultValue */); + setBooleanPreference(Settings.PREF_AUTO_CORRECTION, mPreviousAutoCorrectSetting, + DEFAULT_AUTO_CORRECTION); setDebugMode(false); mLatinIME.recycle(); super.tearDown(); diff --git a/tests/src/com/android/inputmethod/latin/PunctuationTests.java b/tests/src/com/android/inputmethod/latin/PunctuationTests.java index 9ac220407..3537918de 100644 --- a/tests/src/com/android/inputmethod/latin/PunctuationTests.java +++ b/tests/src/com/android/inputmethod/latin/PunctuationTests.java @@ -19,23 +19,37 @@ package com.android.inputmethod.latin; import android.provider.Settings.Secure; import android.test.suitebuilder.annotation.LargeTest; +import com.android.inputmethod.latin.R; + @LargeTest public class PunctuationTests extends InputTestsBase { + final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction"; + public void testWordThenSpaceThenPunctuationFromStripTwice() { final String WORD_TO_TYPE = "this "; final String PUNCTUATION_FROM_STRIP = "!"; final String EXPECTED_RESULT = "this!! "; - mLatinIME.loadSettings(); - type(WORD_TO_TYPE); - sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); - runMessages(); - assertTrue("type word then type space should display punctuation strip", - mLatinIME.getSuggestedWordsForTest().isPunctuationSuggestions()); - pickSuggestionManually(PUNCTUATION_FROM_STRIP); - pickSuggestionManually(PUNCTUATION_FROM_STRIP); - assertEquals("type word then type space then punctuation from strip twice", - EXPECTED_RESULT, mEditText.getText().toString()); + final boolean defaultNextWordPredictionOption = + mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction); + final boolean previousNextWordPredictionOption = + setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, false, + defaultNextWordPredictionOption); + try { + mLatinIME.loadSettings(); + type(WORD_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); + runMessages(); + assertTrue("type word then type space should display punctuation strip", + mLatinIME.getSuggestedWordsForTest().isPunctuationSuggestions()); + pickSuggestionManually(PUNCTUATION_FROM_STRIP); + pickSuggestionManually(PUNCTUATION_FROM_STRIP); + assertEquals("type word then type space then punctuation from strip twice", + EXPECTED_RESULT, mEditText.getText().toString()); + } finally { + setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption, + defaultNextWordPredictionOption); + } } public void testWordThenSpaceThenPunctuationFromKeyboardTwice() { diff --git a/tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java b/tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java index 81a0f6934..0878e74cb 100644 --- a/tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java +++ b/tests/src/com/android/inputmethod/latin/settings/AccountsSettingsFragmentTests.java @@ -16,7 +16,12 @@ package com.android.inputmethod.latin.settings; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import android.app.AlertDialog; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.test.ActivityInstrumentationTestCase2; @@ -24,6 +29,11 @@ import android.test.suitebuilder.annotation.MediumTest; import android.view.View; import android.widget.ListView; +import com.android.inputmethod.latin.utils.ManagedProfileUtils; + +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -33,6 +43,8 @@ public class AccountsSettingsFragmentTests private static final String FRAG_NAME = AccountsSettingsFragment.class.getName(); private static final long TEST_TIMEOUT_MILLIS = 5000; + @Mock private ManagedProfileUtils mManagedProfileUtils; + public AccountsSettingsFragmentTests() { super(TestFragmentActivity.class); } @@ -40,11 +52,22 @@ public class AccountsSettingsFragmentTests @Override protected void setUp() throws Exception { super.setUp(); + + // Initialize the mocks. + MockitoAnnotations.initMocks(this); + ManagedProfileUtils.setTestInstance(mManagedProfileUtils); + Intent intent = new Intent(); intent.putExtra(TestFragmentActivity.EXTRA_SHOW_FRAGMENT, FRAG_NAME); setActivityIntent(intent); } + @Override + public void tearDown() throws Exception { + ManagedProfileUtils.setTestInstance(null); + super.tearDown(); + } + public void testEmptyAccounts() { final AccountsSettingsFragment fragment = (AccountsSettingsFragment) getActivity().mFragment; @@ -61,36 +84,26 @@ public class AccountsSettingsFragmentTests DialogHolder() {} } - public void testMultipleAccounts_noCurrentAccount() { + public void testMultipleAccounts_noSettingsForManagedProfile() { + when(mManagedProfileUtils.hasManagedWorkProfile(any(Context.class))).thenReturn(true); + final AccountsSettingsFragment fragment = (AccountsSettingsFragment) getActivity().mFragment; - final DialogHolder dialogHolder = new DialogHolder(); - final CountDownLatch latch = new CountDownLatch(1); + final AlertDialog dialog = initDialog(fragment, null).mDialog; + final ListView lv = dialog.getListView(); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - final AlertDialog dialog = fragment.createAccountPicker( - new String[] { - "1@example.com", - "2@example.com", - "3@example.com", - "4@example.com"}, - null, null /* positiveButtonListner */); - dialog.show(); - dialogHolder.mDialog = dialog; - latch.countDown(); - } - }); + // Nothing to check/uncheck. + assertNull(fragment.findPreference(AccountsSettingsFragment.PREF_ACCCOUNT_SWITCHER)); + } - try { - latch.await(TEST_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); - } catch (InterruptedException ex) { - fail(); - } - getInstrumentation().waitForIdleSync(); - final AlertDialog dialog = dialogHolder.mDialog; + public void testMultipleAccounts_noCurrentAccount() { + when(mManagedProfileUtils.hasManagedWorkProfile(any(Context.class))).thenReturn(false); + + final AccountsSettingsFragment fragment = + (AccountsSettingsFragment) getActivity().mFragment; + final AlertDialog dialog = initDialog(fragment, null).mDialog; final ListView lv = dialog.getListView(); + // The 1st account should be checked by default. assertEquals("checked-item", 0, lv.getCheckedItemPosition()); // There should be 4 accounts in the list. @@ -105,10 +118,32 @@ public class AccountsSettingsFragmentTests } public void testMultipleAccounts_currentAccount() { + when(mManagedProfileUtils.hasManagedWorkProfile(any(Context.class))).thenReturn(false); + final AccountsSettingsFragment fragment = (AccountsSettingsFragment) getActivity().mFragment; + final AlertDialog dialog = initDialog(fragment, "3@example.com").mDialog; + final ListView lv = dialog.getListView(); + + // The 3rd account should be checked by default. + assertEquals("checked-item", 2, lv.getCheckedItemPosition()); + // There should be 4 accounts in the list. + assertEquals("count", 4, lv.getCount()); + // The sign-out button should be shown + assertEquals(View.VISIBLE, + dialog.getButton(DialogInterface.BUTTON_NEUTRAL).getVisibility()); + assertEquals(View.VISIBLE, + dialog.getButton(DialogInterface.BUTTON_NEGATIVE).getVisibility()); + assertEquals(View.VISIBLE, + dialog.getButton(DialogInterface.BUTTON_POSITIVE).getVisibility()); + } + + private DialogHolder initDialog( + final AccountsSettingsFragment fragment, + final String selectedAccount) { final DialogHolder dialogHolder = new DialogHolder(); final CountDownLatch latch = new CountDownLatch(1); + getActivity().runOnUiThread(new Runnable() { @Override public void run() { @@ -118,7 +153,7 @@ public class AccountsSettingsFragmentTests "2@example.com", "3@example.com", "4@example.com"}, - "3@example.com", null /* positiveButtonListner */); + selectedAccount, null /* positiveButtonListner */); dialog.show(); dialogHolder.mDialog = dialog; latch.countDown(); @@ -131,18 +166,6 @@ public class AccountsSettingsFragmentTests fail(); } getInstrumentation().waitForIdleSync(); - final AlertDialog dialog = dialogHolder.mDialog; - final ListView lv = dialog.getListView(); - // The 3rd account should be checked by default. - assertEquals("checked-item", 2, lv.getCheckedItemPosition()); - // There should be 4 accounts in the list. - assertEquals("count", 4, lv.getCount()); - // The sign-out button should be shown - assertEquals(View.VISIBLE, - dialog.getButton(DialogInterface.BUTTON_NEUTRAL).getVisibility()); - assertEquals(View.VISIBLE, - dialog.getButton(DialogInterface.BUTTON_NEGATIVE).getVisibility()); - assertEquals(View.VISIBLE, - dialog.getButton(DialogInterface.BUTTON_POSITIVE).getVisibility()); + return dialogHolder; } } |