| 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/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/public/cpp/config.h" | |
| 9 #include "ash/public/cpp/shell_window_ids.h" | 8 #include "ash/public/cpp/shell_window_ids.h" |
| 10 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 11 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/test/test_app_list_view_presenter_impl.h" | 11 #include "ash/test/test_app_list_view_presenter_impl.h" |
| 13 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
| 14 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 15 #include "base/macros.h" | 14 #include "base/macros.h" |
| 16 #include "base/test/scoped_feature_list.h" | 15 #include "base/test/scoped_feature_list.h" |
| 17 #include "ui/app_list/app_list_features.h" | 16 #include "ui/app_list/app_list_features.h" |
| 18 #include "ui/app_list/app_list_switches.h" | |
| 19 #include "ui/app_list/views/app_list_main_view.h" | |
| 20 #include "ui/app_list/views/app_list_view.h" | 17 #include "ui/app_list/views/app_list_view.h" |
| 21 #include "ui/aura/test/test_windows.h" | 18 #include "ui/aura/test/test_windows.h" |
| 22 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 23 #include "ui/display/display.h" | 20 #include "ui/display/display.h" |
| 24 #include "ui/display/screen.h" | 21 #include "ui/display/screen.h" |
| 25 #include "ui/events/test/event_generator.h" | 22 #include "ui/events/test/event_generator.h" |
| 26 | 23 |
| 27 namespace ash { | 24 namespace ash { |
| 28 namespace { | 25 namespace { |
| 29 | 26 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 50 // If the current test is parameterized. | 47 // If the current test is parameterized. |
| 51 if (testing::UnitTest::GetInstance()->current_test_info()->value_param()) { | 48 if (testing::UnitTest::GetInstance()->current_test_info()->value_param()) { |
| 52 test_with_fullscreen_ = GetParam(); | 49 test_with_fullscreen_ = GetParam(); |
| 53 if (test_with_fullscreen_) | 50 if (test_with_fullscreen_) |
| 54 EnableFullscreenAppList(); | 51 EnableFullscreenAppList(); |
| 55 } | 52 } |
| 56 // Make the display big enough to hold the app list. | 53 // Make the display big enough to hold the app list. |
| 57 UpdateDisplay("1024x768"); | 54 UpdateDisplay("1024x768"); |
| 58 } | 55 } |
| 59 | 56 |
| 57 private: |
| 60 void EnableFullscreenAppList() { | 58 void EnableFullscreenAppList() { |
| 61 scoped_feature_list_.InitAndEnableFeature( | 59 scoped_feature_list_.InitAndEnableFeature( |
| 62 app_list::features::kEnableFullscreenAppList); | 60 app_list::features::kEnableFullscreenAppList); |
| 63 } | 61 } |
| 64 | 62 |
| 65 private: | |
| 66 test::TestAppListViewPresenterImpl app_list_presenter_impl_; | 63 test::TestAppListViewPresenterImpl app_list_presenter_impl_; |
| 67 bool test_with_fullscreen_; | 64 bool test_with_fullscreen_; |
| 68 base::test::ScopedFeatureList scoped_feature_list_; | 65 base::test::ScopedFeatureList scoped_feature_list_; |
| 69 | 66 |
| 70 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateTest); | 67 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateTest); |
| 71 }; | 68 }; |
| 72 | 69 |
| 73 // Instantiate the Boolean which is used to toggle the Fullscreen app list in | 70 // Instantiate the Boolean which is used to toggle the Fullscreen app list in |
| 74 // the parameterized tests. | 71 // the parameterized tests. |
| 75 INSTANTIATE_TEST_CASE_P(, AppListPresenterDelegateTest, testing::Bool()); | 72 INSTANTIATE_TEST_CASE_P(, AppListPresenterDelegateTest, testing::Bool()); |
| 76 | 73 |
| 77 // Tests that app list hides when focus moves to a normal window. | 74 // Tests that app launcher hides when focus moves to a normal window. |
| 78 TEST_P(AppListPresenterDelegateTest, HideOnFocusOut) { | 75 TEST_P(AppListPresenterDelegateTest, HideOnFocusOut) { |
| 79 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); | 76 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| 80 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 77 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 81 | 78 |
| 82 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 79 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 83 wm::ActivateWindow(window.get()); | 80 wm::ActivateWindow(window.get()); |
| 84 | 81 |
| 85 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); | 82 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |
| 86 } | 83 } |
| 87 | 84 |
| 88 // Tests that app list remains visible when focus is moved to a different | 85 // Tests that app launcher remains visible when focus is moved to a different |
| 89 // window in kShellWindowId_AppListContainer. | 86 // window in kShellWindowId_AppListContainer. |
| 90 TEST_P(AppListPresenterDelegateTest, | 87 TEST_P(AppListPresenterDelegateTest, |
| 91 RemainVisibleWhenFocusingToApplistContainer) { | 88 RemainVisibleWhenFocusingToApplistContainer) { |
| 92 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); | 89 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| 93 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 90 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 94 | 91 |
| 95 aura::Window* applist_container = Shell::GetContainer( | 92 aura::Window* applist_container = Shell::GetContainer( |
| 96 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); | 93 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); |
| 97 std::unique_ptr<aura::Window> window( | 94 std::unique_ptr<aura::Window> window( |
| 98 aura::test::CreateTestWindowWithId(0, applist_container)); | 95 aura::test::CreateTestWindowWithId(0, applist_container)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 133 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 137 | 134 |
| 138 // Click outside the bubble. This should close it. | 135 // Click outside the bubble. This should close it. |
| 139 gfx::Point point_outside = | 136 gfx::Point point_outside = |
| 140 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + | 137 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + |
| 141 gfx::Vector2d(10, 0); | 138 gfx::Vector2d(10, 0); |
| 142 generator.GestureTapAt(point_outside); | 139 generator.GestureTapAt(point_outside); |
| 143 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); | 140 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |
| 144 } | 141 } |
| 145 | 142 |
| 146 // Tests opening the app list on a non-primary display, then deleting the | 143 // Tests opening the app launcher on a non-primary display, then deleting the |
| 147 // display. | 144 // display. |
| 148 TEST_P(AppListPresenterDelegateTest, NonPrimaryDisplay) { | 145 TEST_P(AppListPresenterDelegateTest, NonPrimaryDisplay) { |
| 149 // Set up a screen with two displays (horizontally adjacent). | 146 // Set up a screen with two displays (horizontally adjacent). |
| 150 UpdateDisplay("1024x768,1024x768"); | 147 UpdateDisplay("1024x768,1024x768"); |
| 151 | 148 |
| 152 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 149 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 153 ASSERT_EQ(2u, root_windows.size()); | 150 ASSERT_EQ(2u, root_windows.size()); |
| 154 aura::Window* secondary_root = root_windows[1]; | 151 aura::Window* secondary_root = root_windows[1]; |
| 155 EXPECT_EQ("1024,0 1024x768", secondary_root->GetBoundsInScreen().ToString()); | 152 EXPECT_EQ("1024,0 1024x768", secondary_root->GetBoundsInScreen().ToString()); |
| 156 | 153 |
| 157 app_list_presenter_impl()->Show(display::Screen::GetScreen() | 154 app_list_presenter_impl()->Show(display::Screen::GetScreen() |
| 158 ->GetDisplayNearestWindow(secondary_root) | 155 ->GetDisplayNearestWindow(secondary_root) |
| 159 .id()); | 156 .id()); |
| 160 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 157 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 161 | 158 |
| 162 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). | 159 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). |
| 163 UpdateDisplay("1024x768"); | 160 UpdateDisplay("1024x768"); |
| 164 | 161 |
| 165 // Updating the displays should close the app list. | 162 // Updating the displays should close the app list. |
| 166 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); | 163 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |
| 167 } | 164 } |
| 168 | 165 |
| 169 // Tests opening the app list on a tiny display that is too small to contain | 166 // Tests opening the app launcher on a tiny display that is too small to contain |
| 170 // it. | 167 // it. |
| 171 TEST_F(AppListPresenterDelegateTest, TinyDisplay) { | 168 TEST_F(AppListPresenterDelegateTest, TinyDisplay) { |
| 172 // Set up a screen with a tiny display (height smaller than the app list). | 169 // Set up a screen with a tiny display (height smaller than the app list). |
| 173 UpdateDisplay("400x300"); | 170 UpdateDisplay("400x300"); |
| 174 | 171 |
| 175 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); | 172 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| 176 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 173 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 177 | 174 |
| 178 // The top of the app list should be on-screen (even if the bottom is not). | 175 // The top of the app list should be on-screen (even if the bottom is not). |
| 179 // We need to manually calculate the Y coordinate of the top of the app list | 176 // We need to manually calculate the Y coordinate of the top of the app list |
| 180 // from the anchor (center) and height. There isn't a bounds rect that gives | 177 // from the anchor (center) and height. There isn't a bounds rect that gives |
| 181 // the actual app list position (the widget bounds include the bubble border | 178 // the actual app list position (the widget bounds include the bubble border |
| 182 // which is much bigger than the actual app list size). | 179 // which is much bigger than the actual app list size). |
| 183 | 180 |
| 184 app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); | 181 app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); |
| 185 int app_list_view_top = | 182 int app_list_view_top = |
| 186 app_list->anchor_rect().y() - app_list->bounds().height() / 2; | 183 app_list->anchor_rect().y() - app_list->bounds().height() / 2; |
| 187 const int kMinimalAppListMargin = 10; | 184 const int kMinimalAppListMargin = 10; |
| 188 | 185 |
| 189 EXPECT_GE(app_list_view_top, kMinimalAppListMargin); | 186 EXPECT_GE(app_list_view_top, kMinimalAppListMargin); |
| 190 } | 187 } |
| 191 | 188 |
| 192 // Tests that the peeking app list is enlarged to fullscreen after the user | |
| 193 // types in the search box. | |
| 194 TEST_F(AppListPresenterDelegateTest, SnapToFullscreenAfterSearchboxInput) { | |
| 195 // TODO(newcomer): investigate failure in mash. http://crbug.com/726838. | |
| 196 if (Shell::GetAshConfig() == Config::MASH) | |
| 197 return; | |
| 198 | |
| 199 EnableFullscreenAppList(); | |
| 200 UpdateDisplay("1024x768"); | |
| 201 EXPECT_TRUE(app_list::features::IsFullscreenAppListEnabled()); | |
| 202 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); | |
| 203 app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); | |
| 204 // Check that it is in peeking mode. | |
| 205 EXPECT_FALSE(app_list->is_fullscreen()); | |
| 206 | |
| 207 // Dummy key event to search box. | |
| 208 ui::test::EventGenerator& generator = GetEventGenerator(); | |
| 209 generator.PressKey(ui::KeyboardCode::VKEY_0, 0); | |
| 210 // Check that it is in fullscreen mode. | |
| 211 EXPECT_TRUE(app_list->is_fullscreen()); | |
| 212 } | |
| 213 | |
| 214 // Tests that the peeking app list closes if the user taps outside its | |
| 215 // bounds. | |
| 216 TEST_F(AppListPresenterDelegateTest, TapAndClickOutsideClosesPeekingAppList) { | |
| 217 EnableFullscreenAppList(); | |
| 218 | |
| 219 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); | |
| 220 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | |
| 221 ui::test::EventGenerator& generator = GetEventGenerator(); | |
| 222 | |
| 223 // Grab the bounds of the search box, | |
| 224 // which is guaranteed to be inside the app list. | |
| 225 gfx::Point tap_point = app_list_presenter_impl() | |
| 226 ->GetView() | |
| 227 ->search_box_widget() | |
| 228 ->GetContentsView() | |
| 229 ->GetBoundsInScreen() | |
| 230 .CenterPoint(); | |
| 231 | |
| 232 // Tapping inside the bounds doesn't close the app list. | |
| 233 generator.GestureTapAt(tap_point); | |
| 234 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | |
| 235 | |
| 236 // Clicking inside the bounds doesn't close the app list. | |
| 237 generator.MoveMouseTo(tap_point); | |
| 238 generator.ClickLeftButton(); | |
| 239 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | |
| 240 | |
| 241 // Tapping outside the bounds closes the app list. | |
| 242 tap_point.set_x(tap_point.x() + 750); | |
| 243 generator.GestureTapAt(tap_point); | |
| 244 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); | |
| 245 | |
| 246 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); | |
| 247 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | |
| 248 | |
| 249 // Clicking outside the bounds closes the app list. | |
| 250 generator.MoveMouseTo(tap_point); | |
| 251 generator.ClickLeftButton(); | |
| 252 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); | |
| 253 } | |
| 254 | |
| 255 } // namespace ash | 189 } // namespace ash |
| OLD | NEW |