OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 5 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
6 | 6 |
7 #include "ash/accelerometer/accelerometer_controller.h" | 7 #include "ash/accelerometer/accelerometer_controller.h" |
| 8 #include "ash/display/display_manager.h" |
8 #include "ash/shell.h" | 9 #include "ash/shell.h" |
9 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
| 11 #include "ash/test/display_manager_test_api.h" |
10 #include "ui/gfx/vector3d_f.h" | 12 #include "ui/gfx/vector3d_f.h" |
11 | 13 |
12 namespace ash { | 14 namespace ash { |
13 | 15 |
| 16 namespace { |
| 17 |
| 18 const float kDegreesToRadians = 3.14159265f / 180.0f; |
| 19 |
| 20 } // namespace |
| 21 |
14 class MaximizeModeControllerTest : public test::AshTestBase { | 22 class MaximizeModeControllerTest : public test::AshTestBase { |
15 public: | 23 public: |
16 MaximizeModeControllerTest() {} | 24 MaximizeModeControllerTest() {} |
17 virtual ~MaximizeModeControllerTest() {} | 25 virtual ~MaximizeModeControllerTest() {} |
18 | 26 |
19 virtual void SetUp() OVERRIDE { | 27 virtual void SetUp() OVERRIDE { |
20 test::AshTestBase::SetUp(); | 28 test::AshTestBase::SetUp(); |
21 Shell::GetInstance()->accelerometer_controller()->RemoveObserver( | 29 Shell::GetInstance()->accelerometer_controller()->RemoveObserver( |
22 maximize_mode_controller()); | 30 maximize_mode_controller()); |
| 31 |
| 32 // Set the first display to be the internal display for the accelerometer |
| 33 // screen rotation tests. |
| 34 test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()). |
| 35 SetFirstDisplayAsInternalDisplay(); |
23 } | 36 } |
24 | 37 |
25 virtual void TearDown() OVERRIDE { | 38 virtual void TearDown() OVERRIDE { |
26 Shell::GetInstance()->accelerometer_controller()->AddObserver( | 39 Shell::GetInstance()->accelerometer_controller()->AddObserver( |
27 maximize_mode_controller()); | 40 maximize_mode_controller()); |
28 test::AshTestBase::TearDown(); | 41 test::AshTestBase::TearDown(); |
29 } | 42 } |
30 | 43 |
31 MaximizeModeController* maximize_mode_controller() { | 44 MaximizeModeController* maximize_mode_controller() { |
32 return Shell::GetInstance()->maximize_mode_controller(); | 45 return Shell::GetInstance()->maximize_mode_controller(); |
33 } | 46 } |
34 | 47 |
35 void TriggerAccelerometerUpdate(const gfx::Vector3dF& base, | 48 void TriggerAccelerometerUpdate(const gfx::Vector3dF& base, |
36 const gfx::Vector3dF& lid) { | 49 const gfx::Vector3dF& lid) { |
37 maximize_mode_controller()->OnAccelerometerUpdated(base, lid); | 50 maximize_mode_controller()->OnAccelerometerUpdated(base, lid); |
38 } | 51 } |
39 | 52 |
40 bool IsMaximizeModeStarted() const { | 53 bool IsMaximizeModeStarted() const { |
41 return Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); | 54 return Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); |
42 } | 55 } |
43 | 56 |
| 57 gfx::Display::Rotation GetInternalDisplayRotation() const { |
| 58 return Shell::GetInstance()->display_manager()->GetDisplayInfo( |
| 59 gfx::Display::InternalDisplayId()).rotation(); |
| 60 } |
| 61 |
44 private: | 62 private: |
45 DISALLOW_COPY_AND_ASSIGN(MaximizeModeControllerTest); | 63 DISALLOW_COPY_AND_ASSIGN(MaximizeModeControllerTest); |
46 }; | 64 }; |
47 | 65 |
48 // Tests that opening the lid beyond 180 will enter touchview, and that it will | 66 // Tests that opening the lid beyond 180 will enter touchview, and that it will |
49 // exit when the lid comes back from 180. Also tests the thresholds, i.e. it | 67 // exit when the lid comes back from 180. Also tests the thresholds, i.e. it |
50 // will stick to the current mode. | 68 // will stick to the current mode. |
51 TEST_F(MaximizeModeControllerTest, EnterExitThresholds) { | 69 TEST_F(MaximizeModeControllerTest, EnterExitThresholds) { |
52 // For the simple test the base remains steady. | 70 // For the simple test the base remains steady. |
53 gfx::Vector3dF base(0.0f, 0.0f, 1.0f); | 71 gfx::Vector3dF base(0.0f, 0.0f, 1.0f); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 gfx::Vector3dF(1.0f, 0.0f, 0.0f)); | 119 gfx::Vector3dF(1.0f, 0.0f, 0.0f)); |
102 EXPECT_TRUE(IsMaximizeModeStarted()); | 120 EXPECT_TRUE(IsMaximizeModeStarted()); |
103 | 121 |
104 // Normal 90 degree orientation but near vertical should stay in maximize | 122 // Normal 90 degree orientation but near vertical should stay in maximize |
105 // mode. | 123 // mode. |
106 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.01f), | 124 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.01f), |
107 gfx::Vector3dF(-0.01f, -1.0f, 0.0f)); | 125 gfx::Vector3dF(-0.01f, -1.0f, 0.0f)); |
108 EXPECT_TRUE(IsMaximizeModeStarted()); | 126 EXPECT_TRUE(IsMaximizeModeStarted()); |
109 } | 127 } |
110 | 128 |
| 129 // Tests that accelerometer readings in each of the screen angles will trigger |
| 130 // a rotation of the internal display. |
| 131 TEST_F(MaximizeModeControllerTest, DisplayRotation) { |
| 132 // Trigger maximize mode by opening to 270. |
| 133 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f), |
| 134 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); |
| 135 ASSERT_TRUE(IsMaximizeModeStarted()); |
| 136 |
| 137 // Now test rotating in all directions. |
| 138 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 1.0f, 0.0f), |
| 139 gfx::Vector3dF(0.0f, 1.0f, 0.0f)); |
| 140 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); |
| 141 TriggerAccelerometerUpdate(gfx::Vector3dF(1.0f, 0.0f, 0.0f), |
| 142 gfx::Vector3dF(1.0f, 0.0f, 0.0f)); |
| 143 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); |
| 144 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.0f), |
| 145 gfx::Vector3dF(0.0f, -1.0f, 0.0f)); |
| 146 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); |
| 147 TriggerAccelerometerUpdate(gfx::Vector3dF(-1.0f, 0.0f, 0.0f), |
| 148 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); |
| 149 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
| 150 } |
| 151 |
| 152 // Tests that low angles are ignored by the accelerometer (i.e. when the device |
| 153 // is almost laying flat). |
| 154 TEST_F(MaximizeModeControllerTest, RotationIgnoresLowAngles) { |
| 155 // Trigger maximize mode by opening to 270. |
| 156 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f), |
| 157 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); |
| 158 ASSERT_TRUE(IsMaximizeModeStarted()); |
| 159 |
| 160 TriggerAccelerometerUpdate(gfx::Vector3dF(-1.0f, 0.0f, -1.0f), |
| 161 gfx::Vector3dF(-1.0f, 0.0f, -1.0f)); |
| 162 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
| 163 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.2f, -1.0f), |
| 164 gfx::Vector3dF(0.0f, 0.2f, -1.0f)); |
| 165 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
| 166 TriggerAccelerometerUpdate(gfx::Vector3dF(0.2f, 0.0f, -1.0f), |
| 167 gfx::Vector3dF(0.2f, 0.0f, -1.0f)); |
| 168 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
| 169 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -0.2f, -1.0f), |
| 170 gfx::Vector3dF(0.0f, -0.2f, -1.0f)); |
| 171 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
| 172 TriggerAccelerometerUpdate(gfx::Vector3dF(-0.2f, 0.0f, -1.0f), |
| 173 gfx::Vector3dF(-0.2f, 0.0f, -1.0f)); |
| 174 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
| 175 } |
| 176 |
| 177 // Tests that the display will stick to the current orientation beyond the |
| 178 // halfway point, preventing frequent updates back and forth. |
| 179 TEST_F(MaximizeModeControllerTest, RotationSticky) { |
| 180 // Trigger maximize mode by opening to 270. |
| 181 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f), |
| 182 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); |
| 183 ASSERT_TRUE(IsMaximizeModeStarted()); |
| 184 |
| 185 gfx::Vector3dF gravity(-1.0f, 0.0f, 0.0f); |
| 186 TriggerAccelerometerUpdate(gravity, gravity); |
| 187 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
| 188 |
| 189 // Turn past half-way point to next direction and rotation should remain |
| 190 // the same. |
| 191 float degrees = 50.0; |
| 192 gravity.set_x(-cos(degrees * kDegreesToRadians)); |
| 193 gravity.set_y(sin(degrees * kDegreesToRadians)); |
| 194 TriggerAccelerometerUpdate(gravity, gravity); |
| 195 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
| 196 |
| 197 // Turn more and the screen should rotate. |
| 198 degrees = 70.0; |
| 199 gravity.set_x(-cos(degrees * kDegreesToRadians)); |
| 200 gravity.set_y(sin(degrees * kDegreesToRadians)); |
| 201 TriggerAccelerometerUpdate(gravity, gravity); |
| 202 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); |
| 203 |
| 204 // Turn back just beyond the half-way point and the new rotation should |
| 205 // still be in effect. |
| 206 degrees = 40.0; |
| 207 gravity.set_x(-cos(degrees * kDegreesToRadians)); |
| 208 gravity.set_y(sin(degrees * kDegreesToRadians)); |
| 209 TriggerAccelerometerUpdate(gravity, gravity); |
| 210 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); |
| 211 } |
| 212 |
| 213 // Tests that the screen only rotates when maximize mode is engaged, and will |
| 214 // return to the standard orientation on exiting maximize mode. |
| 215 TEST_F(MaximizeModeControllerTest, RotationOnlyInMaximizeMode) { |
| 216 // Rotate on side with lid only open 90 degrees. |
| 217 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.8f, 0.3f), |
| 218 gfx::Vector3dF(-0.3f, 0.8f, 0.0f)); |
| 219 ASSERT_FALSE(IsMaximizeModeStarted()); |
| 220 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
| 221 |
| 222 // Open lid, screen should now rotate to match orientation. |
| 223 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.8f, -0.3f), |
| 224 gfx::Vector3dF(-0.3f, 0.8f, 0.0f)); |
| 225 ASSERT_TRUE(IsMaximizeModeStarted()); |
| 226 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); |
| 227 |
| 228 // Close lid back to 90, screen should rotate back. |
| 229 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.8f, 0.3f), |
| 230 gfx::Vector3dF(-0.3f, 0.8f, 0.0f)); |
| 231 ASSERT_FALSE(IsMaximizeModeStarted()); |
| 232 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); |
| 233 } |
| 234 |
111 } // namespace ash | 235 } // namespace ash |
OLD | NEW |