am b68e6130: Merge "Fix a flaky test."

* commit 'b68e6130162ee8a8e0e87042a2a25961e7c6db4b':
  Fix a flaky test.
main
Jean Chalard 2013-11-25 00:55:30 -08:00 committed by Android Git Automerger
commit c13523228a
3 changed files with 49 additions and 20 deletions

View File

@ -70,38 +70,47 @@ public final class Constants {
public static final class ExtraValue { public static final class ExtraValue {
/** /**
* The subtype extra value used to indicate that the subtype keyboard layout is capable * The subtype extra value used to indicate that this subtype is capable of
* for typing ASCII characters. * entering ASCII characters.
*/ */
public static final String ASCII_CAPABLE = "AsciiCapable"; public static final String ASCII_CAPABLE = "AsciiCapable";
/** /**
* The subtype extra value used to indicate that the subtype keyboard layout is capable * The subtype extra value used to indicate that this subtype is enabled
* for typing EMOJI characters. * when the default subtype is not marked as ascii capable.
*/
public static final String ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE =
"EnabledWhenDefaultIsNotAsciiCapable";
/**
* The subtype extra value used to indicate that this subtype is capable of
* entering emoji characters.
*/ */
public static final String EMOJI_CAPABLE = "EmojiCapable"; public static final String EMOJI_CAPABLE = "EmojiCapable";
/** /**
* The subtype extra value used to indicate that the subtype require network connection * The subtype extra value used to indicate that this subtype requires a network
* to work. * connection to work.
*/ */
public static final String REQ_NETWORK_CONNECTIVITY = "requireNetworkConnectivity"; public static final String REQ_NETWORK_CONNECTIVITY = "requireNetworkConnectivity";
/** /**
* The subtype extra value used to indicate that the subtype display name contains "%s" * The subtype extra value used to indicate that the display name of this subtype
* for replacement mark and it should be replaced by this extra value. * contains a "%s" for printf-like replacement and it should be replaced by
* this extra value.
* This extra value is supported on JellyBean and later. * This extra value is supported on JellyBean and later.
*/ */
public static final String UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME = public static final String UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME =
"UntranslatableReplacementStringInSubtypeName"; "UntranslatableReplacementStringInSubtypeName";
/** /**
* The subtype extra value used to indicate that the subtype keyboard layout set name. * The subtype extra value used to indicate this subtype keyboard layout set name.
* This extra value is private to LatinIME. * This extra value is private to LatinIME.
*/ */
public static final String KEYBOARD_LAYOUT_SET = "KeyboardLayoutSet"; public static final String KEYBOARD_LAYOUT_SET = "KeyboardLayoutSet";
/** /**
* The subtype extra value used to indicate that the subtype is additional subtype * The subtype extra value used to indicate that this subtype is an additional subtype
* that the user defined. This extra value is private to LatinIME. * that the user defined. This extra value is private to LatinIME.
*/ */
public static final String IS_ADDITIONAL_SUBTYPE = "isAdditionalSubtype"; public static final String IS_ADDITIONAL_SUBTYPE = "isAdditionalSubtype";

View File

@ -33,6 +33,7 @@ import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.latin.utils.LocaleUtils;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
import java.util.List; import java.util.List;
@ -62,7 +63,7 @@ public final class SubtypeSwitcher {
SubtypeLocaleUtils.NO_LANGUAGE, "keyboard", "KeyboardLayoutSet=" SubtypeLocaleUtils.NO_LANGUAGE, "keyboard", "KeyboardLayoutSet="
+ SubtypeLocaleUtils.QWERTY + SubtypeLocaleUtils.QWERTY
+ "," + Constants.Subtype.ExtraValue.ASCII_CAPABLE + "," + Constants.Subtype.ExtraValue.ASCII_CAPABLE
+ ",EnabledWhenDefaultIsNotAsciiCapable," + "," + Constants.Subtype.ExtraValue.ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE
+ Constants.Subtype.ExtraValue.EMOJI_CAPABLE, + Constants.Subtype.ExtraValue.EMOJI_CAPABLE,
false /* isAuxiliary */, false /* overridesImplicitlyEnabledSubtype */); false /* isAuxiliary */, false /* overridesImplicitlyEnabledSubtype */);
// Caveat: We probably should remove this when we add an Emoji subtype in {@link R.xml.method}. // Caveat: We probably should remove this when we add an Emoji subtype in {@link R.xml.method}.
@ -256,18 +257,23 @@ public final class SubtypeSwitcher {
return mNeedsToDisplayLanguage.getValue(); return mNeedsToDisplayLanguage.getValue();
} }
private static Locale sForcedLocaleForTesting = null; private static InputMethodSubtype sForcedSubtypeForTesting = null;
@UsedForTesting @UsedForTesting
void forceLocale(final Locale locale) { void forceSubtype(final InputMethodSubtype subtype) {
sForcedLocaleForTesting = locale; sForcedSubtypeForTesting = subtype;
} }
public Locale getCurrentSubtypeLocale() { public Locale getCurrentSubtypeLocale() {
if (null != sForcedLocaleForTesting) return sForcedLocaleForTesting; if (null != sForcedSubtypeForTesting) {
return LocaleUtils.constructLocaleFromString(sForcedSubtypeForTesting.getLocale());
}
return SubtypeLocaleUtils.getSubtypeLocale(getCurrentSubtype()); return SubtypeLocaleUtils.getSubtypeLocale(getCurrentSubtype());
} }
public InputMethodSubtype getCurrentSubtype() { public InputMethodSubtype getCurrentSubtype() {
if (null != sForcedSubtypeForTesting) {
return sForcedSubtypeForTesting;
}
return mRichImm.getCurrentInputMethodSubtype(getNoLanguageSubtype()); return mRichImm.getCurrentInputMethodSubtype(getNoLanguageSubtype());
} }
@ -279,8 +285,8 @@ public final class SubtypeSwitcher {
if (mNoLanguageSubtype != null) { if (mNoLanguageSubtype != null) {
return mNoLanguageSubtype; return mNoLanguageSubtype;
} }
Log.w(TAG, "Can't find no lanugage with QWERTY subtype"); Log.w(TAG, "Can't find any language with QWERTY subtype");
Log.w(TAG, "No input method subtype found; return dummy subtype: " Log.w(TAG, "No input method subtype found; returning dummy subtype: "
+ DUMMY_NO_LANGUAGE_SUBTYPE); + DUMMY_NO_LANGUAGE_SUBTYPE);
return DUMMY_NO_LANGUAGE_SUBTYPE; return DUMMY_NO_LANGUAGE_SUBTYPE;
} }
@ -293,8 +299,9 @@ public final class SubtypeSwitcher {
if (mEmojiSubtype != null) { if (mEmojiSubtype != null) {
return mEmojiSubtype; return mEmojiSubtype;
} }
Log.w(TAG, "Can't find Emoji subtype"); Log.w(TAG, "Can't find emoji subtype");
Log.w(TAG, "No input method subtype found; return dummy subtype: " + DUMMY_EMOJI_SUBTYPE); Log.w(TAG, "No input method subtype found; returning dummy subtype: "
+ DUMMY_EMOJI_SUBTYPE);
return DUMMY_EMOJI_SUBTYPE; return DUMMY_EMOJI_SUBTYPE;
} }
} }

