blob: 3706574ef3f6977a0b416513095701fefcd0b58c [file] [log] [blame]
Tadashi G. Takaoka2637be22014-08-13 14:52:36 +09001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.inputmethod.latin.suggestions;
18
Yohei Yukawad3b93cc2018-07-06 10:10:54 -070019import static junit.framework.TestCase.assertEquals;
20
21import static org.junit.Assert.assertFalse;
22import static org.junit.Assert.assertTrue;
23
Brett Chabotc05a70a2018-12-13 19:06:42 -080024import androidx.test.filters.SmallTest;
25import androidx.test.runner.AndroidJUnit4;
Tadashi G. Takaoka2637be22014-08-13 14:52:36 +090026
27import com.android.inputmethod.latin.SuggestedWords;
28
Yohei Yukawad3b93cc2018-07-06 10:10:54 -070029import org.junit.Test;
30import org.junit.runner.RunWith;
31
Tadashi G. Takaoka2637be22014-08-13 14:52:36 +090032@SmallTest
Yohei Yukawad3b93cc2018-07-06 10:10:54 -070033@RunWith(AndroidJUnit4.class)
34public class SuggestionStripLayoutHelperTests {
Tadashi G. Takaoka2637be22014-08-13 14:52:36 +090035 private static void confirmShowTypedWord(final String message, final int inputType) {
36 assertFalse(message, SuggestionStripLayoutHelper.shouldOmitTypedWord(
37 inputType,
38 false /* gestureFloatingPreviewTextEnabled */,
39 false /* shouldShowUiToAcceptTypedWord */));
40 assertFalse(message, SuggestionStripLayoutHelper.shouldOmitTypedWord(
41 inputType,
42 true /* gestureFloatingPreviewTextEnabled */,
43 false /* shouldShowUiToAcceptTypedWord */));
44 assertFalse(message, SuggestionStripLayoutHelper.shouldOmitTypedWord(
45 inputType,
46 false /* gestureFloatingPreviewTextEnabled */,
47 true /* shouldShowUiToAcceptTypedWord */));
48 assertFalse(message, SuggestionStripLayoutHelper.shouldOmitTypedWord(
49 inputType,
50 true /* gestureFloatingPreviewTextEnabled */,
51 true /* shouldShowUiToAcceptTypedWord */));
52 }
53
Yohei Yukawad3b93cc2018-07-06 10:10:54 -070054 @Test
Tadashi G. Takaoka2637be22014-08-13 14:52:36 +090055 public void testShouldShowTypedWord() {
56 confirmShowTypedWord("no input style",
57 SuggestedWords.INPUT_STYLE_NONE);
58 confirmShowTypedWord("application specifed",
59 SuggestedWords.INPUT_STYLE_APPLICATION_SPECIFIED);
60 confirmShowTypedWord("recorrection",
61 SuggestedWords.INPUT_STYLE_RECORRECTION);
62 }
63
Yohei Yukawad3b93cc2018-07-06 10:10:54 -070064 @Test
65 public void testShouldOmitTypedWordWhileTyping() {
Tadashi G. Takaoka2637be22014-08-13 14:52:36 +090066 assertFalse("typing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
67 SuggestedWords.INPUT_STYLE_TYPING,
68 false /* gestureFloatingPreviewTextEnabled */,
69 false /* shouldShowUiToAcceptTypedWord */));
70 assertFalse("typing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
71 SuggestedWords.INPUT_STYLE_TYPING,
72 true /* gestureFloatingPreviewTextEnabled */,
73 false /* shouldShowUiToAcceptTypedWord */));
74 assertTrue("typing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
75 SuggestedWords.INPUT_STYLE_TYPING,
76 false /* gestureFloatingPreviewTextEnabled */,
77 true /* shouldShowUiToAcceptTypedWord */));
78 assertTrue("typing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
79 SuggestedWords.INPUT_STYLE_TYPING,
80 true /* gestureFloatingPreviewTextEnabled */,
81 true /* shouldShowUiToAcceptTypedWord */));
82 }
83
Yohei Yukawad3b93cc2018-07-06 10:10:54 -070084 @Test
85 public void testShouldOmitTypedWordWhileGesturing() {
Tadashi G. Takaoka2637be22014-08-13 14:52:36 +090086 assertFalse("gesturing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
87 SuggestedWords.INPUT_STYLE_UPDATE_BATCH,
88 false /* gestureFloatingPreviewTextEnabled */,
89 false /* shouldShowUiToAcceptTypedWord */));
90 assertFalse("gesturing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
91 SuggestedWords.INPUT_STYLE_UPDATE_BATCH,
92 true /* gestureFloatingPreviewTextEnabled */,
93 false /* shouldShowUiToAcceptTypedWord */));
94 assertFalse("gesturing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
95 SuggestedWords.INPUT_STYLE_UPDATE_BATCH,
96 false /* gestureFloatingPreviewTextEnabled */,
97 true /* shouldShowUiToAcceptTypedWord */));
98 assertTrue("gesturing", SuggestionStripLayoutHelper.shouldOmitTypedWord(
99 SuggestedWords.INPUT_STYLE_UPDATE_BATCH,
100 true /* gestureFloatingPreviewTextEnabled */,
101 true /* shouldShowUiToAcceptTypedWord */));
102 }
103
Yohei Yukawad3b93cc2018-07-06 10:10:54 -0700104 @Test
105 public void testShouldOmitTypedWordWhenGestured() {
Tadashi G. Takaoka2637be22014-08-13 14:52:36 +0900106 assertFalse("gestured", SuggestionStripLayoutHelper.shouldOmitTypedWord(
107 SuggestedWords.INPUT_STYLE_TAIL_BATCH,
108 false /* gestureFloatingPreviewTextEnabled */,
109 false /* shouldShowUiToAcceptTypedWord */));
110 assertFalse("gestured", SuggestionStripLayoutHelper.shouldOmitTypedWord(
111 SuggestedWords.INPUT_STYLE_TAIL_BATCH,
112 true /* gestureFloatingPreviewTextEnabled */,
113 false /* shouldShowUiToAcceptTypedWord */));
114 assertTrue("gestured", SuggestionStripLayoutHelper.shouldOmitTypedWord(
115 SuggestedWords.INPUT_STYLE_TAIL_BATCH,
116 false /* gestureFloatingPreviewTextEnabled */,
117 true /* shouldShowUiToAcceptTypedWord */));
118 assertTrue("gestured", SuggestionStripLayoutHelper.shouldOmitTypedWord(
119 SuggestedWords.INPUT_STYLE_TAIL_BATCH,
120 true /* gestureFloatingPreviewTextEnabled */,
121 true /* shouldShowUiToAcceptTypedWord */));
122 }
123
124 // Note that this unit test assumes that the number of suggested words in the suggestion strip
125 // is 3.
126 private static final int POSITION_OMIT = -1;
127 private static final int POSITION_LEFT = 0;
128 private static final int POSITION_CENTER = 1;
129 private static final int POSITION_RIGHT = 2;
130
Yohei Yukawad3b93cc2018-07-06 10:10:54 -0700131 @Test
Tadashi G. Takaoka2637be22014-08-13 14:52:36 +0900132 public void testGetPositionInSuggestionStrip() {
133 assertEquals("1st word without auto correction", POSITION_CENTER,
134 SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
135 SuggestedWords.INDEX_OF_TYPED_WORD /* indexInSuggestedWords */,
136 false /* willAutoCorrect */,
137 false /* omitTypedWord */,
138 POSITION_CENTER /* centerPositionInStrip */,
139 POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
140 assertEquals("2nd word without auto correction", POSITION_LEFT,
141 SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
142 SuggestedWords.INDEX_OF_AUTO_CORRECTION /* indexInSuggestedWords */,
143 false /* willAutoCorrect */,
144 false /* omitTypedWord */,
145 POSITION_CENTER /* centerPositionInStrip */,
146 POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
147 assertEquals("3rd word without auto correction", POSITION_RIGHT,
148 SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
149 2 /* indexInSuggestedWords */,
150 false /* willAutoCorrect */,
151 false /* omitTypedWord */,
152 POSITION_CENTER /* centerPositionInStrip */,
153 POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
154
155 assertEquals("typed word with auto correction", POSITION_LEFT,
156 SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
157 SuggestedWords.INDEX_OF_TYPED_WORD /* indexInSuggestedWords */,
158 true /* willAutoCorrect */,
159 false /* omitTypedWord */,
160 POSITION_CENTER /* centerPositionInStrip */,
161 POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
162 assertEquals("2nd word with auto correction", POSITION_CENTER,
163 SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
164 SuggestedWords.INDEX_OF_AUTO_CORRECTION /* indexInSuggestedWords */,
165 true /* willAutoCorrect */,
166 false /* omitTypedWord */,
167 POSITION_CENTER /* centerPositionInStrip */,
168 POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
169 assertEquals("3rd word with auto correction", POSITION_RIGHT,
170 SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
171 2 /* indexInSuggestedWords */,
172 true /* willAutoCorrect */,
173 false /* omitTypedWord */,
174 POSITION_CENTER /* centerPositionInStrip */,
175 POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
176
177 assertEquals("1st word without auto correction", POSITION_OMIT,
178 SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
179 SuggestedWords.INDEX_OF_TYPED_WORD /* indexInSuggestedWords */,
180 false /* willAutoCorrect */,
181 true /* omitTypedWord */,
182 POSITION_CENTER /* centerPositionInStrip */,
183 POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
184 assertEquals("2nd word without auto correction", POSITION_CENTER,
185 SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
186 SuggestedWords.INDEX_OF_AUTO_CORRECTION /* indexInSuggestedWords */,
187 false /* willAutoCorrect */,
188 true /* omitTypedWord */,
189 POSITION_CENTER /* centerPositionInStrip */,
190 POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
191 assertEquals("3rd word without auto correction", POSITION_LEFT,
192 SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
193 2 /* indexInSuggestedWords */,
194 false /* willAutoCorrect */,
195 true /* omitTypedWord */,
196 POSITION_CENTER /* centerPositionInStrip */,
197 POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
198 assertEquals("4th word without auto correction", POSITION_RIGHT,
199 SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
200 3 /* indexInSuggestedWords */,
201 false /* willAutoCorrect */,
202 true /* omitTypedWord */,
203 POSITION_CENTER /* centerPositionInStrip */,
204 POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
205
206 assertEquals("typed word with auto correction", POSITION_OMIT,
207 SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
208 SuggestedWords.INDEX_OF_TYPED_WORD /* indexInSuggestedWords */,
209 true /* willAutoCorrect */,
210 true /* omitTypedWord */,
211 POSITION_CENTER /* centerPositionInStrip */,
212 POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
213 assertEquals("2nd word with auto correction", POSITION_CENTER,
214 SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
215 SuggestedWords.INDEX_OF_AUTO_CORRECTION /* indexInSuggestedWords */,
216 true /* willAutoCorrect */,
217 true /* omitTypedWord */,
218 POSITION_CENTER /* centerPositionInStrip */,
219 POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
220 assertEquals("3rd word with auto correction", POSITION_LEFT,
221 SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
222 2 /* indexInSuggestedWords */,
223 true /* willAutoCorrect */,
224 true /* omitTypedWord */,
225 POSITION_CENTER /* centerPositionInStrip */,
226 POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
227 assertEquals("4th word with auto correction", POSITION_RIGHT,
228 SuggestionStripLayoutHelper.getPositionInSuggestionStrip(
229 3 /* indexInSuggestedWords */,
230 true /* willAutoCorrect */,
231 true /* omitTypedWord */,
232 POSITION_CENTER /* centerPositionInStrip */,
233 POSITION_LEFT /* typedWordPositionWhenAutoCorrect */));
234 }
235}