Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: ash/wm/maximize_mode/maximize_mode_controller_unittest.cc

Issue 303723003: Lock Rotation on user settings changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/display/display_manager.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/system/tray/system_tray_delegate.h" 10 #include "ash/system/tray/system_tray_delegate.h"
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 // Tests that the display will stick to its current orientation when the 519 // Tests that the display will stick to its current orientation when the
520 // rotation lock has been set. 520 // rotation lock has been set.
521 TEST_F(MaximizeModeControllerTest, RotationLockPreventsRotation) { 521 TEST_F(MaximizeModeControllerTest, RotationLockPreventsRotation) {
522 // Trigger maximize mode by opening to 270. 522 // Trigger maximize mode by opening to 270.
523 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f), 523 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
524 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 524 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
525 ASSERT_TRUE(IsMaximizeModeStarted()); 525 ASSERT_TRUE(IsMaximizeModeStarted());
526 526
527 gfx::Vector3dF gravity(-1.0f, 0.0f, 0.0f); 527 gfx::Vector3dF gravity(-1.0f, 0.0f, 0.0f);
528 528
529 maximize_mode_controller()->set_rotation_locked(true); 529 maximize_mode_controller()->SetRotationLocked(true);
530 530
531 // Turn past the threshold for rotation. 531 // Turn past the threshold for rotation.
532 float degrees = 90.0; 532 float degrees = 90.0;
533 gravity.set_x(-cos(degrees * kDegreesToRadians)); 533 gravity.set_x(-cos(degrees * kDegreesToRadians));
534 gravity.set_y(sin(degrees * kDegreesToRadians)); 534 gravity.set_y(sin(degrees * kDegreesToRadians));
535 TriggerAccelerometerUpdate(gravity, gravity); 535 TriggerAccelerometerUpdate(gravity, gravity);
536 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 536 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
537 537
538 maximize_mode_controller()->set_rotation_locked(false); 538 maximize_mode_controller()->SetRotationLocked(false);
539 TriggerAccelerometerUpdate(gravity, gravity); 539 TriggerAccelerometerUpdate(gravity, gravity);
540 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 540 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
541 } 541 }
542 542
543 // Tests that when MaximizeModeController turns off MaximizeMode that on the 543 // Tests that when MaximizeModeController turns off MaximizeMode that on the
544 // next accelerometer update the rotation lock is cleared. 544 // next accelerometer update the rotation lock is cleared.
545 TEST_F(MaximizeModeControllerTest, ExitingMaximizeModeClearRotationLock) { 545 TEST_F(MaximizeModeControllerTest, ExitingMaximizeModeClearRotationLock) {
546 // The base remains steady. 546 // The base remains steady.
547 gfx::Vector3dF base(0.0f, 0.0f, 1.0f); 547 gfx::Vector3dF base(0.0f, 0.0f, 1.0f);
548 548
549 // Trigger maximize mode by opening to 270. 549 // Trigger maximize mode by opening to 270.
550 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f), 550 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
551 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 551 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
552 ASSERT_TRUE(IsMaximizeModeStarted()); 552 ASSERT_TRUE(IsMaximizeModeStarted());
553 553
554 maximize_mode_controller()->set_rotation_locked(true); 554 maximize_mode_controller()->SetRotationLocked(true);
555 555
556 // Open 90 degrees. 556 // Open 90 degrees.
557 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 557 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
558 EXPECT_FALSE(IsMaximizeModeStarted()); 558 EXPECT_FALSE(IsMaximizeModeStarted());
559 559
560 // Send an update that would not relaunch MaximizeMode. 90 degrees. 560 // Send an update that would not relaunch MaximizeMode. 90 degrees.
561 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 561 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
562 EXPECT_FALSE(maximize_mode_controller()->rotation_locked()); 562 EXPECT_FALSE(maximize_mode_controller()->rotation_locked());
563 } 563 }
564 564
(...skipping 30 matching lines...) Expand all
595 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f), 595 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
596 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 596 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
597 EXPECT_TRUE(IsMaximizeModeStarted()); 597 EXPECT_TRUE(IsMaximizeModeStarted());
598 EXPECT_EQ(0u, message_center->NotificationCount()); 598 EXPECT_EQ(0u, message_center->NotificationCount());
599 EXPECT_FALSE(message_center->HasPopupNotifications()); 599 EXPECT_FALSE(message_center->HasPopupNotifications());
600 600
601 // Make sure notifications are still displayed when 601 // Make sure notifications are still displayed when
602 // adjusting the screen rotation directly when in maximize mode 602 // adjusting the screen rotation directly when in maximize mode
603 ASSERT_NE(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); 603 ASSERT_NE(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
604 SetInternalDisplayRotation(gfx::Display::ROTATE_270); 604 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
605 maximize_mode_controller()->SetRotationLocked(false);
605 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation()); 606 EXPECT_EQ(gfx::Display::ROTATE_270, GetInternalDisplayRotation());
606 EXPECT_EQ(1u, message_center->NotificationCount()); 607 EXPECT_EQ(1u, message_center->NotificationCount());
607 EXPECT_TRUE(message_center->HasPopupNotifications()); 608 EXPECT_TRUE(message_center->HasPopupNotifications());
608 609
609 // Clear all notifications 610 // Clear all notifications
610 message_center->RemoveAllNotifications(false); 611 message_center->RemoveAllNotifications(false);
611 EXPECT_EQ(0u, message_center->NotificationCount()); 612 EXPECT_EQ(0u, message_center->NotificationCount());
612 EXPECT_FALSE(message_center->HasPopupNotifications()); 613 EXPECT_FALSE(message_center->HasPopupNotifications());
613 614
614 // Make sure notifications are blocked when adjusting the screen rotation 615 // Make sure notifications are blocked when adjusting the screen rotation
(...skipping 24 matching lines...) Expand all
639 gfx::Vector3dF(1.0f, 0.0f, 0.0f)); 640 gfx::Vector3dF(1.0f, 0.0f, 0.0f));
640 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation()); 641 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());
641 642
642 // Exit maximize mode 643 // Exit maximize mode
643 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), 644 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
644 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 645 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
645 EXPECT_FALSE(IsMaximizeModeStarted()); 646 EXPECT_FALSE(IsMaximizeModeStarted());
646 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 647 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
647 } 648 }
648 649
650 // Tests that if a user sets a display rotation that accelerometer rotation
651 // becomes locked.
652 TEST_F(MaximizeModeControllerTest,
653 NonAccelerometerRotationChangesLockRotation) {
654 // Trigger maximize mode by opening to 270.
655 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
656 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
657 ASSERT_FALSE(maximize_mode_controller()->rotation_locked());
658 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
659 EXPECT_TRUE(maximize_mode_controller()->rotation_locked());
660 }
661
662 // Tests that if a user changes the display rotation, while rotation is locked,
663 // that the updates are recorded. Upon exiting maximize mode the latest user
664 // rotation should be applied.
665 TEST_F(MaximizeModeControllerTest, UpdateUserRotationWhileRotationLocked) {
666 // Trigger maximize mode by opening to 270.
667 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
668 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
669 SetInternalDisplayRotation(gfx::Display::ROTATE_270);
670 // User sets rotation to the same rotation that the display was at when
671 // maximize mode was activated.
672 SetInternalDisplayRotation(gfx::Display::ROTATE_0);
673 // Exit maximize mode
674 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
675 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
676 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
677 }
678
649 } // namespace ash 679 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698