| 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/chromeos/rotation/tray_rotation_lock.h" | 5 #include "ash/system/chromeos/rotation/tray_rotation_lock.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/common/ash_switches.h" | 9 #include "ash/common/ash_switches.h" |
| 10 #include "ash/common/system/tray/system_tray_delegate.h" | 10 #include "ash/common/system/tray/system_tray_delegate.h" |
| 11 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 11 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 12 #include "ash/common/wm_shell.h" |
| 12 #include "ash/display/display_manager.h" | 13 #include "ash/display/display_manager.h" |
| 13 #include "ash/display/screen_orientation_controller_chromeos.h" | 14 #include "ash/display/screen_orientation_controller_chromeos.h" |
| 14 #include "ash/root_window_controller.h" | 15 #include "ash/root_window_controller.h" |
| 15 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 16 #include "ash/system/status_area_widget.h" | 17 #include "ash/system/status_area_widget.h" |
| 17 #include "ash/system/tray/system_tray.h" | 18 #include "ash/system/tray/system_tray.h" |
| 18 #include "ash/test/ash_test_base.h" | 19 #include "ash/test/ash_test_base.h" |
| 19 #include "ash/test/status_area_widget_test_helper.h" | 20 #include "ash/test/status_area_widget_test_helper.h" |
| 20 #include "base/command_line.h" | 21 #include "base/command_line.h" |
| 21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // 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 |
| 111 // not visible. | 112 // not visible. |
| 112 TEST_F(TrayRotationLockTest, CreateTrayView) { | 113 TEST_F(TrayRotationLockTest, CreateTrayView) { |
| 113 EXPECT_FALSE(tray_view()->visible()); | 114 EXPECT_FALSE(tray_view()->visible()); |
| 114 } | 115 } |
| 115 | 116 |
| 116 // Tests that when the tray view is created, while MaximizeMode is active, that | 117 // Tests that when the tray view is created, while MaximizeMode is active, that |
| 117 // it is not visible. | 118 // it is not visible. |
| 118 TEST_F(TrayRotationLockTest, CreateTrayViewDuringMaximizeMode) { | 119 TEST_F(TrayRotationLockTest, CreateTrayViewDuringMaximizeMode) { |
| 119 TearDownViews(); | 120 TearDownViews(); |
| 120 Shell::GetInstance() | 121 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 121 ->maximize_mode_controller() | 122 true); |
| 122 ->EnableMaximizeModeWindowManager(true); | |
| 123 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); | 123 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); |
| 124 EXPECT_FALSE(tray_view()->visible()); | 124 EXPECT_FALSE(tray_view()->visible()); |
| 125 Shell::GetInstance() | 125 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 126 ->maximize_mode_controller() | 126 false); |
| 127 ->EnableMaximizeModeWindowManager(false); | |
| 128 } | 127 } |
| 129 | 128 |
| 130 // Tests that when the tray view is created, while MaximizeMode is active, and | 129 // Tests that when the tray view is created, while MaximizeMode is active, and |
| 131 // rotation is locked, that it is visible. | 130 // rotation is locked, that it is visible. |
| 132 TEST_F(TrayRotationLockTest, CreateTrayViewDuringMaximizeModeAndRotationLock) { | 131 TEST_F(TrayRotationLockTest, CreateTrayViewDuringMaximizeModeAndRotationLock) { |
| 133 TearDownViews(); | 132 TearDownViews(); |
| 134 Shell::GetInstance() | 133 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 135 ->maximize_mode_controller() | 134 true); |
| 136 ->EnableMaximizeModeWindowManager(true); | |
| 137 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( | 135 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( |
| 138 true); | 136 true); |
| 139 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); | 137 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); |
| 140 EXPECT_TRUE(tray_view()->visible()); | 138 EXPECT_TRUE(tray_view()->visible()); |
| 141 Shell::GetInstance() | 139 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 142 ->maximize_mode_controller() | 140 false); |
| 143 ->EnableMaximizeModeWindowManager(false); | |
| 144 EXPECT_FALSE(tray_view()->visible()); | 141 EXPECT_FALSE(tray_view()->visible()); |
| 145 } | 142 } |
| 146 | 143 |
| 147 // Tests that the enabling of MaximizeMode affects a previously created tray | 144 // Tests that the enabling of MaximizeMode affects a previously created tray |
| 148 // view, changing the visibility. | 145 // view, changing the visibility. |
| 149 TEST_F(TrayRotationLockTest, TrayViewVisibilityChangesDuringMaximizeMode) { | 146 TEST_F(TrayRotationLockTest, TrayViewVisibilityChangesDuringMaximizeMode) { |
| 150 ASSERT_FALSE(tray_view()->visible()); | 147 ASSERT_FALSE(tray_view()->visible()); |
| 151 Shell::GetInstance() | 148 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 152 ->maximize_mode_controller() | 149 true); |
| 153 ->EnableMaximizeModeWindowManager(true); | |
| 154 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( | 150 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( |
| 155 true); | 151 true); |
| 156 EXPECT_TRUE(tray_view()->visible()); | 152 EXPECT_TRUE(tray_view()->visible()); |
| 157 Shell::GetInstance() | 153 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 158 ->maximize_mode_controller() | 154 false); |
| 159 ->EnableMaximizeModeWindowManager(false); | |
| 160 EXPECT_FALSE(tray_view()->visible()); | 155 EXPECT_FALSE(tray_view()->visible()); |
| 161 } | 156 } |
| 162 | 157 |
| 163 // Tests that the when the tray view is created for a secondary display, that | 158 // Tests that the when the tray view is created for a secondary display, that |
| 164 // it is not visible, and that MaximizeMode does not affect visibility. | 159 // it is not visible, and that MaximizeMode does not affect visibility. |
| 165 TEST_F(TrayRotationLockTest, CreateSecondaryTrayView) { | 160 TEST_F(TrayRotationLockTest, CreateSecondaryTrayView) { |
| 166 if (!SupportsMultipleDisplays()) | 161 if (!SupportsMultipleDisplays()) |
| 167 return; | 162 return; |
| 168 UpdateDisplay("400x400,200x200"); | 163 UpdateDisplay("400x400,200x200"); |
| 169 | 164 |
| 170 SetUpForStatusAreaWidget( | 165 SetUpForStatusAreaWidget( |
| 171 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget()); | 166 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget()); |
| 172 EXPECT_FALSE(tray_view()->visible()); | 167 EXPECT_FALSE(tray_view()->visible()); |
| 173 Shell::GetInstance() | 168 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 174 ->maximize_mode_controller() | 169 true); |
| 175 ->EnableMaximizeModeWindowManager(true); | |
| 176 EXPECT_FALSE(tray_view()->visible()); | 170 EXPECT_FALSE(tray_view()->visible()); |
| 177 Shell::GetInstance() | 171 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 178 ->maximize_mode_controller() | 172 false); |
| 179 ->EnableMaximizeModeWindowManager(false); | |
| 180 EXPECT_FALSE(tray_view()->visible()); | 173 EXPECT_FALSE(tray_view()->visible()); |
| 181 } | 174 } |
| 182 | 175 |
| 183 // Tests that when the default view is initially created, that it is created | 176 // Tests that when the default view is initially created, that it is created |
| 184 // not visible. | 177 // not visible. |
| 185 TEST_F(TrayRotationLockTest, CreateDefaultView) { | 178 TEST_F(TrayRotationLockTest, CreateDefaultView) { |
| 186 EXPECT_FALSE(default_view()->visible()); | 179 EXPECT_FALSE(default_view()->visible()); |
| 187 } | 180 } |
| 188 | 181 |
| 189 // Tests that when the default view is created, while MaximizeMode is active, | 182 // Tests that when the default view is created, while MaximizeMode is active, |
| 190 // that it is visible. | 183 // that it is visible. |
| 191 TEST_F(TrayRotationLockTest, CreateDefaultViewDuringMaximizeMode) { | 184 TEST_F(TrayRotationLockTest, CreateDefaultViewDuringMaximizeMode) { |
| 192 TearDownViews(); | 185 TearDownViews(); |
| 193 Shell::GetInstance() | 186 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 194 ->maximize_mode_controller() | 187 true); |
| 195 ->EnableMaximizeModeWindowManager(true); | |
| 196 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); | 188 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); |
| 197 EXPECT_TRUE(default_view()->visible()); | 189 EXPECT_TRUE(default_view()->visible()); |
| 198 Shell::GetInstance() | 190 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 199 ->maximize_mode_controller() | 191 false); |
| 200 ->EnableMaximizeModeWindowManager(false); | |
| 201 } | 192 } |
| 202 | 193 |
| 203 // Tests that the enabling of MaximizeMode affects a previously created default | 194 // Tests that the enabling of MaximizeMode affects a previously created default |
| 204 // view, changing the visibility. | 195 // view, changing the visibility. |
| 205 TEST_F(TrayRotationLockTest, DefaultViewVisibilityChangesDuringMaximizeMode) { | 196 TEST_F(TrayRotationLockTest, DefaultViewVisibilityChangesDuringMaximizeMode) { |
| 206 Shell::GetInstance() | 197 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 207 ->maximize_mode_controller() | 198 true); |
| 208 ->EnableMaximizeModeWindowManager(true); | |
| 209 EXPECT_TRUE(default_view()->visible()); | 199 EXPECT_TRUE(default_view()->visible()); |
| 210 Shell::GetInstance() | 200 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 211 ->maximize_mode_controller() | 201 false); |
| 212 ->EnableMaximizeModeWindowManager(false); | |
| 213 EXPECT_FALSE(default_view()->visible()); | 202 EXPECT_FALSE(default_view()->visible()); |
| 214 } | 203 } |
| 215 | 204 |
| 216 // Tests that no default view is created when the target is a secondary | 205 // Tests that no default view is created when the target is a secondary |
| 217 // display. | 206 // display. |
| 218 TEST_F(TrayRotationLockTest, CreateSecondaryDefaultView) { | 207 TEST_F(TrayRotationLockTest, CreateSecondaryDefaultView) { |
| 219 if (!SupportsMultipleDisplays()) | 208 if (!SupportsMultipleDisplays()) |
| 220 return; | 209 return; |
| 221 UpdateDisplay("400x400,200x200"); | 210 UpdateDisplay("400x400,200x200"); |
| 222 | 211 |
| 223 TearDownViews(); | 212 TearDownViews(); |
| 224 SetUpForStatusAreaWidget( | 213 SetUpForStatusAreaWidget( |
| 225 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget()); | 214 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget()); |
| 226 EXPECT_EQ(NULL, default_view()); | 215 EXPECT_EQ(NULL, default_view()); |
| 227 } | 216 } |
| 228 | 217 |
| 229 // Tests that activating the default view causes the display to have its | 218 // Tests that activating the default view causes the display to have its |
| 230 // rotation locked, and that the tray view becomes visible. | 219 // rotation locked, and that the tray view becomes visible. |
| 231 TEST_F(TrayRotationLockTest, PerformActionOnDefaultView) { | 220 TEST_F(TrayRotationLockTest, PerformActionOnDefaultView) { |
| 232 MaximizeModeController* maximize_mode_controller = | 221 MaximizeModeController* maximize_mode_controller = |
| 233 Shell::GetInstance()->maximize_mode_controller(); | 222 WmShell::Get()->maximize_mode_controller(); |
| 234 ScreenOrientationController* screen_orientation_controller = | 223 ScreenOrientationController* screen_orientation_controller = |
| 235 Shell::GetInstance()->screen_orientation_controller(); | 224 Shell::GetInstance()->screen_orientation_controller(); |
| 236 ASSERT_FALSE(screen_orientation_controller->rotation_locked()); | 225 ASSERT_FALSE(screen_orientation_controller->rotation_locked()); |
| 237 maximize_mode_controller->EnableMaximizeModeWindowManager(true); | 226 maximize_mode_controller->EnableMaximizeModeWindowManager(true); |
| 238 ASSERT_FALSE(tray_view()->visible()); | 227 ASSERT_FALSE(tray_view()->visible()); |
| 239 | 228 |
| 240 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), | 229 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), |
| 241 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | 230 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); |
| 242 default_view()->OnGestureEvent(&tap); | 231 default_view()->OnGestureEvent(&tap); |
| 243 EXPECT_TRUE(screen_orientation_controller->rotation_locked()); | 232 EXPECT_TRUE(screen_orientation_controller->rotation_locked()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 254 display::Display::SetInternalDisplayId(display::Display::kInvalidDisplayID); | 243 display::Display::SetInternalDisplayId(display::Display::kInvalidDisplayID); |
| 255 | 244 |
| 256 std::unique_ptr<TrayRotationLock> tray(new TrayRotationLock( | 245 std::unique_ptr<TrayRotationLock> tray(new TrayRotationLock( |
| 257 StatusAreaWidgetTestHelper::GetStatusAreaWidget()->system_tray())); | 246 StatusAreaWidgetTestHelper::GetStatusAreaWidget()->system_tray())); |
| 258 | 247 |
| 259 display::Display::SetInternalDisplayId(internal_display_id); | 248 display::Display::SetInternalDisplayId(internal_display_id); |
| 260 std::unique_ptr<views::View> tray_view(CreateTrayView(tray.get())); | 249 std::unique_ptr<views::View> tray_view(CreateTrayView(tray.get())); |
| 261 std::unique_ptr<views::View> default_view(tray->CreateDefaultView( | 250 std::unique_ptr<views::View> default_view(tray->CreateDefaultView( |
| 262 StatusAreaWidgetTestHelper::GetUserLoginStatus())); | 251 StatusAreaWidgetTestHelper::GetUserLoginStatus())); |
| 263 EXPECT_TRUE(default_view); | 252 EXPECT_TRUE(default_view); |
| 264 Shell::GetInstance() | 253 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 265 ->maximize_mode_controller() | 254 true); |
| 266 ->EnableMaximizeModeWindowManager(true); | |
| 267 EXPECT_TRUE(default_view->visible()); | 255 EXPECT_TRUE(default_view->visible()); |
| 268 } | 256 } |
| 269 | 257 |
| 270 // Tests that when the tray view is deleted, while TrayRotationLock has not been | 258 // Tests that when the tray view is deleted, while TrayRotationLock has not been |
| 271 // deleted, that updates to the rotation lock state do not crash. | 259 // deleted, that updates to the rotation lock state do not crash. |
| 272 TEST_F(TrayRotationLockTest, LockUpdatedDuringDesctruction) { | 260 TEST_F(TrayRotationLockTest, LockUpdatedDuringDesctruction) { |
| 273 Shell::GetInstance() | 261 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 274 ->maximize_mode_controller() | 262 true); |
| 275 ->EnableMaximizeModeWindowManager(true); | |
| 276 DestroyTrayView(); | 263 DestroyTrayView(); |
| 277 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( | 264 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( |
| 278 true); | 265 true); |
| 279 Shell::GetInstance() | 266 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 280 ->maximize_mode_controller() | 267 false); |
| 281 ->EnableMaximizeModeWindowManager(false); | |
| 282 } | 268 } |
| 283 | 269 |
| 284 } // namespace ash | 270 } // namespace ash |
| OLD | NEW |