| Index: ash/display/display_manager_unittest.cc
|
| diff --git a/ash/display/display_manager_unittest.cc b/ash/display/display_manager_unittest.cc
|
| index 85df8bb553ceb1610d871e93a44fb26b18b7aae4..41f52eff03b61cd634d69d4224682ee07ba0763d 100644
|
| --- a/ash/display/display_manager_unittest.cc
|
| +++ b/ash/display/display_manager_unittest.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "ash/display/display_manager.h"
|
|
|
| +#include "ash/accelerometer/accelerometer_controller.h"
|
| #include "ash/display/display_controller.h"
|
| #include "ash/display/display_layout_store.h"
|
| #include "ash/screen_util.h"
|
| @@ -22,6 +23,7 @@
|
| #include "ui/gfx/display.h"
|
| #include "ui/gfx/screen.h"
|
| #include "ui/gfx/screen_type_delegate.h"
|
| +#include "ui/gfx/vector3d_f.h"
|
|
|
| namespace ash {
|
| namespace internal {
|
| @@ -37,6 +39,10 @@ std::string ToDisplayName(int64 id) {
|
| return "x-" + base::Int64ToString(id);
|
| }
|
|
|
| +const float DegreesToRadians(float degrees) {
|
| + return degrees * 3.1415926f / 180.0f;
|
| +}
|
| +
|
| } // namespace
|
|
|
| class DisplayManagerTest : public test::AshTestBase,
|
| @@ -53,8 +59,18 @@ class DisplayManagerTest : public test::AshTestBase,
|
| AshTestBase::SetUp();
|
| Shell::GetScreen()->AddObserver(this);
|
| Shell::GetPrimaryRootWindow()->AddObserver(this);
|
| +
|
| + // Set the primary display to be the internal display for the accelerometer
|
| + // tests.
|
| + gfx::Display::SetInternalDisplayId(display_manager()->GetDisplayAt(0).id());
|
| +
|
| + // Remove the accelerometer observer so that tests can deliver test values.
|
| + Shell::GetInstance()->accelerometer_controller()->RemoveObserver(
|
| + display_manager());
|
| }
|
| virtual void TearDown() OVERRIDE {
|
| + Shell::GetInstance()->accelerometer_controller()->AddObserver(
|
| + display_manager());
|
| Shell::GetPrimaryRootWindow()->RemoveObserver(this);
|
| Shell::GetScreen()->RemoveObserver(this);
|
| AshTestBase::TearDown();
|
| @@ -63,6 +79,9 @@ class DisplayManagerTest : public test::AshTestBase,
|
| DisplayManager* display_manager() {
|
| return Shell::GetInstance()->display_manager();
|
| }
|
| + const DisplayManager* display_manager() const {
|
| + return Shell::GetInstance()->display_manager();
|
| + }
|
| const vector<gfx::Display>& changed() const { return changed_; }
|
| const vector<gfx::Display>& added() const { return added_; }
|
|
|
| @@ -78,6 +97,16 @@ class DisplayManagerTest : public test::AshTestBase,
|
| root_window_destroyed_ = false;
|
| }
|
|
|
| + void TriggerAccelerometerUpdate(const gfx::Vector3dF& base,
|
| + const gfx::Vector3dF& lid) {
|
| + display_manager()->OnAccelerometerUpdated(base, lid);
|
| + }
|
| +
|
| + gfx::Display::Rotation GetInternalDisplayRotation() const {
|
| + return display_manager()->GetDisplayInfo(
|
| + gfx::Display::InternalDisplayId()).rotation();
|
| + }
|
| +
|
| bool root_window_destroyed() const {
|
| return root_window_destroyed_;
|
| }
|
| @@ -1197,6 +1226,73 @@ TEST_F(DisplayManagerTest, MAYBE_UpdateDisplayWithHostOrigin) {
|
| EXPECT_EQ("200x300", host1->GetBounds().size().ToString());
|
| }
|
|
|
| +// Tests that accelerometer readings in each of the screen angles will trigger
|
| +// a rotation of the internal display.
|
| +TEST_F(DisplayManagerTest, AccelerometerRotation) {
|
| + 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(DisplayManagerTest, AccelerometerIgnoresLowAngles) {
|
| + 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(DisplayManagerTest, AccelerometerSticky) {
|
| + 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(DegreesToRadians(degrees)));
|
| + gravity.set_y(sin(DegreesToRadians(degrees)));
|
| + TriggerAccelerometerUpdate(gravity, gravity);
|
| + EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
|
| +
|
| + // Turn more and the screen should rotate.
|
| + degrees = 70.0;
|
| + gravity.set_x(-cos(DegreesToRadians(degrees)));
|
| + gravity.set_y(sin(DegreesToRadians(degrees)));
|
| + 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(DegreesToRadians(degrees)));
|
| + gravity.set_y(sin(DegreesToRadians(degrees)));
|
| + TriggerAccelerometerUpdate(gravity, gravity);
|
| + EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
|
| +}
|
|
|
| class ScreenShutdownTest : public test::AshTestBase {
|
| public:
|
|
|