View File

@ -30,6 +30,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodSubtype;
import android.widget.EditText; import android.widget.EditText;
import android.widget.FrameLayout; import android.widget.FrameLayout;
@ -37,6 +38,7 @@ import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.utils.LocaleUtils; import com.android.inputmethod.latin.utils.LocaleUtils;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
import java.util.Locale; import java.util.Locale;
@ -244,7 +246,18 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
protected void changeLanguageWithoutWait(final String locale) { protected void changeLanguageWithoutWait(final String locale) {
mEditText.mCurrentLocale = LocaleUtils.constructLocaleFromString(locale); mEditText.mCurrentLocale = LocaleUtils.constructLocaleFromString(locale);
SubtypeSwitcher.getInstance().forceLocale(mEditText.mCurrentLocale); final InputMethodSubtype subtype = new InputMethodSubtype(
R.string.subtype_no_language_qwerty, R.drawable.ic_ime_switcher_dark,
locale, "keyboard", "KeyboardLayoutSet="
// TODO: this is forcing a QWERTY keyboard for all locales, which is wrong.
// It's still better than using whatever keyboard is the current one, but we
// should actually use the default keyboard for this locale.
+ SubtypeLocaleUtils.QWERTY
+ "," + Constants.Subtype.ExtraValue.ASCII_CAPABLE
+ "," + Constants.Subtype.ExtraValue.ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE
+ Constants.Subtype.ExtraValue.EMOJI_CAPABLE,
false /* isAuxiliary */, false /* overridesImplicitlyEnabledSubtype */);
SubtypeSwitcher.getInstance().forceSubtype(subtype);
mLatinIME.loadKeyboard(); mLatinIME.loadKeyboard();
runMessages(); runMessages();
mKeyboard = mLatinIME.mKeyboardSwitcher.getKeyboard(); mKeyboard = mLatinIME.mKeyboardSwitcher.getKeyboard();