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