| 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 ee3afc4d1046928db9892131f3ada9ed0cfe5c5e..3237524bf4b61f0007049067068f1fa1078d5008 100644
|
| --- a/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc
|
| +++ b/ash/wm/maximize_mode/maximize_mode_controller_unittest.cc
|
| @@ -5,12 +5,20 @@
|
| #include "ash/wm/maximize_mode/maximize_mode_controller.h"
|
|
|
| #include "ash/accelerometer/accelerometer_controller.h"
|
| +#include "ash/display/display_manager.h"
|
| #include "ash/shell.h"
|
| #include "ash/test/ash_test_base.h"
|
| +#include "ash/test/display_manager_test_api.h"
|
| #include "ui/gfx/vector3d_f.h"
|
|
|
| namespace ash {
|
|
|
| +namespace {
|
| +
|
| +const float kDegreesToRadians = 3.14159265f / 180.0f;
|
| +
|
| +} // namespace
|
| +
|
| class MaximizeModeControllerTest : public test::AshTestBase {
|
| public:
|
| MaximizeModeControllerTest() {}
|
| @@ -20,6 +28,11 @@ class MaximizeModeControllerTest : public test::AshTestBase {
|
| 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();
|
| }
|
|
|
| virtual void TearDown() OVERRIDE {
|
| @@ -41,6 +54,11 @@ class MaximizeModeControllerTest : public test::AshTestBase {
|
| return Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled();
|
| }
|
|
|
| + gfx::Display::Rotation GetInternalDisplayRotation() const {
|
| + return Shell::GetInstance()->display_manager()->GetDisplayInfo(
|
| + gfx::Display::InternalDisplayId()).rotation();
|
| + }
|
| +
|
| private:
|
| DISALLOW_COPY_AND_ASSIGN(MaximizeModeControllerTest);
|
| };
|
| @@ -108,4 +126,110 @@ TEST_F(MaximizeModeControllerTest, HingeAligned) {
|
| EXPECT_TRUE(IsMaximizeModeStarted());
|
| }
|
|
|
| +// 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.
|
| + TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
|
| + gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
|
| + ASSERT_TRUE(IsMaximizeModeStarted());
|
| +
|
| + // Now test rotating in all directions.
|
| + TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 1.0f, 0.0f),
|
| + gfx::Vector3dF(0.0f, 1.0f, 0.0f));
|
| + EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
|
| + TriggerAccelerometerUpdate(gfx::Vector3dF(1.0f, 0.0f, 0.0f),
|
| + gfx::Vector3dF(1.0f, 0.0f, 0.0f));
|
| + EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
|
| + TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.0f),
|
| + gfx::Vector3dF(0.0f, -1.0f, 0.0f));
|
| + EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
|
| + TriggerAccelerometerUpdate(gfx::Vector3dF(-1.0f, 0.0f, 0.0f),
|
| + gfx::Vector3dF(-1.0f, 0.0f, 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.
|
| + TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
|
| + gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
|
| + ASSERT_TRUE(IsMaximizeModeStarted());
|
| +
|
| + TriggerAccelerometerUpdate(gfx::Vector3dF(-1.0f, 0.0f, -1.0f),
|
| + gfx::Vector3dF(-1.0f, 0.0f, -1.0f));
|
| + EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| + TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.2f, -1.0f),
|
| + gfx::Vector3dF(0.0f, 0.2f, -1.0f));
|
| + EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| + TriggerAccelerometerUpdate(gfx::Vector3dF(0.2f, 0.0f, -1.0f),
|
| + gfx::Vector3dF(0.2f, 0.0f, -1.0f));
|
| + EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| + TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -0.2f, -1.0f),
|
| + gfx::Vector3dF(0.0f, -0.2f, -1.0f));
|
| + EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| + TriggerAccelerometerUpdate(gfx::Vector3dF(-0.2f, 0.0f, -1.0f),
|
| + gfx::Vector3dF(-0.2f, 0.0f, -1.0f));
|
| + 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.
|
| + TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
|
| + gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
|
| + ASSERT_TRUE(IsMaximizeModeStarted());
|
| +
|
| + gfx::Vector3dF gravity(-1.0f, 0.0f, 0.0f);
|
| + TriggerAccelerometerUpdate(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(-cos(degrees * kDegreesToRadians));
|
| + gravity.set_y(sin(degrees * kDegreesToRadians));
|
| + TriggerAccelerometerUpdate(gravity, gravity);
|
| + EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| +
|
| + // Turn more and the screen should rotate.
|
| + degrees = 70.0;
|
| + gravity.set_x(-cos(degrees * kDegreesToRadians));
|
| + gravity.set_y(sin(degrees * kDegreesToRadians));
|
| + TriggerAccelerometerUpdate(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(-cos(degrees * kDegreesToRadians));
|
| + gravity.set_y(sin(degrees * kDegreesToRadians));
|
| + TriggerAccelerometerUpdate(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.
|
| + TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.8f, 0.3f),
|
| + gfx::Vector3dF(-0.3f, 0.8f, 0.0f));
|
| + ASSERT_FALSE(IsMaximizeModeStarted());
|
| + EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| +
|
| + // Open lid, screen should now rotate to match orientation.
|
| + TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.8f, -0.3f),
|
| + gfx::Vector3dF(-0.3f, 0.8f, 0.0f));
|
| + ASSERT_TRUE(IsMaximizeModeStarted());
|
| + EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
|
| +
|
| + // Close lid back to 90, screen should rotate back.
|
| + TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.8f, 0.3f),
|
| + gfx::Vector3dF(-0.3f, 0.8f, 0.0f));
|
| + ASSERT_FALSE(IsMaximizeModeStarted());
|
| + EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| +}
|
| +
|
| } // namespace ash
|
|
|