| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "ash/app_list/app_list_presenter_delegate_factory.h" |
| 7 #include "ash/common/wm_shell.h" | 8 #include "ash/common/wm_shell.h" |
| 8 #include "ash/common/wm_window.h" | 9 #include "ash/common/wm_window.h" |
| 9 #include "ash/public/cpp/shell_window_ids.h" | 10 #include "ash/public/cpp/shell_window_ids.h" |
| 10 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 11 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/test/ash_test_helper.h" | |
| 13 #include "ash/test/test_shell_delegate.h" | |
| 14 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
| 15 #include "base/command_line.h" | 14 #include "base/macros.h" |
| 16 #include "ui/app_list/app_list_switches.h" | |
| 17 #include "ui/app_list/presenter/app_list_presenter_impl.h" | 15 #include "ui/app_list/presenter/app_list_presenter_impl.h" |
| 16 #include "ui/app_list/presenter/test/test_app_list_view_delegate_factory.h" |
| 18 #include "ui/app_list/views/app_list_view.h" | 17 #include "ui/app_list/views/app_list_view.h" |
| 19 #include "ui/aura/test/test_windows.h" | 18 #include "ui/aura/test/test_windows.h" |
| 20 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 20 #include "ui/display/manager/display_manager.h" |
| 21 #include "ui/events/test/event_generator.h" | 21 #include "ui/events/test/event_generator.h" |
| 22 | 22 |
| 23 namespace ash { | 23 namespace ash { |
| 24 | 24 |
| 25 namespace { | |
| 26 const int kMinimalAppListMargin = 10; | |
| 27 } | |
| 28 | |
| 29 class AppListPresenterDelegateTest : public test::AshTestBase { | 25 class AppListPresenterDelegateTest : public test::AshTestBase { |
| 30 public: | 26 public: |
| 31 AppListPresenterDelegateTest(); | 27 AppListPresenterDelegateTest() |
| 32 ~AppListPresenterDelegateTest() override; | 28 : app_list_presenter_delegate_factory_( |
| 29 base::MakeUnique<app_list::TestAppListViewDelegateFactory>()), |
| 30 app_list_presenter_impl_(&app_list_presenter_delegate_factory_) {} |
| 31 ~AppListPresenterDelegateTest() override {} |
| 32 |
| 33 app_list::AppListPresenterImpl* app_list_presenter_impl() { |
| 34 return &app_list_presenter_impl_; |
| 35 } |
| 33 | 36 |
| 34 // testing::Test: | 37 // testing::Test: |
| 35 void SetUp() override; | 38 void SetUp() override { |
| 39 AshTestBase::SetUp(); |
| 36 | 40 |
| 37 app_list::AppListPresenterImpl* GetAppListPresenter(); | 41 // Make the display big enough to hold the app list. |
| 42 UpdateDisplay("1024x768"); |
| 43 } |
| 44 |
| 45 private: |
| 46 AppListPresenterDelegateFactory app_list_presenter_delegate_factory_; |
| 47 app_list::AppListPresenterImpl app_list_presenter_impl_; |
| 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateTest); |
| 38 }; | 50 }; |
| 39 | 51 |
| 40 AppListPresenterDelegateTest::AppListPresenterDelegateTest() {} | |
| 41 | |
| 42 AppListPresenterDelegateTest::~AppListPresenterDelegateTest() {} | |
| 43 | |
| 44 void AppListPresenterDelegateTest::SetUp() { | |
| 45 AshTestBase::SetUp(); | |
| 46 | |
| 47 // Make the display big enough to hold the app list. | |
| 48 UpdateDisplay("1024x768"); | |
| 49 } | |
| 50 | |
| 51 app_list::AppListPresenterImpl* | |
| 52 AppListPresenterDelegateTest::GetAppListPresenter() { | |
| 53 return ash_test_helper()->test_shell_delegate()->app_list_presenter(); | |
| 54 } | |
| 55 | |
| 56 // Tests that app launcher hides when focus moves to a normal window. | 52 // Tests that app launcher hides when focus moves to a normal window. |
| 57 TEST_F(AppListPresenterDelegateTest, HideOnFocusOut) { | 53 TEST_F(AppListPresenterDelegateTest, HideOnFocusOut) { |
| 58 WmShell::Get()->ShowAppList(); | 54 app_list_presenter_impl()->Show(display_manager()->first_display_id()); |
| 59 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); | 55 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 60 | 56 |
| 61 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 57 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 62 wm::ActivateWindow(window.get()); | 58 wm::ActivateWindow(window.get()); |
| 63 | 59 |
| 64 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); | 60 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |
| 65 } | 61 } |
| 66 | 62 |
| 67 // Tests that app launcher remains visible when focus is moved to a different | 63 // Tests that app launcher remains visible when focus is moved to a different |
| 68 // window in kShellWindowId_AppListContainer. | 64 // window in kShellWindowId_AppListContainer. |
| 69 TEST_F(AppListPresenterDelegateTest, | 65 TEST_F(AppListPresenterDelegateTest, |
| 70 RemainVisibleWhenFocusingToApplistContainer) { | 66 RemainVisibleWhenFocusingToApplistContainer) { |
| 71 WmShell::Get()->ShowAppList(); | 67 app_list_presenter_impl()->Show(display_manager()->first_display_id()); |
| 72 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); | 68 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 73 | 69 |
| 74 aura::Window* applist_container = Shell::GetContainer( | 70 aura::Window* applist_container = Shell::GetContainer( |
| 75 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); | 71 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); |
| 76 std::unique_ptr<aura::Window> window( | 72 std::unique_ptr<aura::Window> window( |
| 77 aura::test::CreateTestWindowWithId(0, applist_container)); | 73 aura::test::CreateTestWindowWithId(0, applist_container)); |
| 78 wm::ActivateWindow(window.get()); | 74 wm::ActivateWindow(window.get()); |
| 79 | 75 |
| 80 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); | 76 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 81 } | 77 } |
| 82 | 78 |
| 83 // Tests that clicking outside the app-list bubble closes it. | 79 // Tests that clicking outside the app-list bubble closes it. |
| 84 TEST_F(AppListPresenterDelegateTest, ClickOutsideBubbleClosesBubble) { | 80 TEST_F(AppListPresenterDelegateTest, ClickOutsideBubbleClosesBubble) { |
| 85 WmShell::Get()->ShowAppList(); | 81 app_list_presenter_impl()->Show(display_manager()->first_display_id()); |
| 86 aura::Window* app_window = GetAppListPresenter()->GetWindow(); | 82 aura::Window* app_window = app_list_presenter_impl()->GetWindow(); |
| 87 ASSERT_TRUE(app_window); | 83 ASSERT_TRUE(app_window); |
| 88 ui::test::EventGenerator& generator = GetEventGenerator(); | 84 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 89 // Click on the bubble itself. The bubble should remain visible. | 85 // Click on the bubble itself. The bubble should remain visible. |
| 90 generator.MoveMouseToCenterOf(app_window); | 86 generator.MoveMouseToCenterOf(app_window); |
| 91 generator.ClickLeftButton(); | 87 generator.ClickLeftButton(); |
| 92 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); | 88 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 93 | 89 |
| 94 // Click outside the bubble. This should close it. | 90 // Click outside the bubble. This should close it. |
| 95 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); | 91 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); |
| 96 gfx::Point point_outside = | 92 gfx::Point point_outside = |
| 97 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + | 93 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + |
| 98 gfx::Vector2d(10, 0); | 94 gfx::Vector2d(10, 0); |
| 99 generator.MoveMouseToInHost(point_outside); | 95 generator.MoveMouseToInHost(point_outside); |
| 100 generator.ClickLeftButton(); | 96 generator.ClickLeftButton(); |
| 101 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); | 97 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |
| 102 } | 98 } |
| 103 | 99 |
| 104 // Tests that clicking outside the app-list bubble closes it. | 100 // Tests that clicking outside the app-list bubble closes it. |
| 105 TEST_F(AppListPresenterDelegateTest, TapOutsideBubbleClosesBubble) { | 101 TEST_F(AppListPresenterDelegateTest, TapOutsideBubbleClosesBubble) { |
| 106 WmShell::Get()->ShowAppList(); | 102 app_list_presenter_impl()->Show(display_manager()->first_display_id()); |
| 107 | 103 |
| 108 aura::Window* app_window = GetAppListPresenter()->GetWindow(); | 104 aura::Window* app_window = app_list_presenter_impl()->GetWindow(); |
| 109 ASSERT_TRUE(app_window); | 105 ASSERT_TRUE(app_window); |
| 110 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); | 106 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); |
| 111 | 107 |
| 112 ui::test::EventGenerator& generator = GetEventGenerator(); | 108 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 113 // Click on the bubble itself. The bubble should remain visible. | 109 // Click on the bubble itself. The bubble should remain visible. |
| 114 generator.GestureTapAt(app_window_bounds.CenterPoint()); | 110 generator.GestureTapAt(app_window_bounds.CenterPoint()); |
| 115 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); | 111 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 116 | 112 |
| 117 // Click outside the bubble. This should close it. | 113 // Click outside the bubble. This should close it. |
| 118 gfx::Point point_outside = | 114 gfx::Point point_outside = |
| 119 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + | 115 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + |
| 120 gfx::Vector2d(10, 0); | 116 gfx::Vector2d(10, 0); |
| 121 generator.GestureTapAt(point_outside); | 117 generator.GestureTapAt(point_outside); |
| 122 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); | 118 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |
| 123 } | 119 } |
| 124 | 120 |
| 125 // Tests opening the app launcher on a non-primary display, then deleting the | 121 // Tests opening the app launcher on a non-primary display, then deleting the |
| 126 // display. | 122 // display. |
| 127 TEST_F(AppListPresenterDelegateTest, NonPrimaryDisplay) { | 123 TEST_F(AppListPresenterDelegateTest, NonPrimaryDisplay) { |
| 128 if (!SupportsMultipleDisplays()) | 124 if (!SupportsMultipleDisplays()) |
| 129 return; | 125 return; |
| 130 | 126 |
| 131 // Set up a screen with two displays (horizontally adjacent). | 127 // Set up a screen with two displays (horizontally adjacent). |
| 132 UpdateDisplay("1024x768,1024x768"); | 128 UpdateDisplay("1024x768,1024x768"); |
| 133 | 129 |
| 134 std::vector<WmWindow*> root_windows = WmShell::Get()->GetAllRootWindows(); | 130 std::vector<WmWindow*> root_windows = WmShell::Get()->GetAllRootWindows(); |
| 135 ASSERT_EQ(2u, root_windows.size()); | 131 ASSERT_EQ(2u, root_windows.size()); |
| 136 WmWindow* secondary_root = root_windows[1]; | 132 WmWindow* secondary_root = root_windows[1]; |
| 137 EXPECT_EQ("1024,0 1024x768", secondary_root->GetBoundsInScreen().ToString()); | 133 EXPECT_EQ("1024,0 1024x768", secondary_root->GetBoundsInScreen().ToString()); |
| 138 | 134 |
| 139 WmShell::Get()->delegate()->GetAppListPresenter()->Show( | 135 app_list_presenter_impl()->Show( |
| 140 secondary_root->GetDisplayNearestWindow().id()); | 136 secondary_root->GetDisplayNearestWindow().id()); |
| 141 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); | 137 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 142 | 138 |
| 143 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). | 139 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). |
| 144 UpdateDisplay("1024x768"); | 140 UpdateDisplay("1024x768"); |
| 145 | 141 |
| 146 // Updating the displays should close the app list. | 142 // Updating the displays should close the app list. |
| 147 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); | 143 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |
| 148 } | 144 } |
| 149 | 145 |
| 150 // Tests opening the app launcher on a tiny display that is too small to contain | 146 // Tests opening the app launcher on a tiny display that is too small to contain |
| 151 // it. | 147 // it. |
| 152 TEST_F(AppListPresenterDelegateTest, TinyDisplay) { | 148 TEST_F(AppListPresenterDelegateTest, TinyDisplay) { |
| 153 // Set up a screen with a tiny display (height smaller than the app list). | 149 // Set up a screen with a tiny display (height smaller than the app list). |
| 154 UpdateDisplay("400x300"); | 150 UpdateDisplay("400x300"); |
| 155 | 151 |
| 156 WmShell::Get()->ShowAppList(); | 152 app_list_presenter_impl()->Show(display_manager()->first_display_id()); |
| 157 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); | 153 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 158 | 154 |
| 159 // The top of the app list should be on-screen (even if the bottom is not). | 155 // The top of the app list should be on-screen (even if the bottom is not). |
| 160 // We need to manually calculate the Y coordinate of the top of the app list | 156 // We need to manually calculate the Y coordinate of the top of the app list |
| 161 // from the anchor (center) and height. There isn't a bounds rect that gives | 157 // from the anchor (center) and height. There isn't a bounds rect that gives |
| 162 // the actual app list position (the widget bounds include the bubble border | 158 // the actual app list position (the widget bounds include the bubble border |
| 163 // which is much bigger than the actual app list size). | 159 // which is much bigger than the actual app list size). |
| 164 app_list::AppListView* app_list = GetAppListPresenter()->GetView(); | 160 app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); |
| 165 int app_list_view_top = | 161 int app_list_view_top = |
| 166 app_list->anchor_rect().y() - app_list->bounds().height() / 2; | 162 app_list->anchor_rect().y() - app_list->bounds().height() / 2; |
| 163 const int kMinimalAppListMargin = 10; |
| 167 EXPECT_GE(app_list_view_top, kMinimalAppListMargin); | 164 EXPECT_GE(app_list_view_top, kMinimalAppListMargin); |
| 168 } | 165 } |
| 169 | 166 |
| 170 } // namespace ash | 167 } // namespace ash |
| OLD | NEW |