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/public/cpp/shell_window_ids.h" | 8 #include "ash/public/cpp/shell_window_ids.h" |
8 #include "ash/shell.h" | 9 #include "ash/shell.h" |
9 #include "ash/shell_port.h" | 10 #include "ash/shell_port.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 "ash/wm_window.h" | 14 #include "ash/wm_window.h" |
15 #include "base/command_line.h" | |
14 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "ui/app_list/app_list_switches.h" | |
15 #include "ui/app_list/views/app_list_view.h" | 18 #include "ui/app_list/views/app_list_view.h" |
16 #include "ui/aura/test/test_windows.h" | 19 #include "ui/aura/test/test_windows.h" |
17 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
18 #include "ui/display/display.h" | 21 #include "ui/display/display.h" |
19 #include "ui/display/screen.h" | 22 #include "ui/display/screen.h" |
20 #include "ui/events/test/event_generator.h" | 23 #include "ui/events/test/event_generator.h" |
21 | 24 |
22 namespace ash { | 25 namespace ash { |
23 namespace { | 26 namespace { |
24 | 27 |
25 int64_t GetPrimaryDisplayId() { | 28 int64_t GetPrimaryDisplayId() { |
26 return display::Screen::GetScreen()->GetPrimaryDisplay().id(); | 29 return display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
27 } | 30 } |
28 | 31 |
29 } // namespace | 32 } // namespace |
30 | 33 |
31 class AppListPresenterDelegateTest : public test::AshTestBase { | 34 class AppListPresenterDelegateTest |
35 : public test::AshTestBase, | |
36 public testing::WithParamInterface<bool> { | |
32 public: | 37 public: |
33 AppListPresenterDelegateTest() {} | 38 AppListPresenterDelegateTest() {} |
34 ~AppListPresenterDelegateTest() override {} | 39 ~AppListPresenterDelegateTest() override {} |
35 | 40 |
36 app_list::AppListPresenterImpl* app_list_presenter_impl() { | 41 app_list::AppListPresenterImpl* app_list_presenter_impl() { |
37 return &app_list_presenter_impl_; | 42 return &app_list_presenter_impl_; |
38 } | 43 } |
39 | 44 |
40 // testing::Test: | 45 // testing::Test: |
41 void SetUp() override { | 46 void SetUp() override { |
42 AshTestBase::SetUp(); | 47 AshTestBase::SetUp(); |
43 | 48 |
49 // If the current test is parameterized. | |
50 if (testing::UnitTest::GetInstance()->current_test_info()->value_param()){ | |
51 test_with_fullscreen = GetParam(); | |
52 if (test_with_fullscreen) | |
53 app_list::switches::SetFullscreenAppListSwitch(); | |
54 } | |
44 // Make the display big enough to hold the app list. | 55 // Make the display big enough to hold the app list. |
45 UpdateDisplay("1024x768"); | 56 UpdateDisplay("1024x768"); |
46 } | 57 } |
47 | 58 |
48 private: | 59 private: |
49 test::TestAppListViewPresenterImpl app_list_presenter_impl_; | 60 test::TestAppListViewPresenterImpl app_list_presenter_impl_; |
61 bool test_with_fullscreen; | |
vadimt
2017/04/20 20:21:34
add "_"
newcomer
2017/04/21 19:51:22
Done.
| |
50 | 62 |
51 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateTest); | 63 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateTest); |
52 }; | 64 }; |
53 | 65 |
66 // Instantiate the Boolean which is used to toggle the Fullscreen app list in | |
67 // the parameterized tests. | |
68 INSTANTIATE_TEST_CASE_P(, AppListPresenterDelegateTest, testing::Bool()); | |
69 | |
54 // Tests that app launcher hides when focus moves to a normal window. | 70 // Tests that app launcher hides when focus moves to a normal window. |
55 TEST_F(AppListPresenterDelegateTest, HideOnFocusOut) { | 71 TEST_P(AppListPresenterDelegateTest, HideOnFocusOut) { |
56 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); | 72 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
57 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 73 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
58 | 74 |
59 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 75 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
60 wm::ActivateWindow(window.get()); | 76 wm::ActivateWindow(window.get()); |
61 | 77 |
62 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); | 78 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |
63 } | 79 } |
64 | 80 |
65 // Tests that app launcher remains visible when focus is moved to a different | 81 // Tests that app launcher remains visible when focus is moved to a different |
66 // window in kShellWindowId_AppListContainer. | 82 // window in kShellWindowId_AppListContainer. |
67 TEST_F(AppListPresenterDelegateTest, | 83 TEST_P(AppListPresenterDelegateTest, |
68 RemainVisibleWhenFocusingToApplistContainer) { | 84 RemainVisibleWhenFocusingToApplistContainer) { |
69 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); | 85 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
70 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 86 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
71 | 87 |
72 aura::Window* applist_container = Shell::GetContainer( | 88 aura::Window* applist_container = Shell::GetContainer( |
73 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); | 89 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); |
74 std::unique_ptr<aura::Window> window( | 90 std::unique_ptr<aura::Window> window( |
75 aura::test::CreateTestWindowWithId(0, applist_container)); | 91 aura::test::CreateTestWindowWithId(0, applist_container)); |
76 wm::ActivateWindow(window.get()); | 92 wm::ActivateWindow(window.get()); |
77 | 93 |
78 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 94 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
79 } | 95 } |
80 | 96 |
81 // Tests that clicking outside the app-list bubble closes it. | 97 // Tests that clicking outside the app-list bubble closes it. |
82 TEST_F(AppListPresenterDelegateTest, ClickOutsideBubbleClosesBubble) { | 98 TEST_P(AppListPresenterDelegateTest, ClickOutsideBubbleClosesBubble) { |
83 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); | 99 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
84 aura::Window* app_window = app_list_presenter_impl()->GetWindow(); | 100 aura::Window* app_window = app_list_presenter_impl()->GetWindow(); |
85 ASSERT_TRUE(app_window); | 101 ASSERT_TRUE(app_window); |
86 ui::test::EventGenerator& generator = GetEventGenerator(); | 102 ui::test::EventGenerator& generator = GetEventGenerator(); |
87 // Click on the bubble itself. The bubble should remain visible. | 103 // Click on the bubble itself. The bubble should remain visible. |
88 generator.MoveMouseToCenterOf(app_window); | 104 generator.MoveMouseToCenterOf(app_window); |
89 generator.ClickLeftButton(); | 105 generator.ClickLeftButton(); |
90 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 106 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
91 | 107 |
92 // Click outside the bubble. This should close it. | 108 // Click outside the bubble. This should close it. |
93 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); | 109 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); |
94 gfx::Point point_outside = | 110 gfx::Point point_outside = |
95 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + | 111 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + |
96 gfx::Vector2d(10, 0); | 112 gfx::Vector2d(10, 0); |
97 generator.MoveMouseToInHost(point_outside); | 113 generator.MoveMouseToInHost(point_outside); |
98 generator.ClickLeftButton(); | 114 generator.ClickLeftButton(); |
99 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); | 115 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |
100 } | 116 } |
101 | 117 |
102 // Tests that clicking outside the app-list bubble closes it. | 118 // Tests that clicking outside the app-list bubble closes it. |
103 TEST_F(AppListPresenterDelegateTest, TapOutsideBubbleClosesBubble) { | 119 TEST_P(AppListPresenterDelegateTest, TapOutsideBubbleClosesBubble) { |
104 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); | 120 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
105 | 121 |
106 aura::Window* app_window = app_list_presenter_impl()->GetWindow(); | 122 aura::Window* app_window = app_list_presenter_impl()->GetWindow(); |
107 ASSERT_TRUE(app_window); | 123 ASSERT_TRUE(app_window); |
108 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); | 124 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); |
109 | 125 |
110 ui::test::EventGenerator& generator = GetEventGenerator(); | 126 ui::test::EventGenerator& generator = GetEventGenerator(); |
111 // Click on the bubble itself. The bubble should remain visible. | 127 // Click on the bubble itself. The bubble should remain visible. |
112 generator.GestureTapAt(app_window_bounds.CenterPoint()); | 128 generator.GestureTapAt(app_window_bounds.CenterPoint()); |
113 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 129 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
114 | 130 |
115 // Click outside the bubble. This should close it. | 131 // Click outside the bubble. This should close it. |
116 gfx::Point point_outside = | 132 gfx::Point point_outside = |
117 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + | 133 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + |
118 gfx::Vector2d(10, 0); | 134 gfx::Vector2d(10, 0); |
119 generator.GestureTapAt(point_outside); | 135 generator.GestureTapAt(point_outside); |
120 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); | 136 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |
121 } | 137 } |
122 | 138 |
123 // Tests opening the app launcher on a non-primary display, then deleting the | 139 // Tests opening the app launcher on a non-primary display, then deleting the |
124 // display. | 140 // display. |
125 TEST_F(AppListPresenterDelegateTest, NonPrimaryDisplay) { | 141 TEST_P(AppListPresenterDelegateTest, NonPrimaryDisplay) { |
126 // Set up a screen with two displays (horizontally adjacent). | 142 // Set up a screen with two displays (horizontally adjacent). |
127 UpdateDisplay("1024x768,1024x768"); | 143 UpdateDisplay("1024x768,1024x768"); |
128 | 144 |
129 std::vector<WmWindow*> root_windows = ShellPort::Get()->GetAllRootWindows(); | 145 std::vector<WmWindow*> root_windows = ShellPort::Get()->GetAllRootWindows(); |
130 ASSERT_EQ(2u, root_windows.size()); | 146 ASSERT_EQ(2u, root_windows.size()); |
131 WmWindow* secondary_root = root_windows[1]; | 147 WmWindow* secondary_root = root_windows[1]; |
132 EXPECT_EQ("1024,0 1024x768", secondary_root->GetBoundsInScreen().ToString()); | 148 EXPECT_EQ("1024,0 1024x768", secondary_root->GetBoundsInScreen().ToString()); |
133 | 149 |
134 app_list_presenter_impl()->Show( | 150 app_list_presenter_impl()->Show( |
135 secondary_root->GetDisplayNearestWindow().id()); | 151 secondary_root->GetDisplayNearestWindow().id()); |
(...skipping 13 matching lines...) Expand all Loading... | |
149 UpdateDisplay("400x300"); | 165 UpdateDisplay("400x300"); |
150 | 166 |
151 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); | 167 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
152 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 168 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
153 | 169 |
154 // The top of the app list should be on-screen (even if the bottom is not). | 170 // The top of the app list should be on-screen (even if the bottom is not). |
155 // We need to manually calculate the Y coordinate of the top of the app list | 171 // We need to manually calculate the Y coordinate of the top of the app list |
156 // from the anchor (center) and height. There isn't a bounds rect that gives | 172 // from the anchor (center) and height. There isn't a bounds rect that gives |
157 // the actual app list position (the widget bounds include the bubble border | 173 // the actual app list position (the widget bounds include the bubble border |
158 // which is much bigger than the actual app list size). | 174 // which is much bigger than the actual app list size). |
175 | |
159 app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); | 176 app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); |
160 int app_list_view_top = | 177 int app_list_view_top = |
161 app_list->anchor_rect().y() - app_list->bounds().height() / 2; | 178 app_list->anchor_rect().y() - app_list->bounds().height() / 2; |
162 const int kMinimalAppListMargin = 10; | 179 const int kMinimalAppListMargin = 10; |
180 | |
163 EXPECT_GE(app_list_view_top, kMinimalAppListMargin); | 181 EXPECT_GE(app_list_view_top, kMinimalAppListMargin); |
164 } | 182 } |
165 | 183 |
166 } // namespace ash | 184 } // namespace ash |
OLD | NEW |