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