| 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 | 4 |
| 5 #include "ash/ime/candidate_window_view.h" | 5 #include "ash/ime/candidate_window_view.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "ash/ime/candidate_view.h" | 9 #include "ash/ime/candidate_view.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 candidate_window->mutable_candidates()->clear(); | 45 candidate_window->mutable_candidates()->clear(); |
| 46 candidate_window->set_orientation(ui::CandidateWindow::VERTICAL); | 46 candidate_window->set_orientation(ui::CandidateWindow::VERTICAL); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void InitCandidateWindowWithCandidatesFilled( | 49 void InitCandidateWindowWithCandidatesFilled( |
| 50 size_t page_size, | 50 size_t page_size, |
| 51 ui::CandidateWindow* candidate_window) { | 51 ui::CandidateWindow* candidate_window) { |
| 52 InitCandidateWindow(page_size, candidate_window); | 52 InitCandidateWindow(page_size, candidate_window); |
| 53 for (size_t i = 0; i < page_size; ++i) { | 53 for (size_t i = 0; i < page_size; ++i) { |
| 54 ui::CandidateWindow::Entry entry; | 54 ui::CandidateWindow::Entry entry; |
| 55 entry.value = base::StringPrintf("value %lld", | 55 entry.value = base::UTF8ToUTF16(base::StringPrintf( |
| 56 static_cast<unsigned long long>(i)); | 56 "value %lld", static_cast<unsigned long long>(i))); |
| 57 entry.label = base::StringPrintf("%lld", | 57 entry.label = base::UTF8ToUTF16(base::StringPrintf( |
| 58 static_cast<unsigned long long>(i)); | 58 "%lld", static_cast<unsigned long long>(i))); |
| 59 candidate_window->mutable_candidates()->push_back(entry); | 59 candidate_window->mutable_candidates()->push_back(entry); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 } // namespace | 63 } // namespace |
| 64 | 64 |
| 65 class CandidateWindowViewTest : public views::ViewsTestBase { | 65 class CandidateWindowViewTest : public views::ViewsTestBase { |
| 66 public: | 66 public: |
| 67 CandidateWindowViewTest() {} | 67 CandidateWindowViewTest() {} |
| 68 virtual ~CandidateWindowViewTest() {} | 68 virtual ~CandidateWindowViewTest() {} |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 181 } |
| 182 { | 182 { |
| 183 SCOPED_TRACE("Empty string for each labels expects empty labels(vertical)"); | 183 SCOPED_TRACE("Empty string for each labels expects empty labels(vertical)"); |
| 184 const size_t kPageSize = 3; | 184 const size_t kPageSize = 3; |
| 185 ui::CandidateWindow candidate_window; | 185 ui::CandidateWindow candidate_window; |
| 186 InitCandidateWindow(kPageSize, &candidate_window); | 186 InitCandidateWindow(kPageSize, &candidate_window); |
| 187 | 187 |
| 188 candidate_window.set_orientation(ui::CandidateWindow::VERTICAL); | 188 candidate_window.set_orientation(ui::CandidateWindow::VERTICAL); |
| 189 for (size_t i = 0; i < kPageSize; ++i) { | 189 for (size_t i = 0; i < kPageSize; ++i) { |
| 190 ui::CandidateWindow::Entry entry; | 190 ui::CandidateWindow::Entry entry; |
| 191 entry.value = kSampleCandidate[i]; | 191 entry.value = base::UTF8ToUTF16(kSampleCandidate[i]); |
| 192 entry.annotation = kSampleAnnotation[i]; | 192 entry.annotation = base::UTF8ToUTF16(kSampleAnnotation[i]); |
| 193 entry.description_title = kSampleDescriptionTitle[i]; | 193 entry.description_title = base::UTF8ToUTF16(kSampleDescriptionTitle[i]); |
| 194 entry.description_body = kSampleDescriptionBody[i]; | 194 entry.description_body = base::UTF8ToUTF16(kSampleDescriptionBody[i]); |
| 195 entry.label = kEmptyLabel; | 195 entry.label = base::UTF8ToUTF16(kEmptyLabel); |
| 196 candidate_window.mutable_candidates()->push_back(entry); | 196 candidate_window.mutable_candidates()->push_back(entry); |
| 197 } | 197 } |
| 198 | 198 |
| 199 candidate_window_view()->UpdateCandidates(candidate_window); | 199 candidate_window_view()->UpdateCandidates(candidate_window); |
| 200 | 200 |
| 201 ASSERT_EQ(kPageSize, GetCandidatesSize()); | 201 ASSERT_EQ(kPageSize, GetCandidatesSize()); |
| 202 for (size_t i = 0; i < kPageSize; ++i) { | 202 for (size_t i = 0; i < kPageSize; ++i) { |
| 203 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], | 203 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], |
| 204 GetCandidateAt(i)); | 204 GetCandidateAt(i)); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 { | 207 { |
| 208 SCOPED_TRACE( | 208 SCOPED_TRACE( |
| 209 "Empty string for each labels expect empty labels(horizontal)"); | 209 "Empty string for each labels expect empty labels(horizontal)"); |
| 210 const size_t kPageSize = 3; | 210 const size_t kPageSize = 3; |
| 211 ui::CandidateWindow candidate_window; | 211 ui::CandidateWindow candidate_window; |
| 212 InitCandidateWindow(kPageSize, &candidate_window); | 212 InitCandidateWindow(kPageSize, &candidate_window); |
| 213 | 213 |
| 214 candidate_window.set_orientation(ui::CandidateWindow::HORIZONTAL); | 214 candidate_window.set_orientation(ui::CandidateWindow::HORIZONTAL); |
| 215 for (size_t i = 0; i < kPageSize; ++i) { | 215 for (size_t i = 0; i < kPageSize; ++i) { |
| 216 ui::CandidateWindow::Entry entry; | 216 ui::CandidateWindow::Entry entry; |
| 217 entry.value = kSampleCandidate[i]; | 217 entry.value = base::UTF8ToUTF16(kSampleCandidate[i]); |
| 218 entry.annotation = kSampleAnnotation[i]; | 218 entry.annotation = base::UTF8ToUTF16(kSampleAnnotation[i]); |
| 219 entry.description_title = kSampleDescriptionTitle[i]; | 219 entry.description_title = base::UTF8ToUTF16(kSampleDescriptionTitle[i]); |
| 220 entry.description_body = kSampleDescriptionBody[i]; | 220 entry.description_body = base::UTF8ToUTF16(kSampleDescriptionBody[i]); |
| 221 entry.label = kEmptyLabel; | 221 entry.label = base::UTF8ToUTF16(kEmptyLabel); |
| 222 candidate_window.mutable_candidates()->push_back(entry); | 222 candidate_window.mutable_candidates()->push_back(entry); |
| 223 } | 223 } |
| 224 | 224 |
| 225 candidate_window_view()->UpdateCandidates(candidate_window); | 225 candidate_window_view()->UpdateCandidates(candidate_window); |
| 226 | 226 |
| 227 ASSERT_EQ(kPageSize, GetCandidatesSize()); | 227 ASSERT_EQ(kPageSize, GetCandidatesSize()); |
| 228 // Confirm actual labels not containing ".". | 228 // Confirm actual labels not containing ".". |
| 229 for (size_t i = 0; i < kPageSize; ++i) { | 229 for (size_t i = 0; i < kPageSize; ++i) { |
| 230 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], | 230 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], |
| 231 GetCandidateAt(i)); | 231 GetCandidateAt(i)); |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 { | 234 { |
| 235 SCOPED_TRACE("Vertical customized label case"); | 235 SCOPED_TRACE("Vertical customized label case"); |
| 236 const size_t kPageSize = 3; | 236 const size_t kPageSize = 3; |
| 237 ui::CandidateWindow candidate_window; | 237 ui::CandidateWindow candidate_window; |
| 238 InitCandidateWindow(kPageSize, &candidate_window); | 238 InitCandidateWindow(kPageSize, &candidate_window); |
| 239 | 239 |
| 240 candidate_window.set_orientation(ui::CandidateWindow::VERTICAL); | 240 candidate_window.set_orientation(ui::CandidateWindow::VERTICAL); |
| 241 for (size_t i = 0; i < kPageSize; ++i) { | 241 for (size_t i = 0; i < kPageSize; ++i) { |
| 242 ui::CandidateWindow::Entry entry; | 242 ui::CandidateWindow::Entry entry; |
| 243 entry.value = kSampleCandidate[i]; | 243 entry.value = base::UTF8ToUTF16(kSampleCandidate[i]); |
| 244 entry.annotation = kSampleAnnotation[i]; | 244 entry.annotation = base::UTF8ToUTF16(kSampleAnnotation[i]); |
| 245 entry.description_title = kSampleDescriptionTitle[i]; | 245 entry.description_title = base::UTF8ToUTF16(kSampleDescriptionTitle[i]); |
| 246 entry.description_body = kSampleDescriptionBody[i]; | 246 entry.description_body = base::UTF8ToUTF16(kSampleDescriptionBody[i]); |
| 247 entry.label = kCustomizedLabel[i]; | 247 entry.label = base::UTF8ToUTF16(kCustomizedLabel[i]); |
| 248 candidate_window.mutable_candidates()->push_back(entry); | 248 candidate_window.mutable_candidates()->push_back(entry); |
| 249 } | 249 } |
| 250 | 250 |
| 251 candidate_window_view()->UpdateCandidates(candidate_window); | 251 candidate_window_view()->UpdateCandidates(candidate_window); |
| 252 | 252 |
| 253 ASSERT_EQ(kPageSize, GetCandidatesSize()); | 253 ASSERT_EQ(kPageSize, GetCandidatesSize()); |
| 254 // Confirm actual labels not containing ".". | 254 // Confirm actual labels not containing ".". |
| 255 for (size_t i = 0; i < kPageSize; ++i) { | 255 for (size_t i = 0; i < kPageSize; ++i) { |
| 256 ExpectLabels(kCustomizedLabel[i], | 256 ExpectLabels(kCustomizedLabel[i], |
| 257 kSampleCandidate[i], | 257 kSampleCandidate[i], |
| 258 kSampleAnnotation[i], | 258 kSampleAnnotation[i], |
| 259 GetCandidateAt(i)); | 259 GetCandidateAt(i)); |
| 260 } | 260 } |
| 261 } | 261 } |
| 262 { | 262 { |
| 263 SCOPED_TRACE("Horizontal customized label case"); | 263 SCOPED_TRACE("Horizontal customized label case"); |
| 264 const size_t kPageSize = 3; | 264 const size_t kPageSize = 3; |
| 265 ui::CandidateWindow candidate_window; | 265 ui::CandidateWindow candidate_window; |
| 266 InitCandidateWindow(kPageSize, &candidate_window); | 266 InitCandidateWindow(kPageSize, &candidate_window); |
| 267 | 267 |
| 268 candidate_window.set_orientation(ui::CandidateWindow::HORIZONTAL); | 268 candidate_window.set_orientation(ui::CandidateWindow::HORIZONTAL); |
| 269 for (size_t i = 0; i < kPageSize; ++i) { | 269 for (size_t i = 0; i < kPageSize; ++i) { |
| 270 ui::CandidateWindow::Entry entry; | 270 ui::CandidateWindow::Entry entry; |
| 271 entry.value = kSampleCandidate[i]; | 271 entry.value = base::UTF8ToUTF16(kSampleCandidate[i]); |
| 272 entry.annotation = kSampleAnnotation[i]; | 272 entry.annotation = base::UTF8ToUTF16(kSampleAnnotation[i]); |
| 273 entry.description_title = kSampleDescriptionTitle[i]; | 273 entry.description_title = base::UTF8ToUTF16(kSampleDescriptionTitle[i]); |
| 274 entry.description_body = kSampleDescriptionBody[i]; | 274 entry.description_body = base::UTF8ToUTF16(kSampleDescriptionBody[i]); |
| 275 entry.label = kCustomizedLabel[i]; | 275 entry.label = base::UTF8ToUTF16(kCustomizedLabel[i]); |
| 276 candidate_window.mutable_candidates()->push_back(entry); | 276 candidate_window.mutable_candidates()->push_back(entry); |
| 277 } | 277 } |
| 278 | 278 |
| 279 candidate_window_view()->UpdateCandidates(candidate_window); | 279 candidate_window_view()->UpdateCandidates(candidate_window); |
| 280 | 280 |
| 281 ASSERT_EQ(kPageSize, GetCandidatesSize()); | 281 ASSERT_EQ(kPageSize, GetCandidatesSize()); |
| 282 // Confirm actual labels not containing ".". | 282 // Confirm actual labels not containing ".". |
| 283 for (size_t i = 0; i < kPageSize; ++i) { | 283 for (size_t i = 0; i < kPageSize; ++i) { |
| 284 ExpectLabels(kExpectedHorizontalCustomizedLabel[i], | 284 ExpectLabels(kExpectedHorizontalCustomizedLabel[i], |
| 285 kSampleCandidate[i], | 285 kSampleCandidate[i], |
| 286 kSampleAnnotation[i], | 286 kSampleAnnotation[i], |
| 287 GetCandidateAt(i)); | 287 GetCandidateAt(i)); |
| 288 } | 288 } |
| 289 } | 289 } |
| 290 } | 290 } |
| 291 | 291 |
| 292 TEST_F(CandidateWindowViewTest, DoNotChangeRowHeightWithLabelSwitchTest) { | 292 TEST_F(CandidateWindowViewTest, DoNotChangeRowHeightWithLabelSwitchTest) { |
| 293 const size_t kPageSize = 10; | 293 const size_t kPageSize = 10; |
| 294 ui::CandidateWindow candidate_window; | 294 ui::CandidateWindow candidate_window; |
| 295 ui::CandidateWindow no_shortcut_candidate_window; | 295 ui::CandidateWindow no_shortcut_candidate_window; |
| 296 | 296 |
| 297 const char kSampleCandidate1[] = "Sample String 1"; | 297 const base::string16 kSampleCandidate1 = base::UTF8ToUTF16( |
| 298 const char kSampleCandidate2[] = "\xE3\x81\x82"; // multi byte string. | 298 "Sample String 1"); |
| 299 const char kSampleCandidate3[] = "....."; | 299 const base::string16 kSampleCandidate2 = base::UTF8ToUTF16( |
| 300 "\xE3\x81\x82"); // multi byte string. |
| 301 const base::string16 kSampleCandidate3 = base::UTF8ToUTF16("....."); |
| 300 | 302 |
| 301 const char kSampleShortcut1[] = "1"; | 303 const base::string16 kSampleShortcut1 = base::UTF8ToUTF16("1"); |
| 302 const char kSampleShortcut2[] = "b"; | 304 const base::string16 kSampleShortcut2 = base::UTF8ToUTF16("b"); |
| 303 const char kSampleShortcut3[] = "C"; | 305 const base::string16 kSampleShortcut3 = base::UTF8ToUTF16("C"); |
| 304 | 306 |
| 305 const char kSampleAnnotation1[] = "Sample Annotation 1"; | 307 const base::string16 kSampleAnnotation1 = base::UTF8ToUTF16( |
| 306 const char kSampleAnnotation2[] = "\xE3\x81\x82"; // multi byte string. | 308 "Sample Annotation 1"); |
| 307 const char kSampleAnnotation3[] = "......"; | 309 const base::string16 kSampleAnnotation2 = base::UTF8ToUTF16( |
| 310 "\xE3\x81\x82"); // multi byte string. |
| 311 const base::string16 kSampleAnnotation3 = base::UTF8ToUTF16("......"); |
| 308 | 312 |
| 309 // Create CandidateWindow object. | 313 // Create CandidateWindow object. |
| 310 InitCandidateWindow(kPageSize, &candidate_window); | 314 InitCandidateWindow(kPageSize, &candidate_window); |
| 311 | 315 |
| 312 candidate_window.set_cursor_position(0); | 316 candidate_window.set_cursor_position(0); |
| 313 candidate_window.set_page_size(3); | 317 candidate_window.set_page_size(3); |
| 314 candidate_window.mutable_candidates()->clear(); | 318 candidate_window.mutable_candidates()->clear(); |
| 315 candidate_window.set_orientation(ui::CandidateWindow::VERTICAL); | 319 candidate_window.set_orientation(ui::CandidateWindow::VERTICAL); |
| 316 no_shortcut_candidate_window.CopyFrom(candidate_window); | 320 no_shortcut_candidate_window.CopyFrom(candidate_window); |
| 317 | 321 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 // Check the selected index is invalidated. | 379 // Check the selected index is invalidated. |
| 376 EXPECT_EQ(-1, selected_candidate_index_in_page()); | 380 EXPECT_EQ(-1, selected_candidate_index_in_page()); |
| 377 EXPECT_EQ(before_height, GetCandidateAt(0)->GetContentsBounds().height()); | 381 EXPECT_EQ(before_height, GetCandidateAt(0)->GetContentsBounds().height()); |
| 378 // Checks all entry have same row height. | 382 // Checks all entry have same row height. |
| 379 for (size_t i = 1; i < GetCandidatesSize(); ++i) | 383 for (size_t i = 1; i < GetCandidatesSize(); ++i) |
| 380 EXPECT_EQ(before_height, GetCandidateAt(i)->GetContentsBounds().height()); | 384 EXPECT_EQ(before_height, GetCandidateAt(i)->GetContentsBounds().height()); |
| 381 } | 385 } |
| 382 | 386 |
| 383 } // namespace ime | 387 } // namespace ime |
| 384 } // namespace ash | 388 } // namespace ash |
| OLD | NEW |