Chromium Code Reviews| Index: ash/app_list/app_list_presenter_delegate_unittest.cc |
| diff --git a/ash/app_list/app_list_presenter_delegate_unittest.cc b/ash/app_list/app_list_presenter_delegate_unittest.cc |
| index 42eaa1309f31e61eaa4f1b3f6c3277d04d1b6c8e..64b0addf66d14269dc367aebbdddad2bdffd3067 100644 |
| --- a/ash/app_list/app_list_presenter_delegate_unittest.cc |
| +++ b/ash/app_list/app_list_presenter_delegate_unittest.cc |
| @@ -7,9 +7,13 @@ |
| #include "ash/ash_switches.h" |
| #include "ash/public/cpp/config.h" |
| #include "ash/public/cpp/shell_window_ids.h" |
| +#include "ash/shelf/shelf.h" |
| +#include "ash/shelf/shelf_layout_manager.h" |
| #include "ash/shell.h" |
| +#include "ash/shell_port.h" |
| #include "ash/test/ash_test_base.h" |
| #include "ash/test/test_app_list_view_presenter_impl.h" |
| +#include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| #include "ash/wm/window_util.h" |
| #include "base/command_line.h" |
| #include "base/macros.h" |
| @@ -31,6 +35,17 @@ int64_t GetPrimaryDisplayId() { |
| return display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| } |
| +void SetShelfAlignment(ShelfAlignment alignment) { |
| + Shelf::ForWindow( |
| + ShellPort::Get()->GetRootWindowForDisplayId(GetPrimaryDisplayId())) |
| + ->SetAlignment(alignment); |
| +} |
| + |
| +void EnableMaximizeMode(bool enable) { |
| + Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| + enable); |
| +} |
| + |
| } // namespace |
| class AppListPresenterDelegateTest : public test::AshTestBase, |
| @@ -189,11 +204,284 @@ TEST_F(AppListPresenterDelegateTest, TinyDisplay) { |
| EXPECT_GE(app_list_view_top, kMinimalAppListMargin); |
| } |
| +// Tests that the app list initializes in fullscreen with side shelf alignment |
| +// and that the state transitions via text input act properly. |
| +TEST_F(AppListPresenterDelegateTest, SideShelfAlignmentTextStateTransitions) { |
| + // Todo(Newcomer): Investigate mash failures crbug.com/726838 |
| + if (Shell::GetAshConfig() == Config::MASH) |
| + return; |
| + |
| + EnableFullscreenAppList(); |
| + SetShelfAlignment(ShelfAlignment::SHELF_ALIGNMENT_LEFT); |
|
vadimt
2017/06/21 00:05:59
Will this alignment stick and influence other test
newcomer
2017/06/21 16:34:47
I just tested this, it does not influence other te
|
| + |
| + // Open the app list with side shelf alignment, then check that it is in |
| + // fullscreen mode. |
| + app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| + app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); |
| + EXPECT_TRUE(app_list->is_fullscreen()); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_ALL_APPS); |
| + |
| + // Enter text in the searchbox, the app list should transition to fullscreen |
| + // search. |
| + ui::test::EventGenerator& generator = GetEventGenerator(); |
| + generator.PressKey(ui::KeyboardCode::VKEY_0, 0); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_SEARCH); |
| + |
| + // Delete the text in the searchbox, the app list should transition to |
| + // fullscreen all apps. |
| + generator.PressKey(ui::KeyboardCode::VKEY_BACK, 0); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_ALL_APPS); |
| +} |
| + |
| +// Tests that the app list initializes in peeking with bottom shelf alignment |
| +// and that the state transitions via text input act properly. |
| +TEST_F(AppListPresenterDelegateTest, BottomShelfAlignmentTextStateTransitions) { |
| + // Todo(Newcomer): Investigate mash failures crbug.com/726838 |
| + if (Shell::GetAshConfig() == Config::MASH) |
| + return; |
|
vadimt
2017/06/21 00:05:59
Empty line below.
newcomer
2017/06/21 16:34:47
Done.
|
| + EnableFullscreenAppList(); |
| + app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| + app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); |
| + EXPECT_FALSE(app_list->is_fullscreen()); |
| + EXPECT_EQ(app_list->app_list_state(), app_list::AppListView::PEEKING); |
| + |
| + // Enter text in the searchbox, this should transition the app list to half |
| + // state. |
| + ui::test::EventGenerator& generator = GetEventGenerator(); |
| + generator.PressKey(ui::KeyboardCode::VKEY_0, 0); |
| + EXPECT_EQ(app_list->app_list_state(), app_list::AppListView::HALF); |
| + |
| + // Empty the searchbox, this should transition the app list to it's previous |
| + // state. |
| + generator.PressKey(ui::KeyboardCode::VKEY_BACK, 0); |
| + EXPECT_EQ(app_list->app_list_state(), app_list::AppListView::PEEKING); |
| +} |
| + |
| +// Tests that the app list initializes in fullscreen with maximize mode active |
| +// and that the state transitions via text input act properly. |
| +TEST_F(AppListPresenterDelegateTest, MaximizeModeTextStateTransitions) { |
| + // Todo(Newcomer): Investigate mash failures crbug.com/726838 |
| + if (Shell::GetAshConfig() == Config::MASH) |
| + return; |
| + EnableFullscreenAppList(); |
| + EnableMaximizeMode(true); |
| + app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| + app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_ALL_APPS); |
| + |
| + // Enter text in the searchbox, the app list should transition to fullscreen |
| + // search. |
| + ui::test::EventGenerator& generator = GetEventGenerator(); |
| + generator.PressKey(ui::KeyboardCode::VKEY_0, 0); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_SEARCH); |
| + |
| + // Delete the text in the searchbox, the app list should transition to |
| + // fullscreen all apps. generator.PressKey(ui::KeyboardCode::VKEY_BACK, 0); |
| + generator.PressKey(ui::KeyboardCode::VKEY_BACK, 0); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_ALL_APPS); |
| +} |
| + |
| +// Tests that the app list state responds correctly to maximize mode being |
| +// enabled while the app list is being shown. |
| +TEST_F(AppListPresenterDelegateTest, |
| + PeekingToFullscreenWhenMaximizeModeIsActive) { |
| + // Todo(Newcomer): Investigate mash failures crbug.com/726838 |
| + if (Shell::GetAshConfig() == Config::MASH) |
| + return; |
| + |
| + EnableFullscreenAppList(); |
| + app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| + app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); |
| + EXPECT_EQ(app_list->app_list_state(), app_list::AppListView::PEEKING); |
| + // Enable maximize mode, this should force the app list to switch to the |
| + // fullscreen equivalent of the current state. |
| + EnableMaximizeMode(true); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_ALL_APPS); |
| + // Disable maximize mode, the state of the app list should not change. |
| + EnableMaximizeMode(false); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_ALL_APPS); |
| + // Enter text in the searchbox, the app list should transition to fullscreen |
| + // search. |
| + ui::test::EventGenerator& generator = GetEventGenerator(); |
| + generator.PressKey(ui::KeyboardCode::VKEY_0, 0); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_SEARCH); |
| + |
| + // Delete the text in the searchbox, the app list should transition to |
| + // fullscreen all apps. generator.PressKey(ui::KeyboardCode::VKEY_BACK, 0); |
| + generator.PressKey(ui::KeyboardCode::VKEY_BACK, 0); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_ALL_APPS); |
| +} |
| + |
| +// Tests that the app list state responds correctly to maximize mode being |
| +// enabled while the app list is being shown with half launcher. |
| +TEST_F(AppListPresenterDelegateTest, HalfToFullscreenWhenMaximizeModeIsActive) { |
| + // Todo(Newcomer): Investigate mash failures crbug.com/726838 |
| + if (Shell::GetAshConfig() == Config::MASH) |
| + return; |
| + EnableFullscreenAppList(); |
| + app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| + app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); |
| + EXPECT_EQ(app_list->app_list_state(), app_list::AppListView::PEEKING); |
| + |
| + // Enter text in the search box to transition to half app list. |
| + ui::test::EventGenerator& generator = GetEventGenerator(); |
| + generator.PressKey(ui::KeyboardCode::VKEY_0, 0); |
| + EXPECT_EQ(app_list->app_list_state(), app_list::AppListView::HALF); |
| + |
| + // Enable maximize mode and force the app list to transition to the fullscreen |
| + // equivalent of the current state. |
| + EnableMaximizeMode(true); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_SEARCH); |
| + generator.PressKey(ui::KeyboardCode::VKEY_BACK, 0); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_ALL_APPS); |
| +} |
| + |
| +// Tests that the app list view handles drag properly in laptop mode. |
| +TEST_F(AppListPresenterDelegateTest, AppListViewDragHandler) { |
| + // Todo(Newcomer): Investigate mash failures crbug.com/726838 |
| + if (Shell::GetAshConfig() == Config::MASH) |
| + return; |
| + |
| + EnableFullscreenAppList(); |
| + app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| + app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); |
| + EXPECT_EQ(app_list->app_list_state(), app_list::AppListView::PEEKING); |
| + |
| + ui::test::EventGenerator& generator = GetEventGenerator(); |
| + // Execute a slow short upwards drag this should fail to transition the app |
| + // list. |
| + int top_of_app_list = app_list_presenter_impl() |
| + ->GetView() |
| + ->GetWidget() |
| + ->GetWindowBoundsInScreen() |
| + .y(); |
| + generator.GestureScrollSequence(gfx::Point(0, top_of_app_list + 20), |
| + gfx::Point(0, top_of_app_list - 20), |
| + base::TimeDelta::FromMilliseconds(500), 50); |
| + EXPECT_EQ(app_list->app_list_state(), app_list::AppListView::PEEKING); |
| + |
| + // Execute a long upwards drag, this should transition the app list. |
| + generator.GestureScrollSequence(gfx::Point(10, top_of_app_list + 20), |
| + gfx::Point(10, 10), |
| + base::TimeDelta::FromMilliseconds(100), 10); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_ALL_APPS); |
| + |
| + // Execute a short downward drag, this should fail to transition the app list. |
| + generator.GestureScrollSequence(gfx::Point(10, 10), gfx::Point(10, 100), |
| + base::TimeDelta::FromMilliseconds(100), 10); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_ALL_APPS); |
| + |
| + // Execute a long downward drag, this should transition the app list. |
| + generator.GestureScrollSequence(gfx::Point(10, 10), gfx::Point(10, 900), |
| + base::TimeDelta::FromMilliseconds(100), 10); |
| + EXPECT_EQ(app_list->app_list_state(), app_list::AppListView::PEEKING); |
| + |
| + // Transition to fullscreen. |
| + generator.GestureScrollSequence(gfx::Point(10, top_of_app_list + 20), |
| + gfx::Point(10, 10), |
| + base::TimeDelta::FromMilliseconds(100), 10); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_ALL_APPS); |
| + |
| + // Enter text to transition to |FULLSCREEN_SEARCH|. |
| + generator.PressKey(ui::KeyboardCode::VKEY_0, 0); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_SEARCH); |
| + |
| + // Execute a short downward drag, this should fail to close the app list. |
| + generator.GestureScrollSequence(gfx::Point(10, 10), gfx::Point(10, 100), |
| + base::TimeDelta::FromMilliseconds(100), 10); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_SEARCH); |
| + |
| + // Execute a long downward drag, this should close the app list. |
| + generator.GestureScrollSequence(gfx::Point(10, 10), gfx::Point(10, 900), |
| + base::TimeDelta::FromMilliseconds(100), 10); |
| + EXPECT_FALSE(app_list_presenter_impl()->IsVisible()); |
| +} |
| + |
| +// Tests that the app list view handles drag properly in maximize mode. |
| +TEST_F(AppListPresenterDelegateTest, |
| + AppListViewDragHandlerMaximizeModeFromAllApps) { |
| + // Todo(Newcomer): Investigate mash failures crbug.com/726838 |
| + if (Shell::GetAshConfig() == Config::MASH) |
| + return; |
| + EnableFullscreenAppList(); |
| + EnableMaximizeMode(true); |
| + app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| + app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_ALL_APPS); |
| + |
| + ui::test::EventGenerator& generator = GetEventGenerator(); |
| + // Drag down. |
| + generator.GestureScrollSequence(gfx::Point(0, 0), gfx::Point(0, 720), |
| + base::TimeDelta::FromMilliseconds(100), 10); |
| + EXPECT_FALSE(app_list_presenter_impl()->IsVisible()); |
| +} |
| + |
| +// Tests that the state of the app list changes properly with drag input from |
| +// fullscreen search. |
| +TEST_F(AppListPresenterDelegateTest, |
| + AppListViewDragHandlerMaximizeModeFromSearch) { |
| + // Todo(Newcomer): Investigate mash failures crbug.com/726838 |
| + if (Shell::GetAshConfig() == Config::MASH) |
| + return; |
| + |
| + // Reset the app list. |
| + EnableFullscreenAppList(); |
| + EnableMaximizeMode(true); |
| + app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| + app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_ALL_APPS); |
| + // Type in the search box to transition to |FULLSCREEN_SEARCH|. |
| + ui::test::EventGenerator& generator = GetEventGenerator(); |
| + generator.PressKey(ui::KeyboardCode::VKEY_0, 0); |
| + EXPECT_EQ(app_list->app_list_state(), |
| + app_list::AppListView::FULLSCREEN_SEARCH); |
| + // Drag down, this should close the app list. |
| + generator.GestureScrollSequence(gfx::Point(0, 0), gfx::Point(0, 720), |
| + base::TimeDelta::FromMilliseconds(100), 10); |
| + EXPECT_FALSE(app_list_presenter_impl()->IsVisible()); |
| +} |
| + |
| +// Tests that the bottom shelf background is hidden when the app list is shown |
| +// in laptop mode. |
| +TEST_F(AppListPresenterDelegateTest, |
| + ShelfBackgroundIsHiddenWhenAppListIsShown) { |
| + EnableFullscreenAppList(); |
| + app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| + ShelfLayoutManager* shelf_layout_manager = |
| + Shelf::ForWindow( |
| + ShellPort::Get()->GetRootWindowForDisplayId(GetPrimaryDisplayId())) |
| + ->shelf_layout_manager(); |
| + EXPECT_TRUE(shelf_layout_manager->GetShelfBackgroundType() == |
| + ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT); |
| +} |
| + |
| // Tests that the peeking app list closes if the user taps outside its |
| // bounds. |
| TEST_F(AppListPresenterDelegateTest, TapAndClickOutsideClosesPeekingAppList) { |
| - EnableFullscreenAppList(); |
| + // Todo(Newcomer): Investigate mash failures crbug.com/726838 |
| + if (Shell::GetAshConfig() == Config::MASH) |
| + return; |
| + EnableFullscreenAppList(); |
| app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| ui::test::EventGenerator& generator = GetEventGenerator(); |
| @@ -230,4 +518,54 @@ TEST_F(AppListPresenterDelegateTest, TapAndClickOutsideClosesPeekingAppList) { |
| EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |
| } |
| +// Tests that the half app list closes if the user taps outside its bounds. |
| +TEST_F(AppListPresenterDelegateTest, TapAndClickOutsideClosesHalfAppList) { |
| + // Todo(Newcomer): Investigate mash failures crbug.com/726838 |
| + if (Shell::GetAshConfig() == Config::MASH) |
| + return; |
| + |
| + EnableFullscreenAppList(); |
| + app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| + ui::test::EventGenerator& generator = GetEventGenerator(); |
| + |
| + // Transition to half app list by entering text. |
| + generator.PressKey(ui::KeyboardCode::VKEY_0, 0); |
| + app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); |
| + EXPECT_EQ(app_list->app_list_state(), app_list::AppListView::HALF); |
| + |
| + // Grab the bounds of the search box, |
| + // which is guaranteed to be inside the app list. |
| + gfx::Point tap_point = app_list_presenter_impl() |
| + ->GetView() |
| + ->search_box_widget() |
| + ->GetContentsView() |
| + ->GetBoundsInScreen() |
| + .CenterPoint(); |
| + |
| + // Tapping inside the bounds doesn't close the app list. |
| + generator.GestureTapAt(tap_point); |
| + EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| + EXPECT_EQ(app_list->app_list_state(), app_list::AppListView::HALF); |
| + |
| + // Clicking inside the bounds doesn't close the app list. |
| + generator.MoveMouseTo(tap_point); |
| + generator.ClickLeftButton(); |
| + EXPECT_TRUE(app_list_presenter_impl()->IsVisible()); |
| + EXPECT_EQ(app_list->app_list_state(), app_list::AppListView::HALF); |
| + |
| + // Tapping outside the bounds closes the app list. |
| + generator.GestureTapAt(gfx::Point(10, 10)); |
| + EXPECT_FALSE(app_list_presenter_impl()->IsVisible()); |
| + |
| + // Reset the app list to half state. |
| + app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| + generator.PressKey(ui::KeyboardCode::VKEY_0, 0); |
| + EXPECT_EQ(app_list->app_list_state(), app_list::AppListView::HALF); |
| + |
| + // Clicking outside the bounds closes the app list. |
| + generator.MoveMouseTo(gfx::Point(10, 10)); |
| + generator.ClickLeftButton(); |
| + EXPECT_FALSE(app_list_presenter_impl()->IsVisible()); |
| +} |
| + |
| } // namespace ash |