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/shell_window_ids.h" | 7 #include "ash/common/shell_window_ids.h" |
| 8 #include "ash/common/wm_shell.h" |
| 9 #include "ash/common/wm_window.h" |
8 #include "ash/shell.h" | 10 #include "ash/shell.h" |
9 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
10 #include "ash/test/ash_test_helper.h" | 12 #include "ash/test/ash_test_helper.h" |
11 #include "ash/test/test_shell_delegate.h" | 13 #include "ash/test/test_shell_delegate.h" |
12 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
13 #include "base/command_line.h" | 15 #include "base/command_line.h" |
14 #include "ui/app_list/app_list_switches.h" | 16 #include "ui/app_list/app_list_switches.h" |
15 #include "ui/app_list/presenter/app_list_presenter_impl.h" | 17 #include "ui/app_list/presenter/app_list_presenter_impl.h" |
16 #include "ui/app_list/views/app_list_view.h" | 18 #include "ui/app_list/views/app_list_view.h" |
17 #include "ui/aura/test/test_windows.h" | 19 #include "ui/aura/test/test_windows.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 AppListPresenterDelegateTest::GetAppListPresenter() { | 61 AppListPresenterDelegateTest::GetAppListPresenter() { |
60 return ash_test_helper()->test_shell_delegate()->app_list_presenter(); | 62 return ash_test_helper()->test_shell_delegate()->app_list_presenter(); |
61 } | 63 } |
62 | 64 |
63 bool AppListPresenterDelegateTest::IsCentered() const { | 65 bool AppListPresenterDelegateTest::IsCentered() const { |
64 return GetParam(); | 66 return GetParam(); |
65 } | 67 } |
66 | 68 |
67 // Tests that app launcher hides when focus moves to a normal window. | 69 // Tests that app launcher hides when focus moves to a normal window. |
68 TEST_P(AppListPresenterDelegateTest, HideOnFocusOut) { | 70 TEST_P(AppListPresenterDelegateTest, HideOnFocusOut) { |
69 Shell::GetInstance()->ShowAppList(NULL); | 71 WmShell::Get()->ShowAppList(); |
70 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 72 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); |
71 | 73 |
72 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 74 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
73 wm::ActivateWindow(window.get()); | 75 wm::ActivateWindow(window.get()); |
74 | 76 |
75 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); | 77 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); |
76 } | 78 } |
77 | 79 |
78 // Tests that app launcher remains visible when focus is moved to a different | 80 // Tests that app launcher remains visible when focus is moved to a different |
79 // window in kShellWindowId_AppListContainer. | 81 // window in kShellWindowId_AppListContainer. |
80 TEST_P(AppListPresenterDelegateTest, | 82 TEST_P(AppListPresenterDelegateTest, |
81 RemainVisibleWhenFocusingToApplistContainer) { | 83 RemainVisibleWhenFocusingToApplistContainer) { |
82 Shell::GetInstance()->ShowAppList(NULL); | 84 WmShell::Get()->ShowAppList(); |
83 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 85 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); |
84 | 86 |
85 aura::Window* applist_container = Shell::GetContainer( | 87 aura::Window* applist_container = Shell::GetContainer( |
86 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); | 88 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); |
87 std::unique_ptr<aura::Window> window( | 89 std::unique_ptr<aura::Window> window( |
88 aura::test::CreateTestWindowWithId(0, applist_container)); | 90 aura::test::CreateTestWindowWithId(0, applist_container)); |
89 wm::ActivateWindow(window.get()); | 91 wm::ActivateWindow(window.get()); |
90 | 92 |
91 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 93 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); |
92 } | 94 } |
93 | 95 |
94 // Tests that clicking outside the app-list bubble closes it. | 96 // Tests that clicking outside the app-list bubble closes it. |
95 TEST_P(AppListPresenterDelegateTest, ClickOutsideBubbleClosesBubble) { | 97 TEST_P(AppListPresenterDelegateTest, ClickOutsideBubbleClosesBubble) { |
96 Shell* shell = Shell::GetInstance(); | 98 Shell* shell = Shell::GetInstance(); |
97 shell->ShowAppList(NULL); | 99 WmShell::Get()->ShowAppList(); |
98 aura::Window* app_window = GetAppListPresenter()->GetWindow(); | 100 aura::Window* app_window = GetAppListPresenter()->GetWindow(); |
99 ASSERT_TRUE(app_window); | 101 ASSERT_TRUE(app_window); |
100 ui::test::EventGenerator generator(shell->GetPrimaryRootWindow(), app_window); | 102 ui::test::EventGenerator generator(shell->GetPrimaryRootWindow(), app_window); |
101 // Click on the bubble itself. The bubble should remain visible. | 103 // Click on the bubble itself. The bubble should remain visible. |
102 generator.ClickLeftButton(); | 104 generator.ClickLeftButton(); |
103 EXPECT_TRUE(shell->GetAppListTargetVisibility()); | 105 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); |
104 | 106 |
105 // Click outside the bubble. This should close it. | 107 // Click outside the bubble. This should close it. |
106 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); | 108 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); |
107 gfx::Point point_outside = | 109 gfx::Point point_outside = |
108 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + | 110 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + |
109 gfx::Vector2d(10, 0); | 111 gfx::Vector2d(10, 0); |
110 EXPECT_TRUE(shell->GetPrimaryRootWindow()->bounds().Contains(point_outside)); | 112 EXPECT_TRUE(shell->GetPrimaryRootWindow()->bounds().Contains(point_outside)); |
111 generator.MoveMouseToInHost(point_outside); | 113 generator.MoveMouseToInHost(point_outside); |
112 generator.ClickLeftButton(); | 114 generator.ClickLeftButton(); |
113 EXPECT_FALSE(shell->GetAppListTargetVisibility()); | 115 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); |
114 } | 116 } |
115 | 117 |
116 // Tests that clicking outside the app-list bubble closes it. | 118 // Tests that clicking outside the app-list bubble closes it. |
117 TEST_P(AppListPresenterDelegateTest, TapOutsideBubbleClosesBubble) { | 119 TEST_P(AppListPresenterDelegateTest, TapOutsideBubbleClosesBubble) { |
118 Shell* shell = Shell::GetInstance(); | 120 Shell* shell = Shell::GetInstance(); |
119 shell->ShowAppList(NULL); | 121 WmShell::Get()->ShowAppList(); |
120 | 122 |
121 aura::Window* app_window = GetAppListPresenter()->GetWindow(); | 123 aura::Window* app_window = GetAppListPresenter()->GetWindow(); |
122 ASSERT_TRUE(app_window); | 124 ASSERT_TRUE(app_window); |
123 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); | 125 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); |
124 | 126 |
125 ui::test::EventGenerator generator(shell->GetPrimaryRootWindow()); | 127 ui::test::EventGenerator& generator = GetEventGenerator(); |
126 // Click on the bubble itself. The bubble should remain visible. | 128 // Click on the bubble itself. The bubble should remain visible. |
127 generator.GestureTapAt(app_window_bounds.CenterPoint()); | 129 generator.GestureTapAt(app_window_bounds.CenterPoint()); |
128 EXPECT_TRUE(shell->GetAppListTargetVisibility()); | 130 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); |
129 | 131 |
130 // Click outside the bubble. This should close it. | 132 // Click outside the bubble. This should close it. |
131 gfx::Point point_outside = | 133 gfx::Point point_outside = |
132 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + | 134 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + |
133 gfx::Vector2d(10, 0); | 135 gfx::Vector2d(10, 0); |
134 EXPECT_TRUE(shell->GetPrimaryRootWindow()->bounds().Contains(point_outside)); | 136 EXPECT_TRUE(shell->GetPrimaryRootWindow()->bounds().Contains(point_outside)); |
135 generator.GestureTapAt(point_outside); | 137 generator.GestureTapAt(point_outside); |
136 EXPECT_FALSE(shell->GetAppListTargetVisibility()); | 138 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); |
137 } | 139 } |
138 | 140 |
139 // Tests opening the app launcher on a non-primary display, then deleting the | 141 // Tests opening the app launcher on a non-primary display, then deleting the |
140 // display. | 142 // display. |
141 TEST_P(AppListPresenterDelegateTest, NonPrimaryDisplay) { | 143 TEST_P(AppListPresenterDelegateTest, NonPrimaryDisplay) { |
142 if (!SupportsMultipleDisplays()) | 144 if (!SupportsMultipleDisplays()) |
143 return; | 145 return; |
144 | 146 |
145 // Set up a screen with two displays (horizontally adjacent). | 147 // Set up a screen with two displays (horizontally adjacent). |
146 UpdateDisplay("1024x768,1024x768"); | 148 UpdateDisplay("1024x768,1024x768"); |
147 | 149 |
148 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 150 std::vector<WmWindow*> root_windows = WmShell::Get()->GetAllRootWindows(); |
149 ASSERT_EQ(2u, root_windows.size()); | 151 ASSERT_EQ(2u, root_windows.size()); |
150 aura::Window* secondary_window = root_windows[1]; | 152 WmWindow* secondary_root = root_windows[1]; |
151 EXPECT_EQ("1024,0 1024x768", | 153 EXPECT_EQ("1024,0 1024x768", secondary_root->GetBoundsInScreen().ToString()); |
152 secondary_window->GetBoundsInScreen().ToString()); | |
153 | 154 |
154 Shell::GetInstance()->ShowAppList(secondary_window); | 155 WmShell::Get()->delegate()->GetAppListPresenter()->Show( |
155 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 156 secondary_root->GetDisplayNearestWindow().id()); |
| 157 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); |
156 | 158 |
157 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). | 159 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). |
158 UpdateDisplay("1024x768"); | 160 UpdateDisplay("1024x768"); |
159 | 161 |
160 // Updating the displays should close the app list. | 162 // Updating the displays should close the app list. |
161 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); | 163 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); |
162 } | 164 } |
163 | 165 |
164 // Tests opening the app launcher 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 |
165 // it. | 167 // it. |
166 TEST_P(AppListPresenterDelegateTest, TinyDisplay) { | 168 TEST_P(AppListPresenterDelegateTest, TinyDisplay) { |
167 // Don't test this for the non-centered app list case; it isn't designed for | 169 // Don't test this for the non-centered app list case; it isn't designed for |
168 // small displays. The most common case of a small display --- when the | 170 // small displays. The most common case of a small display --- when the |
169 // virtual keyboard is open --- switches into the centered app list mode, so | 171 // virtual keyboard is open --- switches into the centered app list mode, so |
170 // we just want to run this test in that case. | 172 // we just want to run this test in that case. |
171 if (!IsCentered()) | 173 if (!IsCentered()) |
172 return; | 174 return; |
173 | 175 |
174 // UpdateDisplay is not supported in this case, so just skip the test. | 176 // UpdateDisplay is not supported in this case, so just skip the test. |
175 if (!SupportsHostWindowResize()) | 177 if (!SupportsHostWindowResize()) |
176 return; | 178 return; |
177 | 179 |
178 // Set up a screen with a tiny display (height smaller than the app list). | 180 // Set up a screen with a tiny display (height smaller than the app list). |
179 UpdateDisplay("400x300"); | 181 UpdateDisplay("400x300"); |
180 | 182 |
181 Shell::GetInstance()->ShowAppList(NULL); | 183 WmShell::Get()->ShowAppList(); |
182 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 184 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); |
183 | 185 |
184 // The top of the app list should be on-screen (even if the bottom is not). | 186 // The top of the app list should be on-screen (even if the bottom is not). |
185 // We need to manually calculate the Y coordinate of the top of the app list | 187 // We need to manually calculate the Y coordinate of the top of the app list |
186 // from the anchor (center) and height. There isn't a bounds rect that gives | 188 // from the anchor (center) and height. There isn't a bounds rect that gives |
187 // the actual app list position (the widget bounds include the bubble border | 189 // the actual app list position (the widget bounds include the bubble border |
188 // which is much bigger than the actual app list size). | 190 // which is much bigger than the actual app list size). |
189 app_list::AppListView* app_list = GetAppListPresenter()->GetView(); | 191 app_list::AppListView* app_list = GetAppListPresenter()->GetView(); |
190 int app_list_view_top = | 192 int app_list_view_top = |
191 app_list->anchor_rect().y() - app_list->bounds().height() / 2; | 193 app_list->anchor_rect().y() - app_list->bounds().height() / 2; |
192 EXPECT_GE(app_list_view_top, kMinimalCenteredAppListMargin); | 194 EXPECT_GE(app_list_view_top, kMinimalCenteredAppListMargin); |
193 } | 195 } |
194 | 196 |
195 INSTANTIATE_TEST_CASE_P(AppListPresenterDelegateTestInstance, | 197 INSTANTIATE_TEST_CASE_P(AppListPresenterDelegateTestInstance, |
196 AppListPresenterDelegateTest, | 198 AppListPresenterDelegateTest, |
197 ::testing::Bool()); | 199 ::testing::Bool()); |
198 | 200 |
199 } // namespace ash | 201 } // namespace ash |
OLD | NEW |