aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelperTests.java
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2014-08-13 14:52:36 +0900
committerTadashi G. Takaoka <takaoka@google.com>2014-08-22 21:25:35 +0900
commit2637be27c51be03e39b0db1c66312c4cc55bc7de (patch)
tree97c6f6e991e5405b121c08e003bf734baa5cb3ba /tests/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelperTests.java
parentcabb66e9bc2d5c13d83ccae6ce2d2e673b6ebf0e (diff)
downloadlatinime-2637be27c51be03e39b0db1c66312c4cc55bc7de.tar.gz
latinime-2637be27c51be03e39b0db1c66312c4cc55bc7de.tar.xz
latinime-2637be27c51be03e39b0db1c66312c4cc55bc7de.zip
Support Accept typed word UI
Change-Id: I58e95b2791a45afdc7dae8e26dcfc200b3b4b854
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelperTests.java')
-rw-r--r--tests/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelperTests.java221
1 files changed, 221 insertions, 0 deletions
diff --git a/tests/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelperTests.java b/tests/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelperTests.java
new file mode 100644
index 000000000..f3273a2d1
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelperTests.java
@@ -0,0 +1,221 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.inputmethod.latin.suggestions;
+
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.android.inputmethod.latin.SuggestedWords;
+
+@SmallTest
+public class SuggestionStripLayoutHelperTests extends AndroidTestCase {
+ private static void confirmShowTypedWord(final String message, final int inputType) {
+ assertFalse(message, SuggestionStripLayoutHelper.shouldOmitTypedWord(
+ inputType,
+ false /* gestureFloatingPreviewTextEnabled */,
+ false /* shouldShowUiToAcceptTypedWord */));
+ assertFalse(message, SuggestionStripLayoutHelper.shouldOmitTypedWord(
+ inputType,
+ true /* gestureFloatingPreviewTextEnabled */,
+ false /* shouldShowUiToAcceptTypedWord */));
+ assertFalse(message, SuggestionStripLayoutHelper.shouldOmitTypedWord(
+ inputType,
+ false /* gestureFloatingPreviewTextEnabled */,
+ true /* shouldShowUiToAcceptTypedWord */));
+ assertFalse(message, SuggestionStripLayoutHelper.shouldOmitTypedWord(
+ inputType,
+ true /* gestureFloatingPreviewTextEnabled */,
+ true /* shouldShowUiToAcceptTypedWord */));
+ }
+
+ public void testShouldShowTypedWord() {
+ confirmShowTypedWord("no input style",
+ SuggestedWords.INPUT_STYLE_NONE);
+ confirmShowTypedWord("application specifed",
+ SuggestedWords.INPUT_STYLE_APPLICATION_SPECIFIED);
+ confirmShowTypedWord("recorrection",
+ SuggestedWords.INPUT_STYLE_RECORRECTION);
+ }
+
+ public void testshouldOmitTypedWordWhileTyping() {
+ assertFalse("typing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
+ SuggestedWords.INPUT_STYLE_TYPING,
+ false /* gestureFloatingPreviewTextEnabled */,
+ false /* shouldShowUiToAcceptTypedWord */));
+ assertFalse("typing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
+ SuggestedWords.INPUT_STYLE_TYPING,
+ true /* gestureFloatingPreviewTextEnabled */,
+ false /* shouldShowUiToAcceptTypedWord */));
+ assertTrue("typing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
+ SuggestedWords.INPUT_STYLE_TYPING,
+ false /* gestureFloatingPreviewTextEnabled */,
+ true /* shouldShowUiToAcceptTypedWord */));
+ assertTrue("typing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
+ SuggestedWords.INPUT_STYLE_TYPING,
+ true /* gestureFloatingPreviewTextEnabled */,
+ true /* shouldShowUiToAcceptTypedWord */));
+ }
+
+ public void testshouldOmitTypedWordWhileGesturing() {
+ assertFalse("gesturing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
+ SuggestedWords.INPUT_STYLE_UPDATE_BATCH,
+ false /* gestureFloatingPreviewTextEnabled */,
+ false /* shouldShowUiToAcceptTypedWord */));
+ assertFalse("gesturing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
+ SuggestedWords.INPUT_STYLE_UPDATE_BATCH,
+ true /* gestureFloatingPreviewTextEnabled */,
+ false /* shouldShowUiToAcceptTypedWord */));
+ assertFalse("gesturing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
+ SuggestedWords.INPUT_STYLE_UPDATE_BATCH,
+ false /* gestureFloatingPreviewTextEnabled */,
+ true /* shouldShowUiToAcceptTypedWord */));
+ assertTrue("gesturing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
+ SuggestedWords.INPUT_STYLE_UPDATE_BATCH,
+ true /* gestureFloatingPreviewTextEnabled */,
+ true /* shouldShowUiToAcceptTypedWord */));
+ }
+
+ public void testshouldOmitTypedWordWhenGestured() {
+ assertFalse("gestured", SuggestionStripLayoutHelper.shouldOmitTypedWord(
+ SuggestedWords.INPUT_STYLE_TAIL_BATCH,
+ false /* gestureFloatingPreviewTextEnabled */,
+ false /* shouldShowUiToAcceptTypedWord */));
+ assertFalse("gestured", SuggestionStripLayoutHelper.shouldOmitTypedWord(
+ SuggestedWords.INPUT_STYLE_TAIL_BATCH,
+ true /* gestureFloatingPreviewTextEnabled */,
+ false /* shouldShowUiToAcceptTypedWord */));
+ assertTrue("gestured", SuggestionStripLayoutHelper.shouldOmitTypedWord(
+ SuggestedWords.INPUT_STYLE_TAIL_BATCH,
+ false /* gestureFloatingPreviewTextEnabled */,
+ true /* shouldShowUiToAcceptTypedWord */));
+ assertTrue("gestured", SuggestionStripLayoutHelper.shouldOmitTypedWord(
+ SuggestedWords.INPUT_STYLE_TAIL_BATCH,
+ true /* gestureFloatingPreviewTextEnabled */,
+ true /* shouldShowUiToAcceptTypedWord */));
+ }
+
+ // Note that this unit test assumes that the number of suggested words in the suggestion strip
+ // is 3.
+ private static final int POSITION_OMIT = -1;
+ private static final int POSITION_LEFT = 0;
+ private static final int POSITION_CENTER = 1;
+ private static final int POSITION_RIGHT = 2;
+
+ public void testGetPositionInSuggestionStrip() {
+ assertEquals("1st word without auto correction", POSITION_CENTER,
+ SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
+ SuggestedWords.INDEX_OF_TYPED_WORD /* indexInSuggestedWords */,
+ false /* willAutoCorrect */,
+ false /* omitTypedWord */,
+ POSITION_CENTER /* centerPositionInStrip */,
+ POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
+ assertEquals("2nd word without auto correction", POSITION_LEFT,
+ SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
+ SuggestedWords.INDEX_OF_AUTO_CORRECTION /* indexInSuggestedWords */,
+ false /* willAutoCorrect */,
+ false /* omitTypedWord */,
+ POSITION_CENTER /* centerPositionInStrip */,
+ POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
+ assertEquals("3rd word without auto correction", POSITION_RIGHT,
+ SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
+ 2 /* indexInSuggestedWords */,
+ false /* willAutoCorrect */,
+ false /* omitTypedWord */,
+ POSITION_CENTER /* centerPositionInStrip */,
+ POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
+
+ assertEquals("typed word with auto correction", POSITION_LEFT,
+ SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
+ SuggestedWords.INDEX_OF_TYPED_WORD /* indexInSuggestedWords */,
+ true /* willAutoCorrect */,
+ false /* omitTypedWord */,
+ POSITION_CENTER /* centerPositionInStrip */,
+ POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
+ assertEquals("2nd word with auto correction", POSITION_CENTER,
+ SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
+ SuggestedWords.INDEX_OF_AUTO_CORRECTION /* indexInSuggestedWords */,
+ true /* willAutoCorrect */,
+ false /* omitTypedWord */,
+ POSITION_CENTER /* centerPositionInStrip */,
+ POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
+ assertEquals("3rd word with auto correction", POSITION_RIGHT,
+ SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
+ 2 /* indexInSuggestedWords */,
+ true /* willAutoCorrect */,
+ false /* omitTypedWord */,
+ POSITION_CENTER /* centerPositionInStrip */,
+ POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
+
+ assertEquals("1st word without auto correction", POSITION_OMIT,
+ SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
+ SuggestedWords.INDEX_OF_TYPED_WORD /* indexInSuggestedWords */,
+ false /* willAutoCorrect */,
+ true /* omitTypedWord */,
+ POSITION_CENTER /* centerPositionInStrip */,
+ POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
+ assertEquals("2nd word without auto correction", POSITION_CENTER,
+ SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
+ SuggestedWords.INDEX_OF_AUTO_CORRECTION /* indexInSuggestedWords */,
+ false /* willAutoCorrect */,
+ true /* omitTypedWord */,
+ POSITION_CENTER /* centerPositionInStrip */,
+ POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
+ assertEquals("3rd word without auto correction", POSITION_LEFT,
+ SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
+ 2 /* indexInSuggestedWords */,
+ false /* willAutoCorrect */,
+ true /* omitTypedWord */,
+ POSITION_CENTER /* centerPositionInStrip */,
+ POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
+ assertEquals("4th word without auto correction", POSITION_RIGHT,
+ SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
+ 3 /* indexInSuggestedWords */,
+ false /* willAutoCorrect */,
+ true /* omitTypedWord */,
+ POSITION_CENTER /* centerPositionInStrip */,
+ POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
+
+ assertEquals("typed word with auto correction", POSITION_OMIT,
+ SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
+ SuggestedWords.INDEX_OF_TYPED_WORD /* indexInSuggestedWords */,
+ true /* willAutoCorrect */,
+ true /* omitTypedWord */,
+ POSITION_CENTER /* centerPositionInStrip */,
+ POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
+ assertEquals("2nd word with auto correction", POSITION_CENTER,
+ SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
+ SuggestedWords.INDEX_OF_AUTO_CORRECTION /* indexInSuggestedWords */,
+ true /* willAutoCorrect */,
+ true /* omitTypedWord */,
+ POSITION_CENTER /* centerPositionInStrip */,
+ POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
+ assertEquals("3rd word with auto correction", POSITION_LEFT,
+ SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
+ 2 /* indexInSuggestedWords */,
+ true /* willAutoCorrect */,
+ true /* omitTypedWord */,
+ POSITION_CENTER /* centerPositionInStrip */,
+ POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
+ assertEquals("4th word with auto correction", POSITION_RIGHT,
+ SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
+ 3 /* indexInSuggestedWords */,
+ true /* willAutoCorrect */,
+ true /* omitTypedWord */,
+ POSITION_CENTER /* centerPositionInStrip */,
+ POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
+ }
+}