Merge "Add DictionaryFacilitatorForSuggest constructor for testing"
This commit is contained in:
commit
e9584a1612
3 changed files with 51 additions and 11 deletions
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.personalization.AccountUtils;
|
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
|
@ -31,6 +29,8 @@ import android.provider.ContactsContract.Contacts;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.inputmethod.annotations.UsedForTesting;
|
||||||
|
import com.android.inputmethod.latin.personalization.AccountUtils;
|
||||||
import com.android.inputmethod.latin.utils.StringUtils;
|
import com.android.inputmethod.latin.utils.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -85,6 +85,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dummy constructor for tests.
|
// Dummy constructor for tests.
|
||||||
|
@UsedForTesting
|
||||||
public ContactsBinaryDictionary(final Context context, final Locale locale, final File file) {
|
public ContactsBinaryDictionary(final Context context, final Locale locale, final File file) {
|
||||||
this(context, locale);
|
this(context, locale);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,9 @@ import com.android.inputmethod.latin.personalization.UserHistoryDictionary;
|
||||||
import com.android.inputmethod.latin.settings.SettingsValues;
|
import com.android.inputmethod.latin.settings.SettingsValues;
|
||||||
import com.android.inputmethod.latin.utils.CollectionUtils;
|
import com.android.inputmethod.latin.utils.CollectionUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -103,13 +106,49 @@ public class DictionaryFacilitatorForSuggest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
DictionaryFacilitatorForSuggest(final Context context, final AssetFileAddress[] dictionaryList,
|
public DictionaryFacilitatorForSuggest(final Context context, final Locale locale,
|
||||||
final Locale locale) {
|
final ArrayList<String> dictionaryTypes, final HashMap<String, File> dictionaryFiles) {
|
||||||
final Dictionary mainDict = DictionaryFactory.createDictionaryForTest(dictionaryList,
|
|
||||||
false /* useFullEditDistance */, locale);
|
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mLocale = locale;
|
mLocale = locale;
|
||||||
setMainDictionary(mainDict);
|
for (final String dictType : dictionaryTypes) {
|
||||||
|
if (dictType.equals(Dictionary.TYPE_MAIN)) {
|
||||||
|
final DictionaryCollection mainDictionary =
|
||||||
|
DictionaryFactory.createMainDictionaryFromManager(context, locale);
|
||||||
|
setMainDictionary(mainDictionary);
|
||||||
|
} else if (dictType.equals(Dictionary.TYPE_USER_HISTORY)) {
|
||||||
|
final UserHistoryDictionary userHistoryDictionary =
|
||||||
|
PersonalizationHelper.getUserHistoryDictionary(context, locale);
|
||||||
|
// Staring with an empty user history dictionary for testing.
|
||||||
|
// Testing program may populate this dictionary before actual testing.
|
||||||
|
userHistoryDictionary.reloadDictionaryIfRequired();
|
||||||
|
userHistoryDictionary.waitAllTasksForTests();
|
||||||
|
setUserHistoryDictionary(userHistoryDictionary);
|
||||||
|
} else if (dictType.equals(Dictionary.TYPE_PERSONALIZATION)) {
|
||||||
|
final PersonalizationDictionary personalizationDictionary =
|
||||||
|
PersonalizationHelper.getPersonalizationDictionary(context, locale);
|
||||||
|
// Staring with an empty personalization dictionary for testing.
|
||||||
|
// Testing program may populate this dictionary before actual testing.
|
||||||
|
personalizationDictionary.reloadDictionaryIfRequired();
|
||||||
|
personalizationDictionary.waitAllTasksForTests();
|
||||||
|
setPersonalizationDictionary(personalizationDictionary);
|
||||||
|
} else if (dictType.equals(Dictionary.TYPE_USER)) {
|
||||||
|
final File file = dictionaryFiles.get(dictType);
|
||||||
|
final UserBinaryDictionary userDictionary = new UserBinaryDictionary(
|
||||||
|
context, locale, file);
|
||||||
|
userDictionary.reloadDictionaryIfRequired();
|
||||||
|
userDictionary.waitAllTasksForTests();
|
||||||
|
setUserDictionary(userDictionary);
|
||||||
|
} else if (dictType.equals(Dictionary.TYPE_CONTACTS)) {
|
||||||
|
final File file = dictionaryFiles.get(dictType);
|
||||||
|
final ContactsBinaryDictionary contactsDictionary = new ContactsBinaryDictionary(
|
||||||
|
context, locale, file);
|
||||||
|
contactsDictionary.reloadDictionaryIfRequired();
|
||||||
|
contactsDictionary.waitAllTasksForTests();
|
||||||
|
setContactsDictionary(contactsDictionary);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Unknown dictionary type: " + dictType);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize a debug flag for the personalization
|
// initialize a debug flag for the personalization
|
||||||
|
@ -169,8 +208,7 @@ public class DictionaryFacilitatorForSuggest {
|
||||||
* Sets an optional user dictionary resource to be loaded. The user dictionary is consulted
|
* Sets an optional user dictionary resource to be loaded. The user dictionary is consulted
|
||||||
* before the main dictionary, if set. This refers to the system-managed user dictionary.
|
* before the main dictionary, if set. This refers to the system-managed user dictionary.
|
||||||
*/
|
*/
|
||||||
@UsedForTesting
|
private void setUserDictionary(final UserBinaryDictionary userDictionary) {
|
||||||
public void setUserDictionary(final UserBinaryDictionary userDictionary) {
|
|
||||||
mUserDictionary = userDictionary;
|
mUserDictionary = userDictionary;
|
||||||
addOrReplaceDictionary(Dictionary.TYPE_USER, userDictionary);
|
addOrReplaceDictionary(Dictionary.TYPE_USER, userDictionary);
|
||||||
}
|
}
|
||||||
|
@ -180,8 +218,7 @@ public class DictionaryFacilitatorForSuggest {
|
||||||
* the contacts dictionary by passing null to this method. In this case no contacts dictionary
|
* the contacts dictionary by passing null to this method. In this case no contacts dictionary
|
||||||
* won't be used.
|
* won't be used.
|
||||||
*/
|
*/
|
||||||
@UsedForTesting
|
private void setContactsDictionary(final ContactsBinaryDictionary contactsDictionary) {
|
||||||
public void setContactsDictionary(final ContactsBinaryDictionary contactsDictionary) {
|
|
||||||
mContactsDictionary = contactsDictionary;
|
mContactsDictionary = contactsDictionary;
|
||||||
addOrReplaceDictionary(Dictionary.TYPE_CONTACTS, contactsDictionary);
|
addOrReplaceDictionary(Dictionary.TYPE_CONTACTS, contactsDictionary);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import android.provider.UserDictionary.Words;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.inputmethod.annotations.UsedForTesting;
|
||||||
import com.android.inputmethod.compat.UserDictionaryCompatUtils;
|
import com.android.inputmethod.compat.UserDictionaryCompatUtils;
|
||||||
import com.android.inputmethod.latin.utils.LocaleUtils;
|
import com.android.inputmethod.latin.utils.LocaleUtils;
|
||||||
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
|
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
|
||||||
|
@ -81,6 +82,7 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dummy constructor for tests.
|
// Dummy constructor for tests.
|
||||||
|
@UsedForTesting
|
||||||
public UserBinaryDictionary(final Context context, final Locale locale, final File file) {
|
public UserBinaryDictionary(final Context context, final Locale locale, final File file) {
|
||||||
this(context, locale);
|
this(context, locale);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue