| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/system/chromeos/rotation/tray_rotation_lock.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "ash/common/system/status_area_widget.h" | |
| 10 #include "ash/common/system/tray/system_tray.h" | |
| 11 #include "ash/common/system/tray/system_tray_delegate.h" | |
| 12 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | |
| 13 #include "ash/common/wm_shell.h" | |
| 14 #include "ash/display/screen_orientation_controller_chromeos.h" | |
| 15 #include "ash/root_window_controller.h" | |
| 16 #include "ash/shell.h" | |
| 17 #include "ash/test/ash_test_base.h" | |
| 18 #include "ash/test/status_area_widget_test_helper.h" | |
| 19 #include "base/command_line.h" | |
| 20 #include "base/time/time.h" | |
| 21 #include "ui/display/display_switches.h" | |
| 22 #include "ui/display/manager/display_manager.h" | |
| 23 #include "ui/display/types/display_constants.h" | |
| 24 #include "ui/events/event.h" | |
| 25 #include "ui/events/event_constants.h" | |
| 26 #include "ui/views/view.h" | |
| 27 | |
| 28 namespace ash { | |
| 29 | |
| 30 class TrayRotationLockTest : public test::AshTestBase { | |
| 31 public: | |
| 32 TrayRotationLockTest() {} | |
| 33 ~TrayRotationLockTest() override {} | |
| 34 | |
| 35 TrayRotationLock* tray() { return tray_.get(); } | |
| 36 | |
| 37 views::View* tray_view() { return tray_view_.get(); } | |
| 38 | |
| 39 views::View* default_view() { return default_view_.get(); } | |
| 40 | |
| 41 // Creates the tray view associated to |tray_rotation_lock|. | |
| 42 views::View* CreateTrayView(TrayRotationLock* tray_rotation_lock); | |
| 43 | |
| 44 // Destroys only the |tray_view_|. Tests may call this to simulate destruction | |
| 45 // order during the deletion of the StatusAreaWidget. | |
| 46 void DestroyTrayView(); | |
| 47 | |
| 48 // Sets up a TrayRotationLock, its tray view, and its default view, for the | |
| 49 // given SystemTray and its display. On a primary display all will be | |
| 50 // created. On a secondary display both the tray view and default view will | |
| 51 // be null. | |
| 52 void SetUpForStatusAreaWidget(StatusAreaWidget* status_area_widget); | |
| 53 | |
| 54 // Resets |tray_| |tray_view_| and |default_view_| so that all components of | |
| 55 // TrayRotationLock have been cleared. Tests may then call | |
| 56 // SetUpForStatusAreaWidget in order to initial the components. | |
| 57 void TearDownViews(); | |
| 58 | |
| 59 // test::AshTestBase: | |
| 60 void SetUp() override; | |
| 61 void TearDown() override; | |
| 62 | |
| 63 private: | |
| 64 std::unique_ptr<TrayRotationLock> tray_; | |
| 65 std::unique_ptr<views::View> tray_view_; | |
| 66 std::unique_ptr<views::View> default_view_; | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(TrayRotationLockTest); | |
| 69 }; | |
| 70 | |
| 71 views::View* TrayRotationLockTest::CreateTrayView( | |
| 72 TrayRotationLock* tray_rotation_lock) { | |
| 73 return tray_rotation_lock->CreateTrayView( | |
| 74 StatusAreaWidgetTestHelper::GetUserLoginStatus()); | |
| 75 } | |
| 76 | |
| 77 void TrayRotationLockTest::DestroyTrayView() { | |
| 78 tray_view_.reset(); | |
| 79 tray_->DestroyTrayView(); | |
| 80 } | |
| 81 | |
| 82 void TrayRotationLockTest::SetUpForStatusAreaWidget( | |
| 83 StatusAreaWidget* status_area_widget) { | |
| 84 tray_.reset(new TrayRotationLock(status_area_widget->system_tray())); | |
| 85 tray_view_.reset( | |
| 86 tray_->CreateTrayView(StatusAreaWidgetTestHelper::GetUserLoginStatus())); | |
| 87 default_view_.reset(tray_->CreateDefaultView( | |
| 88 StatusAreaWidgetTestHelper::GetUserLoginStatus())); | |
| 89 } | |
| 90 | |
| 91 void TrayRotationLockTest::TearDownViews() { | |
| 92 tray_view_.reset(); | |
| 93 default_view_.reset(); | |
| 94 tray_.reset(); | |
| 95 } | |
| 96 | |
| 97 void TrayRotationLockTest::SetUp() { | |
| 98 // The Display used for testing is not an internal display. This flag | |
| 99 // allows for DisplayManager to treat it as one. TrayRotationLock is only | |
| 100 // visible on internal primary displays. | |
| 101 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 102 ::switches::kUseFirstDisplayAsInternal); | |
| 103 test::AshTestBase::SetUp(); | |
| 104 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); | |
| 105 } | |
| 106 | |
| 107 void TrayRotationLockTest::TearDown() { | |
| 108 TearDownViews(); | |
| 109 test::AshTestBase::TearDown(); | |
| 110 } | |
| 111 | |
| 112 // Tests that when the tray view is initially created, that it is created | |
| 113 // not visible. | |
| 114 TEST_F(TrayRotationLockTest, CreateTrayView) { | |
| 115 EXPECT_FALSE(tray_view()->visible()); | |
| 116 } | |
| 117 | |
| 118 // Tests that when the tray view is created, while MaximizeMode is active, that | |
| 119 // it is not visible. | |
| 120 TEST_F(TrayRotationLockTest, CreateTrayViewDuringMaximizeMode) { | |
| 121 TearDownViews(); | |
| 122 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 123 true); | |
| 124 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); | |
| 125 EXPECT_FALSE(tray_view()->visible()); | |
| 126 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 127 false); | |
| 128 } | |
| 129 | |
| 130 // Tests that when the tray view is created, while MaximizeMode is active, and | |
| 131 // rotation is locked, that it is visible. | |
| 132 TEST_F(TrayRotationLockTest, CreateTrayViewDuringMaximizeModeAndRotationLock) { | |
| 133 TearDownViews(); | |
| 134 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 135 true); | |
| 136 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( | |
| 137 true); | |
| 138 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); | |
| 139 EXPECT_TRUE(tray_view()->visible()); | |
| 140 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 141 false); | |
| 142 EXPECT_FALSE(tray_view()->visible()); | |
| 143 } | |
| 144 | |
| 145 // Tests that the enabling of MaximizeMode affects a previously created tray | |
| 146 // view, changing the visibility. | |
| 147 TEST_F(TrayRotationLockTest, TrayViewVisibilityChangesDuringMaximizeMode) { | |
| 148 ASSERT_FALSE(tray_view()->visible()); | |
| 149 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 150 true); | |
| 151 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( | |
| 152 true); | |
| 153 EXPECT_TRUE(tray_view()->visible()); | |
| 154 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 155 false); | |
| 156 EXPECT_FALSE(tray_view()->visible()); | |
| 157 } | |
| 158 | |
| 159 // Tests that the when the tray view is created for a secondary display, that | |
| 160 // it is not visible, and that MaximizeMode does not affect visibility. | |
| 161 TEST_F(TrayRotationLockTest, CreateSecondaryTrayView) { | |
| 162 UpdateDisplay("400x400,200x200"); | |
| 163 | |
| 164 SetUpForStatusAreaWidget( | |
| 165 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget()); | |
| 166 EXPECT_FALSE(tray_view()->visible()); | |
| 167 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 168 true); | |
| 169 EXPECT_FALSE(tray_view()->visible()); | |
| 170 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 171 false); | |
| 172 EXPECT_FALSE(tray_view()->visible()); | |
| 173 } | |
| 174 | |
| 175 // Tests that when the default view is initially created, that it is created | |
| 176 // not visible. | |
| 177 TEST_F(TrayRotationLockTest, CreateDefaultView) { | |
| 178 EXPECT_FALSE(default_view()->visible()); | |
| 179 } | |
| 180 | |
| 181 // Tests that when the default view is created, while MaximizeMode is active, | |
| 182 // that it is visible. | |
| 183 TEST_F(TrayRotationLockTest, CreateDefaultViewDuringMaximizeMode) { | |
| 184 TearDownViews(); | |
| 185 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 186 true); | |
| 187 SetUpForStatusAreaWidget(StatusAreaWidgetTestHelper::GetStatusAreaWidget()); | |
| 188 EXPECT_TRUE(default_view()->visible()); | |
| 189 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 190 false); | |
| 191 } | |
| 192 | |
| 193 // Tests that the enabling of MaximizeMode affects a previously created default | |
| 194 // view, changing the visibility. | |
| 195 TEST_F(TrayRotationLockTest, DefaultViewVisibilityChangesDuringMaximizeMode) { | |
| 196 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 197 true); | |
| 198 EXPECT_TRUE(default_view()->visible()); | |
| 199 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 200 false); | |
| 201 EXPECT_FALSE(default_view()->visible()); | |
| 202 } | |
| 203 | |
| 204 // Tests that no default view is created when the target is a secondary | |
| 205 // display. | |
| 206 TEST_F(TrayRotationLockTest, CreateSecondaryDefaultView) { | |
| 207 UpdateDisplay("400x400,200x200"); | |
| 208 | |
| 209 TearDownViews(); | |
| 210 SetUpForStatusAreaWidget( | |
| 211 StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget()); | |
| 212 EXPECT_EQ(NULL, default_view()); | |
| 213 } | |
| 214 | |
| 215 // Tests that activating the default view causes the display to have its | |
| 216 // rotation locked, and that the tray view becomes visible. | |
| 217 TEST_F(TrayRotationLockTest, PerformActionOnDefaultView) { | |
| 218 MaximizeModeController* maximize_mode_controller = | |
| 219 WmShell::Get()->maximize_mode_controller(); | |
| 220 ScreenOrientationController* screen_orientation_controller = | |
| 221 Shell::GetInstance()->screen_orientation_controller(); | |
| 222 ASSERT_FALSE(screen_orientation_controller->rotation_locked()); | |
| 223 maximize_mode_controller->EnableMaximizeModeWindowManager(true); | |
| 224 ASSERT_FALSE(tray_view()->visible()); | |
| 225 | |
| 226 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), | |
| 227 ui::GestureEventDetails(ui::ET_GESTURE_TAP)); | |
| 228 default_view()->OnGestureEvent(&tap); | |
| 229 EXPECT_TRUE(screen_orientation_controller->rotation_locked()); | |
| 230 EXPECT_TRUE(tray_view()->visible()); | |
| 231 | |
| 232 maximize_mode_controller->EnableMaximizeModeWindowManager(false); | |
| 233 } | |
| 234 | |
| 235 // Tests that when the tray is created without the internal display being known, | |
| 236 // that it will still display correctly once the internal display is known. | |
| 237 TEST_F(TrayRotationLockTest, InternalDisplayNotAvailableAtCreation) { | |
| 238 int64_t internal_display_id = display::Display::InternalDisplayId(); | |
| 239 TearDownViews(); | |
| 240 display::Display::SetInternalDisplayId(display::kInvalidDisplayId); | |
| 241 | |
| 242 std::unique_ptr<TrayRotationLock> tray(new TrayRotationLock( | |
| 243 StatusAreaWidgetTestHelper::GetStatusAreaWidget()->system_tray())); | |
| 244 | |
| 245 display::Display::SetInternalDisplayId(internal_display_id); | |
| 246 std::unique_ptr<views::View> tray_view(CreateTrayView(tray.get())); | |
| 247 std::unique_ptr<views::View> default_view(tray->CreateDefaultView( | |
| 248 StatusAreaWidgetTestHelper::GetUserLoginStatus())); | |
| 249 EXPECT_TRUE(default_view); | |
| 250 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 251 true); | |
| 252 EXPECT_TRUE(default_view->visible()); | |
| 253 } | |
| 254 | |
| 255 // Tests that when the tray view is deleted, while TrayRotationLock has not been | |
| 256 // deleted, that updates to the rotation lock state do not crash. | |
| 257 TEST_F(TrayRotationLockTest, LockUpdatedDuringDesctruction) { | |
| 258 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 259 true); | |
| 260 DestroyTrayView(); | |
| 261 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( | |
| 262 true); | |
| 263 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 264 false); | |
| 265 } | |
| 266 | |
| 267 } // namespace ash | |
| OLD | NEW |