| Index: ash/wm/maximize_mode/maximize_mode_controller_unittest.cc
|
| diff --git a/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc b/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc
|
| index 537a58cb6417d9d9a5e72be1a5b2533ee20de1b8..1bcfb9e956371e1a4d0b5c0c56a90d0f2725b5d1 100644
|
| --- a/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc
|
| +++ b/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc
|
| @@ -57,21 +57,12 @@ class MaximizeModeControllerTest : public test::AshTestBase {
|
|
|
| void SetUp() override {
|
| test::AshTestBase::SetUp();
|
| - Shell::GetInstance()->accelerometer_controller()->RemoveObserver(
|
| - maximize_mode_controller());
|
| -
|
| // Set the first display to be the internal display for the accelerometer
|
| // screen rotation tests.
|
| test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()).
|
| SetFirstDisplayAsInternalDisplay();
|
| }
|
|
|
| - void TearDown() override {
|
| - Shell::GetInstance()->accelerometer_controller()->AddObserver(
|
| - maximize_mode_controller());
|
| - test::AshTestBase::TearDown();
|
| - }
|
| -
|
| MaximizeModeController* maximize_mode_controller() {
|
| return Shell::GetInstance()->maximize_mode_controller();
|
| }
|
| @@ -92,6 +83,18 @@ class MaximizeModeControllerTest : public test::AshTestBase {
|
| maximize_mode_controller()->OnAccelerometerUpdated(update);
|
| }
|
|
|
| +#if defined(OS_CHROMEOS)
|
| + void TriggerAccelerometerController(const gfx::Vector3dF& base,
|
| + const gfx::Vector3dF& lid) {
|
| + ui::AccelerometerUpdate update;
|
| + update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, base.x(), base.y(),
|
| + base.z());
|
| + update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, lid.x(), lid.y(), lid.z());
|
| + Shell::GetInstance()->accelerometer_controller()->HandleAccelerometerUpdate(
|
| + update);
|
| + }
|
| +#endif
|
| +
|
| bool IsMaximizeModeStarted() {
|
| return maximize_mode_controller()->IsMaximizeModeWindowManagerEnabled();
|
| }
|
| @@ -310,129 +313,30 @@ TEST_F(MaximizeModeControllerTest, HingeAligned) {
|
| EXPECT_TRUE(IsMaximizeModeStarted());
|
| }
|
|
|
| -// Tests that only getting a lid accelerometer update will enter maximize
|
| -// mode and rotate the screen.
|
| -TEST_F(MaximizeModeControllerTest, LidOnlyDisplayRotation) {
|
| - ASSERT_FALSE(IsMaximizeModeStarted());
|
| - // Test rotating in all directions.
|
| - TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
|
| - // The first update should have entered maximize mode.
|
| - ASSERT_TRUE(IsMaximizeModeStarted());
|
| - EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
|
| - TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
|
| - EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
|
| - TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
|
| - EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
|
| - TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
|
| - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| -}
|
| -
|
| -// Tests that accelerometer readings in each of the screen angles will trigger a
|
| -// rotation of the internal display.
|
| -TEST_F(MaximizeModeControllerTest, DisplayRotation) {
|
| - // Trigger maximize mode by opening to 270.
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
|
| - gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
|
| - ASSERT_TRUE(IsMaximizeModeStarted());
|
| -
|
| - // Now test rotating in all directions.
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f),
|
| - gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
|
| - EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f),
|
| - gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
|
| - EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f),
|
| - gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
|
| - EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f),
|
| - gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
|
| - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| -}
|
| -
|
| -// Tests that low angles are ignored by the accelerometer (i.e. when the device
|
| -// is almost laying flat).
|
| -TEST_F(MaximizeModeControllerTest, RotationIgnoresLowAngles) {
|
| - // Trigger maximize mode by opening to 270.
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
|
| - gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
|
| - ASSERT_TRUE(IsMaximizeModeStarted());
|
| -
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, kMeanGravity),
|
| - gfx::Vector3dF(0.0f, -kMeanGravity, -kMeanGravity));
|
| - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(-2.0f, 0.0f, kMeanGravity),
|
| - gfx::Vector3dF(-2.0f, 0.0f, -kMeanGravity));
|
| - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, -2.0f, kMeanGravity),
|
| - gfx::Vector3dF(0.0f, 2.0f, -kMeanGravity));
|
| - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(2.0f, 0.0f, kMeanGravity),
|
| - gfx::Vector3dF(2.0f, 0.0f, -kMeanGravity));
|
| - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 2.0f, kMeanGravity),
|
| - gfx::Vector3dF(0.0f, -2.0f, -kMeanGravity));
|
| - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| -}
|
| -
|
| -// Tests that the display will stick to the current orientation beyond the
|
| -// halfway point, preventing frequent updates back and forth.
|
| -TEST_F(MaximizeModeControllerTest, RotationSticky) {
|
| - // Trigger maximize mode by opening to 270.
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
|
| - gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
|
| - ASSERT_TRUE(IsMaximizeModeStarted());
|
| -
|
| - gfx::Vector3dF gravity(0.0f, -kMeanGravity, 0.0f);
|
| - TriggerBaseAndLidUpdate(gravity, gravity);
|
| - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| -
|
| - // Turn past half-way point to next direction and rotation should remain
|
| - // the same.
|
| - float degrees = 50.0;
|
| - gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
|
| - gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
|
| - TriggerBaseAndLidUpdate(gravity, gravity);
|
| - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| -
|
| - // Turn more and the screen should rotate.
|
| - degrees = 70.0;
|
| - gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
|
| - gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
|
| - TriggerBaseAndLidUpdate(gravity, gravity);
|
| - EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
|
| -
|
| - // Turn back just beyond the half-way point and the new rotation should
|
| - // still be in effect.
|
| - degrees = 40.0;
|
| - gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
|
| - gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
|
| - TriggerBaseAndLidUpdate(gravity, gravity);
|
| - EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
|
| -}
|
| +#if defined(OS_CHROMEOS)
|
|
|
| // Tests that the screen only rotates when maximize mode is engaged, and will
|
| // return to the standard orientation on exiting maximize mode.
|
| TEST_F(MaximizeModeControllerTest, RotationOnlyInMaximizeMode) {
|
| // Rotate on side with lid only open 90 degrees.
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(-9.5f, 0.0f, -3.5f),
|
| - gfx::Vector3dF(-9.5f, -3.5f, 0.0f));
|
| + TriggerAccelerometerController(gfx::Vector3dF(-9.5f, 0.0f, -3.5f),
|
| + gfx::Vector3dF(-9.5f, -3.5f, 0.0f));
|
| ASSERT_FALSE(IsMaximizeModeStarted());
|
| EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
|
|
| // Open lid, screen should now rotate to match orientation.
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(-9.5f, 0.0f, 3.5f),
|
| - gfx::Vector3dF(-9.5f, -3.5f, 0.0f));
|
| + TriggerAccelerometerController(gfx::Vector3dF(-9.5f, 0.0f, 3.5f),
|
| + gfx::Vector3dF(-9.5f, -3.5f, 0.0f));
|
| ASSERT_TRUE(IsMaximizeModeStarted());
|
| EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
|
|
|
| // Close lid back to 90, screen should rotate back.
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(-9.5f, 0.0f, -3.5f),
|
| - gfx::Vector3dF(-9.5f, -3.5f, 0.0f));
|
| + TriggerAccelerometerController(gfx::Vector3dF(-9.5f, 0.0f, -3.5f),
|
| + gfx::Vector3dF(-9.5f, -3.5f, 0.0f));
|
| ASSERT_FALSE(IsMaximizeModeStarted());
|
| EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| }
|
| -
|
| +#endif // OS_CHROMEOS
|
|
|
| TEST_F(MaximizeModeControllerTest, LaptopTest) {
|
| // Feeds in sample accelerometer data and verifies that there are no
|
| @@ -483,161 +387,7 @@ TEST_F(MaximizeModeControllerTest, MaximizeModeTest) {
|
| }
|
| }
|
|
|
| -// Tests that the display will stick to its current orientation when the
|
| -// rotation lock has been set.
|
| -TEST_F(MaximizeModeControllerTest, RotationLockPreventsRotation) {
|
| - // Trigger maximize mode by opening to 270.
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
|
| - gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
|
| - ASSERT_TRUE(IsMaximizeModeStarted());
|
| -
|
| - gfx::Vector3dF gravity(-kMeanGravity, 0.0f, 0.0f);
|
| -
|
| - maximize_mode_controller()->SetRotationLocked(true);
|
| -
|
| - // Turn past the threshold for rotation.
|
| - float degrees = 90.0;
|
| - gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
|
| - gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
|
| - TriggerBaseAndLidUpdate(gravity, gravity);
|
| - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| -
|
| - maximize_mode_controller()->SetRotationLocked(false);
|
| - TriggerBaseAndLidUpdate(gravity, gravity);
|
| - EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
|
| -}
|
| -
|
| -// Tests that when MaximizeModeController turns off MaximizeMode that on the
|
| -// next accelerometer update the rotation lock is cleared.
|
| -TEST_F(MaximizeModeControllerTest, ExitingMaximizeModeClearRotationLock) {
|
| - // Trigger maximize mode by opening to 270.
|
| - OpenLidToAngle(270.0f);
|
| - ASSERT_TRUE(IsMaximizeModeStarted());
|
| -
|
| - maximize_mode_controller()->SetRotationLocked(true);
|
| -
|
| - OpenLidToAngle(90.0f);
|
| - EXPECT_FALSE(IsMaximizeModeStarted());
|
| -
|
| - // Send an update that would not relaunch MaximizeMode.
|
| - OpenLidToAngle(90.0f);
|
| - EXPECT_FALSE(maximize_mode_controller()->rotation_locked());
|
| -}
|
| -
|
| -// The TrayDisplay class that is responsible for adding/updating MessageCenter
|
| -// notifications is only added to the SystemTray on ChromeOS.
|
| #if defined(OS_CHROMEOS)
|
| -// Tests that the screen rotation notifications are suppressed when
|
| -// triggered by the accelerometer.
|
| -TEST_F(MaximizeModeControllerTest, BlockRotationNotifications) {
|
| - test::TestSystemTrayDelegate* tray_delegate =
|
| - static_cast<test::TestSystemTrayDelegate*>(
|
| - Shell::GetInstance()->system_tray_delegate());
|
| - tray_delegate->set_should_show_display_notification(true);
|
| -
|
| - message_center::MessageCenter* message_center =
|
| - message_center::MessageCenter::Get();
|
| -
|
| - // Make sure notifications are still displayed when
|
| - // adjusting the screen rotation directly when not in maximize mode
|
| - ASSERT_FALSE(IsMaximizeModeStarted());
|
| - ASSERT_NE(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
|
| - ASSERT_EQ(0u, message_center->NotificationCount());
|
| - ASSERT_FALSE(message_center->HasPopupNotifications());
|
| - SetInternalDisplayRotation(gfx::Display::ROTATE_180);
|
| - EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
|
| - EXPECT_EQ(1u, message_center->NotificationCount());
|
| - EXPECT_TRUE(message_center->HasPopupNotifications());
|
| -
|
| - // Reset the screen rotation.
|
| - SetInternalDisplayRotation(gfx::Display::ROTATE_0);
|
| - // Clear all notifications
|
| - message_center->RemoveAllNotifications(false);
|
| - // Trigger maximize mode by opening to 270.
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
|
| - gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
|
| - EXPECT_TRUE(IsMaximizeModeStarted());
|
| - EXPECT_EQ(0u, message_center->NotificationCount());
|
| - EXPECT_FALSE(message_center->HasPopupNotifications());
|
| -
|
| - // Make sure notifications are still displayed when
|
| - // adjusting the screen rotation directly when in maximize mode
|
| - ASSERT_NE(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
|
| - SetInternalDisplayRotation(gfx::Display::ROTATE_270);
|
| - maximize_mode_controller()->SetRotationLocked(false);
|
| - EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
|
| - EXPECT_EQ(1u, message_center->NotificationCount());
|
| - EXPECT_TRUE(message_center->HasPopupNotifications());
|
| -
|
| - // Clear all notifications
|
| - message_center->RemoveAllNotifications(false);
|
| - EXPECT_EQ(0u, message_center->NotificationCount());
|
| - EXPECT_FALSE(message_center->HasPopupNotifications());
|
| -
|
| - // Make sure notifications are blocked when adjusting the screen rotation
|
| - // via the accelerometer while in maximize mode
|
| - // Rotate the screen 90 degrees
|
| - ASSERT_NE(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f),
|
| - gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
|
| - ASSERT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
|
| - EXPECT_EQ(0u, message_center->NotificationCount());
|
| - EXPECT_FALSE(message_center->HasPopupNotifications());
|
| -}
|
| -#endif
|
| -
|
| -// Tests that if a user has set a display rotation that it is restored upon
|
| -// exiting maximize mode.
|
| -TEST_F(MaximizeModeControllerTest, ResetUserRotationUponExit) {
|
| - DisplayManager* display_manager = Shell::GetInstance()->display_manager();
|
| - display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
|
| - gfx::Display::ROTATE_90);
|
| -
|
| - // Trigger maximize mode
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
|
| - gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
|
| - ASSERT_TRUE(IsMaximizeModeStarted());
|
| -
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f),
|
| - gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
|
| - EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
|
| -
|
| - // Exit maximize mode
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, -kMeanGravity),
|
| - gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
|
| - EXPECT_FALSE(IsMaximizeModeStarted());
|
| - EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
|
| -}
|
| -
|
| -// Tests that if a user sets a display rotation that accelerometer rotation
|
| -// becomes locked.
|
| -TEST_F(MaximizeModeControllerTest,
|
| - NonAccelerometerRotationChangesLockRotation) {
|
| - // Trigger maximize mode by opening to 270.
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
|
| - gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
|
| - ASSERT_FALSE(maximize_mode_controller()->rotation_locked());
|
| - SetInternalDisplayRotation(gfx::Display::ROTATE_270);
|
| - EXPECT_TRUE(maximize_mode_controller()->rotation_locked());
|
| -}
|
| -
|
| -// Tests that if a user changes the display rotation, while rotation is locked,
|
| -// that the updates are recorded. Upon exiting maximize mode the latest user
|
| -// rotation should be applied.
|
| -TEST_F(MaximizeModeControllerTest, UpdateUserRotationWhileRotationLocked) {
|
| - // Trigger maximize mode by opening to 270.
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, kMeanGravity),
|
| - gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
|
| - SetInternalDisplayRotation(gfx::Display::ROTATE_270);
|
| - // User sets rotation to the same rotation that the display was at when
|
| - // maximize mode was activated.
|
| - SetInternalDisplayRotation(gfx::Display::ROTATE_0);
|
| - // Exit maximize mode
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(0.0f, 0.0f, -kMeanGravity),
|
| - gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
|
| - EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| -}
|
| -
|
| class MaximizeModeControllerSwitchesTest : public MaximizeModeControllerTest {
|
| public:
|
| MaximizeModeControllerSwitchesTest() {}
|
| @@ -653,18 +403,14 @@ class MaximizeModeControllerSwitchesTest : public MaximizeModeControllerTest {
|
| };
|
|
|
| // Tests that when the command line switch for testing maximize mode is on, that
|
| -// accelerometer updates which would normally cause it to exit do not, and that
|
| -// screen rotations still occur.
|
| +// accelerometer updates which would normally cause it to exit do not.
|
| TEST_F(MaximizeModeControllerSwitchesTest, IgnoreHingeAngles) {
|
| maximize_mode_controller()->EnableMaximizeModeWindowManager(true);
|
|
|
| // Would normally trigger an exit from maximize mode.
|
| OpenLidToAngle(90.0f);
|
| EXPECT_TRUE(IsMaximizeModeStarted());
|
| -
|
| - TriggerBaseAndLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f),
|
| - gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
|
| - EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
|
| }
|
| +#endif // OS_CHROMEOS
|
|
|
| } // namespace ash
|
|
|