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