| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 97 |
| 98 // Tests that pressing the search box's back button navigates correctly. | 98 // Tests that pressing the search box's back button navigates correctly. |
| 99 void RunBackTest(); | 99 void RunBackTest(); |
| 100 | 100 |
| 101 // Tests displaying of the app list and shows the start page. | 101 // Tests displaying of the app list and shows the start page. |
| 102 void RunStartPageTest(); | 102 void RunStartPageTest(); |
| 103 | 103 |
| 104 // Tests switching rapidly between multiple pages of the launcher. | 104 // Tests switching rapidly between multiple pages of the launcher. |
| 105 void RunPageSwitchingAnimationTest(); | 105 void RunPageSwitchingAnimationTest(); |
| 106 | 106 |
| 107 // Tests changing the App List profile. | |
| 108 void RunProfileChangeTest(); | |
| 109 | |
| 110 // Tests displaying of the search results. | 107 // Tests displaying of the search results. |
| 111 void RunSearchResultsTest(); | 108 void RunSearchResultsTest(); |
| 112 | 109 |
| 113 // Tests displaying the app list overlay. | 110 // Tests displaying the app list overlay. |
| 114 void RunAppListOverlayTest(); | 111 void RunAppListOverlayTest(); |
| 115 | 112 |
| 116 // A standard set of checks on a view, e.g., ensuring it is drawn and visible. | 113 // A standard set of checks on a view, e.g., ensuring it is drawn and visible. |
| 117 static void CheckView(views::View* subview); | 114 static void CheckView(views::View* subview); |
| 118 | 115 |
| 119 // Invoked when the Widget is closing, and the view it contains is about to | 116 // Invoked when the Widget is closing, and the view it contains is about to |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 contents_view->SetActiveState(AppListModel::STATE_APPS); | 451 contents_view->SetActiveState(AppListModel::STATE_APPS); |
| 455 IsStateShown(AppListModel::STATE_START); | 452 IsStateShown(AppListModel::STATE_START); |
| 456 | 453 |
| 457 // Call Layout(). Should jump to the third page. | 454 // Call Layout(). Should jump to the third page. |
| 458 contents_view->Layout(); | 455 contents_view->Layout(); |
| 459 IsStateShown(AppListModel::STATE_APPS); | 456 IsStateShown(AppListModel::STATE_APPS); |
| 460 | 457 |
| 461 Close(); | 458 Close(); |
| 462 } | 459 } |
| 463 | 460 |
| 464 void AppListViewTestContext::RunProfileChangeTest() { | |
| 465 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | |
| 466 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); | |
| 467 delegate_->GetTestModel()->PopulateApps(kInitialItems); | |
| 468 | |
| 469 Show(); | |
| 470 | |
| 471 EXPECT_EQ(2, GetPaginationModel()->total_pages()); | |
| 472 | |
| 473 // Change the profile. The original model needs to be kept alive for | |
| 474 // observers to unregister themselves. | |
| 475 std::unique_ptr<AppListTestModel> original_test_model( | |
| 476 delegate_->ReleaseTestModel()); | |
| 477 delegate_->set_next_profile_app_count(1); | |
| 478 | |
| 479 // The original ContentsView is destroyed here. | |
| 480 view_->SetProfileByPath(base::FilePath()); | |
| 481 EXPECT_EQ(1, GetPaginationModel()->total_pages()); | |
| 482 | |
| 483 StartPageView* start_page_view = | |
| 484 view_->app_list_main_view()->contents_view()->start_page_view(); | |
| 485 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view)); | |
| 486 | |
| 487 // New model updates should be processed by the start page view. | |
| 488 delegate_->GetTestModel()->results()->Add( | |
| 489 base::MakeUnique<TestStartPageSearchResult>()); | |
| 490 start_page_view->UpdateForTesting(); | |
| 491 EXPECT_EQ(1u, GetVisibleViews(start_page_view->tile_views())); | |
| 492 | |
| 493 // Old model updates should be ignored. | |
| 494 original_test_model->results()->Add( | |
| 495 base::MakeUnique<TestStartPageSearchResult>()); | |
| 496 original_test_model->results()->Add( | |
| 497 base::MakeUnique<TestStartPageSearchResult>()); | |
| 498 start_page_view->UpdateForTesting(); | |
| 499 EXPECT_EQ(1u, GetVisibleViews(start_page_view->tile_views())); | |
| 500 | |
| 501 Close(); | |
| 502 } | |
| 503 | |
| 504 void AppListViewTestContext::RunSearchResultsTest() { | 461 void AppListViewTestContext::RunSearchResultsTest() { |
| 505 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 462 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
| 506 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); | 463 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); |
| 507 AppListTestModel* model = delegate_->GetTestModel(); | 464 AppListTestModel* model = delegate_->GetTestModel(); |
| 508 model->PopulateApps(3); | 465 model->PopulateApps(3); |
| 509 | 466 |
| 510 Show(); | 467 Show(); |
| 511 | 468 |
| 512 AppListMainView* main_view = view_->app_list_main_view(); | 469 AppListMainView* main_view = view_->app_list_main_view(); |
| 513 ContentsView* contents_view = main_view->contents_view(); | 470 ContentsView* contents_view = main_view->contents_view(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 | 545 |
| 589 // testing::Test overrides: | 546 // testing::Test overrides: |
| 590 void SetUp() override { | 547 void SetUp() override { |
| 591 views::ViewsTestBase::SetUp(); | 548 views::ViewsTestBase::SetUp(); |
| 592 | 549 |
| 593 // On Ash (only) the app list is placed into an aura::Window "container", | 550 // On Ash (only) the app list is placed into an aura::Window "container", |
| 594 // which is also used to determine the context. In tests, use the ash root | 551 // which is also used to determine the context. In tests, use the ash root |
| 595 // window as the parent. This only works on aura where the root window is a | 552 // window as the parent. This only works on aura where the root window is a |
| 596 // NativeView as well as a NativeWindow. | 553 // NativeView as well as a NativeWindow. |
| 597 gfx::NativeView container = NULL; | 554 gfx::NativeView container = NULL; |
| 598 #if defined(USE_AURA) | |
| 599 container = GetContext(); | 555 container = GetContext(); |
| 600 #endif | |
| 601 | |
| 602 test_context_.reset(new AppListViewTestContext(container)); | 556 test_context_.reset(new AppListViewTestContext(container)); |
| 603 } | 557 } |
| 604 | 558 |
| 605 void TearDown() override { | 559 void TearDown() override { |
| 606 test_context_.reset(); | 560 test_context_.reset(); |
| 607 views::ViewsTestBase::TearDown(); | 561 views::ViewsTestBase::TearDown(); |
| 608 } | 562 } |
| 609 | 563 |
| 610 protected: | 564 protected: |
| 611 std::unique_ptr<AppListViewTestContext> test_context_; | 565 std::unique_ptr<AppListViewTestContext> test_context_; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 631 views::ViewsTestBase::TearDown(); | 585 views::ViewsTestBase::TearDown(); |
| 632 } | 586 } |
| 633 | 587 |
| 634 protected: | 588 protected: |
| 635 std::unique_ptr<AppListViewTestContext> test_context_; | 589 std::unique_ptr<AppListViewTestContext> test_context_; |
| 636 | 590 |
| 637 private: | 591 private: |
| 638 class AppListViewTestViewsDelegate : public views::TestViewsDelegate { | 592 class AppListViewTestViewsDelegate : public views::TestViewsDelegate { |
| 639 public: | 593 public: |
| 640 explicit AppListViewTestViewsDelegate(AppListViewTestDesktop* parent) | 594 explicit AppListViewTestViewsDelegate(AppListViewTestDesktop* parent) |
| 641 #if defined(OS_CHROMEOS) | |
| 642 : parent_(parent) | 595 : parent_(parent) |
| 643 #endif | |
| 644 { | 596 { |
| 645 } | 597 } |
| 646 | 598 |
| 647 // Overridden from views::ViewsDelegate: | 599 // Overridden from views::ViewsDelegate: |
| 648 void OnBeforeWidgetInit( | 600 void OnBeforeWidgetInit( |
| 649 views::Widget::InitParams* params, | 601 views::Widget::InitParams* params, |
| 650 views::internal::NativeWidgetDelegate* delegate) override; | 602 views::internal::NativeWidgetDelegate* delegate) override; |
| 651 | 603 |
| 652 private: | 604 private: |
| 653 #if defined(OS_CHROMEOS) | |
| 654 AppListViewTestDesktop* parent_; | 605 AppListViewTestDesktop* parent_; |
| 655 #endif | |
| 656 | 606 |
| 657 DISALLOW_COPY_AND_ASSIGN(AppListViewTestViewsDelegate); | 607 DISALLOW_COPY_AND_ASSIGN(AppListViewTestViewsDelegate); |
| 658 }; | 608 }; |
| 659 | 609 |
| 660 DISALLOW_COPY_AND_ASSIGN(AppListViewTestDesktop); | 610 DISALLOW_COPY_AND_ASSIGN(AppListViewTestDesktop); |
| 661 }; | 611 }; |
| 662 | 612 |
| 663 void AppListViewTestDesktop::AppListViewTestViewsDelegate::OnBeforeWidgetInit( | 613 void AppListViewTestDesktop::AppListViewTestViewsDelegate::OnBeforeWidgetInit( |
| 664 views::Widget::InitParams* params, | 614 views::Widget::InitParams* params, |
| 665 views::internal::NativeWidgetDelegate* delegate) { | 615 views::internal::NativeWidgetDelegate* delegate) { |
| 666 // Mimic the logic in ChromeViewsDelegate::OnBeforeWidgetInit(). Except, for | 616 // Mimic the logic in ChromeViewsDelegate::OnBeforeWidgetInit(). Except, for |
| 667 // ChromeOS, use the root window from the AuraTestHelper rather than depending | 617 // ChromeOS, use the root window from the AuraTestHelper rather than depending |
| 668 // on ash::Shell:GetPrimaryRootWindow(). Also assume non-ChromeOS is never the | 618 // on ash::Shell:GetPrimaryRootWindow(). Also assume non-ChromeOS is never the |
| 669 // Ash desktop, as that is covered by AppListViewTestAura. | 619 // Ash desktop, as that is covered by AppListViewTestAura. |
| 670 #if defined(OS_CHROMEOS) | |
| 671 if (!params->parent && !params->context) | 620 if (!params->parent && !params->context) |
| 672 params->context = parent_->GetContext(); | 621 params->context = parent_->GetContext(); |
| 673 #elif defined(USE_AURA) | |
| 674 if (params->parent == NULL && params->context == NULL && !params->child) | |
| 675 params->native_widget = new views::DesktopNativeWidgetAura(delegate); | |
| 676 #endif | |
| 677 } | 622 } |
| 678 | 623 |
| 679 } // namespace | 624 } // namespace |
| 680 | 625 |
| 681 // Tests showing the app list with basic test model in an ash-style root window. | 626 // Tests showing the app list with basic test model in an ash-style root window. |
| 682 TEST_F(AppListViewTestAura, Display) { | 627 TEST_F(AppListViewTestAura, Display) { |
| 683 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest()); | 628 EXPECT_NO_FATAL_FAILURE(test_context_->RunDisplayTest()); |
| 684 } | 629 } |
| 685 | 630 |
| 686 // Tests showing the app list on the desktop. Note on ChromeOS, this will still | 631 // Tests showing the app list on the desktop. Note on ChromeOS, this will still |
| (...skipping 23 matching lines...) Expand all Loading... |
| 710 | 655 |
| 711 // Tests that the start page view operates correctly. | 656 // Tests that the start page view operates correctly. |
| 712 TEST_F(AppListViewTestAura, PageSwitchingAnimationTest) { | 657 TEST_F(AppListViewTestAura, PageSwitchingAnimationTest) { |
| 713 EXPECT_NO_FATAL_FAILURE(test_context_->RunPageSwitchingAnimationTest()); | 658 EXPECT_NO_FATAL_FAILURE(test_context_->RunPageSwitchingAnimationTest()); |
| 714 } | 659 } |
| 715 | 660 |
| 716 TEST_F(AppListViewTestDesktop, PageSwitchingAnimationTest) { | 661 TEST_F(AppListViewTestDesktop, PageSwitchingAnimationTest) { |
| 717 EXPECT_NO_FATAL_FAILURE(test_context_->RunPageSwitchingAnimationTest()); | 662 EXPECT_NO_FATAL_FAILURE(test_context_->RunPageSwitchingAnimationTest()); |
| 718 } | 663 } |
| 719 | 664 |
| 720 // Tests that the profile changes operate correctly. | |
| 721 TEST_F(AppListViewTestAura, ProfileChangeTest) { | |
| 722 EXPECT_NO_FATAL_FAILURE(test_context_->RunProfileChangeTest()); | |
| 723 } | |
| 724 | |
| 725 TEST_F(AppListViewTestDesktop, ProfileChangeTest) { | |
| 726 EXPECT_NO_FATAL_FAILURE(test_context_->RunProfileChangeTest()); | |
| 727 } | |
| 728 | |
| 729 // Tests that the correct views are displayed for showing search results. | 665 // Tests that the correct views are displayed for showing search results. |
| 730 TEST_F(AppListViewTestAura, SearchResultsTest) { | 666 TEST_F(AppListViewTestAura, SearchResultsTest) { |
| 731 EXPECT_NO_FATAL_FAILURE(test_context_->RunSearchResultsTest()); | 667 EXPECT_NO_FATAL_FAILURE(test_context_->RunSearchResultsTest()); |
| 732 } | 668 } |
| 733 | 669 |
| 734 TEST_F(AppListViewTestDesktop, SearchResultsTest) { | 670 TEST_F(AppListViewTestDesktop, SearchResultsTest) { |
| 735 EXPECT_NO_FATAL_FAILURE(test_context_->RunSearchResultsTest()); | 671 EXPECT_NO_FATAL_FAILURE(test_context_->RunSearchResultsTest()); |
| 736 } | 672 } |
| 737 | 673 |
| 738 // Tests that the back button navigates through the app list correctly. | 674 // Tests that the back button navigates through the app list correctly. |
| 739 TEST_F(AppListViewTestAura, BackTest) { | 675 TEST_F(AppListViewTestAura, BackTest) { |
| 740 EXPECT_NO_FATAL_FAILURE(test_context_->RunBackTest()); | 676 EXPECT_NO_FATAL_FAILURE(test_context_->RunBackTest()); |
| 741 } | 677 } |
| 742 | 678 |
| 743 TEST_F(AppListViewTestDesktop, BackTest) { | 679 TEST_F(AppListViewTestDesktop, BackTest) { |
| 744 EXPECT_NO_FATAL_FAILURE(test_context_->RunBackTest()); | 680 EXPECT_NO_FATAL_FAILURE(test_context_->RunBackTest()); |
| 745 } | 681 } |
| 746 | 682 |
| 747 // Tests that the correct views are displayed for showing search results. | 683 // Tests that the correct views are displayed for showing search results. |
| 748 TEST_F(AppListViewTestAura, AppListOverlayTest) { | 684 TEST_F(AppListViewTestAura, AppListOverlayTest) { |
| 749 EXPECT_NO_FATAL_FAILURE(test_context_->RunAppListOverlayTest()); | 685 EXPECT_NO_FATAL_FAILURE(test_context_->RunAppListOverlayTest()); |
| 750 } | 686 } |
| 751 | 687 |
| 752 TEST_F(AppListViewTestDesktop, AppListOverlayTest) { | 688 TEST_F(AppListViewTestDesktop, AppListOverlayTest) { |
| 753 EXPECT_NO_FATAL_FAILURE(test_context_->RunAppListOverlayTest()); | 689 EXPECT_NO_FATAL_FAILURE(test_context_->RunAppListOverlayTest()); |
| 754 } | 690 } |
| 755 | 691 |
| 756 } // namespace test | 692 } // namespace test |
| 757 } // namespace app_list | 693 } // namespace app_list |
| OLD | NEW |