OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/input_method/candidate_window_controller_impl.
h" | 5 #include "chrome/browser/chromeos/input_method/candidate_window_controller_impl.
h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace chromeos { | 9 namespace chromeos { |
10 namespace input_method { | 10 namespace input_method { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 kScreenRect.bottom() - infolist_window_size.height()); | 122 kScreenRect.bottom() - infolist_window_size.height()); |
123 EXPECT_EQ(expected_point, | 123 EXPECT_EQ(expected_point, |
124 TestableCandidateWindowControllerImpl::GetInfolistWindowPosition( | 124 TestableCandidateWindowControllerImpl::GetInfolistWindowPosition( |
125 candidate_window_rect, | 125 candidate_window_rect, |
126 kScreenRect, | 126 kScreenRect, |
127 infolist_window_size)); | 127 infolist_window_size)); |
128 } | 128 } |
129 | 129 |
130 TEST_F(CandidateWindowControllerImplTest, | 130 TEST_F(CandidateWindowControllerImplTest, |
131 ConvertLookupTableToInfolistEntryTest_DenseCase) { | 131 ConvertLookupTableToInfolistEntryTest_DenseCase) { |
132 ibus::IBusLookupTable table; | 132 IBusLookupTable table; |
133 table.set_page_size(10); | 133 table.set_page_size(10); |
134 for (size_t i = 0; i < kSampleCandidateSize; ++i) { | 134 for (size_t i = 0; i < kSampleCandidateSize; ++i) { |
135 ibus::IBusLookupTable::Entry entry; | 135 IBusLookupTable::Entry entry; |
136 entry.value = kSampleCandidate[i]; | 136 entry.value = kSampleCandidate[i]; |
137 entry.description_title = kSampleDescriptionTitle[i]; | 137 entry.description_title = kSampleDescriptionTitle[i]; |
138 entry.description_body = kSampleDescriptionBody[i]; | 138 entry.description_body = kSampleDescriptionBody[i]; |
139 table.mutable_candidates()->push_back(entry); | 139 table.mutable_candidates()->push_back(entry); |
140 } | 140 } |
141 table.set_cursor_position(1); | 141 table.set_cursor_position(1); |
142 | 142 |
143 std::vector<InfolistWindowView::Entry> infolist_entries; | 143 std::vector<InfolistWindowView::Entry> infolist_entries; |
144 size_t focused_index = 0; | 144 size_t focused_index = 0; |
145 | 145 |
146 TestableCandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( | 146 TestableCandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( |
147 table, | 147 table, |
148 &infolist_entries, | 148 &infolist_entries, |
149 &focused_index); | 149 &focused_index); |
150 | 150 |
151 EXPECT_EQ(kSampleCandidateSize, infolist_entries.size()); | 151 EXPECT_EQ(kSampleCandidateSize, infolist_entries.size()); |
152 EXPECT_EQ(1UL, focused_index); | 152 EXPECT_EQ(1UL, focused_index); |
153 } | 153 } |
154 | 154 |
155 TEST_F(CandidateWindowControllerImplTest, | 155 TEST_F(CandidateWindowControllerImplTest, |
156 ConvertLookupTableToInfolistEntryTest_SparseCase) { | 156 ConvertLookupTableToInfolistEntryTest_SparseCase) { |
157 ibus::IBusLookupTable table; | 157 IBusLookupTable table; |
158 table.set_page_size(10); | 158 table.set_page_size(10); |
159 for (size_t i = 0; i < kSampleCandidateSize; ++i) { | 159 for (size_t i = 0; i < kSampleCandidateSize; ++i) { |
160 ibus::IBusLookupTable::Entry entry; | 160 IBusLookupTable::Entry entry; |
161 entry.value = kSampleCandidate[i]; | 161 entry.value = kSampleCandidate[i]; |
162 table.mutable_candidates()->push_back(entry); | 162 table.mutable_candidates()->push_back(entry); |
163 } | 163 } |
164 | 164 |
165 std::vector<ibus::IBusLookupTable::Entry>* candidates = | 165 std::vector<IBusLookupTable::Entry>* candidates = |
166 table.mutable_candidates(); | 166 table.mutable_candidates(); |
167 (*candidates)[2].description_title = kSampleDescriptionTitle[2]; | 167 (*candidates)[2].description_title = kSampleDescriptionTitle[2]; |
168 (*candidates)[2].description_body = kSampleDescriptionBody[2]; | 168 (*candidates)[2].description_body = kSampleDescriptionBody[2]; |
169 | 169 |
170 table.set_cursor_position(2); | 170 table.set_cursor_position(2); |
171 | 171 |
172 std::vector<InfolistWindowView::Entry> infolist_entries; | 172 std::vector<InfolistWindowView::Entry> infolist_entries; |
173 size_t focused_index = 0; | 173 size_t focused_index = 0; |
174 | 174 |
175 TestableCandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( | 175 TestableCandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( |
176 table, | 176 table, |
177 &infolist_entries, | 177 &infolist_entries, |
178 &focused_index); | 178 &focused_index); |
179 | 179 |
180 // Infolist entries skips empty descriptions, so expected entry size is 1 and | 180 // Infolist entries skips empty descriptions, so expected entry size is 1 and |
181 // expected focus index is 0. | 181 // expected focus index is 0. |
182 EXPECT_EQ(1UL, infolist_entries.size()); | 182 EXPECT_EQ(1UL, infolist_entries.size()); |
183 EXPECT_EQ(0UL, focused_index); | 183 EXPECT_EQ(0UL, focused_index); |
184 } | 184 } |
185 | 185 |
186 TEST_F(CandidateWindowControllerImplTest, | 186 TEST_F(CandidateWindowControllerImplTest, |
187 ConvertLookupTableToInfolistEntryTest_SparseNoSelectionCase) { | 187 ConvertLookupTableToInfolistEntryTest_SparseNoSelectionCase) { |
188 ibus::IBusLookupTable table; | 188 IBusLookupTable table; |
189 table.set_page_size(10); | 189 table.set_page_size(10); |
190 | 190 |
191 for (size_t i = 0; i < kSampleCandidateSize; ++i) { | 191 for (size_t i = 0; i < kSampleCandidateSize; ++i) { |
192 ibus::IBusLookupTable::Entry entry; | 192 IBusLookupTable::Entry entry; |
193 entry.value = kSampleCandidate[i]; | 193 entry.value = kSampleCandidate[i]; |
194 table.mutable_candidates()->push_back(entry); | 194 table.mutable_candidates()->push_back(entry); |
195 } | 195 } |
196 | 196 |
197 std::vector<ibus::IBusLookupTable::Entry>* candidates = | 197 std::vector<IBusLookupTable::Entry>* candidates = |
198 table.mutable_candidates(); | 198 table.mutable_candidates(); |
199 (*candidates)[2].description_title = kSampleDescriptionTitle[2]; | 199 (*candidates)[2].description_title = kSampleDescriptionTitle[2]; |
200 (*candidates)[2].description_body = kSampleDescriptionBody[2]; | 200 (*candidates)[2].description_body = kSampleDescriptionBody[2]; |
201 | 201 |
202 table.set_cursor_position(0); | 202 table.set_cursor_position(0); |
203 | 203 |
204 std::vector<InfolistWindowView::Entry> infolist_entries; | 204 std::vector<InfolistWindowView::Entry> infolist_entries; |
205 size_t focused_index = 0; | 205 size_t focused_index = 0; |
206 | 206 |
207 TestableCandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( | 207 TestableCandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( |
208 table, | 208 table, |
209 &infolist_entries, | 209 &infolist_entries, |
210 &focused_index); | 210 &focused_index); |
211 | 211 |
212 // Infolist entries skips empty descriptions, so expected entry size is 1 and | 212 // Infolist entries skips empty descriptions, so expected entry size is 1 and |
213 // there is no focused index because no infolist entry candidate is selected. | 213 // there is no focused index because no infolist entry candidate is selected. |
214 EXPECT_EQ(1UL, infolist_entries.size()); | 214 EXPECT_EQ(1UL, infolist_entries.size()); |
215 EXPECT_EQ(static_cast<size_t>(-1), focused_index); | 215 EXPECT_EQ(static_cast<size_t>(-1), focused_index); |
216 } | 216 } |
217 | 217 |
218 TEST_F(CandidateWindowControllerImplTest, | 218 TEST_F(CandidateWindowControllerImplTest, |
219 ConvertLookupTableToInfolistEntryTest_NoInfolistCase) { | 219 ConvertLookupTableToInfolistEntryTest_NoInfolistCase) { |
220 ibus::IBusLookupTable table; | 220 IBusLookupTable table; |
221 table.set_page_size(10); | 221 table.set_page_size(10); |
222 | 222 |
223 for (size_t i = 0; i < kSampleCandidateSize; ++i) { | 223 for (size_t i = 0; i < kSampleCandidateSize; ++i) { |
224 ibus::IBusLookupTable::Entry entry; | 224 IBusLookupTable::Entry entry; |
225 entry.value = kSampleCandidate[i]; | 225 entry.value = kSampleCandidate[i]; |
226 table.mutable_candidates()->push_back(entry); | 226 table.mutable_candidates()->push_back(entry); |
227 } | 227 } |
228 table.set_cursor_position(1); | 228 table.set_cursor_position(1); |
229 | 229 |
230 std::vector<InfolistWindowView::Entry> infolist_entries; | 230 std::vector<InfolistWindowView::Entry> infolist_entries; |
231 size_t focused_index = 0; | 231 size_t focused_index = 0; |
232 | 232 |
233 TestableCandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( | 233 TestableCandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( |
234 table, | 234 table, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 EXPECT_TRUE(TestableCandidateWindowControllerImpl::ShouldUpdateInfolist( | 324 EXPECT_TRUE(TestableCandidateWindowControllerImpl::ShouldUpdateInfolist( |
325 old_entry, | 325 old_entry, |
326 InfolistWindowView::InvalidFocusIndex(), | 326 InfolistWindowView::InvalidFocusIndex(), |
327 new_entry, | 327 new_entry, |
328 InfolistWindowView::InvalidFocusIndex())); | 328 InfolistWindowView::InvalidFocusIndex())); |
329 new_entry.clear(); | 329 new_entry.clear(); |
330 } | 330 } |
331 | 331 |
332 } // namespace input_method | 332 } // namespace input_method |
333 } // namespace chromeos | 333 } // namespace chromeos |
OLD | NEW |