| 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 InputMethodLookupTable table; | 132 ibus::IBusLookupTable table; |
| 133 table.visible = true; | 133 table.set_page_size(10); |
| 134 table.page_size = 10; | |
| 135 for (size_t i = 0; i < kSampleCandidateSize; ++i) { | 134 for (size_t i = 0; i < kSampleCandidateSize; ++i) { |
| 136 table.candidates.push_back(kSampleCandidate[i]); | 135 ibus::IBusLookupTable::Entry entry; |
| 137 InputMethodLookupTable::Description description; | 136 entry.value = kSampleCandidate[i]; |
| 138 description.title = kSampleDescriptionTitle[i]; | 137 entry.description_title = kSampleDescriptionTitle[i]; |
| 139 description.body = kSampleDescriptionBody[i]; | 138 entry.description_body = kSampleDescriptionBody[i]; |
| 140 table.descriptions.push_back(description); | 139 table.mutable_candidates()->push_back(entry); |
| 141 } | 140 } |
| 142 table.cursor_absolute_index = 1; | 141 table.set_cursor_position(1); |
| 143 | 142 |
| 144 std::vector<InfolistWindowView::Entry> infolist_entries; | 143 std::vector<InfolistWindowView::Entry> infolist_entries; |
| 145 size_t focused_index = 0; | 144 size_t focused_index = 0; |
| 146 | 145 |
| 147 TestableCandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( | 146 TestableCandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( |
| 148 table, | 147 table, |
| 149 &infolist_entries, | 148 &infolist_entries, |
| 150 &focused_index); | 149 &focused_index); |
| 151 | 150 |
| 152 EXPECT_EQ(kSampleCandidateSize, infolist_entries.size()); | 151 EXPECT_EQ(kSampleCandidateSize, infolist_entries.size()); |
| 153 EXPECT_EQ(1UL, focused_index); | 152 EXPECT_EQ(1UL, focused_index); |
| 154 } | 153 } |
| 155 | 154 |
| 156 TEST_F(CandidateWindowControllerImplTest, | 155 TEST_F(CandidateWindowControllerImplTest, |
| 157 ConvertLookupTableToInfolistEntryTest_SparseCase) { | 156 ConvertLookupTableToInfolistEntryTest_SparseCase) { |
| 158 InputMethodLookupTable table; | 157 ibus::IBusLookupTable table; |
| 159 table.visible = true; | 158 table.set_page_size(10); |
| 160 table.page_size = 10; | |
| 161 for (size_t i = 0; i < kSampleCandidateSize; ++i) { | 159 for (size_t i = 0; i < kSampleCandidateSize; ++i) { |
| 162 table.candidates.push_back(kSampleCandidate[i]); | 160 ibus::IBusLookupTable::Entry entry; |
| 163 InputMethodLookupTable::Description description; | 161 entry.value = kSampleCandidate[i]; |
| 164 table.descriptions.push_back(description); | 162 table.mutable_candidates()->push_back(entry); |
| 165 } | 163 } |
| 166 | 164 |
| 167 table.descriptions[2].title = kSampleDescriptionTitle[2]; | 165 std::vector<ibus::IBusLookupTable::Entry>* candidates = |
| 168 table.descriptions[2].body = kSampleDescriptionBody[2]; | 166 table.mutable_candidates(); |
| 167 (*candidates)[2].description_title = kSampleDescriptionTitle[2]; |
| 168 (*candidates)[2].description_body = kSampleDescriptionBody[2]; |
| 169 | 169 |
| 170 table.cursor_absolute_index = 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 InputMethodLookupTable table; | 188 ibus::IBusLookupTable table; |
| 189 table.visible = true; | 189 table.set_page_size(10); |
| 190 table.page_size = 10; | 190 |
| 191 for (size_t i = 0; i < kSampleCandidateSize; ++i) { | 191 for (size_t i = 0; i < kSampleCandidateSize; ++i) { |
| 192 table.candidates.push_back(kSampleCandidate[i]); | 192 ibus::IBusLookupTable::Entry entry; |
| 193 InputMethodLookupTable::Description description; | 193 entry.value = kSampleCandidate[i]; |
| 194 table.descriptions.push_back(description); | 194 table.mutable_candidates()->push_back(entry); |
| 195 } | 195 } |
| 196 | 196 |
| 197 table.descriptions[2].title = kSampleDescriptionTitle[2]; | 197 std::vector<ibus::IBusLookupTable::Entry>* candidates = |
| 198 table.descriptions[2].body = kSampleDescriptionBody[2]; | 198 table.mutable_candidates(); |
| 199 (*candidates)[2].description_title = kSampleDescriptionTitle[2]; |
| 200 (*candidates)[2].description_body = kSampleDescriptionBody[2]; |
| 199 | 201 |
| 200 table.cursor_absolute_index = 0; | 202 table.set_cursor_position(0); |
| 201 | 203 |
| 202 std::vector<InfolistWindowView::Entry> infolist_entries; | 204 std::vector<InfolistWindowView::Entry> infolist_entries; |
| 203 size_t focused_index = 0; | 205 size_t focused_index = 0; |
| 204 | 206 |
| 205 TestableCandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( | 207 TestableCandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( |
| 206 table, | 208 table, |
| 207 &infolist_entries, | 209 &infolist_entries, |
| 208 &focused_index); | 210 &focused_index); |
| 209 | 211 |
| 210 // 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 |
| 211 // 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. |
| 212 EXPECT_EQ(1UL, infolist_entries.size()); | 214 EXPECT_EQ(1UL, infolist_entries.size()); |
| 213 EXPECT_EQ(static_cast<size_t>(-1), focused_index); | 215 EXPECT_EQ(static_cast<size_t>(-1), focused_index); |
| 214 } | 216 } |
| 215 | 217 |
| 216 TEST_F(CandidateWindowControllerImplTest, | 218 TEST_F(CandidateWindowControllerImplTest, |
| 217 ConvertLookupTableToInfolistEntryTest_NoInfolistCase) { | 219 ConvertLookupTableToInfolistEntryTest_NoInfolistCase) { |
| 218 InputMethodLookupTable table; | 220 ibus::IBusLookupTable table; |
| 219 table.visible = true; | 221 table.set_page_size(10); |
| 220 table.page_size = 10; | 222 |
| 221 for (size_t i = 0; i < kSampleCandidateSize; ++i) { | 223 for (size_t i = 0; i < kSampleCandidateSize; ++i) { |
| 222 table.candidates.push_back(kSampleCandidate[i]); | 224 ibus::IBusLookupTable::Entry entry; |
| 223 InputMethodLookupTable::Description description; | 225 entry.value = kSampleCandidate[i]; |
| 224 table.descriptions.push_back(description); | 226 table.mutable_candidates()->push_back(entry); |
| 225 } | 227 } |
| 226 table.cursor_absolute_index = 1; | 228 table.set_cursor_position(1); |
| 227 | 229 |
| 228 std::vector<InfolistWindowView::Entry> infolist_entries; | 230 std::vector<InfolistWindowView::Entry> infolist_entries; |
| 229 size_t focused_index = 0; | 231 size_t focused_index = 0; |
| 230 | 232 |
| 231 TestableCandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( | 233 TestableCandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( |
| 232 table, | 234 table, |
| 233 &infolist_entries, | 235 &infolist_entries, |
| 234 &focused_index); | 236 &focused_index); |
| 235 | 237 |
| 236 EXPECT_TRUE(infolist_entries.empty()); | 238 EXPECT_TRUE(infolist_entries.empty()); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 EXPECT_TRUE(TestableCandidateWindowControllerImpl::ShouldUpdateInfolist( | 324 EXPECT_TRUE(TestableCandidateWindowControllerImpl::ShouldUpdateInfolist( |
| 323 old_entry, | 325 old_entry, |
| 324 InfolistWindowView::InvalidFocusIndex(), | 326 InfolistWindowView::InvalidFocusIndex(), |
| 325 new_entry, | 327 new_entry, |
| 326 InfolistWindowView::InvalidFocusIndex())); | 328 InfolistWindowView::InvalidFocusIndex())); |
| 327 new_entry.clear(); | 329 new_entry.clear(); |
| 328 } | 330 } |
| 329 | 331 |
| 330 } // namespace input_method | 332 } // namespace input_method |
| 331 } // namespace chromeos | 333 } // namespace chromeos |
| OLD | NEW |