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_delegate_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() { |
| 46 return ash::Shell::GetInstance() |
| 47 ->screen_orientation_delegate() |
| 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); |
684 EXPECT_EQ(gfx::Display::ROTATE_90, display_manager-> | 691 EXPECT_EQ(gfx::Display::ROTATE_90, display_manager-> |
685 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation()); | 692 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation()); |
686 | 693 |
687 const base::DictionaryValue* properties = | 694 const base::DictionaryValue* properties = |
688 local_state()->GetDictionary(prefs::kDisplayProperties); | 695 local_state()->GetDictionary(prefs::kDisplayProperties); |
689 const base::DictionaryValue* property = NULL; | 696 const base::DictionaryValue* property = NULL; |
690 EXPECT_TRUE(properties->GetDictionary( | 697 EXPECT_TRUE(properties->GetDictionary( |
691 base::Int64ToString(gfx::Display::InternalDisplayId()), &property)); | 698 base::Int64ToString(gfx::Display::InternalDisplayId()), &property)); |
692 int rotation = -1; | 699 int rotation = -1; |
693 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); | 700 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); |
694 EXPECT_EQ(gfx::Display::ROTATE_0, rotation); | 701 EXPECT_EQ(gfx::Display::ROTATE_0, rotation); |
695 } | 702 } |
696 | 703 |
697 // Tests that the rotation state is saved without a user being logged in. | 704 // Tests that the rotation state is saved without a user being logged in. |
698 TEST_F(DisplayPreferencesTest, StoreRotationStateNoLogin) { | 705 TEST_F(DisplayPreferencesTest, StoreRotationStateNoLogin) { |
699 gfx::Display::SetInternalDisplayId( | 706 gfx::Display::SetInternalDisplayId( |
700 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 707 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
701 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 708 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
702 | 709 |
703 bool current_rotation_lock = | 710 bool current_rotation_lock = rotation_locked(); |
704 ash::Shell::GetInstance()->maximize_mode_controller()->rotation_locked(); | |
705 StoreDisplayRotationPrefs(current_rotation_lock); | 711 StoreDisplayRotationPrefs(current_rotation_lock); |
706 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 712 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
707 | 713 |
708 const base::DictionaryValue* properties = | 714 const base::DictionaryValue* properties = |
709 local_state()->GetDictionary(prefs::kDisplayRotationLock); | 715 local_state()->GetDictionary(prefs::kDisplayRotationLock); |
710 bool rotation_lock; | 716 bool rotation_lock; |
711 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); | 717 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
712 EXPECT_EQ(current_rotation_lock, rotation_lock); | 718 EXPECT_EQ(current_rotation_lock, rotation_lock); |
713 | 719 |
714 int orientation; | 720 int orientation; |
715 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> | 721 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> |
716 display_manager()-> | 722 display_manager()-> |
717 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 723 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
718 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); | 724 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); |
719 EXPECT_EQ(current_rotation, orientation); | 725 EXPECT_EQ(current_rotation, orientation); |
720 } | 726 } |
721 | 727 |
722 // Tests that the rotation state is saved when a guest is logged in. | 728 // Tests that the rotation state is saved when a guest is logged in. |
723 TEST_F(DisplayPreferencesTest, StoreRotationStateGuest) { | 729 TEST_F(DisplayPreferencesTest, StoreRotationStateGuest) { |
724 gfx::Display::SetInternalDisplayId( | 730 gfx::Display::SetInternalDisplayId( |
725 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 731 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
726 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 732 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
727 LoggedInAsGuest(); | 733 LoggedInAsGuest(); |
728 | 734 |
729 bool current_rotation_lock = | 735 bool current_rotation_lock = rotation_locked(); |
730 ash::Shell::GetInstance()->maximize_mode_controller()->rotation_locked(); | |
731 StoreDisplayRotationPrefs(current_rotation_lock); | 736 StoreDisplayRotationPrefs(current_rotation_lock); |
732 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 737 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
733 | 738 |
734 const base::DictionaryValue* properties = | 739 const base::DictionaryValue* properties = |
735 local_state()->GetDictionary(prefs::kDisplayRotationLock); | 740 local_state()->GetDictionary(prefs::kDisplayRotationLock); |
736 bool rotation_lock; | 741 bool rotation_lock; |
737 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); | 742 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
738 EXPECT_EQ(current_rotation_lock, rotation_lock); | 743 EXPECT_EQ(current_rotation_lock, rotation_lock); |
739 | 744 |
740 int orientation; | 745 int orientation; |
741 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> | 746 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> |
742 display_manager()-> | 747 display_manager()-> |
743 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 748 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
744 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); | 749 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); |
745 EXPECT_EQ(current_rotation, orientation); | 750 EXPECT_EQ(current_rotation, orientation); |
746 } | 751 } |
747 | 752 |
748 // Tests that the rotation state is saved when a normal user is logged in. | 753 // Tests that the rotation state is saved when a normal user is logged in. |
749 TEST_F(DisplayPreferencesTest, StoreRotationStateNormalUser) { | 754 TEST_F(DisplayPreferencesTest, StoreRotationStateNormalUser) { |
750 gfx::Display::SetInternalDisplayId( | 755 gfx::Display::SetInternalDisplayId( |
751 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 756 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
752 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 757 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
753 LoggedInAsGuest(); | 758 LoggedInAsGuest(); |
754 | 759 |
755 bool current_rotation_lock = | 760 bool current_rotation_lock = rotation_locked(); |
756 ash::Shell::GetInstance()->maximize_mode_controller()->rotation_locked(); | |
757 StoreDisplayRotationPrefs(current_rotation_lock); | 761 StoreDisplayRotationPrefs(current_rotation_lock); |
758 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 762 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
759 | 763 |
760 const base::DictionaryValue* properties = | 764 const base::DictionaryValue* properties = |
761 local_state()->GetDictionary(prefs::kDisplayRotationLock); | 765 local_state()->GetDictionary(prefs::kDisplayRotationLock); |
762 bool rotation_lock; | 766 bool rotation_lock; |
763 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); | 767 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
764 EXPECT_EQ(current_rotation_lock, rotation_lock); | 768 EXPECT_EQ(current_rotation_lock, rotation_lock); |
765 | 769 |
766 int orientation; | 770 int orientation; |
767 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> | 771 gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> |
768 display_manager()-> | 772 display_manager()-> |
769 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 773 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
770 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); | 774 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); |
771 EXPECT_EQ(current_rotation, orientation); | 775 EXPECT_EQ(current_rotation, orientation); |
772 } | 776 } |
773 | 777 |
774 // Tests that rotation state is loaded without a user being logged in, and that | 778 // Tests that rotation state is loaded without a user being logged in, and that |
775 // entering maximize mode applies the state. | 779 // entering maximize mode applies the state. |
776 TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) { | 780 TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) { |
777 gfx::Display::SetInternalDisplayId( | 781 gfx::Display::SetInternalDisplayId( |
778 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 782 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
779 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 783 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
780 | 784 |
781 ash::Shell* shell = ash::Shell::GetInstance(); | 785 ash::Shell* shell = ash::Shell::GetInstance(); |
782 ash::MaximizeModeController* maximize_mode_controller = | 786 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); | 787 ASSERT_FALSE(initial_rotation_lock); |
786 ash::DisplayManager* display_manager = shell->display_manager(); | 788 ash::DisplayManager* display_manager = shell->display_manager(); |
787 gfx::Display::Rotation initial_rotation = display_manager-> | 789 gfx::Display::Rotation initial_rotation = display_manager-> |
788 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 790 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
789 ASSERT_EQ(gfx::Display::ROTATE_0, initial_rotation); | 791 ASSERT_EQ(gfx::Display::ROTATE_0, initial_rotation); |
790 | 792 |
791 StoreDisplayRotationPrefs(initial_rotation_lock); | 793 StoreDisplayRotationPrefs(initial_rotation_lock); |
792 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 794 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
793 | 795 |
794 StoreDisplayRotationPrefsForTest(true, gfx::Display::ROTATE_90); | 796 StoreDisplayRotationPrefsForTest(true, gfx::Display::ROTATE_90); |
795 LoadDisplayPreferences(false); | 797 LoadDisplayPreferences(false); |
796 | 798 |
797 bool display_rotation_lock = | 799 bool display_rotation_lock = |
798 display_manager->registered_internal_display_rotation_lock(); | 800 display_manager->registered_internal_display_rotation_lock(); |
799 bool display_rotation = | 801 bool display_rotation = |
800 display_manager->registered_internal_display_rotation(); | 802 display_manager->registered_internal_display_rotation(); |
801 EXPECT_TRUE(display_rotation_lock); | 803 EXPECT_TRUE(display_rotation_lock); |
802 EXPECT_EQ(gfx::Display::ROTATE_90, display_rotation); | 804 EXPECT_EQ(gfx::Display::ROTATE_90, display_rotation); |
803 | 805 |
804 bool rotation_lock = maximize_mode_controller->rotation_locked(); | 806 bool rotation_lock = rotation_locked(); |
805 gfx::Display::Rotation before_maximize_mode_rotation = display_manager-> | 807 gfx::Display::Rotation before_maximize_mode_rotation = display_manager-> |
806 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 808 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
807 | 809 |
808 // Settings should not be applied until maximize mode activates | 810 // Settings should not be applied until maximize mode activates |
809 EXPECT_FALSE(rotation_lock); | 811 EXPECT_FALSE(rotation_lock); |
810 EXPECT_EQ(gfx::Display::ROTATE_0, before_maximize_mode_rotation); | 812 EXPECT_EQ(gfx::Display::ROTATE_0, before_maximize_mode_rotation); |
811 | 813 |
812 // Open up 270 degrees to trigger maximize mode | 814 // Open up 270 degrees to trigger maximize mode |
813 ui::AccelerometerUpdate update; | 815 ui::AccelerometerUpdate update; |
814 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, | 816 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, |
815 0.0f, 0.0f, kMeanGravity); | 817 0.0f, 0.0f, kMeanGravity); |
816 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, | 818 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, |
817 0.0f, -kMeanGravity, 0.0f); | 819 0.0f, -kMeanGravity, 0.0f); |
| 820 ash::MaximizeModeController* maximize_mode_controller = |
| 821 shell->maximize_mode_controller(); |
818 maximize_mode_controller->OnAccelerometerUpdated(update); | 822 maximize_mode_controller->OnAccelerometerUpdated(update); |
819 EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); | 823 EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); |
820 bool maximize_mode_rotation_lock = | 824 bool screen_orientation_rotation_lock = rotation_locked(); |
821 maximize_mode_controller->rotation_locked(); | |
822 gfx::Display::Rotation maximize_mode_rotation = display_manager-> | 825 gfx::Display::Rotation maximize_mode_rotation = display_manager-> |
823 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 826 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
824 EXPECT_TRUE(maximize_mode_rotation_lock); | 827 EXPECT_TRUE(screen_orientation_rotation_lock); |
825 EXPECT_EQ(gfx::Display::ROTATE_90, maximize_mode_rotation); | 828 EXPECT_EQ(gfx::Display::ROTATE_90, maximize_mode_rotation); |
826 } | 829 } |
827 | 830 |
828 // Tests that loaded rotation state is ignored if the device starts in normal | 831 // 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. | 832 // mode, and that they are not applied upon first entering maximize mode. |
830 TEST_F(DisplayPreferencesTest, LoadRotationIgnoredInNormalMode) { | 833 TEST_F(DisplayPreferencesTest, LoadRotationIgnoredInNormalMode) { |
831 gfx::Display::SetInternalDisplayId( | 834 gfx::Display::SetInternalDisplayId( |
832 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 835 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
833 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 836 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
834 StoreDisplayRotationPrefs(false /* rotation_lock*/); | 837 StoreDisplayRotationPrefs(false /* rotation_lock*/); |
835 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 838 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
836 | 839 |
837 StoreDisplayRotationPrefsForTest(true, gfx::Display::ROTATE_90); | 840 StoreDisplayRotationPrefsForTest(true, gfx::Display::ROTATE_90); |
838 LoadDisplayPreferences(false); | 841 LoadDisplayPreferences(false); |
839 | 842 |
840 ash::MaximizeModeController* maximize_mode_controller = | 843 ash::MaximizeModeController* maximize_mode_controller = |
841 ash::Shell::GetInstance()->maximize_mode_controller(); | 844 ash::Shell::GetInstance()->maximize_mode_controller(); |
842 // Lid open to 90 degrees | 845 // Lid open to 90 degrees |
843 ui::AccelerometerUpdate update; | 846 ui::AccelerometerUpdate update; |
844 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, | 847 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, |
845 -kMeanGravity, 0.0f, 0.0f); | 848 -kMeanGravity, 0.0f, 0.0f); |
846 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, | 849 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, |
847 -kMeanGravity, 0.0f, 0.0f); | 850 -kMeanGravity, 0.0f, 0.0f); |
848 maximize_mode_controller->OnAccelerometerUpdated(update); | 851 maximize_mode_controller->OnAccelerometerUpdated(update); |
849 EXPECT_FALSE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); | 852 EXPECT_FALSE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); |
850 EXPECT_FALSE(maximize_mode_controller->rotation_locked()); | 853 EXPECT_FALSE(rotation_locked()); |
851 | 854 |
852 // Open up 270 degrees to trigger maximize mode | 855 // Open up 270 degrees to trigger maximize mode |
853 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, | 856 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, |
854 0.0f, 0.0f, kMeanGravity); | 857 0.0f, 0.0f, kMeanGravity); |
855 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, | 858 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, |
856 0.0f, -kMeanGravity, 0.0f); | 859 0.0f, -kMeanGravity, 0.0f); |
857 maximize_mode_controller->OnAccelerometerUpdated(update); | 860 maximize_mode_controller->OnAccelerometerUpdated(update); |
858 EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); | 861 EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); |
859 EXPECT_FALSE(maximize_mode_controller->rotation_locked()); | 862 EXPECT_FALSE(rotation_locked()); |
860 } | 863 } |
861 | 864 |
862 // Tests that rotation lock being set causes the rotation state to be saved. | 865 // Tests that rotation lock being set causes the rotation state to be saved. |
863 TEST_F(DisplayPreferencesTest, RotationLockTriggersStore) { | 866 TEST_F(DisplayPreferencesTest, RotationLockTriggersStore) { |
864 gfx::Display::SetInternalDisplayId( | 867 gfx::Display::SetInternalDisplayId( |
865 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 868 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
866 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 869 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
867 | 870 |
868 ash::MaximizeModeController* maximize_mode_controller = | 871 ash::Shell::GetInstance()->screen_orientation_delegate()->SetRotationLocked( |
869 ash::Shell::GetInstance()->maximize_mode_controller(); | 872 true); |
870 maximize_mode_controller->SetRotationLocked(true); | |
871 | 873 |
872 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 874 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
873 | 875 |
874 const base::DictionaryValue* properties = | 876 const base::DictionaryValue* properties = |
875 local_state()->GetDictionary(prefs::kDisplayRotationLock); | 877 local_state()->GetDictionary(prefs::kDisplayRotationLock); |
876 bool rotation_lock; | 878 bool rotation_lock; |
877 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); | 879 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
878 } | 880 } |
879 | 881 |
880 } // namespace chromeos | 882 } // namespace chromeos |
OLD | NEW |