| 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/display/display_controller.h" | 10 #include "ash/display/display_controller.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 using ash::ResolutionNotificationController; | 32 using ash::ResolutionNotificationController; |
| 33 | 33 |
| 34 namespace chromeos { | 34 namespace chromeos { |
| 35 namespace { | 35 namespace { |
| 36 const char kPrimaryIdKey[] = "primary-id"; | 36 const char kPrimaryIdKey[] = "primary-id"; |
| 37 const char kMirroredKey[] = "mirrored"; | 37 const char kMirroredKey[] = "mirrored"; |
| 38 const char kPositionKey[] = "position"; | 38 const char kPositionKey[] = "position"; |
| 39 const char kOffsetKey[] = "offset"; | 39 const char kOffsetKey[] = "offset"; |
| 40 | 40 |
| 41 // The mean acceleration due to gravity on Earth in m/s^2. |
| 42 const float kMeanGravity = 9.80665f; |
| 43 |
| 41 class DisplayPreferencesTest : public ash::test::AshTestBase { | 44 class DisplayPreferencesTest : public ash::test::AshTestBase { |
| 42 protected: | 45 protected: |
| 43 DisplayPreferencesTest() | 46 DisplayPreferencesTest() |
| 44 : mock_user_manager_(new MockUserManager), | 47 : mock_user_manager_(new MockUserManager), |
| 45 user_manager_enabler_(mock_user_manager_) { | 48 user_manager_enabler_(mock_user_manager_) { |
| 46 } | 49 } |
| 47 | 50 |
| 48 virtual ~DisplayPreferencesTest() {} | 51 virtual ~DisplayPreferencesTest() {} |
| 49 | 52 |
| 50 virtual void SetUp() OVERRIDE { | 53 virtual void SetUp() OVERRIDE { |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 ash::DisplayManager* display_manager = shell->display_manager(); | 659 ash::DisplayManager* display_manager = shell->display_manager(); |
| 657 LoggedInAsUser(); | 660 LoggedInAsUser(); |
| 658 // Populate the properties. | 661 // Populate the properties. |
| 659 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 662 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
| 660 gfx::Display::ROTATE_180); | 663 gfx::Display::ROTATE_180); |
| 661 // Reset property to avoid rotation lock | 664 // Reset property to avoid rotation lock |
| 662 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 665 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
| 663 gfx::Display::ROTATE_0); | 666 gfx::Display::ROTATE_0); |
| 664 | 667 |
| 665 // Open up 270 degrees to trigger maximize mode | 668 // Open up 270 degrees to trigger maximize mode |
| 666 controller->OnAccelerometerUpdated(gfx::Vector3dF(0.0f, 0.0f, -1.0f), | 669 ui::AccelerometerUpdate update; |
| 667 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); | 670 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, |
| 671 0.0f, 0.0f, kMeanGravity); |
| 672 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, |
| 673 0.0f, -kMeanGravity, 0.0f); |
| 674 controller->OnAccelerometerUpdated(update); |
| 668 EXPECT_TRUE(controller->IsMaximizeModeWindowManagerEnabled()); | 675 EXPECT_TRUE(controller->IsMaximizeModeWindowManagerEnabled()); |
| 669 | 676 |
| 670 // Trigger 90 degree rotation | 677 // Trigger 90 degree rotation |
| 671 controller->OnAccelerometerUpdated(gfx::Vector3dF(0.0f, 1.0f, 0.0f), | 678 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, |
| 672 gfx::Vector3dF(0.0f, 1.0f, 0.0f)); | 679 -kMeanGravity, 0.0f, 0.0f); |
| 680 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, |
| 681 -kMeanGravity, 0.0f, 0.0f); |
| 682 controller->OnAccelerometerUpdated(update); |
| 673 EXPECT_EQ(gfx::Display::ROTATE_90, display_manager-> | 683 EXPECT_EQ(gfx::Display::ROTATE_90, display_manager-> |
| 674 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation()); | 684 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation()); |
| 675 | 685 |
| 676 const base::DictionaryValue* properties = | 686 const base::DictionaryValue* properties = |
| 677 local_state()->GetDictionary(prefs::kDisplayProperties); | 687 local_state()->GetDictionary(prefs::kDisplayProperties); |
| 678 const base::DictionaryValue* property = NULL; | 688 const base::DictionaryValue* property = NULL; |
| 679 EXPECT_TRUE(properties->GetDictionary( | 689 EXPECT_TRUE(properties->GetDictionary( |
| 680 base::Int64ToString(gfx::Display::InternalDisplayId()), &property)); | 690 base::Int64ToString(gfx::Display::InternalDisplayId()), &property)); |
| 681 int rotation = -1; | 691 int rotation = -1; |
| 682 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); | 692 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 | 802 |
| 793 bool rotation_lock = maximize_mode_controller->rotation_locked(); | 803 bool rotation_lock = maximize_mode_controller->rotation_locked(); |
| 794 gfx::Display::Rotation before_maximize_mode_rotation = display_manager-> | 804 gfx::Display::Rotation before_maximize_mode_rotation = display_manager-> |
| 795 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 805 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| 796 | 806 |
| 797 // Settings should not be applied until maximize mode activates | 807 // Settings should not be applied until maximize mode activates |
| 798 EXPECT_FALSE(rotation_lock); | 808 EXPECT_FALSE(rotation_lock); |
| 799 EXPECT_EQ(gfx::Display::ROTATE_0, before_maximize_mode_rotation); | 809 EXPECT_EQ(gfx::Display::ROTATE_0, before_maximize_mode_rotation); |
| 800 | 810 |
| 801 // Open up 270 degrees to trigger maximize mode | 811 // Open up 270 degrees to trigger maximize mode |
| 802 maximize_mode_controller-> | 812 ui::AccelerometerUpdate update; |
| 803 OnAccelerometerUpdated(gfx::Vector3dF(0.0f, 0.0f, -1.0f), | 813 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, |
| 804 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); | 814 0.0f, 0.0f, kMeanGravity); |
| 815 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, |
| 816 0.0f, -kMeanGravity, 0.0f); |
| 817 maximize_mode_controller->OnAccelerometerUpdated(update); |
| 805 EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); | 818 EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); |
| 806 bool maximize_mode_rotation_lock = | 819 bool maximize_mode_rotation_lock = |
| 807 maximize_mode_controller->rotation_locked(); | 820 maximize_mode_controller->rotation_locked(); |
| 808 gfx::Display::Rotation maximize_mode_rotation = display_manager-> | 821 gfx::Display::Rotation maximize_mode_rotation = display_manager-> |
| 809 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 822 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| 810 EXPECT_TRUE(maximize_mode_rotation_lock); | 823 EXPECT_TRUE(maximize_mode_rotation_lock); |
| 811 EXPECT_EQ(gfx::Display::ROTATE_90, maximize_mode_rotation); | 824 EXPECT_EQ(gfx::Display::ROTATE_90, maximize_mode_rotation); |
| 812 } | 825 } |
| 813 | 826 |
| 814 // Tests that loaded rotation state is ignored if the device starts in normal | 827 // Tests that loaded rotation state is ignored if the device starts in normal |
| 815 // mode, and that they are not applied upon first entering maximize mode. | 828 // mode, and that they are not applied upon first entering maximize mode. |
| 816 TEST_F(DisplayPreferencesTest, LoadRotationIgnoredInNormalMode) { | 829 TEST_F(DisplayPreferencesTest, LoadRotationIgnoredInNormalMode) { |
| 817 gfx::Display::SetInternalDisplayId( | 830 gfx::Display::SetInternalDisplayId( |
| 818 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 831 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
| 819 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 832 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 820 StoreDisplayRotationPrefs(false /* rotation_lock*/); | 833 StoreDisplayRotationPrefs(false /* rotation_lock*/); |
| 821 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 834 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 822 | 835 |
| 823 StoreDisplayRotationPrefsForTest(true, gfx::Display::ROTATE_90); | 836 StoreDisplayRotationPrefsForTest(true, gfx::Display::ROTATE_90); |
| 824 LoadDisplayPreferences(false); | 837 LoadDisplayPreferences(false); |
| 825 | 838 |
| 826 ash::MaximizeModeController* maximize_mode_controller = | 839 ash::MaximizeModeController* maximize_mode_controller = |
| 827 ash::Shell::GetInstance()->maximize_mode_controller(); | 840 ash::Shell::GetInstance()->maximize_mode_controller(); |
| 828 // Lid open to 90 degrees | 841 // Lid open to 90 degrees |
| 829 maximize_mode_controller-> | 842 ui::AccelerometerUpdate update; |
| 830 OnAccelerometerUpdated(gfx::Vector3dF(0.0f, 0.0f, 1.0f), | 843 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, |
| 831 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); | 844 -kMeanGravity, 0.0f, 0.0f); |
| 845 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, |
| 846 -kMeanGravity, 0.0f, 0.0f); |
| 847 maximize_mode_controller->OnAccelerometerUpdated(update); |
| 832 EXPECT_FALSE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); | 848 EXPECT_FALSE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); |
| 833 EXPECT_FALSE(maximize_mode_controller->rotation_locked()); | 849 EXPECT_FALSE(maximize_mode_controller->rotation_locked()); |
| 834 | 850 |
| 835 // Open up 270 degrees to trigger maximize mode | 851 // Open up 270 degrees to trigger maximize mode |
| 836 maximize_mode_controller-> | 852 update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, |
| 837 OnAccelerometerUpdated(gfx::Vector3dF(0.0f, 0.0f, -1.0f), | 853 0.0f, 0.0f, kMeanGravity); |
| 838 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); | 854 update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, |
| 855 0.0f, -kMeanGravity, 0.0f); |
| 856 maximize_mode_controller->OnAccelerometerUpdated(update); |
| 839 EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); | 857 EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); |
| 840 EXPECT_FALSE(maximize_mode_controller->rotation_locked()); | 858 EXPECT_FALSE(maximize_mode_controller->rotation_locked()); |
| 841 } | 859 } |
| 842 | 860 |
| 843 // Tests that rotation lock being set causes the rotation state to be saved. | 861 // Tests that rotation lock being set causes the rotation state to be saved. |
| 844 TEST_F(DisplayPreferencesTest, RotationLockTriggersStore) { | 862 TEST_F(DisplayPreferencesTest, RotationLockTriggersStore) { |
| 845 gfx::Display::SetInternalDisplayId( | 863 gfx::Display::SetInternalDisplayId( |
| 846 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); | 864 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); |
| 847 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 865 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 848 | 866 |
| 849 ash::MaximizeModeController* maximize_mode_controller = | 867 ash::MaximizeModeController* maximize_mode_controller = |
| 850 ash::Shell::GetInstance()->maximize_mode_controller(); | 868 ash::Shell::GetInstance()->maximize_mode_controller(); |
| 851 maximize_mode_controller->SetRotationLocked(true); | 869 maximize_mode_controller->SetRotationLocked(true); |
| 852 | 870 |
| 853 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 871 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 854 | 872 |
| 855 const base::DictionaryValue* properties = | 873 const base::DictionaryValue* properties = |
| 856 local_state()->GetDictionary(prefs::kDisplayRotationLock); | 874 local_state()->GetDictionary(prefs::kDisplayRotationLock); |
| 857 bool rotation_lock; | 875 bool rotation_lock; |
| 858 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); | 876 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
| 859 } | 877 } |
| 860 | 878 |
| 861 } // namespace chromeos | 879 } // namespace chromeos |
| OLD | NEW |