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/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" |
(...skipping 20 matching lines...) Expand all Loading... |
31 "Sample Description Title 2", | 31 "Sample Description Title 2", |
32 "Sample Description Title 3", | 32 "Sample Description Title 3", |
33 }; | 33 }; |
34 const char* kSampleDescriptionBody[] = { | 34 const char* kSampleDescriptionBody[] = { |
35 "Sample Description Body 1", | 35 "Sample Description Body 1", |
36 "Sample Description Body 2", | 36 "Sample Description Body 2", |
37 "Sample Description Body 3", | 37 "Sample Description Body 3", |
38 }; | 38 }; |
39 | 39 |
40 void InitIBusLookupTable(size_t page_size, | 40 void InitIBusLookupTable(size_t page_size, |
41 ibus::IBusLookupTable* table) { | 41 IBusLookupTable* table) { |
42 table->set_cursor_position(0); | 42 table->set_cursor_position(0); |
43 table->set_page_size(page_size); | 43 table->set_page_size(page_size); |
44 table->mutable_candidates()->clear(); | 44 table->mutable_candidates()->clear(); |
45 table->set_orientation(ibus::IBusLookupTable::VERTICAL); | 45 table->set_orientation(IBusLookupTable::VERTICAL); |
46 } | 46 } |
47 | 47 |
48 } // namespace | 48 } // namespace |
49 | 49 |
50 class CandidateWindowViewTest : public views::ViewsTestBase { | 50 class CandidateWindowViewTest : public views::ViewsTestBase { |
51 protected: | 51 protected: |
52 void ExpectLabels(const std::string shortcut, | 52 void ExpectLabels(const std::string shortcut, |
53 const std::string candidate, | 53 const std::string candidate, |
54 const std::string annotation, | 54 const std::string annotation, |
55 const CandidateView* row) { | 55 const CandidateView* row) { |
(...skipping 13 matching lines...) Expand all Loading... |
69 CreateParams(views::Widget::InitParams::TYPE_WINDOW); | 69 CreateParams(views::Widget::InitParams::TYPE_WINDOW); |
70 widget->Init(params); | 70 widget->Init(params); |
71 | 71 |
72 CandidateWindowView candidate_window_view(widget); | 72 CandidateWindowView candidate_window_view(widget); |
73 candidate_window_view.Init(); | 73 candidate_window_view.Init(); |
74 | 74 |
75 { | 75 { |
76 SCOPED_TRACE("candidate_views allocation test"); | 76 SCOPED_TRACE("candidate_views allocation test"); |
77 const size_t kMaxPageSize = 16; | 77 const size_t kMaxPageSize = 16; |
78 for (size_t i = 1; i < kMaxPageSize; ++i) { | 78 for (size_t i = 1; i < kMaxPageSize; ++i) { |
79 ibus::IBusLookupTable table; | 79 IBusLookupTable table; |
80 InitIBusLookupTable(i, &table); | 80 InitIBusLookupTable(i, &table); |
81 candidate_window_view.UpdateCandidates(table); | 81 candidate_window_view.UpdateCandidates(table); |
82 EXPECT_EQ(i, candidate_window_view.candidate_views_.size()); | 82 EXPECT_EQ(i, candidate_window_view.candidate_views_.size()); |
83 } | 83 } |
84 } | 84 } |
85 { | 85 { |
86 SCOPED_TRACE("Empty string for each labels expects empty labels(vertical)"); | 86 SCOPED_TRACE("Empty string for each labels expects empty labels(vertical)"); |
87 const size_t kPageSize = 3; | 87 const size_t kPageSize = 3; |
88 ibus::IBusLookupTable table; | 88 IBusLookupTable table; |
89 InitIBusLookupTable(kPageSize, &table); | 89 InitIBusLookupTable(kPageSize, &table); |
90 | 90 |
91 table.set_orientation(ibus::IBusLookupTable::VERTICAL); | 91 table.set_orientation(IBusLookupTable::VERTICAL); |
92 for (size_t i = 0; i < kPageSize; ++i) { | 92 for (size_t i = 0; i < kPageSize; ++i) { |
93 ibus::IBusLookupTable::Entry entry; | 93 IBusLookupTable::Entry entry; |
94 entry.value = kSampleCandidate[i]; | 94 entry.value = kSampleCandidate[i]; |
95 entry.annotation = kSampleAnnotation[i]; | 95 entry.annotation = kSampleAnnotation[i]; |
96 entry.description_title = kSampleDescriptionTitle[i]; | 96 entry.description_title = kSampleDescriptionTitle[i]; |
97 entry.description_body = kSampleDescriptionBody[i]; | 97 entry.description_body = kSampleDescriptionBody[i]; |
98 entry.label = kEmptyLabel; | 98 entry.label = kEmptyLabel; |
99 table.mutable_candidates()->push_back(entry); | 99 table.mutable_candidates()->push_back(entry); |
100 } | 100 } |
101 | 101 |
102 candidate_window_view.UpdateCandidates(table); | 102 candidate_window_view.UpdateCandidates(table); |
103 | 103 |
104 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); | 104 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); |
105 for (size_t i = 0; i < kPageSize; ++i) { | 105 for (size_t i = 0; i < kPageSize; ++i) { |
106 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], | 106 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], |
107 candidate_window_view.candidate_views_[i]); | 107 candidate_window_view.candidate_views_[i]); |
108 } | 108 } |
109 } | 109 } |
110 { | 110 { |
111 SCOPED_TRACE( | 111 SCOPED_TRACE( |
112 "Empty string for each labels expect empty labels(horizontal)"); | 112 "Empty string for each labels expect empty labels(horizontal)"); |
113 const size_t kPageSize = 3; | 113 const size_t kPageSize = 3; |
114 ibus::IBusLookupTable table; | 114 IBusLookupTable table; |
115 InitIBusLookupTable(kPageSize, &table); | 115 InitIBusLookupTable(kPageSize, &table); |
116 | 116 |
117 table.set_orientation(ibus::IBusLookupTable::HORIZONTAL); | 117 table.set_orientation(IBusLookupTable::HORIZONTAL); |
118 for (size_t i = 0; i < kPageSize; ++i) { | 118 for (size_t i = 0; i < kPageSize; ++i) { |
119 ibus::IBusLookupTable::Entry entry; | 119 IBusLookupTable::Entry entry; |
120 entry.value = kSampleCandidate[i]; | 120 entry.value = kSampleCandidate[i]; |
121 entry.annotation = kSampleAnnotation[i]; | 121 entry.annotation = kSampleAnnotation[i]; |
122 entry.description_title = kSampleDescriptionTitle[i]; | 122 entry.description_title = kSampleDescriptionTitle[i]; |
123 entry.description_body = kSampleDescriptionBody[i]; | 123 entry.description_body = kSampleDescriptionBody[i]; |
124 entry.label = kEmptyLabel; | 124 entry.label = kEmptyLabel; |
125 table.mutable_candidates()->push_back(entry); | 125 table.mutable_candidates()->push_back(entry); |
126 } | 126 } |
127 | 127 |
128 candidate_window_view.UpdateCandidates(table); | 128 candidate_window_view.UpdateCandidates(table); |
129 | 129 |
130 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); | 130 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); |
131 // Confirm actual labels not containing ".". | 131 // Confirm actual labels not containing ".". |
132 for (size_t i = 0; i < kPageSize; ++i) { | 132 for (size_t i = 0; i < kPageSize; ++i) { |
133 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], | 133 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], |
134 candidate_window_view.candidate_views_[i]); | 134 candidate_window_view.candidate_views_[i]); |
135 } | 135 } |
136 } | 136 } |
137 { | 137 { |
138 SCOPED_TRACE("Vertical customized label case"); | 138 SCOPED_TRACE("Vertical customized label case"); |
139 const size_t kPageSize = 3; | 139 const size_t kPageSize = 3; |
140 ibus::IBusLookupTable table; | 140 IBusLookupTable table; |
141 InitIBusLookupTable(kPageSize, &table); | 141 InitIBusLookupTable(kPageSize, &table); |
142 | 142 |
143 table.set_orientation(ibus::IBusLookupTable::VERTICAL); | 143 table.set_orientation(IBusLookupTable::VERTICAL); |
144 for (size_t i = 0; i < kPageSize; ++i) { | 144 for (size_t i = 0; i < kPageSize; ++i) { |
145 ibus::IBusLookupTable::Entry entry; | 145 IBusLookupTable::Entry entry; |
146 entry.value = kSampleCandidate[i]; | 146 entry.value = kSampleCandidate[i]; |
147 entry.annotation = kSampleAnnotation[i]; | 147 entry.annotation = kSampleAnnotation[i]; |
148 entry.description_title = kSampleDescriptionTitle[i]; | 148 entry.description_title = kSampleDescriptionTitle[i]; |
149 entry.description_body = kSampleDescriptionBody[i]; | 149 entry.description_body = kSampleDescriptionBody[i]; |
150 entry.label = kCustomizedLabel[i]; | 150 entry.label = kCustomizedLabel[i]; |
151 table.mutable_candidates()->push_back(entry); | 151 table.mutable_candidates()->push_back(entry); |
152 } | 152 } |
153 | 153 |
154 candidate_window_view.UpdateCandidates(table); | 154 candidate_window_view.UpdateCandidates(table); |
155 | 155 |
156 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); | 156 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); |
157 // Confirm actual labels not containing ".". | 157 // Confirm actual labels not containing ".". |
158 for (size_t i = 0; i < kPageSize; ++i) { | 158 for (size_t i = 0; i < kPageSize; ++i) { |
159 ExpectLabels(kCustomizedLabel[i], | 159 ExpectLabels(kCustomizedLabel[i], |
160 kSampleCandidate[i], | 160 kSampleCandidate[i], |
161 kSampleAnnotation[i], | 161 kSampleAnnotation[i], |
162 candidate_window_view.candidate_views_[i]); | 162 candidate_window_view.candidate_views_[i]); |
163 } | 163 } |
164 } | 164 } |
165 { | 165 { |
166 SCOPED_TRACE("Horizontal customized label case"); | 166 SCOPED_TRACE("Horizontal customized label case"); |
167 const size_t kPageSize = 3; | 167 const size_t kPageSize = 3; |
168 ibus::IBusLookupTable table; | 168 IBusLookupTable table; |
169 InitIBusLookupTable(kPageSize, &table); | 169 InitIBusLookupTable(kPageSize, &table); |
170 | 170 |
171 table.set_orientation(ibus::IBusLookupTable::HORIZONTAL); | 171 table.set_orientation(IBusLookupTable::HORIZONTAL); |
172 for (size_t i = 0; i < kPageSize; ++i) { | 172 for (size_t i = 0; i < kPageSize; ++i) { |
173 ibus::IBusLookupTable::Entry entry; | 173 IBusLookupTable::Entry entry; |
174 entry.value = kSampleCandidate[i]; | 174 entry.value = kSampleCandidate[i]; |
175 entry.annotation = kSampleAnnotation[i]; | 175 entry.annotation = kSampleAnnotation[i]; |
176 entry.description_title = kSampleDescriptionTitle[i]; | 176 entry.description_title = kSampleDescriptionTitle[i]; |
177 entry.description_body = kSampleDescriptionBody[i]; | 177 entry.description_body = kSampleDescriptionBody[i]; |
178 entry.label = kCustomizedLabel[i]; | 178 entry.label = kCustomizedLabel[i]; |
179 table.mutable_candidates()->push_back(entry); | 179 table.mutable_candidates()->push_back(entry); |
180 } | 180 } |
181 | 181 |
182 candidate_window_view.UpdateCandidates(table); | 182 candidate_window_view.UpdateCandidates(table); |
183 | 183 |
184 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); | 184 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); |
185 // Confirm actual labels not containing ".". | 185 // Confirm actual labels not containing ".". |
186 for (size_t i = 0; i < kPageSize; ++i) { | 186 for (size_t i = 0; i < kPageSize; ++i) { |
187 ExpectLabels(kExpectedHorizontalCustomizedLabel[i], | 187 ExpectLabels(kExpectedHorizontalCustomizedLabel[i], |
188 kSampleCandidate[i], | 188 kSampleCandidate[i], |
189 kSampleAnnotation[i], | 189 kSampleAnnotation[i], |
190 candidate_window_view.candidate_views_[i]); | 190 candidate_window_view.candidate_views_[i]); |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 // We should call CloseNow method, otherwise this test will leak memory. | 194 // We should call CloseNow method, otherwise this test will leak memory. |
195 widget->CloseNow(); | 195 widget->CloseNow(); |
196 } | 196 } |
197 | 197 |
198 TEST_F(CandidateWindowViewTest, DoNotChangeRowHeightWithLabelSwitchTest) { | 198 TEST_F(CandidateWindowViewTest, DoNotChangeRowHeightWithLabelSwitchTest) { |
199 const size_t kPageSize = 10; | 199 const size_t kPageSize = 10; |
200 ibus::IBusLookupTable table; | 200 IBusLookupTable table; |
201 ibus::IBusLookupTable no_shortcut_table; | 201 IBusLookupTable no_shortcut_table; |
202 | 202 |
203 const char kSampleCandidate1[] = "Sample String 1"; | 203 const char kSampleCandidate1[] = "Sample String 1"; |
204 const char kSampleCandidate2[] = "\xE3\x81\x82"; // multi byte string. | 204 const char kSampleCandidate2[] = "\xE3\x81\x82"; // multi byte string. |
205 const char kSampleCandidate3[] = "....."; | 205 const char kSampleCandidate3[] = "....."; |
206 | 206 |
207 const char kSampleShortcut1[] = "1"; | 207 const char kSampleShortcut1[] = "1"; |
208 const char kSampleShortcut2[] = "b"; | 208 const char kSampleShortcut2[] = "b"; |
209 const char kSampleShortcut3[] = "C"; | 209 const char kSampleShortcut3[] = "C"; |
210 | 210 |
211 const char kSampleAnnotation1[] = "Sample Annotation 1"; | 211 const char kSampleAnnotation1[] = "Sample Annotation 1"; |
(...skipping 10 matching lines...) Expand all Loading... |
222 | 222 |
223 CandidateWindowView candidate_window_view(widget); | 223 CandidateWindowView candidate_window_view(widget); |
224 candidate_window_view.Init(); | 224 candidate_window_view.Init(); |
225 | 225 |
226 // Create LookupTable object. | 226 // Create LookupTable object. |
227 InitIBusLookupTable(kPageSize, &table); | 227 InitIBusLookupTable(kPageSize, &table); |
228 | 228 |
229 table.set_cursor_position(0); | 229 table.set_cursor_position(0); |
230 table.set_page_size(3); | 230 table.set_page_size(3); |
231 table.mutable_candidates()->clear(); | 231 table.mutable_candidates()->clear(); |
232 table.set_orientation(ibus::IBusLookupTable::VERTICAL); | 232 table.set_orientation(IBusLookupTable::VERTICAL); |
233 no_shortcut_table.CopyFrom(table); | 233 no_shortcut_table.CopyFrom(table); |
234 | 234 |
235 ibus::IBusLookupTable::Entry entry; | 235 IBusLookupTable::Entry entry; |
236 entry.value = kSampleCandidate1; | 236 entry.value = kSampleCandidate1; |
237 entry.annotation = kSampleAnnotation1; | 237 entry.annotation = kSampleAnnotation1; |
238 table.mutable_candidates()->push_back(entry); | 238 table.mutable_candidates()->push_back(entry); |
239 entry.label = kSampleShortcut1; | 239 entry.label = kSampleShortcut1; |
240 no_shortcut_table.mutable_candidates()->push_back(entry); | 240 no_shortcut_table.mutable_candidates()->push_back(entry); |
241 | 241 |
242 entry.value = kSampleCandidate2; | 242 entry.value = kSampleCandidate2; |
243 entry.annotation = kSampleAnnotation2; | 243 entry.annotation = kSampleAnnotation2; |
244 table.mutable_candidates()->push_back(entry); | 244 table.mutable_candidates()->push_back(entry); |
245 entry.label = kSampleShortcut2; | 245 entry.label = kSampleShortcut2; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 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) { |
300 const CandidateView* view = candidate_window_view.candidate_views_[i]; | 300 const CandidateView* view = candidate_window_view.candidate_views_[i]; |
301 EXPECT_EQ(before_height, view->GetContentsBounds().height()); | 301 EXPECT_EQ(before_height, view->GetContentsBounds().height()); |
302 } | 302 } |
303 | 303 |
304 // We should call CloseNow method, otherwise this test will leak memory. | 304 // We should call CloseNow method, otherwise this test will leak memory. |
305 widget->CloseNow(); | 305 widget->CloseNow(); |
306 } | 306 } |
307 } // namespace input_method | 307 } // namespace input_method |
308 } // namespace chromeos | 308 } // namespace chromeos |
OLD | NEW |