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 "ui/app_list/views/app_list_view.h" | 5 #include "ui/app_list/views/app_list_view.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 contents_view->Layout(); | 239 contents_view->Layout(); |
240 return IsStateShown(state); | 240 return IsStateShown(state); |
241 } | 241 } |
242 | 242 |
243 bool AppListViewTestContext::IsStateShown(AppListModel::State state) { | 243 bool AppListViewTestContext::IsStateShown(AppListModel::State state) { |
244 ContentsView* contents_view = view_->app_list_main_view()->contents_view(); | 244 ContentsView* contents_view = view_->app_list_main_view()->contents_view(); |
245 int index = contents_view->GetPageIndexForState(state); | 245 int index = contents_view->GetPageIndexForState(state); |
246 bool success = true; | 246 bool success = true; |
247 for (int i = 0; i < contents_view->NumLauncherPages(); ++i) { | 247 for (int i = 0; i < contents_view->NumLauncherPages(); ++i) { |
248 success = success && | 248 success = success && |
249 (i == index) == (contents_view->GetDefaultContentsBounds() == | 249 (i == index) == (contents_view->GetOnscreenPageBounds(i) == |
250 contents_view->GetPageView(i)->bounds()); | 250 contents_view->GetPageView(i)->bounds()); |
251 } | 251 } |
252 return success && state == delegate_->GetTestModel()->state(); | 252 return success && state == delegate_->GetTestModel()->state(); |
253 } | 253 } |
254 | 254 |
255 void AppListViewTestContext::Show() { | 255 void AppListViewTestContext::Show() { |
256 view_->GetWidget()->Show(); | 256 view_->GetWidget()->Show(); |
257 run_loop_.reset(new base::RunLoop); | 257 run_loop_.reset(new base::RunLoop); |
258 view_->SetNextPaintCallback(run_loop_->QuitClosure()); | 258 view_->SetNextPaintCallback(run_loop_->QuitClosure()); |
259 run_loop_->Run(); | 259 run_loop_->Run(); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); | 500 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); |
501 | 501 |
502 ContentsView* contents_view = main_view->contents_view(); | 502 ContentsView* contents_view = main_view->contents_view(); |
503 // Pad the ContentsView with blank pages so we have at least 3 views. | 503 // Pad the ContentsView with blank pages so we have at least 3 views. |
504 while (contents_view->NumLauncherPages() < 3) | 504 while (contents_view->NumLauncherPages() < 3) |
505 contents_view->AddBlankPageForTesting(); | 505 contents_view->AddBlankPageForTesting(); |
506 | 506 |
507 contents_view->SetActivePage(0); | 507 contents_view->SetActivePage(0); |
508 contents_view->Layout(); | 508 contents_view->Layout(); |
509 | 509 |
510 const gfx::Rect expected_bounds = contents_view->GetDefaultContentsBounds(); | 510 EXPECT_EQ(contents_view->GetOnscreenPageBounds(0), |
511 | 511 contents_view->GetPageView(0)->bounds()); |
512 EXPECT_EQ(expected_bounds, contents_view->GetPageView(0)->bounds()); | 512 EXPECT_NE(contents_view->GetOnscreenPageBounds(1), |
513 EXPECT_NE(expected_bounds, contents_view->GetPageView(1)->bounds()); | 513 contents_view->GetPageView(1)->bounds()); |
514 EXPECT_NE(expected_bounds, contents_view->GetPageView(2)->bounds()); | 514 EXPECT_NE(contents_view->GetOnscreenPageBounds(2), |
| 515 contents_view->GetPageView(2)->bounds()); |
515 | 516 |
516 // Change pages. View should not have moved without Layout(). | 517 // Change pages. View should not have moved without Layout(). |
517 contents_view->SetActivePage(1); | 518 contents_view->SetActivePage(1); |
518 EXPECT_EQ(expected_bounds, contents_view->GetPageView(0)->bounds()); | 519 EXPECT_EQ(contents_view->GetOnscreenPageBounds(0), |
519 EXPECT_NE(expected_bounds, contents_view->GetPageView(1)->bounds()); | 520 contents_view->GetPageView(0)->bounds()); |
520 EXPECT_NE(expected_bounds, contents_view->GetPageView(2)->bounds()); | 521 EXPECT_NE(contents_view->GetOnscreenPageBounds(1), |
| 522 contents_view->GetPageView(1)->bounds()); |
| 523 EXPECT_NE(contents_view->GetOnscreenPageBounds(2), |
| 524 contents_view->GetPageView(2)->bounds()); |
521 | 525 |
522 // Change to a third page. This queues up the second animation behind the | 526 // Change to a third page. This queues up the second animation behind the |
523 // first. | 527 // first. |
524 contents_view->SetActivePage(2); | 528 contents_view->SetActivePage(2); |
525 EXPECT_EQ(expected_bounds, contents_view->GetPageView(0)->bounds()); | 529 EXPECT_EQ(contents_view->GetOnscreenPageBounds(0), |
526 EXPECT_NE(expected_bounds, contents_view->GetPageView(1)->bounds()); | 530 contents_view->GetPageView(0)->bounds()); |
527 EXPECT_NE(expected_bounds, contents_view->GetPageView(2)->bounds()); | 531 EXPECT_NE(contents_view->GetOnscreenPageBounds(1), |
| 532 contents_view->GetPageView(1)->bounds()); |
| 533 EXPECT_NE(contents_view->GetOnscreenPageBounds(2), |
| 534 contents_view->GetPageView(2)->bounds()); |
528 | 535 |
529 // Call Layout(). Should jump to the third page. | 536 // Call Layout(). Should jump to the third page. |
530 contents_view->Layout(); | 537 contents_view->Layout(); |
531 EXPECT_NE(expected_bounds, contents_view->GetPageView(0)->bounds()); | 538 EXPECT_NE(contents_view->GetOnscreenPageBounds(0), |
532 EXPECT_NE(expected_bounds, contents_view->GetPageView(1)->bounds()); | 539 contents_view->GetPageView(0)->bounds()); |
533 EXPECT_EQ(expected_bounds, contents_view->GetPageView(2)->bounds()); | 540 EXPECT_NE(contents_view->GetOnscreenPageBounds(1), |
| 541 contents_view->GetPageView(1)->bounds()); |
| 542 EXPECT_EQ(contents_view->GetOnscreenPageBounds(2), |
| 543 contents_view->GetPageView(2)->bounds()); |
534 } | 544 } |
535 | 545 |
536 Close(); | 546 Close(); |
537 } | 547 } |
538 | 548 |
539 void AppListViewTestContext::RunProfileChangeTest() { | 549 void AppListViewTestContext::RunProfileChangeTest() { |
540 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 550 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
541 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); | 551 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); |
542 delegate_->GetTestModel()->PopulateApps(kInitialItems); | 552 delegate_->GetTestModel()->PopulateApps(kInitialItems); |
543 | 553 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 | 603 |
594 AppListMainView* main_view = view_->app_list_main_view(); | 604 AppListMainView* main_view = view_->app_list_main_view(); |
595 ContentsView* contents_view = main_view->contents_view(); | 605 ContentsView* contents_view = main_view->contents_view(); |
596 EXPECT_TRUE(SetAppListState(AppListModel::STATE_APPS)); | 606 EXPECT_TRUE(SetAppListState(AppListModel::STATE_APPS)); |
597 | 607 |
598 // Show the search results. | 608 // Show the search results. |
599 contents_view->ShowSearchResults(true); | 609 contents_view->ShowSearchResults(true); |
600 contents_view->Layout(); | 610 contents_view->Layout(); |
601 EXPECT_TRUE(contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); | 611 EXPECT_TRUE(contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); |
602 | 612 |
603 const gfx::Rect default_contents_bounds = | 613 EXPECT_TRUE(IsStateShown(AppListModel::STATE_SEARCH_RESULTS)); |
604 contents_view->GetDefaultContentsBounds(); | |
605 EXPECT_EQ(AppListModel::STATE_SEARCH_RESULTS, | |
606 delegate_->GetTestModel()->state()); | |
607 EXPECT_EQ(default_contents_bounds, | |
608 contents_view->search_results_page_view()->bounds()); | |
609 | 614 |
610 // Hide the search results. | 615 // Hide the search results. |
611 contents_view->ShowSearchResults(false); | 616 contents_view->ShowSearchResults(false); |
612 contents_view->Layout(); | 617 contents_view->Layout(); |
613 | 618 |
614 // Check that we return to the page that we were on before the search. | 619 // Check that we return to the page that we were on before the search. |
615 EXPECT_TRUE(contents_view->IsStateActive(AppListModel::STATE_APPS)); | 620 EXPECT_TRUE(IsStateShown(AppListModel::STATE_APPS)); |
616 EXPECT_EQ(AppListModel::STATE_APPS, delegate_->GetTestModel()->state()); | |
617 EXPECT_EQ(default_contents_bounds, | |
618 contents_view->apps_container_view()->bounds()); | |
619 | 621 |
620 if (test_type_ == EXPERIMENTAL) { | 622 if (test_type_ == EXPERIMENTAL) { |
621 // Check that typing into the search box triggers the search page. | 623 // Check that typing into the search box triggers the search page. |
622 EXPECT_TRUE(SetAppListState(AppListModel::STATE_START)); | 624 EXPECT_TRUE(SetAppListState(AppListModel::STATE_START)); |
623 view_->Layout(); | 625 view_->Layout(); |
624 EXPECT_EQ(default_contents_bounds, | 626 EXPECT_TRUE(IsStateShown(AppListModel::STATE_START)); |
625 contents_view->start_page_view()->bounds()); | |
626 EXPECT_TRUE(CheckSearchBoxWidget( | |
627 contents_view->GetSearchBoxBoundsForState(AppListModel::STATE_START))); | |
628 | 627 |
629 base::string16 search_text = base::UTF8ToUTF16("test"); | 628 base::string16 search_text = base::UTF8ToUTF16("test"); |
630 main_view->search_box_view()->search_box()->SetText(base::string16()); | 629 main_view->search_box_view()->search_box()->SetText(base::string16()); |
631 main_view->search_box_view()->search_box()->InsertText(search_text); | 630 main_view->search_box_view()->search_box()->InsertText(search_text); |
632 // Check that the current search is using |search_text|. | 631 // Check that the current search is using |search_text|. |
633 EXPECT_EQ(search_text, delegate_->GetTestModel()->search_box()->text()); | 632 EXPECT_EQ(search_text, delegate_->GetTestModel()->search_box()->text()); |
634 EXPECT_EQ(search_text, main_view->search_box_view()->search_box()->text()); | 633 EXPECT_EQ(search_text, main_view->search_box_view()->search_box()->text()); |
635 contents_view->Layout(); | 634 contents_view->Layout(); |
636 EXPECT_TRUE( | 635 EXPECT_TRUE( |
637 contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); | 636 contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); |
638 EXPECT_TRUE( | 637 EXPECT_TRUE( |
639 CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); | 638 CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); |
640 | 639 |
641 // Check that typing into the search box triggers the search page. | 640 // Check that typing into the search box triggers the search page. |
642 EXPECT_TRUE(SetAppListState(AppListModel::STATE_APPS)); | 641 EXPECT_TRUE(SetAppListState(AppListModel::STATE_APPS)); |
643 contents_view->Layout(); | 642 contents_view->Layout(); |
644 EXPECT_EQ(default_contents_bounds, | 643 EXPECT_TRUE(IsStateShown(AppListModel::STATE_APPS)); |
645 contents_view->apps_container_view()->bounds()); | |
646 EXPECT_TRUE( | 644 EXPECT_TRUE( |
647 CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); | 645 CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); |
648 | 646 |
649 base::string16 new_search_text = base::UTF8ToUTF16("apple"); | 647 base::string16 new_search_text = base::UTF8ToUTF16("apple"); |
650 main_view->search_box_view()->search_box()->SetText(base::string16()); | 648 main_view->search_box_view()->search_box()->SetText(base::string16()); |
651 main_view->search_box_view()->search_box()->InsertText(new_search_text); | 649 main_view->search_box_view()->search_box()->InsertText(new_search_text); |
652 // Check that the current search is using |new_search_text|. | 650 // Check that the current search is using |new_search_text|. |
653 EXPECT_EQ(new_search_text, delegate_->GetTestModel()->search_box()->text()); | 651 EXPECT_EQ(new_search_text, delegate_->GetTestModel()->search_box()->text()); |
654 EXPECT_EQ(new_search_text, | 652 EXPECT_EQ(new_search_text, |
655 main_view->search_box_view()->search_box()->text()); | 653 main_view->search_box_view()->search_box()->text()); |
656 contents_view->Layout(); | 654 contents_view->Layout(); |
657 EXPECT_TRUE( | 655 EXPECT_TRUE(IsStateShown(AppListModel::STATE_SEARCH_RESULTS)); |
658 contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); | |
659 EXPECT_TRUE( | 656 EXPECT_TRUE( |
660 CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); | 657 CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); |
661 } | 658 } |
662 | 659 |
663 Close(); | 660 Close(); |
664 } | 661 } |
665 | 662 |
666 class AppListViewTestAura : public views::ViewsTestBase, | 663 class AppListViewTestAura : public views::ViewsTestBase, |
667 public ::testing::WithParamInterface<int> { | 664 public ::testing::WithParamInterface<int> { |
668 public: | 665 public: |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 AppListViewTestAura, | 824 AppListViewTestAura, |
828 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 825 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
829 #endif | 826 #endif |
830 | 827 |
831 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, | 828 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, |
832 AppListViewTestDesktop, | 829 AppListViewTestDesktop, |
833 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 830 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
834 | 831 |
835 } // namespace test | 832 } // namespace test |
836 } // namespace app_list | 833 } // namespace app_list |
OLD | NEW |