OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // TODO(nona): Add more tests. | 4 // TODO(nona): Add more tests. |
5 | 5 |
6 #include "ui/base/ime/candidate_window.h" | 6 #include "ui/base/ime/candidate_window.h" |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/utf_string_conversions.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 namespace ui { | 16 namespace ui { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 const size_t kSampleCandidateSize = 3; | 20 const size_t kSampleCandidateSize = 3; |
20 const char* kSampleCandidate[] = { | 21 const char* kSampleCandidate[] = { |
21 "Sample Candidate 1", | 22 "Sample Candidate 1", |
22 "Sample Candidate 2", | 23 "Sample Candidate 2", |
23 "Sample Candidate 3", | 24 "Sample Candidate 3", |
24 }; | 25 }; |
25 const char* kSampleDescriptionTitle[] = { | 26 const char* kSampleDescriptionTitle[] = { |
26 "Sample Description Title 1", | 27 "Sample Description Title 1", |
27 "Sample Description Title 2", | 28 "Sample Description Title 2", |
28 "Sample Description Title 3", | 29 "Sample Description Title 3", |
29 }; | 30 }; |
30 const char* kSampleDescriptionBody[] = { | 31 const char* kSampleDescriptionBody[] = { |
31 "Sample Description Body 1", | 32 "Sample Description Body 1", |
32 "Sample Description Body 2", | 33 "Sample Description Body 2", |
33 "Sample Description Body 3", | 34 "Sample Description Body 3", |
34 }; | 35 }; |
35 | 36 |
36 } | 37 } |
37 | 38 |
38 TEST(CandidateWindow, IsEqualTest) { | 39 TEST(CandidateWindow, IsEqualTest) { |
39 CandidateWindow cw1; | 40 CandidateWindow cw1; |
40 CandidateWindow cw2; | 41 CandidateWindow cw2; |
41 | 42 |
42 const char kSampleString1[] = "Sample 1"; | 43 const base::string16 kSampleString1 = base::UTF8ToUTF16("Sample 1"); |
43 const char kSampleString2[] = "Sample 2"; | 44 const base::string16 kSampleString2 = base::UTF8ToUTF16("Sample 2"); |
44 | 45 |
45 EXPECT_TRUE(cw1.IsEqual(cw2)); | 46 EXPECT_TRUE(cw1.IsEqual(cw2)); |
46 EXPECT_TRUE(cw2.IsEqual(cw1)); | 47 EXPECT_TRUE(cw2.IsEqual(cw1)); |
47 | 48 |
48 cw1.set_page_size(1); | 49 cw1.set_page_size(1); |
49 cw2.set_page_size(2); | 50 cw2.set_page_size(2); |
50 EXPECT_FALSE(cw1.IsEqual(cw2)); | 51 EXPECT_FALSE(cw1.IsEqual(cw2)); |
51 EXPECT_FALSE(cw2.IsEqual(cw1)); | 52 EXPECT_FALSE(cw2.IsEqual(cw1)); |
52 cw2.set_page_size(1); | 53 cw2.set_page_size(1); |
53 | 54 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 EXPECT_FALSE(cw1.IsEqual(cw2)); | 130 EXPECT_FALSE(cw1.IsEqual(cw2)); |
130 EXPECT_FALSE(cw2.IsEqual(cw1)); | 131 EXPECT_FALSE(cw2.IsEqual(cw1)); |
131 cw1.mutable_candidates()->clear(); | 132 cw1.mutable_candidates()->clear(); |
132 cw2.mutable_candidates()->clear(); | 133 cw2.mutable_candidates()->clear(); |
133 } | 134 } |
134 | 135 |
135 TEST(CandidateWindow, CopyFromTest) { | 136 TEST(CandidateWindow, CopyFromTest) { |
136 CandidateWindow cw1; | 137 CandidateWindow cw1; |
137 CandidateWindow cw2; | 138 CandidateWindow cw2; |
138 | 139 |
139 const char kSampleString[] = "Sample"; | 140 const base::string16 kSampleString = base::UTF8ToUTF16("Sample"); |
140 | 141 |
141 cw1.set_page_size(1); | 142 cw1.set_page_size(1); |
142 cw1.set_cursor_position(2); | 143 cw1.set_cursor_position(2); |
143 cw1.set_is_cursor_visible(false); | 144 cw1.set_is_cursor_visible(false); |
144 cw1.set_orientation(CandidateWindow::HORIZONTAL); | 145 cw1.set_orientation(CandidateWindow::HORIZONTAL); |
145 cw1.set_show_window_at_composition(false); | 146 cw1.set_show_window_at_composition(false); |
146 | 147 |
147 CandidateWindow::Entry entry; | 148 CandidateWindow::Entry entry; |
148 entry.value = kSampleString; | 149 entry.value = kSampleString; |
149 entry.label = kSampleString; | 150 entry.label = kSampleString; |
150 entry.annotation = kSampleString; | 151 entry.annotation = kSampleString; |
151 entry.description_title = kSampleString; | 152 entry.description_title = kSampleString; |
152 entry.description_body = kSampleString; | 153 entry.description_body = kSampleString; |
153 cw1.mutable_candidates()->push_back(entry); | 154 cw1.mutable_candidates()->push_back(entry); |
154 | 155 |
155 cw2.CopyFrom(cw1); | 156 cw2.CopyFrom(cw1); |
156 EXPECT_TRUE(cw1.IsEqual(cw2)); | 157 EXPECT_TRUE(cw1.IsEqual(cw2)); |
157 } | 158 } |
158 | 159 |
159 TEST(CandidateWindow, GetInfolistEntries_DenseCase) { | 160 TEST(CandidateWindow, GetInfolistEntries_DenseCase) { |
160 CandidateWindow candidate_window; | 161 CandidateWindow candidate_window; |
161 candidate_window.set_page_size(10); | 162 candidate_window.set_page_size(10); |
162 for (size_t i = 0; i < kSampleCandidateSize; ++i) { | 163 for (size_t i = 0; i < kSampleCandidateSize; ++i) { |
163 CandidateWindow::Entry entry; | 164 CandidateWindow::Entry entry; |
164 entry.value = kSampleCandidate[i]; | 165 entry.value = base::UTF8ToUTF16(kSampleCandidate[i]); |
165 entry.description_title = kSampleDescriptionTitle[i]; | 166 entry.description_title = base::UTF8ToUTF16(kSampleDescriptionTitle[i]); |
166 entry.description_body = kSampleDescriptionBody[i]; | 167 entry.description_body = base::UTF8ToUTF16(kSampleDescriptionBody[i]); |
167 candidate_window.mutable_candidates()->push_back(entry); | 168 candidate_window.mutable_candidates()->push_back(entry); |
168 } | 169 } |
169 candidate_window.set_cursor_position(1); | 170 candidate_window.set_cursor_position(1); |
170 | 171 |
171 std::vector<InfolistEntry> infolist_entries; | 172 std::vector<InfolistEntry> infolist_entries; |
172 bool has_highlighted = false; | 173 bool has_highlighted = false; |
173 | 174 |
174 candidate_window.GetInfolistEntries(&infolist_entries, &has_highlighted); | 175 candidate_window.GetInfolistEntries(&infolist_entries, &has_highlighted); |
175 | 176 |
176 EXPECT_EQ(kSampleCandidateSize, infolist_entries.size()); | 177 EXPECT_EQ(kSampleCandidateSize, infolist_entries.size()); |
177 EXPECT_TRUE(has_highlighted); | 178 EXPECT_TRUE(has_highlighted); |
178 EXPECT_TRUE(infolist_entries[1].highlighted); | 179 EXPECT_TRUE(infolist_entries[1].highlighted); |
179 } | 180 } |
180 | 181 |
181 TEST(CandidateWindow, GetInfolistEntries_SparseCase) { | 182 TEST(CandidateWindow, GetInfolistEntries_SparseCase) { |
182 CandidateWindow candidate_window; | 183 CandidateWindow candidate_window; |
183 candidate_window.set_page_size(10); | 184 candidate_window.set_page_size(10); |
184 for (size_t i = 0; i < kSampleCandidateSize; ++i) { | 185 for (size_t i = 0; i < kSampleCandidateSize; ++i) { |
185 CandidateWindow::Entry entry; | 186 CandidateWindow::Entry entry; |
186 entry.value = kSampleCandidate[i]; | 187 entry.value = base::UTF8ToUTF16(kSampleCandidate[i]); |
187 candidate_window.mutable_candidates()->push_back(entry); | 188 candidate_window.mutable_candidates()->push_back(entry); |
188 } | 189 } |
189 | 190 |
190 std::vector<CandidateWindow::Entry>* candidates = | 191 std::vector<CandidateWindow::Entry>* candidates = |
191 candidate_window.mutable_candidates(); | 192 candidate_window.mutable_candidates(); |
192 (*candidates)[2].description_title = kSampleDescriptionTitle[2]; | 193 (*candidates)[2].description_title = |
193 (*candidates)[2].description_body = kSampleDescriptionBody[2]; | 194 base::UTF8ToUTF16(kSampleDescriptionTitle[2]); |
| 195 (*candidates)[2].description_body = |
| 196 base::UTF8ToUTF16(kSampleDescriptionBody[2]); |
194 | 197 |
195 candidate_window.set_cursor_position(2); | 198 candidate_window.set_cursor_position(2); |
196 | 199 |
197 std::vector<InfolistEntry> infolist_entries; | 200 std::vector<InfolistEntry> infolist_entries; |
198 bool has_highlighted = false; | 201 bool has_highlighted = false; |
199 | 202 |
200 candidate_window.GetInfolistEntries(&infolist_entries, &has_highlighted); | 203 candidate_window.GetInfolistEntries(&infolist_entries, &has_highlighted); |
201 | 204 |
202 // Infolist entries skips empty descriptions, so expected entry size is 1. | 205 // Infolist entries skips empty descriptions, so expected entry size is 1. |
203 EXPECT_EQ(1UL, infolist_entries.size()); | 206 EXPECT_EQ(1UL, infolist_entries.size()); |
204 EXPECT_TRUE(has_highlighted); | 207 EXPECT_TRUE(has_highlighted); |
205 EXPECT_TRUE(infolist_entries[0].highlighted); | 208 EXPECT_TRUE(infolist_entries[0].highlighted); |
206 } | 209 } |
207 | 210 |
208 TEST(CandidateWindow, GetInfolistEntries_SparseNoSelectionCase) { | 211 TEST(CandidateWindow, GetInfolistEntries_SparseNoSelectionCase) { |
209 CandidateWindow candidate_window; | 212 CandidateWindow candidate_window; |
210 candidate_window.set_page_size(10); | 213 candidate_window.set_page_size(10); |
211 | 214 |
212 for (size_t i = 0; i < kSampleCandidateSize; ++i) { | 215 for (size_t i = 0; i < kSampleCandidateSize; ++i) { |
213 CandidateWindow::Entry entry; | 216 CandidateWindow::Entry entry; |
214 entry.value = kSampleCandidate[i]; | 217 entry.value = base::UTF8ToUTF16(kSampleCandidate[i]); |
215 candidate_window.mutable_candidates()->push_back(entry); | 218 candidate_window.mutable_candidates()->push_back(entry); |
216 } | 219 } |
217 | 220 |
218 std::vector<CandidateWindow::Entry>* candidates = | 221 std::vector<CandidateWindow::Entry>* candidates = |
219 candidate_window.mutable_candidates(); | 222 candidate_window.mutable_candidates(); |
220 (*candidates)[2].description_title = kSampleDescriptionTitle[2]; | 223 (*candidates)[2].description_title = |
221 (*candidates)[2].description_body = kSampleDescriptionBody[2]; | 224 base::UTF8ToUTF16(kSampleDescriptionTitle[2]); |
| 225 (*candidates)[2].description_body = |
| 226 base::UTF8ToUTF16(kSampleDescriptionBody[2]); |
222 | 227 |
223 candidate_window.set_cursor_position(0); | 228 candidate_window.set_cursor_position(0); |
224 | 229 |
225 std::vector<InfolistEntry> infolist_entries; | 230 std::vector<InfolistEntry> infolist_entries; |
226 bool has_highlighted; | 231 bool has_highlighted; |
227 | 232 |
228 candidate_window.GetInfolistEntries(&infolist_entries, &has_highlighted); | 233 candidate_window.GetInfolistEntries(&infolist_entries, &has_highlighted); |
229 | 234 |
230 // Infolist entries skips empty descriptions, so expected entry size is 1 and | 235 // Infolist entries skips empty descriptions, so expected entry size is 1 and |
231 // no highlighted entries. | 236 // no highlighted entries. |
232 EXPECT_EQ(1UL, infolist_entries.size()); | 237 EXPECT_EQ(1UL, infolist_entries.size()); |
233 EXPECT_FALSE(has_highlighted); | 238 EXPECT_FALSE(has_highlighted); |
234 EXPECT_FALSE(infolist_entries[0].highlighted); | 239 EXPECT_FALSE(infolist_entries[0].highlighted); |
235 } | 240 } |
236 | 241 |
237 TEST(CandidateWindow, GetInfolistEntries_NoInfolistCase) { | 242 TEST(CandidateWindow, GetInfolistEntries_NoInfolistCase) { |
238 CandidateWindow candidate_window; | 243 CandidateWindow candidate_window; |
239 candidate_window.set_page_size(10); | 244 candidate_window.set_page_size(10); |
240 | 245 |
241 for (size_t i = 0; i < kSampleCandidateSize; ++i) { | 246 for (size_t i = 0; i < kSampleCandidateSize; ++i) { |
242 CandidateWindow::Entry entry; | 247 CandidateWindow::Entry entry; |
243 entry.value = kSampleCandidate[i]; | 248 entry.value = base::UTF8ToUTF16(kSampleCandidate[i]); |
244 candidate_window.mutable_candidates()->push_back(entry); | 249 candidate_window.mutable_candidates()->push_back(entry); |
245 } | 250 } |
246 candidate_window.set_cursor_position(1); | 251 candidate_window.set_cursor_position(1); |
247 | 252 |
248 std::vector<InfolistEntry> infolist_entries; | 253 std::vector<InfolistEntry> infolist_entries; |
249 bool has_highlighted = false; | 254 bool has_highlighted = false; |
250 | 255 |
251 candidate_window.GetInfolistEntries(&infolist_entries, &has_highlighted); | 256 candidate_window.GetInfolistEntries(&infolist_entries, &has_highlighted); |
252 | 257 |
253 EXPECT_TRUE(infolist_entries.empty()); | 258 EXPECT_TRUE(infolist_entries.empty()); |
254 EXPECT_FALSE(has_highlighted); | 259 EXPECT_FALSE(has_highlighted); |
255 } | 260 } |
256 | 261 |
257 } // namespace ui | 262 } // namespace ui |
OLD | NEW |