This source file includes following definitions.
- SetUp
- TearDown
- maximize_mode_controller
- TriggerAccelerometerUpdate
- IsMaximizeModeStarted
- GetInternalDisplayRotation
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#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;
}
class MaximizeModeControllerTest : public test::AshTestBase {
public:
MaximizeModeControllerTest() {}
virtual ~MaximizeModeControllerTest() {}
virtual void SetUp() OVERRIDE {
test::AshTestBase::SetUp();
Shell::GetInstance()->accelerometer_controller()->RemoveObserver(
maximize_mode_controller());
test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()).
SetFirstDisplayAsInternalDisplay();
}
virtual void TearDown() OVERRIDE {
Shell::GetInstance()->accelerometer_controller()->AddObserver(
maximize_mode_controller());
test::AshTestBase::TearDown();
}
MaximizeModeController* maximize_mode_controller() {
return Shell::GetInstance()->maximize_mode_controller();
}
void TriggerAccelerometerUpdate(const gfx::Vector3dF& base,
const gfx::Vector3dF& lid) {
maximize_mode_controller()->OnAccelerometerUpdated(base, lid);
}
bool IsMaximizeModeStarted() const {
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);
};
TEST_F(MaximizeModeControllerTest, EnterExitThresholds) {
gfx::Vector3dF base(0.0f, 0.0f, 1.0f);
TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
EXPECT_FALSE(IsMaximizeModeStarted());
TriggerAccelerometerUpdate(base, gfx::Vector3dF(0.05f, 0.0f, -1.0f));
EXPECT_FALSE(IsMaximizeModeStarted());
TriggerAccelerometerUpdate(base, gfx::Vector3dF(1.0f, 0.0f, 0.0f));
EXPECT_TRUE(IsMaximizeModeStarted());
TriggerAccelerometerUpdate(base, gfx::Vector3dF(-0.05f, 0.0f, 1.0f));
EXPECT_TRUE(IsMaximizeModeStarted());
TriggerAccelerometerUpdate(base, gfx::Vector3dF(-0.05f, 0.0f, -1.0f));
EXPECT_TRUE(IsMaximizeModeStarted());
TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
EXPECT_FALSE(IsMaximizeModeStarted());
}
TEST_F(MaximizeModeControllerTest, HingeAligned) {
TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
EXPECT_FALSE(IsMaximizeModeStarted());
TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.0f),
gfx::Vector3dF(0.0f, -1.0f, 0.0f));
EXPECT_FALSE(IsMaximizeModeStarted());
TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.01f),
gfx::Vector3dF(0.01f, -1.0f, 0.0f));
EXPECT_FALSE(IsMaximizeModeStarted());
TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
gfx::Vector3dF(1.0f, 0.0f, 0.0f));
EXPECT_TRUE(IsMaximizeModeStarted());
TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.01f),
gfx::Vector3dF(-0.01f, -1.0f, 0.0f));
EXPECT_TRUE(IsMaximizeModeStarted());
}
TEST_F(MaximizeModeControllerTest, DisplayRotation) {
TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
ASSERT_TRUE(IsMaximizeModeStarted());
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());
}
TEST_F(MaximizeModeControllerTest, RotationIgnoresLowAngles) {
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());
}
TEST_F(MaximizeModeControllerTest, RotationSticky) {
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());
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());
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());
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());
}
TEST_F(MaximizeModeControllerTest, RotationOnlyInMaximizeMode) {
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());
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());
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());
}
}