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