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_view.h" | 5 #include "chrome/browser/chromeos/input_method/candidate_window_view.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 "Sample Description Title 1", | 31 "Sample Description Title 1", |
32 "Sample Description Title 2", | 32 "Sample Description Title 2", |
33 "Sample Description Title 3", | 33 "Sample Description Title 3", |
34 }; | 34 }; |
35 const char* kSampleDescriptionBody[] = { | 35 const char* kSampleDescriptionBody[] = { |
36 "Sample Description Body 1", | 36 "Sample Description Body 1", |
37 "Sample Description Body 2", | 37 "Sample Description Body 2", |
38 "Sample Description Body 3", | 38 "Sample Description Body 3", |
39 }; | 39 }; |
40 | 40 |
41 void InitIBusLookupTable(size_t page_size, | 41 void InitCandidateWindow(size_t page_size, |
42 IBusLookupTable* table) { | 42 CandidateWindow* candidate_window) { |
43 table->set_cursor_position(0); | 43 candidate_window->set_cursor_position(0); |
44 table->set_page_size(page_size); | 44 candidate_window->set_page_size(page_size); |
45 table->mutable_candidates()->clear(); | 45 candidate_window->mutable_candidates()->clear(); |
46 table->set_orientation(IBusLookupTable::VERTICAL); | 46 candidate_window->set_orientation(CandidateWindow::VERTICAL); |
47 } | 47 } |
48 | 48 |
49 void InitIBusLookupTableWithCandidatesFilled(size_t page_size, | 49 void InitCandidateWindowWithCandidatesFilled( |
50 IBusLookupTable* table) { | 50 size_t page_size, |
51 InitIBusLookupTable(page_size, table); | 51 CandidateWindow* candidate_window) { |
| 52 InitCandidateWindow(page_size, candidate_window); |
52 for (size_t i = 0; i < page_size; ++i) { | 53 for (size_t i = 0; i < page_size; ++i) { |
53 IBusLookupTable::Entry entry; | 54 CandidateWindow::Entry entry; |
54 entry.value = base::StringPrintf("value %lld", | 55 entry.value = base::StringPrintf("value %lld", |
55 static_cast<unsigned long long>(i)); | 56 static_cast<unsigned long long>(i)); |
56 entry.label = base::StringPrintf("%lld", | 57 entry.label = base::StringPrintf("%lld", |
57 static_cast<unsigned long long>(i)); | 58 static_cast<unsigned long long>(i)); |
58 table->mutable_candidates()->push_back(entry); | 59 candidate_window->mutable_candidates()->push_back(entry); |
59 } | 60 } |
60 } | 61 } |
61 | 62 |
62 } // namespace | 63 } // namespace |
63 | 64 |
64 class CandidateWindowViewTest : public views::ViewsTestBase { | 65 class CandidateWindowViewTest : public views::ViewsTestBase { |
65 protected: | 66 protected: |
66 void ExpectLabels(const std::string& shortcut, | 67 void ExpectLabels(const std::string& shortcut, |
67 const std::string& candidate, | 68 const std::string& candidate, |
68 const std::string& annotation, | 69 const std::string& annotation, |
69 const CandidateView* row) { | 70 const CandidateView* row) { |
70 EXPECT_EQ(shortcut, UTF16ToUTF8(row->shortcut_label_->text())); | 71 EXPECT_EQ(shortcut, UTF16ToUTF8(row->shortcut_label_->text())); |
71 EXPECT_EQ(candidate, UTF16ToUTF8(row->candidate_label_->text())); | 72 EXPECT_EQ(candidate, UTF16ToUTF8(row->candidate_label_->text())); |
72 EXPECT_EQ(annotation, UTF16ToUTF8(row->annotation_label_->text())); | 73 EXPECT_EQ(annotation, UTF16ToUTF8(row->annotation_label_->text())); |
73 } | 74 } |
74 }; | 75 }; |
75 | 76 |
76 TEST_F(CandidateWindowViewTest, UpdateCandidatesTest_CursorVisibility) { | 77 TEST_F(CandidateWindowViewTest, UpdateCandidatesTest_CursorVisibility) { |
77 views::Widget* widget = new views::Widget; | 78 views::Widget* widget = new views::Widget; |
78 views::Widget::InitParams params = | 79 views::Widget::InitParams params = |
79 CreateParams(views::Widget::InitParams::TYPE_WINDOW); | 80 CreateParams(views::Widget::InitParams::TYPE_WINDOW); |
80 widget->Init(params); | 81 widget->Init(params); |
81 | 82 |
82 CandidateWindowView candidate_window_view(widget); | 83 CandidateWindowView candidate_window_view(widget); |
83 candidate_window_view.Init(); | 84 candidate_window_view.Init(); |
84 | 85 |
85 // Visible (by default) cursor. | 86 // Visible (by default) cursor. |
86 IBusLookupTable table; | 87 CandidateWindow candidate_window; |
87 const int table_size = 9; | 88 const int candidate_window_size = 9; |
88 InitIBusLookupTableWithCandidatesFilled(table_size, &table); | 89 InitCandidateWindowWithCandidatesFilled(candidate_window_size, |
89 candidate_window_view.UpdateCandidates(table); | 90 &candidate_window); |
| 91 candidate_window_view.UpdateCandidates(candidate_window); |
90 EXPECT_EQ(0, candidate_window_view.selected_candidate_index_in_page_); | 92 EXPECT_EQ(0, candidate_window_view.selected_candidate_index_in_page_); |
91 | 93 |
92 // Invisible cursor. | 94 // Invisible cursor. |
93 table.set_is_cursor_visible(false); | 95 candidate_window.set_is_cursor_visible(false); |
94 candidate_window_view.UpdateCandidates(table); | 96 candidate_window_view.UpdateCandidates(candidate_window); |
95 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); | 97 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); |
96 | 98 |
97 // Move the cursor to the end. | 99 // Move the cursor to the end. |
98 table.set_cursor_position(table_size - 1); | 100 candidate_window.set_cursor_position(candidate_window_size - 1); |
99 candidate_window_view.UpdateCandidates(table); | 101 candidate_window_view.UpdateCandidates(candidate_window); |
100 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); | 102 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); |
101 | 103 |
102 // Change the cursor to visible. The cursor must be at the end. | 104 // Change the cursor to visible. The cursor must be at the end. |
103 table.set_is_cursor_visible(true); | 105 candidate_window.set_is_cursor_visible(true); |
104 candidate_window_view.UpdateCandidates(table); | 106 candidate_window_view.UpdateCandidates(candidate_window); |
105 EXPECT_EQ(table_size - 1, | 107 EXPECT_EQ(candidate_window_size - 1, |
106 candidate_window_view.selected_candidate_index_in_page_); | 108 candidate_window_view.selected_candidate_index_in_page_); |
107 } | 109 } |
108 | 110 |
109 TEST_F(CandidateWindowViewTest, SelectCandidateAtTest) { | 111 TEST_F(CandidateWindowViewTest, SelectCandidateAtTest) { |
110 views::Widget* widget = new views::Widget; | 112 views::Widget* widget = new views::Widget; |
111 views::Widget::InitParams params = | 113 views::Widget::InitParams params = |
112 CreateParams(views::Widget::InitParams::TYPE_WINDOW); | 114 CreateParams(views::Widget::InitParams::TYPE_WINDOW); |
113 widget->Init(params); | 115 widget->Init(params); |
114 | 116 |
115 CandidateWindowView candidate_window_view(widget); | 117 CandidateWindowView candidate_window_view(widget); |
116 candidate_window_view.Init(); | 118 candidate_window_view.Init(); |
117 | 119 |
118 // Set 9 candidates. | 120 // Set 9 candidates. |
119 IBusLookupTable table_large; | 121 CandidateWindow candidate_window_large; |
120 const int table_large_size = 9; | 122 const int candidate_window_large_size = 9; |
121 InitIBusLookupTableWithCandidatesFilled(table_large_size, &table_large); | 123 InitCandidateWindowWithCandidatesFilled(candidate_window_large_size, |
122 table_large.set_cursor_position(table_large_size - 1); | 124 &candidate_window_large); |
123 candidate_window_view.UpdateCandidates(table_large); | 125 candidate_window_large.set_cursor_position(candidate_window_large_size - 1); |
| 126 candidate_window_view.UpdateCandidates(candidate_window_large); |
124 // Select the last candidate. | 127 // Select the last candidate. |
125 candidate_window_view.SelectCandidateAt(table_large_size - 1); | 128 candidate_window_view.SelectCandidateAt(candidate_window_large_size - 1); |
126 | 129 |
127 // Reduce the number of candidates to 3. | 130 // Reduce the number of candidates to 3. |
128 IBusLookupTable table_small; | 131 CandidateWindow candidate_window_small; |
129 const int table_small_size = 3; | 132 const int candidate_window_small_size = 3; |
130 InitIBusLookupTableWithCandidatesFilled(table_small_size, &table_small); | 133 InitCandidateWindowWithCandidatesFilled(candidate_window_small_size, |
131 table_small.set_cursor_position(table_small_size - 1); | 134 &candidate_window_small); |
132 // Make sure the test doesn't crash if the candidate table reduced its size. | 135 candidate_window_small.set_cursor_position(candidate_window_small_size - 1); |
133 // (crbug.com/174163) | 136 // Make sure the test doesn't crash if the candidate window reduced |
134 candidate_window_view.UpdateCandidates(table_small); | 137 // its size. (crbug.com/174163) |
135 candidate_window_view.SelectCandidateAt(table_small_size - 1); | 138 candidate_window_view.UpdateCandidates(candidate_window_small); |
| 139 candidate_window_view.SelectCandidateAt(candidate_window_small_size - 1); |
136 } | 140 } |
137 | 141 |
138 TEST_F(CandidateWindowViewTest, ShortcutSettingTest) { | 142 TEST_F(CandidateWindowViewTest, ShortcutSettingTest) { |
139 const char* kEmptyLabel = ""; | 143 const char* kEmptyLabel = ""; |
140 const char* kCustomizedLabel[] = { "a", "s", "d" }; | 144 const char* kCustomizedLabel[] = { "a", "s", "d" }; |
141 const char* kExpectedHorizontalCustomizedLabel[] = { "a.", "s.", "d." }; | 145 const char* kExpectedHorizontalCustomizedLabel[] = { "a.", "s.", "d." }; |
142 | 146 |
143 views::Widget* widget = new views::Widget; | 147 views::Widget* widget = new views::Widget; |
144 views::Widget::InitParams params = | 148 views::Widget::InitParams params = |
145 CreateParams(views::Widget::InitParams::TYPE_WINDOW); | 149 CreateParams(views::Widget::InitParams::TYPE_WINDOW); |
146 widget->Init(params); | 150 widget->Init(params); |
147 | 151 |
148 CandidateWindowView candidate_window_view(widget); | 152 CandidateWindowView candidate_window_view(widget); |
149 candidate_window_view.Init(); | 153 candidate_window_view.Init(); |
150 | 154 |
151 { | 155 { |
152 SCOPED_TRACE("candidate_views allocation test"); | 156 SCOPED_TRACE("candidate_views allocation test"); |
153 const size_t kMaxPageSize = 16; | 157 const size_t kMaxPageSize = 16; |
154 for (size_t i = 1; i < kMaxPageSize; ++i) { | 158 for (size_t i = 1; i < kMaxPageSize; ++i) { |
155 IBusLookupTable table; | 159 CandidateWindow candidate_window; |
156 InitIBusLookupTable(i, &table); | 160 InitCandidateWindow(i, &candidate_window); |
157 candidate_window_view.UpdateCandidates(table); | 161 candidate_window_view.UpdateCandidates(candidate_window); |
158 EXPECT_EQ(i, candidate_window_view.candidate_views_.size()); | 162 EXPECT_EQ(i, candidate_window_view.candidate_views_.size()); |
159 } | 163 } |
160 } | 164 } |
161 { | 165 { |
162 SCOPED_TRACE("Empty string for each labels expects empty labels(vertical)"); | 166 SCOPED_TRACE("Empty string for each labels expects empty labels(vertical)"); |
163 const size_t kPageSize = 3; | 167 const size_t kPageSize = 3; |
164 IBusLookupTable table; | 168 CandidateWindow candidate_window; |
165 InitIBusLookupTable(kPageSize, &table); | 169 InitCandidateWindow(kPageSize, &candidate_window); |
166 | 170 |
167 table.set_orientation(IBusLookupTable::VERTICAL); | 171 candidate_window.set_orientation(CandidateWindow::VERTICAL); |
168 for (size_t i = 0; i < kPageSize; ++i) { | 172 for (size_t i = 0; i < kPageSize; ++i) { |
169 IBusLookupTable::Entry entry; | 173 CandidateWindow::Entry entry; |
170 entry.value = kSampleCandidate[i]; | 174 entry.value = kSampleCandidate[i]; |
171 entry.annotation = kSampleAnnotation[i]; | 175 entry.annotation = kSampleAnnotation[i]; |
172 entry.description_title = kSampleDescriptionTitle[i]; | 176 entry.description_title = kSampleDescriptionTitle[i]; |
173 entry.description_body = kSampleDescriptionBody[i]; | 177 entry.description_body = kSampleDescriptionBody[i]; |
174 entry.label = kEmptyLabel; | 178 entry.label = kEmptyLabel; |
175 table.mutable_candidates()->push_back(entry); | 179 candidate_window.mutable_candidates()->push_back(entry); |
176 } | 180 } |
177 | 181 |
178 candidate_window_view.UpdateCandidates(table); | 182 candidate_window_view.UpdateCandidates(candidate_window); |
179 | 183 |
180 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); | 184 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); |
181 for (size_t i = 0; i < kPageSize; ++i) { | 185 for (size_t i = 0; i < kPageSize; ++i) { |
182 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], | 186 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], |
183 candidate_window_view.candidate_views_[i]); | 187 candidate_window_view.candidate_views_[i]); |
184 } | 188 } |
185 } | 189 } |
186 { | 190 { |
187 SCOPED_TRACE( | 191 SCOPED_TRACE( |
188 "Empty string for each labels expect empty labels(horizontal)"); | 192 "Empty string for each labels expect empty labels(horizontal)"); |
189 const size_t kPageSize = 3; | 193 const size_t kPageSize = 3; |
190 IBusLookupTable table; | 194 CandidateWindow candidate_window; |
191 InitIBusLookupTable(kPageSize, &table); | 195 InitCandidateWindow(kPageSize, &candidate_window); |
192 | 196 |
193 table.set_orientation(IBusLookupTable::HORIZONTAL); | 197 candidate_window.set_orientation(CandidateWindow::HORIZONTAL); |
194 for (size_t i = 0; i < kPageSize; ++i) { | 198 for (size_t i = 0; i < kPageSize; ++i) { |
195 IBusLookupTable::Entry entry; | 199 CandidateWindow::Entry entry; |
196 entry.value = kSampleCandidate[i]; | 200 entry.value = kSampleCandidate[i]; |
197 entry.annotation = kSampleAnnotation[i]; | 201 entry.annotation = kSampleAnnotation[i]; |
198 entry.description_title = kSampleDescriptionTitle[i]; | 202 entry.description_title = kSampleDescriptionTitle[i]; |
199 entry.description_body = kSampleDescriptionBody[i]; | 203 entry.description_body = kSampleDescriptionBody[i]; |
200 entry.label = kEmptyLabel; | 204 entry.label = kEmptyLabel; |
201 table.mutable_candidates()->push_back(entry); | 205 candidate_window.mutable_candidates()->push_back(entry); |
202 } | 206 } |
203 | 207 |
204 candidate_window_view.UpdateCandidates(table); | 208 candidate_window_view.UpdateCandidates(candidate_window); |
205 | 209 |
206 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); | 210 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); |
207 // Confirm actual labels not containing ".". | 211 // Confirm actual labels not containing ".". |
208 for (size_t i = 0; i < kPageSize; ++i) { | 212 for (size_t i = 0; i < kPageSize; ++i) { |
209 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], | 213 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], |
210 candidate_window_view.candidate_views_[i]); | 214 candidate_window_view.candidate_views_[i]); |
211 } | 215 } |
212 } | 216 } |
213 { | 217 { |
214 SCOPED_TRACE("Vertical customized label case"); | 218 SCOPED_TRACE("Vertical customized label case"); |
215 const size_t kPageSize = 3; | 219 const size_t kPageSize = 3; |
216 IBusLookupTable table; | 220 CandidateWindow candidate_window; |
217 InitIBusLookupTable(kPageSize, &table); | 221 InitCandidateWindow(kPageSize, &candidate_window); |
218 | 222 |
219 table.set_orientation(IBusLookupTable::VERTICAL); | 223 candidate_window.set_orientation(CandidateWindow::VERTICAL); |
220 for (size_t i = 0; i < kPageSize; ++i) { | 224 for (size_t i = 0; i < kPageSize; ++i) { |
221 IBusLookupTable::Entry entry; | 225 CandidateWindow::Entry entry; |
222 entry.value = kSampleCandidate[i]; | 226 entry.value = kSampleCandidate[i]; |
223 entry.annotation = kSampleAnnotation[i]; | 227 entry.annotation = kSampleAnnotation[i]; |
224 entry.description_title = kSampleDescriptionTitle[i]; | 228 entry.description_title = kSampleDescriptionTitle[i]; |
225 entry.description_body = kSampleDescriptionBody[i]; | 229 entry.description_body = kSampleDescriptionBody[i]; |
226 entry.label = kCustomizedLabel[i]; | 230 entry.label = kCustomizedLabel[i]; |
227 table.mutable_candidates()->push_back(entry); | 231 candidate_window.mutable_candidates()->push_back(entry); |
228 } | 232 } |
229 | 233 |
230 candidate_window_view.UpdateCandidates(table); | 234 candidate_window_view.UpdateCandidates(candidate_window); |
231 | 235 |
232 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); | 236 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); |
233 // Confirm actual labels not containing ".". | 237 // Confirm actual labels not containing ".". |
234 for (size_t i = 0; i < kPageSize; ++i) { | 238 for (size_t i = 0; i < kPageSize; ++i) { |
235 ExpectLabels(kCustomizedLabel[i], | 239 ExpectLabels(kCustomizedLabel[i], |
236 kSampleCandidate[i], | 240 kSampleCandidate[i], |
237 kSampleAnnotation[i], | 241 kSampleAnnotation[i], |
238 candidate_window_view.candidate_views_[i]); | 242 candidate_window_view.candidate_views_[i]); |
239 } | 243 } |
240 } | 244 } |
241 { | 245 { |
242 SCOPED_TRACE("Horizontal customized label case"); | 246 SCOPED_TRACE("Horizontal customized label case"); |
243 const size_t kPageSize = 3; | 247 const size_t kPageSize = 3; |
244 IBusLookupTable table; | 248 CandidateWindow candidate_window; |
245 InitIBusLookupTable(kPageSize, &table); | 249 InitCandidateWindow(kPageSize, &candidate_window); |
246 | 250 |
247 table.set_orientation(IBusLookupTable::HORIZONTAL); | 251 candidate_window.set_orientation(CandidateWindow::HORIZONTAL); |
248 for (size_t i = 0; i < kPageSize; ++i) { | 252 for (size_t i = 0; i < kPageSize; ++i) { |
249 IBusLookupTable::Entry entry; | 253 CandidateWindow::Entry entry; |
250 entry.value = kSampleCandidate[i]; | 254 entry.value = kSampleCandidate[i]; |
251 entry.annotation = kSampleAnnotation[i]; | 255 entry.annotation = kSampleAnnotation[i]; |
252 entry.description_title = kSampleDescriptionTitle[i]; | 256 entry.description_title = kSampleDescriptionTitle[i]; |
253 entry.description_body = kSampleDescriptionBody[i]; | 257 entry.description_body = kSampleDescriptionBody[i]; |
254 entry.label = kCustomizedLabel[i]; | 258 entry.label = kCustomizedLabel[i]; |
255 table.mutable_candidates()->push_back(entry); | 259 candidate_window.mutable_candidates()->push_back(entry); |
256 } | 260 } |
257 | 261 |
258 candidate_window_view.UpdateCandidates(table); | 262 candidate_window_view.UpdateCandidates(candidate_window); |
259 | 263 |
260 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); | 264 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); |
261 // Confirm actual labels not containing ".". | 265 // Confirm actual labels not containing ".". |
262 for (size_t i = 0; i < kPageSize; ++i) { | 266 for (size_t i = 0; i < kPageSize; ++i) { |
263 ExpectLabels(kExpectedHorizontalCustomizedLabel[i], | 267 ExpectLabels(kExpectedHorizontalCustomizedLabel[i], |
264 kSampleCandidate[i], | 268 kSampleCandidate[i], |
265 kSampleAnnotation[i], | 269 kSampleAnnotation[i], |
266 candidate_window_view.candidate_views_[i]); | 270 candidate_window_view.candidate_views_[i]); |
267 } | 271 } |
268 } | 272 } |
269 | 273 |
270 // We should call CloseNow method, otherwise this test will leak memory. | 274 // We should call CloseNow method, otherwise this test will leak memory. |
271 widget->CloseNow(); | 275 widget->CloseNow(); |
272 } | 276 } |
273 | 277 |
274 TEST_F(CandidateWindowViewTest, DoNotChangeRowHeightWithLabelSwitchTest) { | 278 TEST_F(CandidateWindowViewTest, DoNotChangeRowHeightWithLabelSwitchTest) { |
275 const size_t kPageSize = 10; | 279 const size_t kPageSize = 10; |
276 IBusLookupTable table; | 280 CandidateWindow candidate_window; |
277 IBusLookupTable no_shortcut_table; | 281 CandidateWindow no_shortcut_candidate_window; |
278 | 282 |
279 const char kSampleCandidate1[] = "Sample String 1"; | 283 const char kSampleCandidate1[] = "Sample String 1"; |
280 const char kSampleCandidate2[] = "\xE3\x81\x82"; // multi byte string. | 284 const char kSampleCandidate2[] = "\xE3\x81\x82"; // multi byte string. |
281 const char kSampleCandidate3[] = "....."; | 285 const char kSampleCandidate3[] = "....."; |
282 | 286 |
283 const char kSampleShortcut1[] = "1"; | 287 const char kSampleShortcut1[] = "1"; |
284 const char kSampleShortcut2[] = "b"; | 288 const char kSampleShortcut2[] = "b"; |
285 const char kSampleShortcut3[] = "C"; | 289 const char kSampleShortcut3[] = "C"; |
286 | 290 |
287 const char kSampleAnnotation1[] = "Sample Annotation 1"; | 291 const char kSampleAnnotation1[] = "Sample Annotation 1"; |
288 const char kSampleAnnotation2[] = "\xE3\x81\x82"; // multi byte string. | 292 const char kSampleAnnotation2[] = "\xE3\x81\x82"; // multi byte string. |
289 const char kSampleAnnotation3[] = "......"; | 293 const char kSampleAnnotation3[] = "......"; |
290 | 294 |
291 // For testing, we have to prepare empty widget. | 295 // For testing, we have to prepare empty widget. |
292 // We should NOT manually free widget by default, otherwise double free will | 296 // We should NOT manually free widget by default, otherwise double free will |
293 // be occurred. So, we should instantiate widget class with "new" operation. | 297 // be occurred. So, we should instantiate widget class with "new" operation. |
294 views::Widget* widget = new views::Widget; | 298 views::Widget* widget = new views::Widget; |
295 views::Widget::InitParams params = | 299 views::Widget::InitParams params = |
296 CreateParams(views::Widget::InitParams::TYPE_WINDOW); | 300 CreateParams(views::Widget::InitParams::TYPE_WINDOW); |
297 widget->Init(params); | 301 widget->Init(params); |
298 | 302 |
299 CandidateWindowView candidate_window_view(widget); | 303 CandidateWindowView candidate_window_view(widget); |
300 candidate_window_view.Init(); | 304 candidate_window_view.Init(); |
301 | 305 |
302 // Create LookupTable object. | 306 // Create CandidateWindow object. |
303 InitIBusLookupTable(kPageSize, &table); | 307 InitCandidateWindow(kPageSize, &candidate_window); |
304 | 308 |
305 table.set_cursor_position(0); | 309 candidate_window.set_cursor_position(0); |
306 table.set_page_size(3); | 310 candidate_window.set_page_size(3); |
307 table.mutable_candidates()->clear(); | 311 candidate_window.mutable_candidates()->clear(); |
308 table.set_orientation(IBusLookupTable::VERTICAL); | 312 candidate_window.set_orientation(CandidateWindow::VERTICAL); |
309 no_shortcut_table.CopyFrom(table); | 313 no_shortcut_candidate_window.CopyFrom(candidate_window); |
310 | 314 |
311 IBusLookupTable::Entry entry; | 315 CandidateWindow::Entry entry; |
312 entry.value = kSampleCandidate1; | 316 entry.value = kSampleCandidate1; |
313 entry.annotation = kSampleAnnotation1; | 317 entry.annotation = kSampleAnnotation1; |
314 table.mutable_candidates()->push_back(entry); | 318 candidate_window.mutable_candidates()->push_back(entry); |
315 entry.label = kSampleShortcut1; | 319 entry.label = kSampleShortcut1; |
316 no_shortcut_table.mutable_candidates()->push_back(entry); | 320 no_shortcut_candidate_window.mutable_candidates()->push_back(entry); |
317 | 321 |
318 entry.value = kSampleCandidate2; | 322 entry.value = kSampleCandidate2; |
319 entry.annotation = kSampleAnnotation2; | 323 entry.annotation = kSampleAnnotation2; |
320 table.mutable_candidates()->push_back(entry); | 324 candidate_window.mutable_candidates()->push_back(entry); |
321 entry.label = kSampleShortcut2; | 325 entry.label = kSampleShortcut2; |
322 no_shortcut_table.mutable_candidates()->push_back(entry); | 326 no_shortcut_candidate_window.mutable_candidates()->push_back(entry); |
323 | 327 |
324 entry.value = kSampleCandidate3; | 328 entry.value = kSampleCandidate3; |
325 entry.annotation = kSampleAnnotation3; | 329 entry.annotation = kSampleAnnotation3; |
326 table.mutable_candidates()->push_back(entry); | 330 candidate_window.mutable_candidates()->push_back(entry); |
327 entry.label = kSampleShortcut3; | 331 entry.label = kSampleShortcut3; |
328 no_shortcut_table.mutable_candidates()->push_back(entry); | 332 no_shortcut_candidate_window.mutable_candidates()->push_back(entry); |
329 | 333 |
330 int before_height = 0; | 334 int before_height = 0; |
331 | 335 |
332 // Test for shortcut mode to no-shortcut mode. | 336 // Test for shortcut mode to no-shortcut mode. |
333 // Initialize with a shortcut mode lookup table. | 337 // Initialize with a shortcut mode candidate window. |
334 candidate_window_view.MaybeInitializeCandidateViews(table); | 338 candidate_window_view.MaybeInitializeCandidateViews(candidate_window); |
335 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size()); | 339 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size()); |
336 // Check the selected index is invalidated. | 340 // Check the selected index is invalidated. |
337 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); | 341 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); |
338 before_height = | 342 before_height = |
339 candidate_window_view.candidate_views_[0]->GetContentsBounds().height(); | 343 candidate_window_view.candidate_views_[0]->GetContentsBounds().height(); |
340 // Checks all entry have same row height. | 344 // Checks all entry have same row height. |
341 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { | 345 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { |
342 const CandidateView* view = candidate_window_view.candidate_views_[i]; | 346 const CandidateView* view = candidate_window_view.candidate_views_[i]; |
343 EXPECT_EQ(before_height, view->GetContentsBounds().height()); | 347 EXPECT_EQ(before_height, view->GetContentsBounds().height()); |
344 } | 348 } |
345 | 349 |
346 // Initialize with a no shortcut mode lookup table. | 350 // Initialize with a no shortcut mode candidate window. |
347 candidate_window_view.MaybeInitializeCandidateViews(no_shortcut_table); | 351 candidate_window_view.MaybeInitializeCandidateViews( |
| 352 no_shortcut_candidate_window); |
348 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size()); | 353 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size()); |
349 // Check the selected index is invalidated. | 354 // Check the selected index is invalidated. |
350 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); | 355 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); |
351 EXPECT_EQ(before_height, | 356 EXPECT_EQ(before_height, |
352 candidate_window_view.candidate_views_[0]->GetContentsBounds() | 357 candidate_window_view.candidate_views_[0]->GetContentsBounds() |
353 .height()); | 358 .height()); |
354 // Checks all entry have same row height. | 359 // Checks all entry have same row height. |
355 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { | 360 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { |
356 const CandidateView* view = candidate_window_view.candidate_views_[i]; | 361 const CandidateView* view = candidate_window_view.candidate_views_[i]; |
357 EXPECT_EQ(before_height, view->GetContentsBounds().height()); | 362 EXPECT_EQ(before_height, view->GetContentsBounds().height()); |
358 } | 363 } |
359 | 364 |
360 // Test for no-shortcut mode to shortcut mode. | 365 // Test for no-shortcut mode to shortcut mode. |
361 // Initialize with a no shortcut mode lookup table. | 366 // Initialize with a no shortcut mode candidate window. |
362 candidate_window_view.MaybeInitializeCandidateViews(no_shortcut_table); | 367 candidate_window_view.MaybeInitializeCandidateViews( |
| 368 no_shortcut_candidate_window); |
363 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size()); | 369 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size()); |
364 // Check the selected index is invalidated. | 370 // Check the selected index is invalidated. |
365 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); | 371 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); |
366 before_height = | 372 before_height = |
367 candidate_window_view.candidate_views_[0]->GetContentsBounds().height(); | 373 candidate_window_view.candidate_views_[0]->GetContentsBounds().height(); |
368 // Checks all entry have same row height. | 374 // Checks all entry have same row height. |
369 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { | 375 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { |
370 const CandidateView* view = candidate_window_view.candidate_views_[i]; | 376 const CandidateView* view = candidate_window_view.candidate_views_[i]; |
371 EXPECT_EQ(before_height, view->GetContentsBounds().height()); | 377 EXPECT_EQ(before_height, view->GetContentsBounds().height()); |
372 } | 378 } |
373 | 379 |
374 // Initialize with a shortcut mode lookup table. | 380 // Initialize with a shortcut mode candidate window. |
375 candidate_window_view.MaybeInitializeCandidateViews(table); | 381 candidate_window_view.MaybeInitializeCandidateViews(candidate_window); |
376 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size()); | 382 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size()); |
377 // Check the selected index is invalidated. | 383 // Check the selected index is invalidated. |
378 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); | 384 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); |
379 EXPECT_EQ(before_height, | 385 EXPECT_EQ(before_height, |
380 candidate_window_view.candidate_views_[0]->GetContentsBounds() | 386 candidate_window_view.candidate_views_[0]->GetContentsBounds() |
381 .height()); | 387 .height()); |
382 // Checks all entry have same row height. | 388 // Checks all entry have same row height. |
383 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { | 389 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { |
384 const CandidateView* view = candidate_window_view.candidate_views_[i]; | 390 const CandidateView* view = candidate_window_view.candidate_views_[i]; |
385 EXPECT_EQ(before_height, view->GetContentsBounds().height()); | 391 EXPECT_EQ(before_height, view->GetContentsBounds().height()); |
386 } | 392 } |
387 | 393 |
388 // We should call CloseNow method, otherwise this test will leak memory. | 394 // We should call CloseNow method, otherwise this test will leak memory. |
389 widget->CloseNow(); | 395 widget->CloseNow(); |
390 } | 396 } |
391 } // namespace input_method | 397 } // namespace input_method |
392 } // namespace chromeos | 398 } // namespace chromeos |
OLD | NEW |