| 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/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
| 9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 10 #include "ash/test/ash_test_helper.h" |
| 10 #include "ash/test/test_shell_delegate.h" | 11 #include "ash/test/test_shell_delegate.h" |
| 11 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
| 12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 13 #include "ui/app_list/app_list_switches.h" | 14 #include "ui/app_list/app_list_switches.h" |
| 15 #include "ui/app_list/shower/app_list_shower_impl.h" |
| 14 #include "ui/app_list/views/app_list_view.h" | 16 #include "ui/app_list/views/app_list_view.h" |
| 15 #include "ui/aura/test/test_windows.h" | 17 #include "ui/aura/test/test_windows.h" |
| 16 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 17 #include "ui/events/test/event_generator.h" | 19 #include "ui/events/test/event_generator.h" |
| 18 | 20 |
| 19 namespace ash { | 21 namespace ash { |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | |
| 23 const int kMinimalCenteredAppListMargin = 10; | 24 const int kMinimalCenteredAppListMargin = 10; |
| 24 | |
| 25 } | 25 } |
| 26 | 26 |
| 27 // The parameter is true to test the centered app list, false for normal. | 27 // The parameter is true to test the centered app list, false for normal. |
| 28 // (The test name ends in "/0" for normal, "/1" for centered.) | 28 // (The test name ends in "/0" for normal, "/1" for centered.) |
| 29 class AppListControllerTest : public test::AshTestBase, | 29 class AppListShowerDelegateTest : public test::AshTestBase, |
| 30 public ::testing::WithParamInterface<bool> { | 30 public ::testing::WithParamInterface<bool> { |
| 31 public: | 31 public: |
| 32 AppListControllerTest(); | 32 AppListShowerDelegateTest(); |
| 33 virtual ~AppListControllerTest(); | 33 virtual ~AppListShowerDelegateTest(); |
| 34 |
| 35 // testing::Test: |
| 34 void SetUp() override; | 36 void SetUp() override; |
| 35 | 37 |
| 38 app_list::AppListShowerImpl* GetAppListShower(); |
| 36 bool IsCentered() const; | 39 bool IsCentered() const; |
| 37 }; | 40 }; |
| 38 | 41 |
| 39 AppListControllerTest::AppListControllerTest() { | 42 AppListShowerDelegateTest::AppListShowerDelegateTest() {} |
| 40 } | |
| 41 | 43 |
| 42 AppListControllerTest::~AppListControllerTest() { | 44 AppListShowerDelegateTest::~AppListShowerDelegateTest() {} |
| 43 } | |
| 44 | 45 |
| 45 void AppListControllerTest::SetUp() { | 46 void AppListShowerDelegateTest::SetUp() { |
| 46 AshTestBase::SetUp(); | 47 AshTestBase::SetUp(); |
| 47 if (IsCentered()) { | 48 if (IsCentered()) { |
| 48 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 49 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 49 command_line->AppendSwitch(app_list::switches::kEnableCenteredAppList); | 50 command_line->AppendSwitch(app_list::switches::kEnableCenteredAppList); |
| 50 } | 51 } |
| 51 | 52 |
| 52 // Make the display big enough to hold the experimental app list. | 53 // Make the display big enough to hold the experimental app list. |
| 53 UpdateDisplay("1024x768"); | 54 UpdateDisplay("1024x768"); |
| 54 } | 55 } |
| 55 | 56 |
| 56 bool AppListControllerTest::IsCentered() const { | 57 app_list::AppListShowerImpl* AppListShowerDelegateTest::GetAppListShower() { |
| 58 return ash_test_helper()->test_shell_delegate()->app_list_shower(); |
| 59 } |
| 60 |
| 61 bool AppListShowerDelegateTest::IsCentered() const { |
| 57 return GetParam(); | 62 return GetParam(); |
| 58 } | 63 } |
| 59 | 64 |
| 60 // Tests that app launcher hides when focus moves to a normal window. | 65 // Tests that app launcher hides when focus moves to a normal window. |
| 61 TEST_P(AppListControllerTest, HideOnFocusOut) { | 66 TEST_P(AppListShowerDelegateTest, HideOnFocusOut) { |
| 62 Shell::GetInstance()->ShowAppList(NULL); | 67 Shell::GetInstance()->ShowAppList(NULL); |
| 63 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 68 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 64 | 69 |
| 65 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 70 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 66 wm::ActivateWindow(window.get()); | 71 wm::ActivateWindow(window.get()); |
| 67 | 72 |
| 68 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); | 73 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 69 } | 74 } |
| 70 | 75 |
| 71 // Tests that app launcher remains visible when focus is moved to a different | 76 // Tests that app launcher remains visible when focus is moved to a different |
| 72 // window in kShellWindowId_AppListContainer. | 77 // window in kShellWindowId_AppListContainer. |
| 73 TEST_P(AppListControllerTest, RemainVisibleWhenFocusingToApplistContainer) { | 78 TEST_P(AppListShowerDelegateTest, RemainVisibleWhenFocusingToApplistContainer) { |
| 74 Shell::GetInstance()->ShowAppList(NULL); | 79 Shell::GetInstance()->ShowAppList(NULL); |
| 75 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 80 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 76 | 81 |
| 77 aura::Window* applist_container = Shell::GetContainer( | 82 aura::Window* applist_container = Shell::GetContainer( |
| 78 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); | 83 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); |
| 79 std::unique_ptr<aura::Window> window( | 84 std::unique_ptr<aura::Window> window( |
| 80 aura::test::CreateTestWindowWithId(0, applist_container)); | 85 aura::test::CreateTestWindowWithId(0, applist_container)); |
| 81 wm::ActivateWindow(window.get()); | 86 wm::ActivateWindow(window.get()); |
| 82 | 87 |
| 83 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 88 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 84 } | 89 } |
| 85 | 90 |
| 86 // Tests that clicking outside the app-list bubble closes it. | 91 // Tests that clicking outside the app-list bubble closes it. |
| 87 TEST_P(AppListControllerTest, ClickOutsideBubbleClosesBubble) { | 92 TEST_P(AppListShowerDelegateTest, ClickOutsideBubbleClosesBubble) { |
| 88 Shell* shell = Shell::GetInstance(); | 93 Shell* shell = Shell::GetInstance(); |
| 89 shell->ShowAppList(NULL); | 94 shell->ShowAppList(NULL); |
| 90 | 95 aura::Window* app_window = GetAppListShower()->GetWindow(); |
| 91 aura::Window* app_window = shell->GetAppListWindow(); | |
| 92 ASSERT_TRUE(app_window); | 96 ASSERT_TRUE(app_window); |
| 93 ui::test::EventGenerator generator(shell->GetPrimaryRootWindow(), app_window); | 97 ui::test::EventGenerator generator(shell->GetPrimaryRootWindow(), app_window); |
| 94 // Click on the bubble itself. The bubble should remain visible. | 98 // Click on the bubble itself. The bubble should remain visible. |
| 95 generator.ClickLeftButton(); | 99 generator.ClickLeftButton(); |
| 96 EXPECT_TRUE(shell->GetAppListTargetVisibility()); | 100 EXPECT_TRUE(shell->GetAppListTargetVisibility()); |
| 97 | 101 |
| 98 // Click outside the bubble. This should close it. | 102 // Click outside the bubble. This should close it. |
| 99 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); | 103 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); |
| 100 gfx::Point point_outside = | 104 gfx::Point point_outside = |
| 101 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + | 105 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + |
| 102 gfx::Vector2d(10, 0); | 106 gfx::Vector2d(10, 0); |
| 103 EXPECT_TRUE(shell->GetPrimaryRootWindow()->bounds().Contains(point_outside)); | 107 EXPECT_TRUE(shell->GetPrimaryRootWindow()->bounds().Contains(point_outside)); |
| 104 generator.MoveMouseToInHost(point_outside); | 108 generator.MoveMouseToInHost(point_outside); |
| 105 generator.ClickLeftButton(); | 109 generator.ClickLeftButton(); |
| 106 EXPECT_FALSE(shell->GetAppListTargetVisibility()); | 110 EXPECT_FALSE(shell->GetAppListTargetVisibility()); |
| 107 } | 111 } |
| 108 | 112 |
| 109 // Tests that clicking outside the app-list bubble closes it. | 113 // Tests that clicking outside the app-list bubble closes it. |
| 110 TEST_P(AppListControllerTest, TapOutsideBubbleClosesBubble) { | 114 TEST_P(AppListShowerDelegateTest, TapOutsideBubbleClosesBubble) { |
| 111 Shell* shell = Shell::GetInstance(); | 115 Shell* shell = Shell::GetInstance(); |
| 112 shell->ShowAppList(NULL); | 116 shell->ShowAppList(NULL); |
| 113 | 117 |
| 114 aura::Window* app_window = shell->GetAppListWindow(); | 118 aura::Window* app_window = GetAppListShower()->GetWindow(); |
| 115 ASSERT_TRUE(app_window); | 119 ASSERT_TRUE(app_window); |
| 116 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); | 120 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); |
| 117 | 121 |
| 118 ui::test::EventGenerator generator(shell->GetPrimaryRootWindow()); | 122 ui::test::EventGenerator generator(shell->GetPrimaryRootWindow()); |
| 119 // Click on the bubble itself. The bubble should remain visible. | 123 // Click on the bubble itself. The bubble should remain visible. |
| 120 generator.GestureTapAt(app_window_bounds.CenterPoint()); | 124 generator.GestureTapAt(app_window_bounds.CenterPoint()); |
| 121 EXPECT_TRUE(shell->GetAppListTargetVisibility()); | 125 EXPECT_TRUE(shell->GetAppListTargetVisibility()); |
| 122 | 126 |
| 123 // Click outside the bubble. This should close it. | 127 // Click outside the bubble. This should close it. |
| 124 gfx::Point point_outside = | 128 gfx::Point point_outside = |
| 125 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + | 129 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + |
| 126 gfx::Vector2d(10, 0); | 130 gfx::Vector2d(10, 0); |
| 127 EXPECT_TRUE(shell->GetPrimaryRootWindow()->bounds().Contains(point_outside)); | 131 EXPECT_TRUE(shell->GetPrimaryRootWindow()->bounds().Contains(point_outside)); |
| 128 generator.GestureTapAt(point_outside); | 132 generator.GestureTapAt(point_outside); |
| 129 EXPECT_FALSE(shell->GetAppListTargetVisibility()); | 133 EXPECT_FALSE(shell->GetAppListTargetVisibility()); |
| 130 } | 134 } |
| 131 | 135 |
| 132 // Tests opening the app launcher on a non-primary display, then deleting the | 136 // Tests opening the app launcher on a non-primary display, then deleting the |
| 133 // display. | 137 // display. |
| 134 TEST_P(AppListControllerTest, NonPrimaryDisplay) { | 138 TEST_P(AppListShowerDelegateTest, NonPrimaryDisplay) { |
| 135 if (!SupportsMultipleDisplays()) | 139 if (!SupportsMultipleDisplays()) |
| 136 return; | 140 return; |
| 137 | 141 |
| 138 // Set up a screen with two displays (horizontally adjacent). | 142 // Set up a screen with two displays (horizontally adjacent). |
| 139 UpdateDisplay("1024x768,1024x768"); | 143 UpdateDisplay("1024x768,1024x768"); |
| 140 | 144 |
| 141 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 145 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 142 ASSERT_EQ(2u, root_windows.size()); | 146 ASSERT_EQ(2u, root_windows.size()); |
| 143 aura::Window* secondary_window = root_windows[1]; | 147 aura::Window* secondary_window = root_windows[1]; |
| 144 EXPECT_EQ("1024,0 1024x768", | 148 EXPECT_EQ("1024,0 1024x768", |
| 145 secondary_window->GetBoundsInScreen().ToString()); | 149 secondary_window->GetBoundsInScreen().ToString()); |
| 146 | 150 |
| 147 Shell::GetInstance()->ShowAppList(secondary_window); | 151 Shell::GetInstance()->ShowAppList(secondary_window); |
| 148 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 152 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 149 | 153 |
| 150 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). | 154 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). |
| 151 UpdateDisplay("1024x768"); | 155 UpdateDisplay("1024x768"); |
| 152 | 156 |
| 153 // Updating the displays should close the app list. | 157 // Updating the displays should close the app list. |
| 154 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); | 158 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 155 } | 159 } |
| 156 | 160 |
| 157 // Tests opening the app launcher on a tiny display that is too small to contain | 161 // Tests opening the app launcher on a tiny display that is too small to contain |
| 158 // it. | 162 // it. |
| 159 TEST_P(AppListControllerTest, TinyDisplay) { | 163 TEST_P(AppListShowerDelegateTest, TinyDisplay) { |
| 160 // Don't test this for the non-centered app list case; it isn't designed for | 164 // Don't test this for the non-centered app list case; it isn't designed for |
| 161 // small displays. The most common case of a small display --- when the | 165 // small displays. The most common case of a small display --- when the |
| 162 // virtual keyboard is open --- switches into the centered app list mode, so | 166 // virtual keyboard is open --- switches into the centered app list mode, so |
| 163 // we just want to run this test in that case. | 167 // we just want to run this test in that case. |
| 164 if (!IsCentered()) | 168 if (!IsCentered()) |
| 165 return; | 169 return; |
| 166 | 170 |
| 167 // UpdateDisplay is not supported in this case, so just skip the test. | 171 // UpdateDisplay is not supported in this case, so just skip the test. |
| 168 if (!SupportsHostWindowResize()) | 172 if (!SupportsHostWindowResize()) |
| 169 return; | 173 return; |
| 170 | 174 |
| 171 // Set up a screen with a tiny display (height smaller than the app list). | 175 // Set up a screen with a tiny display (height smaller than the app list). |
| 172 UpdateDisplay("400x300"); | 176 UpdateDisplay("400x300"); |
| 173 | 177 |
| 174 Shell::GetInstance()->ShowAppList(NULL); | 178 Shell::GetInstance()->ShowAppList(NULL); |
| 175 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 179 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 176 | 180 |
| 177 // The top of the app list should be on-screen (even if the bottom is not). | 181 // The top of the app list should be on-screen (even if the bottom is not). |
| 178 // We need to manually calculate the Y coordinate of the top of the app list | 182 // We need to manually calculate the Y coordinate of the top of the app list |
| 179 // from the anchor (center) and height. There isn't a bounds rect that gives | 183 // from the anchor (center) and height. There isn't a bounds rect that gives |
| 180 // the actual app list position (the widget bounds include the bubble border | 184 // the actual app list position (the widget bounds include the bubble border |
| 181 // which is much bigger than the actual app list size). | 185 // which is much bigger than the actual app list size). |
| 182 app_list::AppListView* app_list = Shell::GetInstance()->GetAppListView(); | 186 app_list::AppListView* app_list = GetAppListShower()->GetView(); |
| 183 int app_list_view_top = | 187 int app_list_view_top = |
| 184 app_list->anchor_rect().y() - app_list->bounds().height() / 2; | 188 app_list->anchor_rect().y() - app_list->bounds().height() / 2; |
| 185 EXPECT_GE(app_list_view_top, kMinimalCenteredAppListMargin); | 189 EXPECT_GE(app_list_view_top, kMinimalCenteredAppListMargin); |
| 186 } | 190 } |
| 187 | 191 |
| 188 INSTANTIATE_TEST_CASE_P(AppListControllerTestInstance, | 192 INSTANTIATE_TEST_CASE_P(AppListShowerDelegateTestInstance, |
| 189 AppListControllerTest, | 193 AppListShowerDelegateTest, |
| 190 ::testing::Bool()); | 194 ::testing::Bool()); |
| 191 | 195 |
| 192 } // namespace ash | 196 } // namespace ash |
| OLD | NEW |