app_list_unittest.cc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <memory>
  5. #include "ash/app_list/app_list_bubble_presenter.h"
  6. #include "ash/app_list/app_list_controller_impl.h"
  7. #include "ash/app_list/app_list_presenter_impl.h"
  8. #include "ash/constants/ash_features.h"
  9. #include "ash/public/cpp/shell_window_ids.h"
  10. #include "ash/shelf/home_button.h"
  11. #include "ash/shelf/shelf.h"
  12. #include "ash/shelf/shelf_navigation_widget.h"
  13. #include "ash/shelf/shelf_view.h"
  14. #include "ash/shelf/shelf_view_test_api.h"
  15. #include "ash/shelf/shelf_widget.h"
  16. #include "ash/shell.h"
  17. #include "ash/test/ash_test_base.h"
  18. #include "base/test/scoped_feature_list.h"
  19. #include "testing/gtest/include/gtest/gtest.h"
  20. #include "ui/aura/window.h"
  21. namespace ash {
  22. namespace {
  23. // Returns visibility from the presenter's perspective.
  24. bool GetPresenterVisibility() {
  25. auto* controller = Shell::Get()->app_list_controller();
  26. if (features::IsProductivityLauncherEnabled())
  27. return controller->bubble_presenter_for_test()->IsShowing();
  28. return controller->fullscreen_presenter()->GetTargetVisibility();
  29. }
  30. } // namespace
  31. class AppListTest : public AshTestBase,
  32. public testing::WithParamInterface<bool> {
  33. public:
  34. AppListTest() {
  35. feature_list_.InitWithFeatureState(features::kProductivityLauncher,
  36. GetParam());
  37. }
  38. base::test::ScopedFeatureList feature_list_;
  39. };
  40. INSTANTIATE_TEST_SUITE_P(ProductivityLauncher, AppListTest, testing::Bool());
  41. // An integration test to toggle the app list by pressing the shelf button.
  42. TEST_P(AppListTest, PressHomeButtonToShowAndDismiss) {
  43. aura::Window* root_window = Shell::GetPrimaryRootWindow();
  44. Shelf* shelf = Shelf::ForWindow(root_window);
  45. ShelfWidget* shelf_widget = shelf->shelf_widget();
  46. ShelfView* shelf_view = shelf->GetShelfViewForTesting();
  47. ShelfViewTestAPI(shelf_view).RunMessageLoopUntilAnimationsDone();
  48. HomeButton* home_button = shelf_widget->navigation_widget()->GetHomeButton();
  49. // Ensure animations progressed to give the home button a non-empty size.
  50. ASSERT_GT(home_button->GetBoundsInScreen().height(), 0);
  51. aura::Window* app_list_container =
  52. root_window->GetChildById(kShellWindowId_AppListContainer);
  53. // Click the home button to show the app list.
  54. auto* controller = Shell::Get()->app_list_controller();
  55. EXPECT_FALSE(controller->GetTargetVisibility(GetPrimaryDisplay().id()));
  56. EXPECT_FALSE(GetPresenterVisibility());
  57. EXPECT_EQ(0u, app_list_container->children().size());
  58. EXPECT_FALSE(home_button->IsShowingAppList());
  59. LeftClickOn(home_button);
  60. EXPECT_TRUE(GetPresenterVisibility());
  61. EXPECT_EQ(1u, app_list_container->children().size());
  62. EXPECT_TRUE(home_button->IsShowingAppList());
  63. // Click the button again to dismiss the app list; it will animate to close.
  64. LeftClickOn(home_button);
  65. EXPECT_FALSE(controller->GetTargetVisibility(GetPrimaryDisplay().id()));
  66. EXPECT_EQ(1u, app_list_container->children().size());
  67. EXPECT_FALSE(home_button->IsShowingAppList());
  68. }
  69. // Tests that the app list gets toggled by pressing the shelf button on
  70. // secondary display.
  71. TEST_P(AppListTest, PressHomeButtonToShowAndDismissOnSecondDisplay) {
  72. UpdateDisplay("1024x768,1024x768");
  73. aura::Window* root_window =
  74. Shell::GetRootWindowForDisplayId(GetSecondaryDisplay().id());
  75. Shelf* shelf = Shelf::ForWindow(root_window);
  76. ShelfWidget* shelf_widget = shelf->shelf_widget();
  77. ShelfView* shelf_view = shelf->GetShelfViewForTesting();
  78. ShelfViewTestAPI(shelf_view).RunMessageLoopUntilAnimationsDone();
  79. HomeButton* home_button = shelf_widget->navigation_widget()->GetHomeButton();
  80. // Ensure animations progressed to give the home button a non-empty size.
  81. ASSERT_GT(home_button->GetBoundsInScreen().height(), 0);
  82. aura::Window* app_list_container =
  83. root_window->GetChildById(kShellWindowId_AppListContainer);
  84. // Click the home button to show the app list.
  85. auto* controller = Shell::Get()->app_list_controller();
  86. EXPECT_FALSE(controller->GetTargetVisibility(GetPrimaryDisplay().id()));
  87. EXPECT_FALSE(controller->GetTargetVisibility(GetSecondaryDisplay().id()));
  88. EXPECT_FALSE(GetPresenterVisibility());
  89. EXPECT_EQ(0u, app_list_container->children().size());
  90. EXPECT_FALSE(home_button->IsShowingAppList());
  91. LeftClickOn(home_button);
  92. EXPECT_FALSE(controller->GetTargetVisibility(GetPrimaryDisplay().id()));
  93. EXPECT_TRUE(controller->GetTargetVisibility(GetSecondaryDisplay().id()));
  94. EXPECT_TRUE(GetPresenterVisibility());
  95. EXPECT_EQ(1u, app_list_container->children().size());
  96. EXPECT_TRUE(home_button->IsShowingAppList());
  97. // Click the button again to dismiss the app list; it will animate to close.
  98. LeftClickOn(home_button);
  99. EXPECT_FALSE(controller->GetTargetVisibility(GetPrimaryDisplay().id()));
  100. EXPECT_FALSE(controller->GetTargetVisibility(GetSecondaryDisplay().id()));
  101. EXPECT_EQ(1u, app_list_container->children().size());
  102. EXPECT_FALSE(home_button->IsShowingAppList());
  103. }
  104. } // namespace ash