| 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" | 
|    8 #include "ash/public/cpp/shell_window_ids.h" |    9 #include "ash/public/cpp/shell_window_ids.h" | 
|    9 #include "ash/shell.h" |   10 #include "ash/shell.h" | 
|   10 #include "ash/test/ash_test_base.h" |   11 #include "ash/test/ash_test_base.h" | 
|   11 #include "ash/test/test_app_list_view_presenter_impl.h" |   12 #include "ash/test/test_app_list_view_presenter_impl.h" | 
|   12 #include "ash/wm/window_util.h" |   13 #include "ash/wm/window_util.h" | 
|   13 #include "base/command_line.h" |   14 #include "base/command_line.h" | 
|   14 #include "base/macros.h" |   15 #include "base/macros.h" | 
|   15 #include "base/test/scoped_feature_list.h" |   16 #include "base/test/scoped_feature_list.h" | 
|   16 #include "ui/app_list/app_list_features.h" |   17 #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" | 
|   17 #include "ui/app_list/views/app_list_view.h" |   20 #include "ui/app_list/views/app_list_view.h" | 
|   18 #include "ui/aura/test/test_windows.h" |   21 #include "ui/aura/test/test_windows.h" | 
|   19 #include "ui/aura/window.h" |   22 #include "ui/aura/window.h" | 
|   20 #include "ui/display/display.h" |   23 #include "ui/display/display.h" | 
|   21 #include "ui/display/screen.h" |   24 #include "ui/display/screen.h" | 
|   22 #include "ui/events/test/event_generator.h" |   25 #include "ui/events/test/event_generator.h" | 
|   23  |   26  | 
|   24 namespace ash { |   27 namespace ash { | 
|   25 namespace { |   28 namespace { | 
|   26  |   29  | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
|   47     // If the current test is parameterized. |   50     // If the current test is parameterized. | 
|   48     if (testing::UnitTest::GetInstance()->current_test_info()->value_param()) { |   51     if (testing::UnitTest::GetInstance()->current_test_info()->value_param()) { | 
|   49       test_with_fullscreen_ = GetParam(); |   52       test_with_fullscreen_ = GetParam(); | 
|   50       if (test_with_fullscreen_) |   53       if (test_with_fullscreen_) | 
|   51         EnableFullscreenAppList(); |   54         EnableFullscreenAppList(); | 
|   52     } |   55     } | 
|   53     // Make the display big enough to hold the app list. |   56     // Make the display big enough to hold the app list. | 
|   54     UpdateDisplay("1024x768"); |   57     UpdateDisplay("1024x768"); | 
|   55   } |   58   } | 
|   56  |   59  | 
|   57  private: |  | 
|   58   void EnableFullscreenAppList() { |   60   void EnableFullscreenAppList() { | 
|   59     scoped_feature_list_.InitAndEnableFeature( |   61     scoped_feature_list_.InitAndEnableFeature( | 
|   60         app_list::features::kEnableFullscreenAppList); |   62         app_list::features::kEnableFullscreenAppList); | 
|   61   } |   63   } | 
|   62  |   64  | 
 |   65  private: | 
|   63   test::TestAppListViewPresenterImpl app_list_presenter_impl_; |   66   test::TestAppListViewPresenterImpl app_list_presenter_impl_; | 
|   64   bool test_with_fullscreen_; |   67   bool test_with_fullscreen_; | 
|   65   base::test::ScopedFeatureList scoped_feature_list_; |   68   base::test::ScopedFeatureList scoped_feature_list_; | 
|   66  |   69  | 
|   67   DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateTest); |   70   DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateTest); | 
|   68 }; |   71 }; | 
|   69  |   72  | 
|   70 // Instantiate the Boolean which is used to toggle the Fullscreen app list in |   73 // Instantiate the Boolean which is used to toggle the Fullscreen app list in | 
|   71 // the parameterized tests. |   74 // the parameterized tests. | 
|   72 INSTANTIATE_TEST_CASE_P(, AppListPresenterDelegateTest, testing::Bool()); |   75 INSTANTIATE_TEST_CASE_P(, AppListPresenterDelegateTest, testing::Bool()); | 
|   73  |   76  | 
|   74 // Tests that app launcher hides when focus moves to a normal window. |   77 // Tests that app list hides when focus moves to a normal window. | 
|   75 TEST_P(AppListPresenterDelegateTest, HideOnFocusOut) { |   78 TEST_P(AppListPresenterDelegateTest, HideOnFocusOut) { | 
|   76   app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |   79   app_list_presenter_impl()->Show(GetPrimaryDisplayId()); | 
|   77   EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |   80   EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 
|   78  |   81  | 
|   79   std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |   82   std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 
|   80   wm::ActivateWindow(window.get()); |   83   wm::ActivateWindow(window.get()); | 
|   81  |   84  | 
|   82   EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |   85   EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); | 
|   83 } |   86 } | 
|   84  |   87  | 
|   85 // Tests that app launcher remains visible when focus is moved to a different |   88 // Tests that app list remains visible when focus is moved to a different | 
|   86 // window in kShellWindowId_AppListContainer. |   89 // window in kShellWindowId_AppListContainer. | 
|   87 TEST_P(AppListPresenterDelegateTest, |   90 TEST_P(AppListPresenterDelegateTest, | 
|   88        RemainVisibleWhenFocusingToApplistContainer) { |   91        RemainVisibleWhenFocusingToApplistContainer) { | 
|   89   app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |   92   app_list_presenter_impl()->Show(GetPrimaryDisplayId()); | 
|   90   EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |   93   EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 
|   91  |   94  | 
|   92   aura::Window* applist_container = Shell::GetContainer( |   95   aura::Window* applist_container = Shell::GetContainer( | 
|   93       Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); |   96       Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); | 
|   94   std::unique_ptr<aura::Window> window( |   97   std::unique_ptr<aura::Window> window( | 
|   95       aura::test::CreateTestWindowWithId(0, applist_container)); |   98       aura::test::CreateTestWindowWithId(0, applist_container)); | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  133   EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |  136   EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 
|  134  |  137  | 
|  135   // Click outside the bubble. This should close it. |  138   // Click outside the bubble. This should close it. | 
|  136   gfx::Point point_outside = |  139   gfx::Point point_outside = | 
|  137       gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + |  140       gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + | 
|  138       gfx::Vector2d(10, 0); |  141       gfx::Vector2d(10, 0); | 
|  139   generator.GestureTapAt(point_outside); |  142   generator.GestureTapAt(point_outside); | 
|  140   EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |  143   EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); | 
|  141 } |  144 } | 
|  142  |  145  | 
|  143 // Tests opening the app launcher on a non-primary display, then deleting the |  146 // Tests opening the app list on a non-primary display, then deleting the | 
|  144 // display. |  147 // display. | 
|  145 TEST_P(AppListPresenterDelegateTest, NonPrimaryDisplay) { |  148 TEST_P(AppListPresenterDelegateTest, NonPrimaryDisplay) { | 
|  146   // Set up a screen with two displays (horizontally adjacent). |  149   // Set up a screen with two displays (horizontally adjacent). | 
|  147   UpdateDisplay("1024x768,1024x768"); |  150   UpdateDisplay("1024x768,1024x768"); | 
|  148  |  151  | 
|  149   aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |  152   aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 
|  150   ASSERT_EQ(2u, root_windows.size()); |  153   ASSERT_EQ(2u, root_windows.size()); | 
|  151   aura::Window* secondary_root = root_windows[1]; |  154   aura::Window* secondary_root = root_windows[1]; | 
|  152   EXPECT_EQ("1024,0 1024x768", secondary_root->GetBoundsInScreen().ToString()); |  155   EXPECT_EQ("1024,0 1024x768", secondary_root->GetBoundsInScreen().ToString()); | 
|  153  |  156  | 
|  154   app_list_presenter_impl()->Show(display::Screen::GetScreen() |  157   app_list_presenter_impl()->Show(display::Screen::GetScreen() | 
|  155                                       ->GetDisplayNearestWindow(secondary_root) |  158                                       ->GetDisplayNearestWindow(secondary_root) | 
|  156                                       .id()); |  159                                       .id()); | 
|  157   EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |  160   EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 
|  158  |  161  | 
|  159   // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). |  162   // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). | 
|  160   UpdateDisplay("1024x768"); |  163   UpdateDisplay("1024x768"); | 
|  161  |  164  | 
|  162   // Updating the displays should close the app list. |  165   // Updating the displays should close the app list. | 
|  163   EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |  166   EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); | 
|  164 } |  167 } | 
|  165  |  168  | 
|  166 // Tests opening the app launcher on a tiny display that is too small to contain |  169 // Tests opening the app list on a tiny display that is too small to contain | 
|  167 // it. |  170 // it. | 
|  168 TEST_F(AppListPresenterDelegateTest, TinyDisplay) { |  171 TEST_F(AppListPresenterDelegateTest, TinyDisplay) { | 
|  169   // Set up a screen with a tiny display (height smaller than the app list). |  172   // Set up a screen with a tiny display (height smaller than the app list). | 
|  170   UpdateDisplay("400x300"); |  173   UpdateDisplay("400x300"); | 
|  171  |  174  | 
|  172   app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |  175   app_list_presenter_impl()->Show(GetPrimaryDisplayId()); | 
|  173   EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |  176   EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 
|  174  |  177  | 
|  175   // The top of the app list should be on-screen (even if the bottom is not). |  178   // The top of the app list should be on-screen (even if the bottom is not). | 
|  176   // We need to manually calculate the Y coordinate of the top of the app list |  179   // We need to manually calculate the Y coordinate of the top of the app list | 
|  177   // from the anchor (center) and height. There isn't a bounds rect that gives |  180   // from the anchor (center) and height. There isn't a bounds rect that gives | 
|  178   // the actual app list position (the widget bounds include the bubble border |  181   // the actual app list position (the widget bounds include the bubble border | 
|  179   // which is much bigger than the actual app list size). |  182   // which is much bigger than the actual app list size). | 
|  180  |  183  | 
|  181   app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); |  184   app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); | 
|  182   int app_list_view_top = |  185   int app_list_view_top = | 
|  183       app_list->anchor_rect().y() - app_list->bounds().height() / 2; |  186       app_list->anchor_rect().y() - app_list->bounds().height() / 2; | 
|  184   const int kMinimalAppListMargin = 10; |  187   const int kMinimalAppListMargin = 10; | 
|  185  |  188  | 
|  186   EXPECT_GE(app_list_view_top, kMinimalAppListMargin); |  189   EXPECT_GE(app_list_view_top, kMinimalAppListMargin); | 
|  187 } |  190 } | 
|  188  |  191  | 
 |  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  | 
|  189 }  // namespace ash |  255 }  // namespace ash | 
| OLD | NEW |