Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: chrome/browser/chromeos/input_method/candidate_window_view_unittest.cc

Issue 11857008: Remove InputMethodLookupTable and use IBusLookupTable instead. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/chromeos/input_method/candidate_view.h" 10 #include "chrome/browser/chromeos/input_method/candidate_view.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/views/test/views_test_base.h" 12 #include "ui/views/test/views_test_base.h"
13 #include "ui/views/widget/widget.h" 13 #include "ui/views/widget/widget.h"
14 14
15 namespace chromeos { 15 namespace chromeos {
16 namespace input_method { 16 namespace input_method {
17 17
18 namespace { 18 namespace {
19 const char* kSampleCandidate[] = { 19 const char* kSampleCandidate[] = {
20 "Sample Candidate 1", 20 "Sample Candidate 1",
21 "Sample Candidate 2", 21 "Sample Candidate 2",
22 "Sample Candidate 3" 22 "Sample Candidate 3"
23 }; 23 };
24 const char* kSampleLabel[] = {
25 "Sample Label 1",
26 "Sample Label 2",
27 "Sample Label 3"
28 };
29 const char* kSampleAnnotation[] = { 24 const char* kSampleAnnotation[] = {
30 "Sample Annotation 1", 25 "Sample Annotation 1",
31 "Sample Annotation 2", 26 "Sample Annotation 2",
32 "Sample Annotation 3" 27 "Sample Annotation 3"
33 }; 28 };
34 const char* kSampleDescriptionTitle[] = { 29 const char* kSampleDescriptionTitle[] = {
35 "Sample Description Title 1", 30 "Sample Description Title 1",
36 "Sample Description Title 2", 31 "Sample Description Title 2",
37 "Sample Description Title 3", 32 "Sample Description Title 3",
38 }; 33 };
39 const char* kSampleDescriptionBody[] = { 34 const char* kSampleDescriptionBody[] = {
40 "Sample Description Body 1", 35 "Sample Description Body 1",
41 "Sample Description Body 2", 36 "Sample Description Body 2",
42 "Sample Description Body 3", 37 "Sample Description Body 3",
43 }; 38 };
44 39
45 void ClearInputMethodLookupTable(size_t page_size, 40 void InitIBusLookupTable(size_t page_size,
46 InputMethodLookupTable* table) { 41 ibus::IBusLookupTable* table) {
47 table->visible = false; 42 table->set_cursor_position(0);
48 table->cursor_absolute_index = 0; 43 table->set_page_size(page_size);
49 table->page_size = page_size; 44 table->mutable_candidates()->clear();
50 table->candidates.clear(); 45 table->set_orientation(ibus::IBusLookupTable::VERTICAL);
51 table->orientation = InputMethodLookupTable::kVertical;
52 table->labels.clear();
53 table->annotations.clear();
54 } 46 }
55 47
56 } // namespace 48 } // namespace
57 49
58 class CandidateWindowViewTest : public views::ViewsTestBase { 50 class CandidateWindowViewTest : public views::ViewsTestBase {
59 protected: 51 protected:
60 void ExpectLabels(const std::string shortcut, 52 void ExpectLabels(const std::string shortcut,
61 const std::string candidate, 53 const std::string candidate,
62 const std::string annotation, 54 const std::string annotation,
63 const CandidateView* row) { 55 const CandidateView* row) {
64 EXPECT_EQ(shortcut, UTF16ToUTF8(row->shortcut_label_->text())); 56 EXPECT_EQ(shortcut, UTF16ToUTF8(row->shortcut_label_->text()));
65 EXPECT_EQ(candidate, UTF16ToUTF8(row->candidate_label_->text())); 57 EXPECT_EQ(candidate, UTF16ToUTF8(row->candidate_label_->text()));
66 EXPECT_EQ(annotation, UTF16ToUTF8(row->annotation_label_->text())); 58 EXPECT_EQ(annotation, UTF16ToUTF8(row->annotation_label_->text()));
67 } 59 }
68 }; 60 };
69 61
70 TEST_F(CandidateWindowViewTest, ShouldUpdateCandidateViewsTest) {
71 // This test verifies the process of judging update lookup-table or not.
72 // This judgement is handled by ShouldUpdateCandidateViews, which returns true
73 // if update is necessary and vice versa.
74 InputMethodLookupTable old_table;
75 InputMethodLookupTable new_table;
76
77 const size_t kPageSize = 10;
78
79 ClearInputMethodLookupTable(kPageSize, &old_table);
80 ClearInputMethodLookupTable(kPageSize, &new_table);
81
82 old_table.visible = true;
83 old_table.cursor_absolute_index = 0;
84 old_table.page_size = 1;
85 old_table.candidates.clear();
86 old_table.orientation = InputMethodLookupTable::kVertical;
87 old_table.labels.clear();
88 old_table.annotations.clear();
89
90 new_table = old_table;
91
92 EXPECT_FALSE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
93 new_table));
94
95 new_table.visible = false;
96 // Visibility would be ignored.
97 EXPECT_FALSE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
98 new_table));
99 new_table = old_table;
100 new_table.candidates.push_back(kSampleCandidate[0]);
101 old_table.candidates.push_back(kSampleCandidate[0]);
102 EXPECT_FALSE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
103 new_table));
104 new_table.labels.push_back(kSampleLabel[0]);
105 old_table.labels.push_back(kSampleLabel[0]);
106 EXPECT_FALSE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
107 new_table));
108 new_table.annotations.push_back(kSampleAnnotation[0]);
109 old_table.annotations.push_back(kSampleAnnotation[0]);
110 EXPECT_FALSE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
111 new_table));
112
113 InputMethodLookupTable::Description description;
114 description.title = kSampleDescriptionTitle[0];
115 description.body = kSampleDescriptionBody[0];
116
117 new_table.descriptions.push_back(description);
118 old_table.descriptions.push_back(description);
119 EXPECT_FALSE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
120 new_table));
121
122 new_table.cursor_absolute_index = 1;
123 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
124 new_table));
125 new_table = old_table;
126
127 new_table.page_size = 2;
128 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
129 new_table));
130 new_table = old_table;
131
132 new_table.orientation = InputMethodLookupTable::kHorizontal;
133 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
134 new_table));
135
136 new_table = old_table;
137 new_table.candidates.push_back(kSampleCandidate[1]);
138 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
139 new_table));
140 old_table.candidates.push_back(kSampleCandidate[2]);
141 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
142 new_table));
143 new_table.candidates.clear();
144 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
145 new_table));
146 new_table.candidates.push_back(kSampleCandidate[1]);
147 old_table.candidates.clear();
148 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
149 new_table));
150
151 new_table = old_table;
152 new_table.labels.push_back(kSampleLabel[1]);
153 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
154 new_table));
155 old_table.labels.push_back(kSampleLabel[2]);
156 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
157 new_table));
158 new_table.labels.clear();
159 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
160 new_table));
161 new_table.labels.push_back(kSampleLabel[1]);
162 old_table.labels.clear();
163 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
164 new_table));
165
166 new_table = old_table;
167 new_table.annotations.push_back(kSampleAnnotation[1]);
168 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
169 new_table));
170 old_table.annotations.push_back(kSampleAnnotation[2]);
171 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
172 new_table));
173 new_table.annotations.clear();
174 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
175 new_table));
176 new_table.annotations.push_back(kSampleAnnotation[1]);
177 old_table.annotations.clear();
178 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
179 new_table));
180
181 new_table = old_table;
182 new_table.annotations.push_back(kSampleDescriptionTitle[1]);
183 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
184 new_table));
185 old_table.annotations.push_back(kSampleDescriptionTitle[2]);
186 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
187 new_table));
188 new_table.annotations.clear();
189 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
190 new_table));
191 new_table.annotations.push_back(kSampleDescriptionTitle[1]);
192 old_table.annotations.clear();
193 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
194 new_table));
195
196 new_table = old_table;
197 new_table.annotations.push_back(kSampleDescriptionBody[1]);
198 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
199 new_table));
200 old_table.annotations.push_back(kSampleDescriptionBody[2]);
201 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
202 new_table));
203 new_table.annotations.clear();
204 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
205 new_table));
206 new_table.annotations.push_back(kSampleDescriptionBody[1]);
207 old_table.annotations.clear();
208 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table,
209 new_table));
210 }
211
212 TEST_F(CandidateWindowViewTest, ShortcutSettingTest) { 62 TEST_F(CandidateWindowViewTest, ShortcutSettingTest) {
213 const char* kEmptyLabel = ""; 63 const char* kEmptyLabel = "";
214 const char* kCustomizedLabel[] = { "a", "s", "d" }; 64 const char* kCustomizedLabel[] = { "a", "s", "d" };
215 const char* kExpectedHorizontalCustomizedLabel[] = { "a.", "s.", "d." }; 65 const char* kExpectedHorizontalCustomizedLabel[] = { "a.", "s.", "d." };
216 66
217 views::Widget* widget = new views::Widget; 67 views::Widget* widget = new views::Widget;
218 views::Widget::InitParams params = 68 views::Widget::InitParams params =
219 CreateParams(views::Widget::InitParams::TYPE_WINDOW); 69 CreateParams(views::Widget::InitParams::TYPE_WINDOW);
220 widget->Init(params); 70 widget->Init(params);
221 71
222 CandidateWindowView candidate_window_view(widget); 72 CandidateWindowView candidate_window_view(widget);
223 candidate_window_view.Init(); 73 candidate_window_view.Init();
224 74
225 { 75 {
226 SCOPED_TRACE("candidate_views allocation test"); 76 SCOPED_TRACE("candidate_views allocation test");
227 const size_t kMaxPageSize = 16; 77 const size_t kMaxPageSize = 16;
228 for (size_t i = 1; i < kMaxPageSize; ++i) { 78 for (size_t i = 1; i < kMaxPageSize; ++i) {
229 InputMethodLookupTable table; 79 ibus::IBusLookupTable table;
230 ClearInputMethodLookupTable(i, &table); 80 InitIBusLookupTable(i, &table);
231 candidate_window_view.UpdateCandidates(table); 81 candidate_window_view.UpdateCandidates(table);
232 EXPECT_EQ(i, candidate_window_view.candidate_views_.size()); 82 EXPECT_EQ(i, candidate_window_view.candidate_views_.size());
233 } 83 }
234 } 84 }
235 { 85 {
236 SCOPED_TRACE("Empty string for each labels expects empty labels(vertical)"); 86 SCOPED_TRACE("Empty string for each labels expects empty labels(vertical)");
237 const size_t kPageSize = 3; 87 const size_t kPageSize = 3;
238 InputMethodLookupTable table; 88 ibus::IBusLookupTable table;
239 ClearInputMethodLookupTable(kPageSize, &table); 89 InitIBusLookupTable(kPageSize, &table);
240 90
241 table.orientation = InputMethodLookupTable::kVertical; 91 table.set_orientation(ibus::IBusLookupTable::VERTICAL);
242 for (size_t i = 0; i < kPageSize; ++i) { 92 for (size_t i = 0; i < kPageSize; ++i) {
243 table.candidates.push_back(kSampleCandidate[i]); 93 ibus::IBusLookupTable::Entry entry;
244 table.annotations.push_back(kSampleAnnotation[i]); 94 entry.value = kSampleCandidate[i];
245 InputMethodLookupTable::Description description; 95 entry.annotation = kSampleAnnotation[i];
246 description.title = kSampleDescriptionTitle[i]; 96 entry.description_title = kSampleDescriptionTitle[i];
247 description.body = kSampleDescriptionBody[i]; 97 entry.description_body = kSampleDescriptionBody[i];
248 table.descriptions.push_back(description); 98 entry.label = kEmptyLabel;
249 table.labels.push_back(kEmptyLabel); 99 table.mutable_candidates()->push_back(entry);
250 } 100 }
251 101
252 candidate_window_view.UpdateCandidates(table); 102 candidate_window_view.UpdateCandidates(table);
253 103
254 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); 104 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size());
255 for (size_t i = 0; i < kPageSize; ++i) { 105 for (size_t i = 0; i < kPageSize; ++i) {
256 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], 106 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i],
257 candidate_window_view.candidate_views_[i]); 107 candidate_window_view.candidate_views_[i]);
258 } 108 }
259 } 109 }
260 { 110 {
261 SCOPED_TRACE( 111 SCOPED_TRACE(
262 "Empty string for each labels expect empty labels(horizontal)"); 112 "Empty string for each labels expect empty labels(horizontal)");
263 const size_t kPageSize = 3; 113 const size_t kPageSize = 3;
264 InputMethodLookupTable table; 114 ibus::IBusLookupTable table;
265 ClearInputMethodLookupTable(kPageSize, &table); 115 InitIBusLookupTable(kPageSize, &table);
266 116
267 table.orientation = InputMethodLookupTable::kHorizontal; 117 table.set_orientation(ibus::IBusLookupTable::HORIZONTAL);
268 for (size_t i = 0; i < kPageSize; ++i) { 118 for (size_t i = 0; i < kPageSize; ++i) {
269 table.candidates.push_back(kSampleCandidate[i]); 119 ibus::IBusLookupTable::Entry entry;
270 table.annotations.push_back(kSampleAnnotation[i]); 120 entry.value = kSampleCandidate[i];
271 InputMethodLookupTable::Description description; 121 entry.annotation = kSampleAnnotation[i];
272 description.title = kSampleDescriptionTitle[i]; 122 entry.description_title = kSampleDescriptionTitle[i];
273 description.body = kSampleDescriptionBody[i]; 123 entry.description_body = kSampleDescriptionBody[i];
274 table.descriptions.push_back(description); 124 entry.label = kEmptyLabel;
275 table.labels.push_back(kEmptyLabel); 125 table.mutable_candidates()->push_back(entry);
276 } 126 }
277 127
278 candidate_window_view.UpdateCandidates(table); 128 candidate_window_view.UpdateCandidates(table);
279 129
280 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); 130 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size());
281 // Confirm actual labels not containing ".". 131 // Confirm actual labels not containing ".".
282 for (size_t i = 0; i < kPageSize; ++i) { 132 for (size_t i = 0; i < kPageSize; ++i) {
283 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], 133 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i],
284 candidate_window_view.candidate_views_[i]); 134 candidate_window_view.candidate_views_[i]);
285 } 135 }
286 } 136 }
287 { 137 {
288 SCOPED_TRACE("Vertical customized label case"); 138 SCOPED_TRACE("Vertical customized label case");
289 const size_t kPageSize = 3; 139 const size_t kPageSize = 3;
290 InputMethodLookupTable table; 140 ibus::IBusLookupTable table;
291 ClearInputMethodLookupTable(kPageSize, &table); 141 InitIBusLookupTable(kPageSize, &table);
292 142
293 table.orientation = InputMethodLookupTable::kVertical; 143 table.set_orientation(ibus::IBusLookupTable::VERTICAL);
294 for (size_t i = 0; i < kPageSize; ++i) { 144 for (size_t i = 0; i < kPageSize; ++i) {
295 table.candidates.push_back(kSampleCandidate[i]); 145 ibus::IBusLookupTable::Entry entry;
296 table.annotations.push_back(kSampleAnnotation[i]); 146 entry.value = kSampleCandidate[i];
297 InputMethodLookupTable::Description description; 147 entry.annotation = kSampleAnnotation[i];
298 description.title = kSampleDescriptionTitle[i]; 148 entry.description_title = kSampleDescriptionTitle[i];
299 description.body = kSampleDescriptionBody[i]; 149 entry.description_body = kSampleDescriptionBody[i];
300 table.descriptions.push_back(description); 150 entry.label = kCustomizedLabel[i];
301 table.labels.push_back(kCustomizedLabel[i]); 151 table.mutable_candidates()->push_back(entry);
302 } 152 }
303 153
304 candidate_window_view.UpdateCandidates(table); 154 candidate_window_view.UpdateCandidates(table);
305 155
306 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); 156 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size());
307 // Confirm actual labels not containing ".". 157 // Confirm actual labels not containing ".".
308 for (size_t i = 0; i < kPageSize; ++i) { 158 for (size_t i = 0; i < kPageSize; ++i) {
309 ExpectLabels(kCustomizedLabel[i], 159 ExpectLabels(kCustomizedLabel[i],
310 kSampleCandidate[i], 160 kSampleCandidate[i],
311 kSampleAnnotation[i], 161 kSampleAnnotation[i],
312 candidate_window_view.candidate_views_[i]); 162 candidate_window_view.candidate_views_[i]);
313 } 163 }
314 } 164 }
315 { 165 {
316 SCOPED_TRACE("Horizontal customized label case"); 166 SCOPED_TRACE("Horizontal customized label case");
317 const size_t kPageSize = 3; 167 const size_t kPageSize = 3;
318 InputMethodLookupTable table; 168 ibus::IBusLookupTable table;
319 ClearInputMethodLookupTable(kPageSize, &table); 169 InitIBusLookupTable(kPageSize, &table);
320 170
321 table.orientation = InputMethodLookupTable::kHorizontal; 171 table.set_orientation(ibus::IBusLookupTable::HORIZONTAL);
322 for (size_t i = 0; i < kPageSize; ++i) { 172 for (size_t i = 0; i < kPageSize; ++i) {
323 table.candidates.push_back(kSampleCandidate[i]); 173 ibus::IBusLookupTable::Entry entry;
324 table.annotations.push_back(kSampleAnnotation[i]); 174 entry.value = kSampleCandidate[i];
325 InputMethodLookupTable::Description description; 175 entry.annotation = kSampleAnnotation[i];
326 description.title = kSampleDescriptionTitle[i]; 176 entry.description_title = kSampleDescriptionTitle[i];
327 description.body = kSampleDescriptionBody[i]; 177 entry.description_body = kSampleDescriptionBody[i];
328 table.descriptions.push_back(description); 178 entry.label = kCustomizedLabel[i];
329 table.labels.push_back(kCustomizedLabel[i]); 179 table.mutable_candidates()->push_back(entry);
330 } 180 }
331 181
332 candidate_window_view.UpdateCandidates(table); 182 candidate_window_view.UpdateCandidates(table);
333 183
334 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); 184 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size());
335 // Confirm actual labels not containing ".". 185 // Confirm actual labels not containing ".".
336 for (size_t i = 0; i < kPageSize; ++i) { 186 for (size_t i = 0; i < kPageSize; ++i) {
337 ExpectLabels(kExpectedHorizontalCustomizedLabel[i], 187 ExpectLabels(kExpectedHorizontalCustomizedLabel[i],
338 kSampleCandidate[i], 188 kSampleCandidate[i],
339 kSampleAnnotation[i], 189 kSampleAnnotation[i],
340 candidate_window_view.candidate_views_[i]); 190 candidate_window_view.candidate_views_[i]);
341 } 191 }
342 } 192 }
343 193
344 // We should call CloseNow method, otherwise this test will leak memory. 194 // We should call CloseNow method, otherwise this test will leak memory.
345 widget->CloseNow(); 195 widget->CloseNow();
346 } 196 }
347 197
348 TEST_F(CandidateWindowViewTest, DoNotChangeRowHeightWithLabelSwitchTest) { 198 TEST_F(CandidateWindowViewTest, DoNotChangeRowHeightWithLabelSwitchTest) {
349 const size_t kPageSize = 10; 199 const size_t kPageSize = 10;
350 InputMethodLookupTable table; 200 ibus::IBusLookupTable table;
351 InputMethodLookupTable no_shortcut_table; 201 ibus::IBusLookupTable no_shortcut_table;
352 202
353 const char kSampleCandidate1[] = "Sample String 1"; 203 const char kSampleCandidate1[] = "Sample String 1";
354 const char kSampleCandidate2[] = "\xE3\x81\x82"; // multi byte string. 204 const char kSampleCandidate2[] = "\xE3\x81\x82"; // multi byte string.
355 const char kSampleCandidate3[] = "....."; 205 const char kSampleCandidate3[] = ".....";
356 206
357 const char kSampleShortcut1[] = "1"; 207 const char kSampleShortcut1[] = "1";
358 const char kSampleShortcut2[] = "b"; 208 const char kSampleShortcut2[] = "b";
359 const char kSampleShortcut3[] = "C"; 209 const char kSampleShortcut3[] = "C";
360 210
361 const char kSampleAnnotation1[] = "Sample Annotation 1"; 211 const char kSampleAnnotation1[] = "Sample Annotation 1";
362 const char kSampleAnnotation2[] = "\xE3\x81\x82"; // multi byte string. 212 const char kSampleAnnotation2[] = "\xE3\x81\x82"; // multi byte string.
363 const char kSampleAnnotation3[] = "......"; 213 const char kSampleAnnotation3[] = "......";
364 214
365 // For testing, we have to prepare empty widget. 215 // For testing, we have to prepare empty widget.
366 // We should NOT manually free widget by default, otherwise double free will 216 // We should NOT manually free widget by default, otherwise double free will
367 // be occurred. So, we should instantiate widget class with "new" operation. 217 // be occurred. So, we should instantiate widget class with "new" operation.
368 views::Widget* widget = new views::Widget; 218 views::Widget* widget = new views::Widget;
369 views::Widget::InitParams params = 219 views::Widget::InitParams params =
370 CreateParams(views::Widget::InitParams::TYPE_WINDOW); 220 CreateParams(views::Widget::InitParams::TYPE_WINDOW);
371 widget->Init(params); 221 widget->Init(params);
372 222
373 CandidateWindowView candidate_window_view(widget); 223 CandidateWindowView candidate_window_view(widget);
374 candidate_window_view.Init(); 224 candidate_window_view.Init();
375 225
376 // Create LookupTable object. 226 // Create LookupTable object.
377 ClearInputMethodLookupTable(kPageSize, &table); 227 InitIBusLookupTable(kPageSize, &table);
378 table.visible = true;
379 table.cursor_absolute_index = 0;
380 table.page_size = 3;
381 table.candidates.clear();
382 table.orientation = InputMethodLookupTable::kVertical;
383 table.labels.clear();
384 table.annotations.clear();
385 228
386 table.candidates.push_back(kSampleCandidate1); 229 table.set_cursor_position(0);
387 table.candidates.push_back(kSampleCandidate2); 230 table.set_page_size(3);
388 table.candidates.push_back(kSampleCandidate3); 231 table.mutable_candidates()->clear();
232 table.set_orientation(ibus::IBusLookupTable::VERTICAL);
233 no_shortcut_table.CopyFrom(table);
389 234
390 table.labels.push_back(kSampleShortcut1); 235 ibus::IBusLookupTable::Entry entry;
391 table.labels.push_back(kSampleShortcut2); 236 entry.value = kSampleCandidate1;
392 table.labels.push_back(kSampleShortcut3); 237 entry.annotation = kSampleAnnotation1;
238 table.mutable_candidates()->push_back(entry);
239 entry.label = kSampleShortcut1;
240 no_shortcut_table.mutable_candidates()->push_back(entry);
393 241
394 table.annotations.push_back(kSampleAnnotation1); 242 entry.value = kSampleCandidate2;
395 table.annotations.push_back(kSampleAnnotation2); 243 entry.annotation = kSampleAnnotation2;
396 table.annotations.push_back(kSampleAnnotation3); 244 table.mutable_candidates()->push_back(entry);
245 entry.label = kSampleShortcut2;
246 no_shortcut_table.mutable_candidates()->push_back(entry);
397 247
398 no_shortcut_table = table; 248 entry.value = kSampleCandidate3;
399 no_shortcut_table.labels.clear(); 249 entry.annotation = kSampleAnnotation3;
250 table.mutable_candidates()->push_back(entry);
251 entry.label = kSampleShortcut3;
252 no_shortcut_table.mutable_candidates()->push_back(entry);
400 253
401 int before_height = 0; 254 int before_height = 0;
402 255
403 // Test for shortcut mode to no-shortcut mode. 256 // Test for shortcut mode to no-shortcut mode.
404 // Initialize with a shortcut mode lookup table. 257 // Initialize with a shortcut mode lookup table.
405 candidate_window_view.MaybeInitializeCandidateViews(table); 258 candidate_window_view.MaybeInitializeCandidateViews(table);
406 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size()); 259 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size());
407 before_height = 260 before_height =
408 candidate_window_view.candidate_views_[0]->GetContentsBounds().height(); 261 candidate_window_view.candidate_views_[0]->GetContentsBounds().height();
409 // Checks all entry have same row height. 262 // Checks all entry have same row height.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { 299 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) {
447 const CandidateView* view = candidate_window_view.candidate_views_[i]; 300 const CandidateView* view = candidate_window_view.candidate_views_[i];
448 EXPECT_EQ(before_height, view->GetContentsBounds().height()); 301 EXPECT_EQ(before_height, view->GetContentsBounds().height());
449 } 302 }
450 303
451 // We should call CloseNow method, otherwise this test will leak memory. 304 // We should call CloseNow method, otherwise this test will leak memory.
452 widget->CloseNow(); 305 widget->CloseNow();
453 } 306 }
454 } // namespace input_method 307 } // namespace input_method
455 } // namespace chromeos 308 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698