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