Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / wm / maximize_mode / maximize_mode_controller_unittest.cc
blobb393bfc443ceabc86a8e8de50cf467fbdfc397c2
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
3 // found in the LICENSE file.
5 #include <math.h>
7 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
9 #include "ash/accelerometer/accelerometer_controller.h"
10 #include "ash/display/display_manager.h"
11 #include "ash/shell.h"
12 #include "ash/system/tray/system_tray_delegate.h"
13 #include "ash/test/ash_test_base.h"
14 #include "ash/test/display_manager_test_api.h"
15 #include "ash/test/test_lock_state_controller_delegate.h"
16 #include "ash/test/test_screenshot_delegate.h"
17 #include "ash/test/test_system_tray_delegate.h"
18 #include "ash/test/test_volume_control_delegate.h"
19 #include "base/test/simple_test_tick_clock.h"
20 #include "ui/events/event_handler.h"
21 #include "ui/events/test/event_generator.h"
22 #include "ui/gfx/vector3d_f.h"
23 #include "ui/message_center/message_center.h"
25 #if defined(USE_X11)
26 #include "ui/events/test/events_test_utils_x11.h"
27 #endif
29 namespace ash {
31 namespace {
33 const float kDegreesToRadians = 3.14159265f / 180.0f;
35 } // namespace
37 // Test accelerometer data taken with the lid at less than 180 degrees while
38 // shaking the device around. The data is to be interpreted in groups of 6 where
39 // each 6 values corresponds to the X, Y, and Z readings from the base and lid
40 // accelerometers in this order.
41 extern const float kAccelerometerLaptopModeTestData[];
42 extern const size_t kAccelerometerLaptopModeTestDataLength;
44 // Test accelerometer data taken with the lid open 360 degrees while
45 // shaking the device around. The data is to be interpreted in groups of 6 where
46 // each 6 values corresponds to the X, Y, and Z readings from the base and lid
47 // accelerometers in this order.
48 extern const float kAccelerometerFullyOpenTestData[];
49 extern const size_t kAccelerometerFullyOpenTestDataLength;
51 class MaximizeModeControllerTest : public test::AshTestBase {
52 public:
53 MaximizeModeControllerTest() {}
54 virtual ~MaximizeModeControllerTest() {}
56 virtual void SetUp() OVERRIDE {
57 test::AshTestBase::SetUp();
58 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(
59 maximize_mode_controller());
61 // Set the first display to be the internal display for the accelerometer
62 // screen rotation tests.
63 test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()).
64 SetFirstDisplayAsInternalDisplay();
67 virtual void TearDown() OVERRIDE {
68 Shell::GetInstance()->accelerometer_controller()->AddObserver(
69 maximize_mode_controller());
70 test::AshTestBase::TearDown();
73 MaximizeModeController* maximize_mode_controller() {
74 return Shell::GetInstance()->maximize_mode_controller();
77 void TriggerAccelerometerUpdate(const gfx::Vector3dF& base,
78 const gfx::Vector3dF& lid) {
79 maximize_mode_controller()->OnAccelerometerUpdated(base, lid);
82 bool IsMaximizeModeStarted() {
83 return maximize_mode_controller()->IsMaximizeModeWindowManagerEnabled();
86 gfx::Display::Rotation GetInternalDisplayRotation() const {
87 return Shell::GetInstance()->display_manager()->GetDisplayInfo(
88 gfx::Display::InternalDisplayId()).rotation();
91 void SetInternalDisplayRotation(gfx::Display::Rotation rotation) const {
92 Shell::GetInstance()->display_manager()->
93 SetDisplayRotation(gfx::Display::InternalDisplayId(), rotation);
96 // Attaches a SimpleTestTickClock to the MaximizeModeController with a non
97 // null value initial value.
98 void AttachTickClockForTest() {
99 scoped_ptr<base::TickClock> tick_clock(
100 test_tick_clock_ = new base::SimpleTestTickClock());
101 test_tick_clock_->Advance(base::TimeDelta::FromSeconds(1));
102 maximize_mode_controller()->SetTickClockForTest(tick_clock.Pass());
105 void AdvanceTickClock(const base::TimeDelta& delta) {
106 DCHECK(test_tick_clock_);
107 test_tick_clock_->Advance(delta);
110 void OpenLidToAngle(float degrees) {
111 DCHECK(degrees >= 0.0f);
112 DCHECK(degrees <= 360.0f);
114 float radians = degrees * kDegreesToRadians;
115 gfx::Vector3dF base_vector(1.0f, 0.0f, 0.0f);
116 gfx::Vector3dF lid_vector(cos(radians), 0.0f, sin(radians));
117 TriggerAccelerometerUpdate(base_vector, lid_vector);
120 #if defined(OS_CHROMEOS)
121 void OpenLid() {
122 maximize_mode_controller()->LidEventReceived(true /* open */,
123 maximize_mode_controller()->tick_clock_->NowTicks());
126 void CloseLid() {
127 maximize_mode_controller()->LidEventReceived(false /* open */,
128 maximize_mode_controller()->tick_clock_->NowTicks());
130 #endif // OS_CHROMEOS
132 bool WasLidOpenedRecently() {
133 return maximize_mode_controller()->WasLidOpenedRecently();
136 private:
137 base::SimpleTestTickClock* test_tick_clock_;
139 DISALLOW_COPY_AND_ASSIGN(MaximizeModeControllerTest);
142 #if defined(OS_CHROMEOS)
144 // Verify that closing the lid will exit maximize mode.
145 TEST_F(MaximizeModeControllerTest, CloseLidWhileInMaximizeMode) {
146 OpenLidToAngle(315.0f);
147 ASSERT_TRUE(IsMaximizeModeStarted());
149 CloseLid();
150 EXPECT_FALSE(IsMaximizeModeStarted());
153 // Verify that maximize mode will not be entered when the lid is closed.
154 TEST_F(MaximizeModeControllerTest,
155 HingeAnglesWithLidClosed) {
156 AttachTickClockForTest();
158 CloseLid();
160 OpenLidToAngle(270.0f);
161 EXPECT_FALSE(IsMaximizeModeStarted());
163 OpenLidToAngle(315.0f);
164 EXPECT_FALSE(IsMaximizeModeStarted());
166 OpenLidToAngle(355.0f);
167 EXPECT_FALSE(IsMaximizeModeStarted());
170 // Verify the maximize mode state for unstable hinge angles when the lid was
171 // recently open.
172 TEST_F(MaximizeModeControllerTest,
173 UnstableHingeAnglesWhenLidRecentlyOpened) {
174 AttachTickClockForTest();
176 OpenLid();
177 ASSERT_TRUE(WasLidOpenedRecently());
179 OpenLidToAngle(5.0f);
180 EXPECT_FALSE(IsMaximizeModeStarted());
182 OpenLidToAngle(355.0f);
183 EXPECT_FALSE(IsMaximizeModeStarted());
185 // This is a stable reading and should clear the last lid opened time.
186 OpenLidToAngle(45.0f);
187 EXPECT_FALSE(IsMaximizeModeStarted());
188 EXPECT_FALSE(WasLidOpenedRecently());
190 OpenLidToAngle(355.0f);
191 EXPECT_TRUE(IsMaximizeModeStarted());
194 #endif // OS_CHROMEOS
196 // Verify the WasLidOpenedRecently signal with respect to time.
197 TEST_F(MaximizeModeControllerTest, WasLidOpenedRecentlyOverTime) {
198 #if defined(OS_CHROMEOS)
200 AttachTickClockForTest();
202 // No lid open time initially.
203 ASSERT_FALSE(WasLidOpenedRecently());
205 CloseLid();
206 EXPECT_FALSE(WasLidOpenedRecently());
208 OpenLid();
209 EXPECT_TRUE(WasLidOpenedRecently());
211 // 1 second after lid open.
212 AdvanceTickClock(base::TimeDelta::FromSeconds(1));
213 EXPECT_TRUE(WasLidOpenedRecently());
215 // 3 seconds after lid open.
216 AdvanceTickClock(base::TimeDelta::FromSeconds(2));
217 EXPECT_FALSE(WasLidOpenedRecently());
219 #else
221 EXPECT_FALSE(WasLidOpenedRecently());
223 #endif // OS_CHROMEOS
226 // Verify the maximize mode enter/exit thresholds for stable angles.
227 TEST_F(MaximizeModeControllerTest, StableHingeAnglesWithLidOpened) {
228 ASSERT_FALSE(IsMaximizeModeStarted());
229 ASSERT_FALSE(WasLidOpenedRecently());
231 OpenLidToAngle(180.0f);
232 EXPECT_FALSE(IsMaximizeModeStarted());
234 OpenLidToAngle(315.0f);
235 EXPECT_TRUE(IsMaximizeModeStarted());
237 OpenLidToAngle(180.0f);
238 EXPECT_TRUE(IsMaximizeModeStarted());
240 OpenLidToAngle(45.0f);
241 EXPECT_FALSE(IsMaximizeModeStarted());
243 OpenLidToAngle(270.0f);
244 EXPECT_TRUE(IsMaximizeModeStarted());
246 OpenLidToAngle(90.0f);
247 EXPECT_FALSE(IsMaximizeModeStarted());
250 // Verify the maximize mode state for unstable hinge angles when the lid is open
251 // but not recently.
252 TEST_F(MaximizeModeControllerTest, UnstableHingeAnglesWithLidOpened) {
253 AttachTickClockForTest();
255 ASSERT_FALSE(WasLidOpenedRecently());
256 ASSERT_FALSE(IsMaximizeModeStarted());
258 OpenLidToAngle(5.0f);
259 EXPECT_FALSE(IsMaximizeModeStarted());
261 OpenLidToAngle(355.0f);
262 EXPECT_TRUE(IsMaximizeModeStarted());
264 OpenLidToAngle(5.0f);
265 EXPECT_TRUE(IsMaximizeModeStarted());
268 // Tests that when the hinge is nearly vertically aligned, the current state
269 // persists as the computed angle is highly inaccurate in this orientation.
270 TEST_F(MaximizeModeControllerTest, HingeAligned) {
271 // Laptop in normal orientation lid open 90 degrees.
272 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
273 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
274 EXPECT_FALSE(IsMaximizeModeStarted());
276 // Completely vertical.
277 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.0f),
278 gfx::Vector3dF(0.0f, -1.0f, 0.0f));
279 EXPECT_FALSE(IsMaximizeModeStarted());
281 // Close to vertical but with hinge appearing to be open 270 degrees.
282 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.01f),
283 gfx::Vector3dF(0.01f, -1.0f, 0.0f));
284 EXPECT_FALSE(IsMaximizeModeStarted());
286 // Flat and open 270 degrees should start maximize mode.
287 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
288 gfx::Vector3dF(1.0f, 0.0f, 0.0f));
289 EXPECT_TRUE(IsMaximizeModeStarted());
291 // Normal 90 degree orientation but near vertical should stay in maximize
292 // mode.
293 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.01f),
294 gfx::Vector3dF(-0.01f, -1.0f, 0.0f));
295 EXPECT_TRUE(IsMaximizeModeStarted());
298 // Tests that accelerometer readings in each of the screen angles will trigger a
299 // rotation of the internal display.
300 TEST_F(MaximizeModeControllerTest, DisplayRotation) {
301 // Trigger maximize mode by opening to 270.
302 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
303 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
304 ASSERT_TRUE(IsMaximizeModeStarted());
306 // Now test rotating in all directions.
307 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 1.0f, 0.0f),
308 gfx::Vector3dF(0.0f, 1.0f, 0.0f));
309 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
310 TriggerAccelerometerUpdate(gfx::Vector3dF(1.0f, 0.0f, 0.0f),
311 gfx::Vector3dF(1.0f, 0.0f, 0.0f));
312 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
313 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.0f),
314 gfx::Vector3dF(0.0f, -1.0f, 0.0f));
315 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
316 TriggerAccelerometerUpdate(gfx::Vector3dF(-1.0f, 0.0f, 0.0f),
317 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
318 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
321 // Tests that low angles are ignored by the accelerometer (i.e. when the device
322 // is almost laying flat).
323 TEST_F(MaximizeModeControllerTest, RotationIgnoresLowAngles) {
324 // Trigger maximize mode by opening to 270.
325 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
326 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
327 ASSERT_TRUE(IsMaximizeModeStarted());
329 TriggerAccelerometerUpdate(gfx::Vector3dF(-1.0f, 0.0f, -1.0f),
330 gfx::Vector3dF(-1.0f, 0.0f, -1.0f));
331 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
332 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.2f, -1.0f),
333 gfx::Vector3dF(0.0f, 0.2f, -1.0f));
334 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
335 TriggerAccelerometerUpdate(gfx::Vector3dF(0.2f, 0.0f, -1.0f),
336 gfx::Vector3dF(0.2f, 0.0f, -1.0f));
337 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
338 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -0.2f, -1.0f),
339 gfx::Vector3dF(0.0f, -0.2f, -1.0f));
340 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
341 TriggerAccelerometerUpdate(gfx::Vector3dF(-0.2f, 0.0f, -1.0f),
342 gfx::Vector3dF(-0.2f, 0.0f, -1.0f));
343 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
346 // Tests that the display will stick to the current orientation beyond the
347 // halfway point, preventing frequent updates back and forth.
348 TEST_F(MaximizeModeControllerTest, RotationSticky) {
349 // Trigger maximize mode by opening to 270.
350 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
351 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
352 ASSERT_TRUE(IsMaximizeModeStarted());
354 gfx::Vector3dF gravity(-1.0f, 0.0f, 0.0f);
355 TriggerAccelerometerUpdate(gravity, gravity);
356 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
358 // Turn past half-way point to next direction and rotation should remain
359 // the same.
360 float degrees = 50.0;
361 gravity.set_x(-cos(degrees * kDegreesToRadians));
362 gravity.set_y(sin(degrees * kDegreesToRadians));
363 TriggerAccelerometerUpdate(gravity, gravity);
364 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
366 // Turn more and the screen should rotate.
367 degrees = 70.0;
368 gravity.set_x(-cos(degrees * kDegreesToRadians));
369 gravity.set_y(sin(degrees * kDegreesToRadians));
370 TriggerAccelerometerUpdate(gravity, gravity);
371 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
373 // Turn back just beyond the half-way point and the new rotation should
374 // still be in effect.
375 degrees = 40.0;
376 gravity.set_x(-cos(degrees * kDegreesToRadians));
377 gravity.set_y(sin(degrees * kDegreesToRadians));
378 TriggerAccelerometerUpdate(gravity, gravity);
379 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
382 // Tests that the screen only rotates when maximize mode is engaged, and will
383 // return to the standard orientation on exiting maximize mode.
384 TEST_F(MaximizeModeControllerTest, RotationOnlyInMaximizeMode) {
385 // Rotate on side with lid only open 90 degrees.
386 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.95f, 0.35f),
387 gfx::Vector3dF(-0.35f, 0.95f, 0.0f));
388 ASSERT_FALSE(IsMaximizeModeStarted());
389 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
391 // Open lid, screen should now rotate to match orientation.
392 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.95f, -0.35f),
393 gfx::Vector3dF(-0.35f, 0.95f, 0.0f));
394 ASSERT_TRUE(IsMaximizeModeStarted());
395 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
397 // Close lid back to 90, screen should rotate back.
398 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.95f, 0.35f),
399 gfx::Vector3dF(-0.35f, 0.95f, 0.0f));
400 ASSERT_FALSE(IsMaximizeModeStarted());
401 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
404 #if defined(OS_CHROMEOS)
405 // Tests that a screenshot can be taken in maximize mode by holding volume down
406 // and pressing power.
407 TEST_F(MaximizeModeControllerTest, Screenshot) {
408 Shell::GetInstance()->lock_state_controller()->SetDelegate(
409 new test::TestLockStateControllerDelegate);
410 aura::Window* root = Shell::GetPrimaryRootWindow();
411 ui::test::EventGenerator event_generator(root, root);
412 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate();
413 delegate->set_can_take_screenshot(true);
415 // Open up 270 degrees.
416 OpenLidToAngle(270.0f);
417 ASSERT_TRUE(IsMaximizeModeStarted());
419 // Pressing power alone does not take a screenshot.
420 event_generator.PressKey(ui::VKEY_POWER, 0);
421 event_generator.ReleaseKey(ui::VKEY_POWER, 0);
422 EXPECT_EQ(0, delegate->handle_take_screenshot_count());
424 // Holding volume down and pressing power takes a screenshot.
425 event_generator.PressKey(ui::VKEY_VOLUME_DOWN, 0);
426 event_generator.PressKey(ui::VKEY_POWER, 0);
427 event_generator.ReleaseKey(ui::VKEY_POWER, 0);
428 EXPECT_EQ(1, delegate->handle_take_screenshot_count());
429 event_generator.ReleaseKey(ui::VKEY_VOLUME_DOWN, 0);
431 #endif // OS_CHROMEOS
433 TEST_F(MaximizeModeControllerTest, LaptopTest) {
434 // Feeds in sample accelerometer data and verifies that there are no
435 // transitions into touchview / maximize mode while shaking the device around
436 // with the hinge at less than 180 degrees.
437 ASSERT_EQ(0u, kAccelerometerLaptopModeTestDataLength % 6);
438 for (size_t i = 0; i < kAccelerometerLaptopModeTestDataLength / 6; ++i) {
439 gfx::Vector3dF base(kAccelerometerLaptopModeTestData[i * 6],
440 kAccelerometerLaptopModeTestData[i * 6 + 1],
441 kAccelerometerLaptopModeTestData[i * 6 + 2]);
442 gfx::Vector3dF lid(kAccelerometerLaptopModeTestData[i * 6 + 3],
443 kAccelerometerLaptopModeTestData[i * 6 + 4],
444 kAccelerometerLaptopModeTestData[i * 6 + 5]);
445 TriggerAccelerometerUpdate(base, lid);
446 // There are a lot of samples, so ASSERT rather than EXPECT to only generate
447 // one failure rather than potentially hundreds.
448 ASSERT_FALSE(IsMaximizeModeStarted());
452 TEST_F(MaximizeModeControllerTest, MaximizeModeTest) {
453 // Trigger maximize mode by opening to 270 to begin the test in maximize mode.
454 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
455 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
456 ASSERT_TRUE(IsMaximizeModeStarted());
458 // Feeds in sample accelerometer data and verifies that there are no
459 // transitions out of touchview / maximize mode while shaking the device
460 // around.
461 ASSERT_EQ(0u, kAccelerometerFullyOpenTestDataLength % 6);
462 for (size_t i = 0; i < kAccelerometerFullyOpenTestDataLength / 6; ++i) {
463 gfx::Vector3dF base(kAccelerometerFullyOpenTestData[i * 6],
464 kAccelerometerFullyOpenTestData[i * 6 + 1],
465 kAccelerometerFullyOpenTestData[i * 6 + 2]);
466 gfx::Vector3dF lid(kAccelerometerFullyOpenTestData[i * 6 + 3],
467 kAccelerometerFullyOpenTestData[i * 6 + 4],
468 kAccelerometerFullyOpenTestData[i * 6 + 5]);
469 TriggerAccelerometerUpdate(base, lid);
470 // There are a lot of samples, so ASSERT rather than EXPECT to only generate
471 // one failure rather than potentially hundreds.
472 ASSERT_TRUE(IsMaximizeModeStarted());
476 // Tests that the display will stick to its current orientation when the
477 // rotation lock has been set.
478 TEST_F(MaximizeModeControllerTest, RotationLockPreventsRotation) {
479 // Trigger maximize mode by opening to 270.
480 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
481 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
482 ASSERT_TRUE(IsMaximizeModeStarted());
484 gfx::Vector3dF gravity(-1.0f, 0.0f, 0.0f);
486 maximize_mode_controller()->SetRotationLocked(true);
488 // Turn past the threshold for rotation.
489 float degrees = 90.0;
490 gravity.set_x(-cos(degrees * kDegreesToRadians));
491 gravity.set_y(sin(degrees * kDegreesToRadians));
492 TriggerAccelerometerUpdate(gravity, gravity);
493 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
495 maximize_mode_controller()->SetRotationLocked(false);
496 TriggerAccelerometerUpdate(gravity, gravity);
497 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
500 // Tests that when MaximizeModeController turns off MaximizeMode that on the
501 // next accelerometer update the rotation lock is cleared.
502 TEST_F(MaximizeModeControllerTest, ExitingMaximizeModeClearRotationLock) {
503 // Trigger maximize mode by opening to 270.
504 OpenLidToAngle(270.0f);
505 ASSERT_TRUE(IsMaximizeModeStarted());
507 maximize_mode_controller()->SetRotationLocked(true);
509 OpenLidToAngle(90.0f);
510 EXPECT_FALSE(IsMaximizeModeStarted());
512 // Send an update that would not relaunch MaximizeMode.
513 OpenLidToAngle(90.0f);
514 EXPECT_FALSE(maximize_mode_controller()->rotation_locked());
517 // The TrayDisplay class that is responsible for adding/updating MessageCenter
518 // notifications is only added to the SystemTray on ChromeOS.
519 #if defined(OS_CHROMEOS)
520 // Tests that the screen rotation notifications are suppressed when
521 // triggered by the accelerometer.
522 TEST_F(MaximizeModeControllerTest, BlockRotationNotifications) {
523 test::TestSystemTrayDelegate* tray_delegate =
524 static_cast<test::TestSystemTrayDelegate*>(
525 Shell::GetInstance()->system_tray_delegate());
526 tray_delegate->set_should_show_display_notification(true);
528 message_center::MessageCenter* message_center =
529 message_center::MessageCenter::Get();
531 // Make sure notifications are still displayed when
532 // adjusting the screen rotation directly when not in maximize mode
533 ASSERT_FALSE(IsMaximizeModeStarted());
534 ASSERT_NE(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
535 ASSERT_EQ(0u, message_center->NotificationCount());
536 ASSERT_FALSE(message_center->HasPopupNotifications());
537 SetInternalDisplayRotation(gfx::Display::ROTATE_180);
538 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
539 EXPECT_EQ(1u, message_center->NotificationCount());
540 EXPECT_TRUE(message_center->HasPopupNotifications());
542 // Reset the screen rotation.
543 SetInternalDisplayRotation(gfx::Display::ROTATE_0);
544 // Clear all notifications
545 message_center->RemoveAllNotifications(false);
546 // Trigger maximize mode by opening to 270.
547 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
548 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
549 EXPECT_TRUE(IsMaximizeModeStarted());
550 EXPECT_EQ(0u, message_center->NotificationCount());
551 EXPECT_FALSE(message_center->HasPopupNotifications());
553 // Make sure notifications are still displayed when
554 // adjusting the screen rotation directly when in maximize mode
555 ASSERT_NE(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
556 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
557 maximize_mode_controller()->SetRotationLocked(false);
558 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
559 EXPECT_EQ(1u, message_center->NotificationCount());
560 EXPECT_TRUE(message_center->HasPopupNotifications());
562 // Clear all notifications
563 message_center->RemoveAllNotifications(false);
564 EXPECT_EQ(0u, message_center->NotificationCount());
565 EXPECT_FALSE(message_center->HasPopupNotifications());
567 // Make sure notifications are blocked when adjusting the screen rotation
568 // via the accelerometer while in maximize mode
569 // Rotate the screen 90 degrees
570 ASSERT_NE(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
571 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 1.0f, 0.0f),
572 gfx::Vector3dF(0.0f, 1.0f, 0.0f));
573 ASSERT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
574 EXPECT_EQ(0u, message_center->NotificationCount());
575 EXPECT_FALSE(message_center->HasPopupNotifications());
577 #endif
579 // Tests that if a user has set a display rotation that it is restored upon
580 // exiting maximize mode.
581 TEST_F(MaximizeModeControllerTest, ResetUserRotationUponExit) {
582 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
583 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
584 gfx::Display::ROTATE_90);
586 // Trigger maximize mode
587 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
588 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
589 ASSERT_TRUE(IsMaximizeModeStarted());
591 TriggerAccelerometerUpdate(gfx::Vector3dF(1.0f, 0.0f, 0.0f),
592 gfx::Vector3dF(1.0f, 0.0f, 0.0f));
593 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
595 // Exit maximize mode
596 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
597 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
598 EXPECT_FALSE(IsMaximizeModeStarted());
599 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
602 // Tests that if a user sets a display rotation that accelerometer rotation
603 // becomes locked.
604 TEST_F(MaximizeModeControllerTest,
605 NonAccelerometerRotationChangesLockRotation) {
606 // Trigger maximize mode by opening to 270.
607 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
608 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
609 ASSERT_FALSE(maximize_mode_controller()->rotation_locked());
610 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
611 EXPECT_TRUE(maximize_mode_controller()->rotation_locked());
614 // Tests that if a user changes the display rotation, while rotation is locked,
615 // that the updates are recorded. Upon exiting maximize mode the latest user
616 // rotation should be applied.
617 TEST_F(MaximizeModeControllerTest, UpdateUserRotationWhileRotationLocked) {
618 // Trigger maximize mode by opening to 270.
619 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
620 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
621 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
622 // User sets rotation to the same rotation that the display was at when
623 // maximize mode was activated.
624 SetInternalDisplayRotation(gfx::Display::ROTATE_0);
625 // Exit maximize mode
626 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
627 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
628 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
631 } // namespace ash