Chromium Code Reviews| 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/common/wm_shell.h" | 7 #include "ash/common/wm_shell.h" |
| 8 #include "ash/common/wm_window.h" | 8 #include "ash/common/wm_window.h" |
| 9 #include "ash/public/cpp/shell_window_ids.h" | 9 #include "ash/public/cpp/shell_window_ids.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/test/test_app_list_view_presenter_impl.h" | 12 #include "ash/test/test_app_list_view_presenter_impl.h" |
| 13 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "ui/app_list/views/app_list_view.h" | 15 #include "ui/app_list/views/app_list_view.h" |
| 16 #include "ui/aura/test/test_windows.h" | 16 #include "ui/aura/test/test_windows.h" |
| 17 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 18 #include "ui/display/manager/display_manager.h" | 18 #include "ui/display/display.h" |
| 19 #include "ui/display/screen.h" | |
| 19 #include "ui/events/test/event_generator.h" | 20 #include "ui/events/test/event_generator.h" |
| 20 | 21 |
| 21 namespace ash { | 22 namespace ash { |
| 23 namespace { | |
| 24 | |
| 25 int64_t GetPrimaryDisplayId() { | |
|
msw
2017/04/06 18:43:22
optional nit: Add this to AshTestBase/AshTestHelpe
sky
2017/04/06 19:00:11
I think this (and some of the other utility functi
| |
| 26 return display::Screen::GetScreen()->GetPrimaryDisplay().id(); | |
| 27 } | |
| 28 } // namespace | |
|
msw
2017/04/06 18:43:22
nit: blank line above
sky
2017/04/06 19:00:11
Done.
| |
| 22 | 29 |
| 23 class AppListPresenterDelegateTest : public test::AshTestBase { | 30 class AppListPresenterDelegateTest : public test::AshTestBase { |
| 24 public: | 31 public: |
| 25 AppListPresenterDelegateTest() {} | 32 AppListPresenterDelegateTest() {} |
| 26 ~AppListPresenterDelegateTest() override {} | 33 ~AppListPresenterDelegateTest() override {} |
| 27 | 34 |
| 28 app_list::AppListPresenterImpl* app_list_presenter_impl() { | 35 app_list::AppListPresenterImpl* app_list_presenter_impl() { |
| 29 return &app_list_presenter_impl_; | 36 return &app_list_presenter_impl_; |
| 30 } | 37 } |
| 31 | 38 |
| 32 // testing::Test: | 39 // testing::Test: |
| 33 void SetUp() override { | 40 void SetUp() override { |
| 34 AshTestBase::SetUp(); | 41 AshTestBase::SetUp(); |
| 35 | 42 |
| 36 // Make the display big enough to hold the app list. | 43 // Make the display big enough to hold the app list. |
| 37 UpdateDisplay("1024x768"); | 44 UpdateDisplay("1024x768"); |
| 38 } | 45 } |
| 39 | 46 |
| 40 private: | 47 private: |
| 41 test::TestAppListViewPresenterImpl app_list_presenter_impl_; | 48 test::TestAppListViewPresenterImpl app_list_presenter_impl_; |
| 42 | 49 |
| 43 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateTest); | 50 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateTest); |
| 44 }; | 51 }; |
| 45 | 52 |
| 46 // Tests that app launcher hides when focus moves to a normal window. | 53 // Tests that app launcher hides when focus moves to a normal window. |
| 47 TEST_F(AppListPresenterDelegateTest, HideOnFocusOut) { | 54 TEST_F(AppListPresenterDelegateTest, HideOnFocusOut) { |
| 48 app_list_presenter_impl()->Show(display_manager()->first_display_id()); | 55 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| 49 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 56 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 50 | 57 |
| 51 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 58 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 52 wm::ActivateWindow(window.get()); | 59 wm::ActivateWindow(window.get()); |
| 53 | 60 |
| 54 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); | 61 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |
| 55 } | 62 } |
| 56 | 63 |
| 57 // Tests that app launcher remains visible when focus is moved to a different | 64 // Tests that app launcher remains visible when focus is moved to a different |
| 58 // window in kShellWindowId_AppListContainer. | 65 // window in kShellWindowId_AppListContainer. |
| 59 TEST_F(AppListPresenterDelegateTest, | 66 TEST_F(AppListPresenterDelegateTest, |
| 60 RemainVisibleWhenFocusingToApplistContainer) { | 67 RemainVisibleWhenFocusingToApplistContainer) { |
| 61 app_list_presenter_impl()->Show(display_manager()->first_display_id()); | 68 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| 62 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 69 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 63 | 70 |
| 64 aura::Window* applist_container = Shell::GetContainer( | 71 aura::Window* applist_container = Shell::GetContainer( |
| 65 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); | 72 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); |
| 66 std::unique_ptr<aura::Window> window( | 73 std::unique_ptr<aura::Window> window( |
| 67 aura::test::CreateTestWindowWithId(0, applist_container)); | 74 aura::test::CreateTestWindowWithId(0, applist_container)); |
| 68 wm::ActivateWindow(window.get()); | 75 wm::ActivateWindow(window.get()); |
| 69 | 76 |
| 70 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 77 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 71 } | 78 } |
| 72 | 79 |
| 73 // Tests that clicking outside the app-list bubble closes it. | 80 // Tests that clicking outside the app-list bubble closes it. |
| 74 TEST_F(AppListPresenterDelegateTest, ClickOutsideBubbleClosesBubble) { | 81 TEST_F(AppListPresenterDelegateTest, ClickOutsideBubbleClosesBubble) { |
| 75 app_list_presenter_impl()->Show(display_manager()->first_display_id()); | 82 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| 76 aura::Window* app_window = app_list_presenter_impl()->GetWindow(); | 83 aura::Window* app_window = app_list_presenter_impl()->GetWindow(); |
| 77 ASSERT_TRUE(app_window); | 84 ASSERT_TRUE(app_window); |
| 78 ui::test::EventGenerator& generator = GetEventGenerator(); | 85 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 79 // Click on the bubble itself. The bubble should remain visible. | 86 // Click on the bubble itself. The bubble should remain visible. |
| 80 generator.MoveMouseToCenterOf(app_window); | 87 generator.MoveMouseToCenterOf(app_window); |
| 81 generator.ClickLeftButton(); | 88 generator.ClickLeftButton(); |
| 82 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 89 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 83 | 90 |
| 84 // Click outside the bubble. This should close it. | 91 // Click outside the bubble. This should close it. |
| 85 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); | 92 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); |
| 86 gfx::Point point_outside = | 93 gfx::Point point_outside = |
| 87 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + | 94 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + |
| 88 gfx::Vector2d(10, 0); | 95 gfx::Vector2d(10, 0); |
| 89 generator.MoveMouseToInHost(point_outside); | 96 generator.MoveMouseToInHost(point_outside); |
| 90 generator.ClickLeftButton(); | 97 generator.ClickLeftButton(); |
| 91 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); | 98 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |
| 92 } | 99 } |
| 93 | 100 |
| 94 // Tests that clicking outside the app-list bubble closes it. | 101 // Tests that clicking outside the app-list bubble closes it. |
| 95 TEST_F(AppListPresenterDelegateTest, TapOutsideBubbleClosesBubble) { | 102 TEST_F(AppListPresenterDelegateTest, TapOutsideBubbleClosesBubble) { |
| 96 app_list_presenter_impl()->Show(display_manager()->first_display_id()); | 103 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| 97 | 104 |
| 98 aura::Window* app_window = app_list_presenter_impl()->GetWindow(); | 105 aura::Window* app_window = app_list_presenter_impl()->GetWindow(); |
| 99 ASSERT_TRUE(app_window); | 106 ASSERT_TRUE(app_window); |
| 100 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); | 107 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); |
| 101 | 108 |
| 102 ui::test::EventGenerator& generator = GetEventGenerator(); | 109 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 103 // Click on the bubble itself. The bubble should remain visible. | 110 // Click on the bubble itself. The bubble should remain visible. |
| 104 generator.GestureTapAt(app_window_bounds.CenterPoint()); | 111 generator.GestureTapAt(app_window_bounds.CenterPoint()); |
| 105 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 112 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 106 | 113 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 133 // Updating the displays should close the app list. | 140 // Updating the displays should close the app list. |
| 134 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); | 141 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |
| 135 } | 142 } |
| 136 | 143 |
| 137 // Tests opening the app launcher on a tiny display that is too small to contain | 144 // Tests opening the app launcher on a tiny display that is too small to contain |
| 138 // it. | 145 // it. |
| 139 TEST_F(AppListPresenterDelegateTest, TinyDisplay) { | 146 TEST_F(AppListPresenterDelegateTest, TinyDisplay) { |
| 140 // Set up a screen with a tiny display (height smaller than the app list). | 147 // Set up a screen with a tiny display (height smaller than the app list). |
| 141 UpdateDisplay("400x300"); | 148 UpdateDisplay("400x300"); |
| 142 | 149 |
| 143 app_list_presenter_impl()->Show(display_manager()->first_display_id()); | 150 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
| 144 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 151 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
| 145 | 152 |
| 146 // The top of the app list should be on-screen (even if the bottom is not). | 153 // The top of the app list should be on-screen (even if the bottom is not). |
| 147 // We need to manually calculate the Y coordinate of the top of the app list | 154 // We need to manually calculate the Y coordinate of the top of the app list |
| 148 // from the anchor (center) and height. There isn't a bounds rect that gives | 155 // from the anchor (center) and height. There isn't a bounds rect that gives |
| 149 // the actual app list position (the widget bounds include the bubble border | 156 // the actual app list position (the widget bounds include the bubble border |
| 150 // which is much bigger than the actual app list size). | 157 // which is much bigger than the actual app list size). |
| 151 app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); | 158 app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); |
| 152 int app_list_view_top = | 159 int app_list_view_top = |
| 153 app_list->anchor_rect().y() - app_list->bounds().height() / 2; | 160 app_list->anchor_rect().y() - app_list->bounds().height() / 2; |
| 154 const int kMinimalAppListMargin = 10; | 161 const int kMinimalAppListMargin = 10; |
| 155 EXPECT_GE(app_list_view_top, kMinimalAppListMargin); | 162 EXPECT_GE(app_list_view_top, kMinimalAppListMargin); |
| 156 } | 163 } |
| 157 | 164 |
| 158 } // namespace ash | 165 } // namespace ash |
| OLD | NEW |