Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Unified Diff: ash/wm/maximize_mode/maximize_mode_controller_unittest.cc

Issue 759063002: Move Screen Rotation from MaximizeModeController to ScreenOrientationController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Linux Compile Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 30d6246b9a9e2c3896ab815fd656a2558fd6b7a1..40ce4b2c76add812b7778492636a8b0387a4734c 100644
--- a/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc
+++ b/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc
@@ -296,130 +296,6 @@ 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());
-}
-
-// 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));
- 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));
- 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));
- ASSERT_FALSE(IsMaximizeModeStarted());
- EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
-}
-
-
TEST_F(MaximizeModeControllerTest, LaptopTest) {
// Feeds in sample accelerometer data and verifies that there are no
// transitions into touchview / maximize mode while shaking the device around
@@ -469,159 +345,6 @@ 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.
-// 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());
-}
-
-// 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() {}
@@ -637,18 +360,13 @@ 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());
}
} // namespace ash
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_controller.cc ('k') | chrome/browser/chromeos/display/display_preferences_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698