diff options
author | 2014-11-24 13:48:16 -0800 | |
---|---|---|
committer | 2014-12-16 15:56:00 -0800 | |
commit | bc4ae6bdc0249f9282efea5d1fe7ccfefd6f93b0 (patch) | |
tree | c6b34da6729328cd1cab530c5134135a079f09a8 /tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java | |
parent | 2c826fd28eb48bd44e8c3e465f90e99bb22649ac (diff) | |
download | latinime-bc4ae6bdc0249f9282efea5d1fe7ccfefd6f93b0.tar.gz latinime-bc4ae6bdc0249f9282efea5d1fe7ccfefd6f93b0.tar.xz latinime-bc4ae6bdc0249f9282efea5d1fe7ccfefd6f93b0.zip |
Passing account info to dictionaryFacilitator
Attempt to use dictionary facilitor without invoking
preference manager. Instead use account from settings only when
things are being reset/changed. Discussion forked from ag/591663
Overall, the idea here is to maintain an account information
inside dictionary groups. Reset the dictionary groups if
account changes (the way we do for locale). Since only user
history dictionary is currently affected, the check to reset user
history dictionary also includes the check to verify the account.
For other things remain the same.
SettingsValues holds the current account (and is updated if prefs change
due to change in account settings). The updated settings are then
propagated to dictionary facilitator via LatinIME#loadSettings.
Bug:18104749,18469539
Change-Id: I553e776e7ea125d0fb7a1fe70a4c7eb0b2277fb8
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java | 83 |
1 files changed, 44 insertions, 39 deletions
diff --git a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java index d83c4a55b..6dddc971b 100644 --- a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java @@ -16,8 +16,6 @@ package com.android.inputmethod.latin.personalization; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.LargeTest; import android.util.Log; @@ -25,7 +23,6 @@ import android.util.Log; import com.android.inputmethod.latin.ExpandableBinaryDictionary; import com.android.inputmethod.latin.NgramContext; import com.android.inputmethod.latin.NgramContext.WordInfo; -import com.android.inputmethod.latin.settings.LocalSettingsConstants; import com.android.inputmethod.latin.utils.BinaryDictionaryUtils; import com.android.inputmethod.latin.utils.DistracterFilter; @@ -35,8 +32,6 @@ import java.util.Locale; import java.util.Random; import java.util.concurrent.TimeUnit; -import javax.annotation.Nullable; - /** * Unit tests for UserHistoryDictionary */ @@ -48,9 +43,6 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { private int mCurrentTime = 0; - private SharedPreferences mPrefs; - private String mLastKnownAccount = null; - private static void printAllFiles(final File dir) { Log.d(TAG, dir.getAbsolutePath()); for (final File file : dir.listFiles()) { @@ -78,12 +70,6 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { @Override protected void setUp() throws Exception { super.setUp(); - - mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - // Keep track of the current account so that we restore it when the test finishes. - mLastKnownAccount = mPrefs.getString(LocalSettingsConstants.PREF_ACCOUNT_NAME, null); - updateAccountName(TEST_ACCOUNT); - resetCurrentTimeForTestMode(); UserHistoryDictionaryTestsHelper.removeAllTestDictFiles( UserHistoryDictionaryTestsHelper.TEST_LOCALE_PREFIX, mContext); @@ -94,10 +80,6 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { UserHistoryDictionaryTestsHelper.removeAllTestDictFiles( UserHistoryDictionaryTestsHelper.TEST_LOCALE_PREFIX, mContext); stopTestModeInNativeCode(); - - // Restore the account that was present before running the test. - updateAccountName(mLastKnownAccount); - super.tearDown(); } @@ -106,14 +88,6 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { setCurrentTimeForTestMode(mCurrentTime); } - private void updateAccountName(@Nullable final String accountName) { - if (accountName == null) { - mPrefs.edit().remove(LocalSettingsConstants.PREF_ACCOUNT_NAME).apply(); - } else { - mPrefs.edit().putString(LocalSettingsConstants.PREF_ACCOUNT_NAME, accountName).apply(); - } - } - private void forcePassingShortTime() { // 3 days. final int timeToElapse = (int)TimeUnit.DAYS.toSeconds(3); @@ -147,17 +121,20 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { dict.waitAllTasksForTests(); } - public void testRandomWords() { + private void doTestRandomWords(final String testAccount) { Log.d(TAG, "This test can be used for profiling."); Log.d(TAG, "Usage: please set UserHistoryDictionary.PROFILE_SAVE_RESTORE to true."); final Locale dummyLocale = UserHistoryDictionaryTestsHelper.getDummyLocale("random_words"); final String dictName = UserHistoryDictionary.getUserHistoryDictName( - UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */, getContext()); + UserHistoryDictionary.NAME, dummyLocale, + null /* dictFile */, + testAccount /* account */); final File dictFile = ExpandableBinaryDictionary.getDictFile( mContext, dictName, null /* dictFile */); final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( - getContext(), dummyLocale, TEST_ACCOUNT); + getContext(), dummyLocale, testAccount); clearHistory(dict); + final int numberOfWords = 1000; final Random random = new Random(123456); assertTrue(UserHistoryDictionaryTestsHelper.addAndWriteRandomWords( @@ -165,7 +142,23 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { assertDictionaryExists(dict, dictFile); } + public void testRandomWords_NullAccount() { + doTestRandomWords(null /* testAccount */); + } + + public void testRandomWords() { + doTestRandomWords(TEST_ACCOUNT); + } + public void testStressTestForSwitchingLanguagesAndAddingWords() { + doTestStressTestForSwitchingLanguagesAndAddingWords(TEST_ACCOUNT); + } + + public void testStressTestForSwitchingLanguagesAndAddingWords_NullAccount() { + doTestStressTestForSwitchingLanguagesAndAddingWords(null /* testAccount */); + } + + private void doTestStressTestForSwitchingLanguagesAndAddingWords(final String testAccount) { final int numberOfLanguages = 2; final int numberOfLanguageSwitching = 80; final int numberOfWordsInsertedForEachLanguageSwitch = 100; @@ -181,11 +174,12 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { final Locale dummyLocale = UserHistoryDictionaryTestsHelper.getDummyLocale("switching_languages" + i); final String dictName = UserHistoryDictionary.getUserHistoryDictName( - UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */, getContext()); + UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */, + testAccount /* account */); dictFiles[i] = ExpandableBinaryDictionary.getDictFile( mContext, dictName, null /* dictFile */); dicts[i] = PersonalizationHelper.getUserHistoryDictionary(getContext(), - dummyLocale, TEST_ACCOUNT); + dummyLocale, testAccount); clearHistory(dicts[i]); } @@ -212,16 +206,24 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { } public void testAddManyWords() { + doTestAddManyWords(TEST_ACCOUNT); + } + + public void testAddManyWords_NullAccount() { + doTestAddManyWords(null /* testAccount */); + } + + private void doTestAddManyWords(final String testAccount) { final Locale dummyLocale = UserHistoryDictionaryTestsHelper.getDummyLocale("many_random_words"); final String dictName = UserHistoryDictionary.getUserHistoryDictName( - UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */, getContext()); + UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */, testAccount); final File dictFile = ExpandableBinaryDictionary.getDictFile( mContext, dictName, null /* dictFile */); final int numberOfWords = 10000; final Random random = new Random(123456); final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( - getContext(), dummyLocale, TEST_ACCOUNT); + getContext(), dummyLocale, testAccount); clearHistory(dict); assertTrue(UserHistoryDictionaryTestsHelper.addAndWriteRandomWords(dict, numberOfWords, random, true /* checksContents */, mCurrentTime)); @@ -229,9 +231,17 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { } public void testDecaying() { + doTestDecaying(TEST_ACCOUNT); + } + + public void testDecaying_NullAccount() { + doTestDecaying(null /* testAccount */); + } + + private void doTestDecaying(final String testAccount) { final Locale dummyLocale = UserHistoryDictionaryTestsHelper.getDummyLocale("decaying"); final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary( - getContext(), dummyLocale, TEST_ACCOUNT); + getContext(), dummyLocale, testAccount); resetCurrentTimeForTestMode(); clearHistory(dict); dict.waitAllTasksForTests(); @@ -262,9 +272,4 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { assertFalse(dict.isInDictionary(word)); } } - - public void testRandomWords_NullAccount() { - updateAccountName(null); - testRandomWords(); - } }
\ No newline at end of file |