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 WmShell::Get()->ShowAppList(); |
97 shell->ShowAppList(NULL); | |
98 aura::Window* app_window = GetAppListPresenter()->GetWindow(); | 99 aura::Window* app_window = GetAppListPresenter()->GetWindow(); |
99 ASSERT_TRUE(app_window); | 100 ASSERT_TRUE(app_window); |
100 ui::test::EventGenerator generator(shell->GetPrimaryRootWindow(), app_window); | 101 ui::test::EventGenerator& generator = GetEventGenerator(); |
101 // Click on the bubble itself. The bubble should remain visible. | 102 // Click on the bubble itself. The bubble should remain visible. |
| 103 generator.MoveMouseToCenterOf(app_window); |
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)); | |
111 generator.MoveMouseToInHost(point_outside); | 112 generator.MoveMouseToInHost(point_outside); |
112 generator.ClickLeftButton(); | 113 generator.ClickLeftButton(); |
113 EXPECT_FALSE(shell->GetAppListTargetVisibility()); | 114 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); |
114 } | 115 } |
115 | 116 |
116 // Tests that clicking outside the app-list bubble closes it. | 117 // Tests that clicking outside the app-list bubble closes it. |
117 TEST_P(AppListPresenterDelegateTest, TapOutsideBubbleClosesBubble) { | 118 TEST_P(AppListPresenterDelegateTest, TapOutsideBubbleClosesBubble) { |
118 Shell* shell = Shell::GetInstance(); | 119 WmShell::Get()->ShowAppList(); |
119 shell->ShowAppList(NULL); | |
120 | 120 |
121 aura::Window* app_window = GetAppListPresenter()->GetWindow(); | 121 aura::Window* app_window = GetAppListPresenter()->GetWindow(); |
122 ASSERT_TRUE(app_window); | 122 ASSERT_TRUE(app_window); |
123 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); | 123 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); |
124 | 124 |
125 ui::test::EventGenerator generator(shell->GetPrimaryRootWindow()); | 125 ui::test::EventGenerator& generator = GetEventGenerator(); |
126 // Click on the bubble itself. The bubble should remain visible. | 126 // Click on the bubble itself. The bubble should remain visible. |
127 generator.GestureTapAt(app_window_bounds.CenterPoint()); | 127 generator.GestureTapAt(app_window_bounds.CenterPoint()); |
128 EXPECT_TRUE(shell->GetAppListTargetVisibility()); | 128 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); |
129 | 129 |
130 // Click outside the bubble. This should close it. | 130 // Click outside the bubble. This should close it. |
131 gfx::Point point_outside = | 131 gfx::Point point_outside = |
132 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + | 132 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + |
133 gfx::Vector2d(10, 0); | 133 gfx::Vector2d(10, 0); |
134 EXPECT_TRUE(shell->GetPrimaryRootWindow()->bounds().Contains(point_outside)); | |
135 generator.GestureTapAt(point_outside); | 134 generator.GestureTapAt(point_outside); |
136 EXPECT_FALSE(shell->GetAppListTargetVisibility()); | 135 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); |
137 } | 136 } |
138 | 137 |
139 // Tests opening the app launcher on a non-primary display, then deleting the | 138 // Tests opening the app launcher on a non-primary display, then deleting the |
140 // display. | 139 // display. |
141 TEST_P(AppListPresenterDelegateTest, NonPrimaryDisplay) { | 140 TEST_P(AppListPresenterDelegateTest, NonPrimaryDisplay) { |
142 if (!SupportsMultipleDisplays()) | 141 if (!SupportsMultipleDisplays()) |
143 return; | 142 return; |
144 | 143 |
145 // Set up a screen with two displays (horizontally adjacent). | 144 // Set up a screen with two displays (horizontally adjacent). |
146 UpdateDisplay("1024x768,1024x768"); | 145 UpdateDisplay("1024x768,1024x768"); |
147 | 146 |
148 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 147 std::vector<WmWindow*> root_windows = WmShell::Get()->GetAllRootWindows(); |
149 ASSERT_EQ(2u, root_windows.size()); | 148 ASSERT_EQ(2u, root_windows.size()); |
150 aura::Window* secondary_window = root_windows[1]; | 149 WmWindow* secondary_root = root_windows[1]; |
151 EXPECT_EQ("1024,0 1024x768", | 150 EXPECT_EQ("1024,0 1024x768", secondary_root->GetBoundsInScreen().ToString()); |
152 secondary_window->GetBoundsInScreen().ToString()); | |
153 | 151 |
154 Shell::GetInstance()->ShowAppList(secondary_window); | 152 WmShell::Get()->delegate()->GetAppListPresenter()->Show( |
155 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 153 secondary_root->GetDisplayNearestWindow().id()); |
| 154 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); |
156 | 155 |
157 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). | 156 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). |
158 UpdateDisplay("1024x768"); | 157 UpdateDisplay("1024x768"); |
159 | 158 |
160 // Updating the displays should close the app list. | 159 // Updating the displays should close the app list. |
161 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); | 160 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); |
162 } | 161 } |
163 | 162 |
164 // Tests opening the app launcher on a tiny display that is too small to contain | 163 // Tests opening the app launcher on a tiny display that is too small to contain |
165 // it. | 164 // it. |
166 TEST_P(AppListPresenterDelegateTest, TinyDisplay) { | 165 TEST_P(AppListPresenterDelegateTest, TinyDisplay) { |
167 // Don't test this for the non-centered app list case; it isn't designed for | 166 // 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 | 167 // 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 | 168 // virtual keyboard is open --- switches into the centered app list mode, so |
170 // we just want to run this test in that case. | 169 // we just want to run this test in that case. |
171 if (!IsCentered()) | 170 if (!IsCentered()) |
172 return; | 171 return; |
173 | 172 |
174 // UpdateDisplay is not supported in this case, so just skip the test. | 173 // UpdateDisplay is not supported in this case, so just skip the test. |
175 if (!SupportsHostWindowResize()) | 174 if (!SupportsHostWindowResize()) |
176 return; | 175 return; |
177 | 176 |
178 // Set up a screen with a tiny display (height smaller than the app list). | 177 // Set up a screen with a tiny display (height smaller than the app list). |
179 UpdateDisplay("400x300"); | 178 UpdateDisplay("400x300"); |
180 | 179 |
181 Shell::GetInstance()->ShowAppList(NULL); | 180 WmShell::Get()->ShowAppList(); |
182 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 181 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); |
183 | 182 |
184 // The top of the app list should be on-screen (even if the bottom is not). | 183 // 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 | 184 // 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 | 185 // 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 | 186 // the actual app list position (the widget bounds include the bubble border |
188 // which is much bigger than the actual app list size). | 187 // which is much bigger than the actual app list size). |
189 app_list::AppListView* app_list = GetAppListPresenter()->GetView(); | 188 app_list::AppListView* app_list = GetAppListPresenter()->GetView(); |
190 int app_list_view_top = | 189 int app_list_view_top = |
191 app_list->anchor_rect().y() - app_list->bounds().height() / 2; | 190 app_list->anchor_rect().y() - app_list->bounds().height() / 2; |
192 EXPECT_GE(app_list_view_top, kMinimalCenteredAppListMargin); | 191 EXPECT_GE(app_list_view_top, kMinimalCenteredAppListMargin); |
193 } | 192 } |
194 | 193 |
195 INSTANTIATE_TEST_CASE_P(AppListPresenterDelegateTestInstance, | 194 INSTANTIATE_TEST_CASE_P(AppListPresenterDelegateTestInstance, |
196 AppListPresenterDelegateTest, | 195 AppListPresenterDelegateTest, |
197 ::testing::Bool()); | 196 ::testing::Bool()); |
198 | 197 |
199 } // namespace ash | 198 } // namespace ash |
OLD | NEW |