| 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 "Sample Candidate 3" | 280 "Sample Candidate 3" |
| 281 }; | 281 }; |
| 282 const char* kSampleAnnotation[] = { | 282 const char* kSampleAnnotation[] = { |
| 283 "Sample Annotation 1", | 283 "Sample Annotation 1", |
| 284 "Sample Annotation 2", | 284 "Sample Annotation 2", |
| 285 "Sample Annotation 3" | 285 "Sample Annotation 3" |
| 286 }; | 286 }; |
| 287 const char* kEmptyLabel = ""; | 287 const char* kEmptyLabel = ""; |
| 288 const char* kDefaultVerticalLabel[] = { "1", "2", "3" }; | 288 const char* kDefaultVerticalLabel[] = { "1", "2", "3" }; |
| 289 const char* kDefaultHorizontalLabel[] = { "1.", "2.", "3." }; | 289 const char* kDefaultHorizontalLabel[] = { "1.", "2.", "3." }; |
| 290 const char* kCustomizedLabel[] = { "a", "s", "d" }; |
| 291 const char* kExpectedHorizontalCustomizedLabel[] = { "a.", "s.", "d." }; |
| 290 | 292 |
| 291 views::Widget* widget = new views::Widget; | 293 views::Widget* widget = new views::Widget; |
| 292 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 294 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 293 widget->Init(params); | 295 widget->Init(params); |
| 294 | 296 |
| 295 CandidateWindowView candidate_window_view(widget); | 297 CandidateWindowView candidate_window_view(widget); |
| 296 candidate_window_view.Init(); | 298 candidate_window_view.Init(); |
| 297 | 299 |
| 298 { | 300 { |
| 299 SCOPED_TRACE("candidate_views allocation test"); | 301 SCOPED_TRACE("candidate_views allocation test"); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 | 392 |
| 391 candidate_window_view.UpdateCandidates(table); | 393 candidate_window_view.UpdateCandidates(table); |
| 392 | 394 |
| 393 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); | 395 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); |
| 394 // Confirm actual labels not containing ".". | 396 // Confirm actual labels not containing ".". |
| 395 for (size_t i = 0; i < kPageSize; ++i) { | 397 for (size_t i = 0; i < kPageSize; ++i) { |
| 396 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], | 398 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], |
| 397 candidate_window_view.candidate_views_[i]); | 399 candidate_window_view.candidate_views_[i]); |
| 398 } | 400 } |
| 399 } | 401 } |
| 402 { |
| 403 SCOPED_TRACE("Vertical customized label case"); |
| 404 const size_t kPageSize = 3; |
| 405 InputMethodLookupTable table; |
| 406 ClearInputMethodLookupTable(kPageSize, &table); |
| 407 |
| 408 table.orientation = InputMethodLookupTable::kVertical; |
| 409 for (size_t i = 0; i < kPageSize; ++i) { |
| 410 table.candidates.push_back(kSampleCandidate[i]); |
| 411 table.annotations.push_back(kSampleAnnotation[i]); |
| 412 table.labels.push_back(kCustomizedLabel[i]); |
| 413 } |
| 414 |
| 415 candidate_window_view.UpdateCandidates(table); |
| 416 |
| 417 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); |
| 418 // Confirm actual labels not containing ".". |
| 419 for (size_t i = 0; i < kPageSize; ++i) { |
| 420 ExpectLabels(kCustomizedLabel[i], |
| 421 kSampleCandidate[i], |
| 422 kSampleAnnotation[i], |
| 423 candidate_window_view.candidate_views_[i]); |
| 424 } |
| 425 } |
| 426 { |
| 427 SCOPED_TRACE("Horizontal customized label case"); |
| 428 const size_t kPageSize = 3; |
| 429 InputMethodLookupTable table; |
| 430 ClearInputMethodLookupTable(kPageSize, &table); |
| 431 |
| 432 table.orientation = InputMethodLookupTable::kHorizontal; |
| 433 for (size_t i = 0; i < kPageSize; ++i) { |
| 434 table.candidates.push_back(kSampleCandidate[i]); |
| 435 table.annotations.push_back(kSampleAnnotation[i]); |
| 436 table.labels.push_back(kCustomizedLabel[i]); |
| 437 } |
| 438 |
| 439 candidate_window_view.UpdateCandidates(table); |
| 440 |
| 441 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); |
| 442 // Confirm actual labels not containing ".". |
| 443 for (size_t i = 0; i < kPageSize; ++i) { |
| 444 ExpectLabels(kExpectedHorizontalCustomizedLabel[i], |
| 445 kSampleCandidate[i], |
| 446 kSampleAnnotation[i], |
| 447 candidate_window_view.candidate_views_[i]); |
| 448 } |
| 449 } |
| 400 | 450 |
| 401 // We should call CloseNow method, otherwise this test will leak memory. | 451 // We should call CloseNow method, otherwise this test will leak memory. |
| 402 widget->CloseNow(); | 452 widget->CloseNow(); |
| 403 } | 453 } |
| 404 | 454 |
| 405 class InfolistWindowViewTest : public views::ViewsTestBase { | 455 class InfolistWindowViewTest : public views::ViewsTestBase { |
| 406 }; | 456 }; |
| 407 | 457 |
| 408 TEST_F(InfolistWindowViewTest, ShouldUpdateViewTest) { | 458 TEST_F(InfolistWindowViewTest, ShouldUpdateViewTest) { |
| 409 { | 459 { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 | 573 |
| 524 const char kSampleCandidate1[] = "Sample String 1"; | 574 const char kSampleCandidate1[] = "Sample String 1"; |
| 525 const char kSampleCandidate2[] = "\xE3\x81\x82"; // multi byte string. | 575 const char kSampleCandidate2[] = "\xE3\x81\x82"; // multi byte string. |
| 526 const char kSampleCandidate3[] = "....."; | 576 const char kSampleCandidate3[] = "....."; |
| 527 | 577 |
| 528 const char kSampleShortcut1[] = "1"; | 578 const char kSampleShortcut1[] = "1"; |
| 529 const char kSampleShortcut2[] = "b"; | 579 const char kSampleShortcut2[] = "b"; |
| 530 const char kSampleShortcut3[] = "C"; | 580 const char kSampleShortcut3[] = "C"; |
| 531 | 581 |
| 532 const char kSampleAnnotation1[] = "Sample Annotation 1"; | 582 const char kSampleAnnotation1[] = "Sample Annotation 1"; |
| 533 const char kSampleAnnotation2[] = "\xE3\x81\x82"; // multi byte string. | 583 const char kSampleAnnotation2[] = "\xE3\x81\x82"; // multi byte string. |
| 534 const char kSampleAnnotation3[] = "......"; | 584 const char kSampleAnnotation3[] = "......"; |
| 535 | 585 |
| 536 // For testing, we have to prepare empty widget. | 586 // For testing, we have to prepare empty widget. |
| 537 // We should NOT manually free widget by default, otherwise double free will | 587 // We should NOT manually free widget by default, otherwise double free will |
| 538 // be occurred. So, we should instantiate widget class with "new" operation. | 588 // be occurred. So, we should instantiate widget class with "new" operation. |
| 539 views::Widget* widget = new views::Widget; | 589 views::Widget* widget = new views::Widget; |
| 540 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 590 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 541 widget->Init(params); | 591 widget->Init(params); |
| 542 | 592 |
| 543 CandidateWindowView candidate_window_view(widget); | 593 CandidateWindowView candidate_window_view(widget); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { | 666 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { |
| 617 const CandidateView* view = candidate_window_view.candidate_views_[i]; | 667 const CandidateView* view = candidate_window_view.candidate_views_[i]; |
| 618 EXPECT_EQ(before_height, view->GetContentsBounds().height()); | 668 EXPECT_EQ(before_height, view->GetContentsBounds().height()); |
| 619 } | 669 } |
| 620 | 670 |
| 621 // We should call CloseNow method, otherwise this test will leak memory. | 671 // We should call CloseNow method, otherwise this test will leak memory. |
| 622 widget->CloseNow(); | 672 widget->CloseNow(); |
| 623 } | 673 } |
| 624 } // namespace input_method | 674 } // namespace input_method |
| 625 } // namespace chromeos | 675 } // namespace chromeos |
| OLD | NEW |