OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/display/display_preferences.h" | 5 #include "chrome/browser/chromeos/display/display_preferences.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/content/display/screen_orientation_controller_chromeos.h" | |
10 #include "ash/display/display_controller.h" | 11 #include "ash/display/display_controller.h" |
11 #include "ash/display/display_layout_store.h" | 12 #include "ash/display/display_layout_store.h" |
12 #include "ash/display/display_manager.h" | 13 #include "ash/display/display_manager.h" |
13 #include "ash/display/resolution_notification_controller.h" | 14 #include "ash/display/resolution_notification_controller.h" |
14 #include "ash/screen_util.h" | 15 #include "ash/screen_util.h" |
15 #include "ash/shell.h" | 16 #include "ash/shell.h" |
16 #include "ash/test/ash_test_base.h" | 17 #include "ash/test/ash_test_base.h" |
17 #include "ash/test/display_manager_test_api.h" | 18 #include "ash/test/display_manager_test_api.h" |
18 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 19 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
19 #include "base/prefs/scoped_user_pref_update.h" | 20 #include "base/prefs/scoped_user_pref_update.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
34 namespace chromeos { | 35 namespace chromeos { |
35 namespace { | 36 namespace { |
36 const char kPrimaryIdKey[] = "primary-id"; | 37 const char kPrimaryIdKey[] = "primary-id"; |
37 const char kMirroredKey[] = "mirrored"; | 38 const char kMirroredKey[] = "mirrored"; |
38 const char kPositionKey[] = "position"; | 39 const char kPositionKey[] = "position"; |
39 const char kOffsetKey[] = "offset"; | 40 const char kOffsetKey[] = "offset"; |
40 | 41 |
41 // The mean acceleration due to gravity on Earth in m/s^2. | 42 // The mean acceleration due to gravity on Earth in m/s^2. |
42 const float kMeanGravity = 9.80665f; | 43 const float kMeanGravity = 9.80665f; |
43 | 44 |
45 bool rotation_locked() { | |
oshima
2014/12/11 23:51:28
IsRotationLocked()
jonross
2014/12/12 18:30:04
Done.
| |
46 return ash::Shell::GetInstance() | |
47 ->screen_orientation_controller() | |
48 ->rotation_locked(); | |
49 } | |
50 | |
44 class DisplayPreferencesTest : public ash::test::AshTestBase { | 51 class DisplayPreferencesTest : public ash::test::AshTestBase { |
45 protected: | 52 protected: |
46 DisplayPreferencesTest() | 53 DisplayPreferencesTest() |
47 : mock_user_manager_(new MockUserManager), | 54 : mock_user_manager_(new MockUserManager), |
48 user_manager_enabler_(mock_user_manager_) { | 55 user_manager_enabler_(mock_user_manager_) { |
49 } | 56 } |
50 | 57 |
51 virtual ~DisplayPreferencesTest() {} | 58 virtual ~DisplayPreferencesTest() {} |
52 | 59 |
53 virtual void SetUp() override { | 60 virtual void SetUp() override { |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
647 local_state()->SetString(prefs::kDisplayPowerState, "all_off"); | 654 local_state()->SetString(prefs::kDisplayPowerState, "all_off"); |
648 LoadDisplayPreferences(false); | 655 LoadDisplayPreferences(false); |
649 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, | 656 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
650 shell->display_configurator()->requested_power_state()); | 657 shell->display_configurator()->requested_power_state()); |
651 } | 658 } |
652 | 659 |
653 // Tests that display configuration changes caused by MaximizeModeController | 660 // Tests that display configuration changes caused by MaximizeModeController |
654 // are not saved. | 661 // are not saved. |
655 TEST_F(DisplayPreferencesTest, DontSaveMaximizeModeControllerRotations) { | 662 TEST_F(DisplayPreferencesTest, DontSaveMaximizeModeControllerRotations) { |
656 ash::Shell* shell = ash::Shell::GetInstance(); | 663 ash::Shell* shell = ash::Shell::GetInstance(); |
657 ash::MaximizeModeController* controller = shell->maximize_mode_controller(); | |
658 gfx::Display::SetInternalDisplayId( | 664 gfx::Display::SetInternalDisplayId( |
659 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 665 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
660 ash::DisplayManager* display_manager = shell->display_manager(); | 666 ash::DisplayManager* display_manager = shell->display_manager(); |
661 LoggedInAsUser(); | 667 LoggedInAsUser(); |
662 // Populate the properties. | 668 // Populate the properties. |
663 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 669 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
664 gfx::Display::ROTATE_180); | 670 gfx::Display::ROTATE_180); |
665 // Reset property to avoid rotation lock | 671 // Reset property to avoid rotation lock |
666 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 672 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
667 gfx::Display::ROTATE_0); | 673 gfx::Display::ROTATE_0); |
668 | 674 |
669 // Open up 270 degrees to trigger maximize mode | 675 // Open up 270 degrees to trigger maximize mode |
670 ui::AccelerometerUpdate update; | 676 ui::AccelerometerUpdate update; |
671 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, | 677 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, |
672 0.0f, 0.0f, kMeanGravity); | 678 0.0f, 0.0f, kMeanGravity); |
673 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, | 679 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, |
674 0.0f, -kMeanGravity, 0.0f); | 680 0.0f, -kMeanGravity, 0.0f); |
681 ash::MaximizeModeController* controller = shell->maximize_mode_controller(); | |
675 controller->OnAccelerometerUpdated(update); | 682 controller->OnAccelerometerUpdated(update); |
676 EXPECT_TRUE(controller->IsMaximizeModeWindowManagerEnabled()); | 683 EXPECT_TRUE(controller->IsMaximizeModeWindowManagerEnabled()); |
677 | 684 |
678 // Trigger 90 degree rotation | 685 // Trigger 90 degree rotation |
679 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, | 686 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, |
680 -kMeanGravity, 0.0f, 0.0f); | 687 -kMeanGravity, 0.0f, 0.0f); |
681 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, | 688 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, |
682 -kMeanGravity, 0.0f, 0.0f); | 689 -kMeanGravity, 0.0f, 0.0f); |
683 controller->OnAccelerometerUpdated(update); | 690 controller->OnAccelerometerUpdated(update); |
691 shell->screen_orientation_controller()->OnAccelerometerUpdated(update); | |
684 EXPECT_EQ(gfx::Display::ROTATE_90, display_manager-> | 692 EXPECT_EQ(gfx::Display::ROTATE_90, display_manager-> |
685 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation()); | 693 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation()); |
686 | 694 |
687 const base::DictionaryValue* properties = | 695 const base::DictionaryValue* properties = |
688 local_state()->GetDictionary(prefs::kDisplayProperties); | 696 local_state()->GetDictionary(prefs::kDisplayProperties); |
689 const base::DictionaryValue* property = NULL; | 697 const base::DictionaryValue* property = NULL; |
690 EXPECT_TRUE(properties->GetDictionary( | 698 EXPECT_TRUE(properties->GetDictionary( |
691 base::Int64ToString(gfx::Display::InternalDisplayId()), &property)); | 699 base::Int64ToString(gfx::Display::InternalDisplayId()), &property)); |
692 int rotation = -1; | 700 int rotation = -1; |
693 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); | 701 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); |
694 EXPECT_EQ(gfx::Display::ROTATE_0, rotation); | 702 EXPECT_EQ(gfx::Display::ROTATE_0, rotation); |
695 } | 703 } |
696 | 704 |
697 // Tests that the rotation state is saved without a user being logged in. | 705 // Tests that the rotation state is saved without a user being logged in. |
698 TEST_F(DisplayPreferencesTest, StoreRotationStateNoLogin) { | 706 TEST_F(DisplayPreferencesTest, StoreRotationStateNoLogin) { |
699 gfx::Display::SetInternalDisplayId( | 707 gfx::Display::SetInternalDisplayId( |
700 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 708 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
701 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 709 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
702 | 710 |
703 bool current_rotation_lock = | 711 bool current_rotation_lock = rotation_locked(); |
704 ash::Shell::GetInstance()->maximize_mode_controller()->rotation_locked(); | |
705 StoreDisplayRotationPrefs(current_rotation_lock); | 712 StoreDisplayRotationPrefs(current_rotation_lock); |
706 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 713 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
707 | 714 |
708 const base::DictionaryValue* properties = | 715 const base::DictionaryValue* properties = |
709 local_state()->GetDictionary(prefs::kDisplayRotationLock); | 716 local_state()->GetDictionary(prefs::kDisplayRotationLock); |
710 bool rotation_lock; | 717 bool rotation_lock; |
711 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); | 718 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
712 EXPECT_EQ(current_rotation_lock, rotation_lock); | 719 EXPECT_EQ(current_rotation_lock, rotation_lock); |
713 | 720 |
714 int orientation; | 721 int orientation; |
715 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> | 722 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> |
716 display_manager()-> | 723 display_manager()-> |
717 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 724 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
718 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); | 725 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); |
719 EXPECT_EQ(current_rotation, orientation); | 726 EXPECT_EQ(current_rotation, orientation); |
720 } | 727 } |
721 | 728 |
722 // Tests that the rotation state is saved when a guest is logged in. | 729 // Tests that the rotation state is saved when a guest is logged in. |
723 TEST_F(DisplayPreferencesTest, StoreRotationStateGuest) { | 730 TEST_F(DisplayPreferencesTest, StoreRotationStateGuest) { |
724 gfx::Display::SetInternalDisplayId( | 731 gfx::Display::SetInternalDisplayId( |
725 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 732 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
726 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 733 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
727 LoggedInAsGuest(); | 734 LoggedInAsGuest(); |
728 | 735 |
729 bool current_rotation_lock = | 736 bool current_rotation_lock = rotation_locked(); |
730 ash::Shell::GetInstance()->maximize_mode_controller()->rotation_locked(); | |
731 StoreDisplayRotationPrefs(current_rotation_lock); | 737 StoreDisplayRotationPrefs(current_rotation_lock); |
732 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 738 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
733 | 739 |
734 const base::DictionaryValue* properties = | 740 const base::DictionaryValue* properties = |
735 local_state()->GetDictionary(prefs::kDisplayRotationLock); | 741 local_state()->GetDictionary(prefs::kDisplayRotationLock); |
736 bool rotation_lock; | 742 bool rotation_lock; |
737 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); | 743 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
738 EXPECT_EQ(current_rotation_lock, rotation_lock); | 744 EXPECT_EQ(current_rotation_lock, rotation_lock); |
739 | 745 |
740 int orientation; | 746 int orientation; |
741 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> | 747 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> |
742 display_manager()-> | 748 display_manager()-> |
743 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 749 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
744 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); | 750 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); |
745 EXPECT_EQ(current_rotation, orientation); | 751 EXPECT_EQ(current_rotation, orientation); |
746 } | 752 } |
747 | 753 |
748 // Tests that the rotation state is saved when a normal user is logged in. | 754 // Tests that the rotation state is saved when a normal user is logged in. |
749 TEST_F(DisplayPreferencesTest, StoreRotationStateNormalUser) { | 755 TEST_F(DisplayPreferencesTest, StoreRotationStateNormalUser) { |
750 gfx::Display::SetInternalDisplayId( | 756 gfx::Display::SetInternalDisplayId( |
751 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 757 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
752 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 758 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
753 LoggedInAsGuest(); | 759 LoggedInAsGuest(); |
754 | 760 |
755 bool current_rotation_lock = | 761 bool current_rotation_lock = rotation_locked(); |
756 ash::Shell::GetInstance()->maximize_mode_controller()->rotation_locked(); | |
757 StoreDisplayRotationPrefs(current_rotation_lock); | 762 StoreDisplayRotationPrefs(current_rotation_lock); |
758 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 763 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
759 | 764 |
760 const base::DictionaryValue* properties = | 765 const base::DictionaryValue* properties = |
761 local_state()->GetDictionary(prefs::kDisplayRotationLock); | 766 local_state()->GetDictionary(prefs::kDisplayRotationLock); |
762 bool rotation_lock; | 767 bool rotation_lock; |
763 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); | 768 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
764 EXPECT_EQ(current_rotation_lock, rotation_lock); | 769 EXPECT_EQ(current_rotation_lock, rotation_lock); |
765 | 770 |
766 int orientation; | 771 int orientation; |
767 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> | 772 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> |
768 display_manager()-> | 773 display_manager()-> |
769 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 774 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
770 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); | 775 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); |
771 EXPECT_EQ(current_rotation, orientation); | 776 EXPECT_EQ(current_rotation, orientation); |
772 } | 777 } |
773 | 778 |
774 // Tests that rotation state is loaded without a user being logged in, and that | 779 // Tests that rotation state is loaded without a user being logged in, and that |
775 // entering maximize mode applies the state. | 780 // entering maximize mode applies the state. |
776 TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) { | 781 TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) { |
777 gfx::Display::SetInternalDisplayId( | 782 gfx::Display::SetInternalDisplayId( |
778 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 783 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
779 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 784 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
780 | 785 |
781 ash::Shell* shell = ash::Shell::GetInstance(); | 786 ash::Shell* shell = ash::Shell::GetInstance(); |
782 ash::MaximizeModeController* maximize_mode_controller = | 787 bool initial_rotation_lock = rotation_locked(); |
783 shell->maximize_mode_controller(); | |
784 bool initial_rotation_lock = maximize_mode_controller->rotation_locked(); | |
785 ASSERT_FALSE(initial_rotation_lock); | 788 ASSERT_FALSE(initial_rotation_lock); |
786 ash::DisplayManager* display_manager = shell->display_manager(); | 789 ash::DisplayManager* display_manager = shell->display_manager(); |
787 gfx::Display::Rotation initial_rotation = display_manager-> | 790 gfx::Display::Rotation initial_rotation = display_manager-> |
788 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 791 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
789 ASSERT_EQ(gfx::Display::ROTATE_0, initial_rotation); | 792 ASSERT_EQ(gfx::Display::ROTATE_0, initial_rotation); |
790 | 793 |
791 StoreDisplayRotationPrefs(initial_rotation_lock); | 794 StoreDisplayRotationPrefs(initial_rotation_lock); |
792 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 795 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
793 | 796 |
794 StoreDisplayRotationPrefsForTest(true, gfx::Display::ROTATE_90); | 797 StoreDisplayRotationPrefsForTest(true, gfx::Display::ROTATE_90); |
795 LoadDisplayPreferences(false); | 798 LoadDisplayPreferences(false); |
796 | 799 |
797 bool display_rotation_lock = | 800 bool display_rotation_lock = |
798 display_manager->registered_internal_display_rotation_lock(); | 801 display_manager->registered_internal_display_rotation_lock(); |
799 bool display_rotation = | 802 bool display_rotation = |
800 display_manager->registered_internal_display_rotation(); | 803 display_manager->registered_internal_display_rotation(); |
801 EXPECT_TRUE(display_rotation_lock); | 804 EXPECT_TRUE(display_rotation_lock); |
802 EXPECT_EQ(gfx::Display::ROTATE_90, display_rotation); | 805 EXPECT_EQ(gfx::Display::ROTATE_90, display_rotation); |
803 | 806 |
804 bool rotation_lock = maximize_mode_controller->rotation_locked(); | 807 bool rotation_lock = rotation_locked(); |
805 gfx::Display::Rotation before_maximize_mode_rotation = display_manager-> | 808 gfx::Display::Rotation before_maximize_mode_rotation = display_manager-> |
806 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 809 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
807 | 810 |
808 // Settings should not be applied until maximize mode activates | 811 // Settings should not be applied until maximize mode activates |
809 EXPECT_FALSE(rotation_lock); | 812 EXPECT_FALSE(rotation_lock); |
810 EXPECT_EQ(gfx::Display::ROTATE_0, before_maximize_mode_rotation); | 813 EXPECT_EQ(gfx::Display::ROTATE_0, before_maximize_mode_rotation); |
811 | 814 |
812 // Open up 270 degrees to trigger maximize mode | 815 // Open up 270 degrees to trigger maximize mode |
813 ui::AccelerometerUpdate update; | 816 ui::AccelerometerUpdate update; |
814 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, | 817 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, |
815 0.0f, 0.0f, kMeanGravity); | 818 0.0f, 0.0f, kMeanGravity); |
816 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, | 819 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, |
817 0.0f, -kMeanGravity, 0.0f); | 820 0.0f, -kMeanGravity, 0.0f); |
821 ash::MaximizeModeController* maximize_mode_controller = | |
822 shell->maximize_mode_controller(); | |
818 maximize_mode_controller->OnAccelerometerUpdated(update); | 823 maximize_mode_controller->OnAccelerometerUpdated(update); |
819 EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); | 824 EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); |
820 bool maximize_mode_rotation_lock = | 825 bool screen_orientation_rotation_lock = rotation_locked(); |
821 maximize_mode_controller->rotation_locked(); | |
822 gfx::Display::Rotation maximize_mode_rotation = display_manager-> | 826 gfx::Display::Rotation maximize_mode_rotation = display_manager-> |
823 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 827 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
824 EXPECT_TRUE(maximize_mode_rotation_lock); | 828 EXPECT_TRUE(screen_orientation_rotation_lock); |
825 EXPECT_EQ(gfx::Display::ROTATE_90, maximize_mode_rotation); | 829 EXPECT_EQ(gfx::Display::ROTATE_90, maximize_mode_rotation); |
826 } | 830 } |
827 | 831 |
828 // Tests that loaded rotation state is ignored if the device starts in normal | |
829 // mode, and that they are not applied upon first entering maximize mode. | |
830 TEST_F(DisplayPreferencesTest, LoadRotationIgnoredInNormalMode) { | |
831 gfx::Display::SetInternalDisplayId( | |
832 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | |
833 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | |
834 StoreDisplayRotationPrefs(false /* rotation_lock*/); | |
835 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | |
836 | |
837 StoreDisplayRotationPrefsForTest(true, gfx::Display::ROTATE_90); | |
838 LoadDisplayPreferences(false); | |
839 | |
840 ash::MaximizeModeController* maximize_mode_controller = | |
841 ash::Shell::GetInstance()->maximize_mode_controller(); | |
842 // Lid open to 90 degrees | |
843 ui::AccelerometerUpdate update; | |
844 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, | |
845 -kMeanGravity, 0.0f, 0.0f); | |
846 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, | |
847 -kMeanGravity, 0.0f, 0.0f); | |
848 maximize_mode_controller->OnAccelerometerUpdated(update); | |
849 EXPECT_FALSE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); | |
850 EXPECT_FALSE(maximize_mode_controller->rotation_locked()); | |
851 | |
852 // Open up 270 degrees to trigger maximize mode | |
853 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, | |
854 0.0f, 0.0f, kMeanGravity); | |
855 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, | |
856 0.0f, -kMeanGravity, 0.0f); | |
857 maximize_mode_controller->OnAccelerometerUpdated(update); | |
858 EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); | |
859 EXPECT_FALSE(maximize_mode_controller->rotation_locked()); | |
860 } | |
861 | |
862 // Tests that rotation lock being set causes the rotation state to be saved. | 832 // Tests that rotation lock being set causes the rotation state to be saved. |
863 TEST_F(DisplayPreferencesTest, RotationLockTriggersStore) { | 833 TEST_F(DisplayPreferencesTest, RotationLockTriggersStore) { |
864 gfx::Display::SetInternalDisplayId( | 834 gfx::Display::SetInternalDisplayId( |
865 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 835 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
866 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 836 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
867 | 837 |
868 ash::MaximizeModeController* maximize_mode_controller = | 838 ash::Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( |
869 ash::Shell::GetInstance()->maximize_mode_controller(); | 839 true); |
870 maximize_mode_controller->SetRotationLocked(true); | |
871 | 840 |
872 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 841 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
873 | 842 |
874 const base::DictionaryValue* properties = | 843 const base::DictionaryValue* properties = |
875 local_state()->GetDictionary(prefs::kDisplayRotationLock); | 844 local_state()->GetDictionary(prefs::kDisplayRotationLock); |
876 bool rotation_lock; | 845 bool rotation_lock; |
877 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); | 846 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
878 } | 847 } |
879 | 848 |
880 } // namespace chromeos | 849 } // namespace chromeos |
OLD | NEW |