OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ash/system/rotation/tray_rotation_lock.h" | 5 #include "ash/system/rotation/tray_rotation_lock.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "ash/display/screen_orientation_controller_chromeos.h" | 9 #include "ash/display/screen_orientation_controller_chromeos.h" |
10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "ash/system/status_area_widget.h" | 12 #include "ash/system/status_area_widget.h" |
13 #include "ash/system/tray/system_tray.h" | 13 #include "ash/system/tray/system_tray.h" |
14 #include "ash/system/tray/system_tray_delegate.h" | 14 #include "ash/system/tray/system_tray_delegate.h" |
15 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
16 #include "ash/test/status_area_widget_test_helper.h" | 16 #include "ash/test/status_area_widget_test_helper.h" |
17 #include "ash/wm/tablet_mode/tablet_mode_controller.h" | 17 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
20 #include "ui/display/display_switches.h" | 20 #include "ui/display/display_switches.h" |
21 #include "ui/display/manager/display_manager.h" | 21 #include "ui/display/manager/display_manager.h" |
22 #include "ui/display/types/display_constants.h" | 22 #include "ui/display/types/display_constants.h" |
23 #include "ui/events/event.h" | 23 #include "ui/events/event.h" |
24 #include "ui/events/event_constants.h" | 24 #include "ui/events/event_constants.h" |
25 #include "ui/views/view.h" | 25 #include "ui/views/view.h" |
26 | 26 |
27 namespace ash { | 27 namespace ash { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 TearDownViews(); | 107 TearDownViews(); |
108 test::AshTestBase::TearDown(); | 108 test::AshTestBase::TearDown(); |
109 } | 109 } |
110 | 110 |
111 // Tests that when the tray view is initially created, that it is created | 111 // Tests that when the tray view is initially created, that it is created |
112 // not visible. | 112 // not visible. |
113 TEST_F(TrayRotationLockTest, CreateTrayView) { | 113 TEST_F(TrayRotationLockTest, CreateTrayView) { |
114 EXPECT_FALSE(tray_view()->visible()); | 114 EXPECT_FALSE(tray_view()->visible()); |
115 } | 115 } |
116 | 116 |
117 // Tests that when the tray view is created, while TabletMode is active, that | 117 // Tests that when the tray view is created, while MaximizeMode is active, that |
118 // it must be visible, and becomes invisible exiting TabletMode. | 118 // it must be visible, and becomes invisible exiting MaximizeMode. |
119 TEST_F(TrayRotationLockTest, CreateTrayViewDuringTabletMode) { | 119 TEST_F(TrayRotationLockTest, CreateTrayViewDuringMaximizeMode) { |
120 TearDownViews(); | 120 TearDownViews(); |
121 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); | 121 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 122 true); |
122 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); | 123 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); |
123 EXPECT_TRUE(tray_view()->visible()); | 124 EXPECT_TRUE(tray_view()->visible()); |
124 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false); | 125 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 126 false); |
125 EXPECT_FALSE(tray_view()->visible()); | 127 EXPECT_FALSE(tray_view()->visible()); |
126 } | 128 } |
127 | 129 |
128 // Tests that the enabling of TabletMode affects a previously created tray | 130 // Tests that the enabling of MaximizeMode affects a previously created tray |
129 // view, changing the visibility. | 131 // view, changing the visibility. |
130 TEST_F(TrayRotationLockTest, TrayViewVisibilityChangesDuringTabletMode) { | 132 TEST_F(TrayRotationLockTest, TrayViewVisibilityChangesDuringMaximizeMode) { |
131 ASSERT_FALSE(tray_view()->visible()); | 133 ASSERT_FALSE(tray_view()->visible()); |
132 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); | 134 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 135 true); |
133 Shell::Get()->screen_orientation_controller()->ToggleUserRotationLock(); | 136 Shell::Get()->screen_orientation_controller()->ToggleUserRotationLock(); |
134 EXPECT_TRUE(tray_view()->visible()); | 137 EXPECT_TRUE(tray_view()->visible()); |
135 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false); | 138 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 139 false); |
136 EXPECT_FALSE(tray_view()->visible()); | 140 EXPECT_FALSE(tray_view()->visible()); |
137 } | 141 } |
138 | 142 |
139 // Tests that when the tray view is created for a secondary display, that it is | 143 // Tests that when the tray view is created for a secondary display, that it is |
140 // not visible, and that TabletMode does not affect visibility. | 144 // not visible, and that MaximizeMode does not affect visibility. |
141 TEST_F(TrayRotationLockTest, CreateSecondaryTrayView) { | 145 TEST_F(TrayRotationLockTest, CreateSecondaryTrayView) { |
142 UpdateDisplay("400x400,200x200"); | 146 UpdateDisplay("400x400,200x200"); |
143 | 147 |
144 SetUpForStatusAreaWidget( | 148 SetUpForStatusAreaWidget( |
145 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget()); | 149 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget()); |
146 EXPECT_FALSE(tray_view()->visible()); | 150 EXPECT_FALSE(tray_view()->visible()); |
147 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); | 151 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 152 true); |
148 EXPECT_FALSE(tray_view()->visible()); | 153 EXPECT_FALSE(tray_view()->visible()); |
149 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false); | 154 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 155 false); |
150 EXPECT_FALSE(tray_view()->visible()); | 156 EXPECT_FALSE(tray_view()->visible()); |
151 } | 157 } |
152 | 158 |
153 // Tests that when the default view is initially created, that it is created | 159 // Tests that when the default view is initially created, that it is created |
154 // not visible. | 160 // not visible. |
155 TEST_F(TrayRotationLockTest, CreateDefaultView) { | 161 TEST_F(TrayRotationLockTest, CreateDefaultView) { |
156 EXPECT_FALSE(default_view()->visible()); | 162 EXPECT_FALSE(default_view()->visible()); |
157 } | 163 } |
158 | 164 |
159 // Tests that when the default view is created, while TabletMode is active, | 165 // Tests that when the default view is created, while MaximizeMode is active, |
160 // that it is visible. | 166 // that it is visible. |
161 TEST_F(TrayRotationLockTest, CreateDefaultViewDuringTabletMode) { | 167 TEST_F(TrayRotationLockTest, CreateDefaultViewDuringMaximizeMode) { |
162 TearDownViews(); | 168 TearDownViews(); |
163 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); | 169 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 170 true); |
164 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); | 171 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); |
165 EXPECT_TRUE(default_view()->visible()); | 172 EXPECT_TRUE(default_view()->visible()); |
166 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false); | 173 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 174 false); |
167 EXPECT_FALSE(default_view()->visible()); | 175 EXPECT_FALSE(default_view()->visible()); |
168 } | 176 } |
169 | 177 |
170 // Tests that the enabling of TabletMode affects a previously created default | 178 // Tests that the enabling of MaximizeMode affects a previously created default |
171 // view, changing the visibility. | 179 // view, changing the visibility. |
172 TEST_F(TrayRotationLockTest, DefaultViewVisibilityChangesDuringTabletMode) { | 180 TEST_F(TrayRotationLockTest, DefaultViewVisibilityChangesDuringMaximizeMode) { |
173 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); | 181 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 182 true); |
174 EXPECT_TRUE(default_view()->visible()); | 183 EXPECT_TRUE(default_view()->visible()); |
175 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false); | 184 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 185 false); |
176 EXPECT_FALSE(default_view()->visible()); | 186 EXPECT_FALSE(default_view()->visible()); |
177 } | 187 } |
178 | 188 |
179 // Tests that no default view is created when the target is a secondary | 189 // Tests that no default view is created when the target is a secondary |
180 // display. | 190 // display. |
181 TEST_F(TrayRotationLockTest, CreateSecondaryDefaultView) { | 191 TEST_F(TrayRotationLockTest, CreateSecondaryDefaultView) { |
182 UpdateDisplay("400x400,200x200"); | 192 UpdateDisplay("400x400,200x200"); |
183 | 193 |
184 TearDownViews(); | 194 TearDownViews(); |
185 SetUpForStatusAreaWidget( | 195 SetUpForStatusAreaWidget( |
186 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget()); | 196 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget()); |
187 EXPECT_EQ(NULL, default_view()); | 197 EXPECT_EQ(NULL, default_view()); |
188 } | 198 } |
189 | 199 |
190 // Tests that activating the default view causes the display to have its | 200 // Tests that activating the default view causes the display to have its |
191 // rotation locked. | 201 // rotation locked. |
192 TEST_F(TrayRotationLockTest, PerformActionOnDefaultView) { | 202 TEST_F(TrayRotationLockTest, PerformActionOnDefaultView) { |
193 TabletModeController* tablet_mode_controller = | 203 MaximizeModeController* maximize_mode_controller = |
194 Shell::Get()->tablet_mode_controller(); | 204 Shell::Get()->maximize_mode_controller(); |
195 ScreenOrientationController* screen_orientation_controller = | 205 ScreenOrientationController* screen_orientation_controller = |
196 Shell::Get()->screen_orientation_controller(); | 206 Shell::Get()->screen_orientation_controller(); |
197 ASSERT_FALSE(screen_orientation_controller->rotation_locked()); | 207 ASSERT_FALSE(screen_orientation_controller->rotation_locked()); |
198 tablet_mode_controller->EnableTabletModeWindowManager(true); | 208 maximize_mode_controller->EnableMaximizeModeWindowManager(true); |
199 ASSERT_TRUE(tray_view()->visible()); | 209 ASSERT_TRUE(tray_view()->visible()); |
200 | 210 |
201 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), | 211 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), |
202 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | 212 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
203 default_view()->OnGestureEvent(&tap); | 213 default_view()->OnGestureEvent(&tap); |
204 EXPECT_TRUE(screen_orientation_controller->rotation_locked()); | 214 EXPECT_TRUE(screen_orientation_controller->rotation_locked()); |
205 EXPECT_TRUE(tray_view()->visible()); | 215 EXPECT_TRUE(tray_view()->visible()); |
206 | 216 |
207 tablet_mode_controller->EnableTabletModeWindowManager(false); | 217 maximize_mode_controller->EnableMaximizeModeWindowManager(false); |
208 } | 218 } |
209 | 219 |
210 // Tests that when the tray is created without the internal display being known, | 220 // Tests that when the tray is created without the internal display being known, |
211 // that it will still display correctly once the internal display is known. | 221 // that it will still display correctly once the internal display is known. |
212 TEST_F(TrayRotationLockTest, InternalDisplayNotAvailableAtCreation) { | 222 TEST_F(TrayRotationLockTest, InternalDisplayNotAvailableAtCreation) { |
213 int64_t internal_display_id = display::Display::InternalDisplayId(); | 223 int64_t internal_display_id = display::Display::InternalDisplayId(); |
214 TearDownViews(); | 224 TearDownViews(); |
215 display::Display::SetInternalDisplayId(display::kInvalidDisplayId); | 225 display::Display::SetInternalDisplayId(display::kInvalidDisplayId); |
216 | 226 |
217 std::unique_ptr<TrayRotationLock> tray(new TrayRotationLock( | 227 std::unique_ptr<TrayRotationLock> tray(new TrayRotationLock( |
218 StatusAreaWidgetTestHelper::GetStatusAreaWidget()->system_tray())); | 228 StatusAreaWidgetTestHelper::GetStatusAreaWidget()->system_tray())); |
219 | 229 |
220 display::Display::SetInternalDisplayId(internal_display_id); | 230 display::Display::SetInternalDisplayId(internal_display_id); |
221 std::unique_ptr<views::View> tray_view(CreateTrayView(tray.get())); | 231 std::unique_ptr<views::View> tray_view(CreateTrayView(tray.get())); |
222 std::unique_ptr<views::View> default_view(tray->CreateDefaultView( | 232 std::unique_ptr<views::View> default_view(tray->CreateDefaultView( |
223 StatusAreaWidgetTestHelper::GetUserLoginStatus())); | 233 StatusAreaWidgetTestHelper::GetUserLoginStatus())); |
224 EXPECT_TRUE(default_view); | 234 EXPECT_TRUE(default_view); |
225 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); | 235 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 236 true); |
226 EXPECT_TRUE(default_view->visible()); | 237 EXPECT_TRUE(default_view->visible()); |
227 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false); | 238 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 239 false); |
228 } | 240 } |
229 | 241 |
230 // Tests that when the tray view is deleted, while TrayRotationLock has not been | 242 // Tests that when the tray view is deleted, while TrayRotationLock has not been |
231 // deleted, that updates to the rotation lock state do not crash. | 243 // deleted, that updates to the rotation lock state do not crash. |
232 TEST_F(TrayRotationLockTest, LockUpdatedDuringDesctruction) { | 244 TEST_F(TrayRotationLockTest, LockUpdatedDuringDesctruction) { |
233 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); | 245 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 246 true); |
234 DestroyTrayView(); | 247 DestroyTrayView(); |
235 Shell::Get()->screen_orientation_controller()->ToggleUserRotationLock(); | 248 Shell::Get()->screen_orientation_controller()->ToggleUserRotationLock(); |
236 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false); | 249 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 250 false); |
237 } | 251 } |
238 | 252 |
239 } // namespace ash | 253 } // namespace ash |
OLD | NEW |