| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "ash/display/display_util.h" | 13 #include "ash/display/display_util.h" |
| 14 #include "ash/display/resolution_notification_controller.h" | 14 #include "ash/display/resolution_notification_controller.h" |
| 15 #include "ash/display/screen_orientation_controller_chromeos.h" | 15 #include "ash/display/screen_orientation_controller_chromeos.h" |
| 16 #include "ash/display/window_tree_host_manager.h" | 16 #include "ash/display/window_tree_host_manager.h" |
| 17 #include "ash/shell.h" | 17 #include "ash/shell.h" |
| 18 #include "ash/test/ash_test_base.h" | 18 #include "ash/test/ash_test_base.h" |
| 19 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 19 #include "ash/wm/tablet_mode/tablet_mode_controller.h" |
| 20 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
| 22 #include "base/memory/ref_counted.h" | 22 #include "base/memory/ref_counted.h" |
| 23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/values.h" | 24 #include "base/values.h" |
| 25 #include "chrome/browser/chromeos/display/display_configuration_observer.h" | 25 #include "chrome/browser/chromeos/display/display_configuration_observer.h" |
| 26 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 26 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
| 27 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 27 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 29 #include "chrome/test/base/testing_browser_process.h" | 29 #include "chrome/test/base/testing_browser_process.h" |
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 EXPECT_EQ("internal_off_external_on", | 803 EXPECT_EQ("internal_off_external_on", |
| 804 local_state()->GetString(prefs::kDisplayPowerState)); | 804 local_state()->GetString(prefs::kDisplayPowerState)); |
| 805 | 805 |
| 806 // Don't try to load | 806 // Don't try to load |
| 807 local_state()->SetString(prefs::kDisplayPowerState, "all_off"); | 807 local_state()->SetString(prefs::kDisplayPowerState, "all_off"); |
| 808 LoadDisplayPreferences(false); | 808 LoadDisplayPreferences(false); |
| 809 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, | 809 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
| 810 shell->display_configurator()->requested_power_state()); | 810 shell->display_configurator()->requested_power_state()); |
| 811 } | 811 } |
| 812 | 812 |
| 813 // Tests that display configuration changes caused by MaximizeModeController | 813 // Tests that display configuration changes caused by TabletModeController |
| 814 // are not saved. | 814 // are not saved. |
| 815 TEST_F(DisplayPreferencesTest, DontSaveMaximizeModeControllerRotations) { | 815 TEST_F(DisplayPreferencesTest, DontSaveTabletModeControllerRotations) { |
| 816 ash::Shell* shell = ash::Shell::Get(); | 816 ash::Shell* shell = ash::Shell::Get(); |
| 817 display::Display::SetInternalDisplayId( | 817 display::Display::SetInternalDisplayId( |
| 818 display::Screen::GetScreen()->GetPrimaryDisplay().id()); | 818 display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 819 LoggedInAsUser(); | 819 LoggedInAsUser(); |
| 820 // Populate the properties. | 820 // Populate the properties. |
| 821 display_manager()->SetDisplayRotation(display::Display::InternalDisplayId(), | 821 display_manager()->SetDisplayRotation(display::Display::InternalDisplayId(), |
| 822 display::Display::ROTATE_180, | 822 display::Display::ROTATE_180, |
| 823 display::Display::ROTATION_SOURCE_USER); | 823 display::Display::ROTATION_SOURCE_USER); |
| 824 // Reset property to avoid rotation lock | 824 // Reset property to avoid rotation lock |
| 825 display_manager()->SetDisplayRotation(display::Display::InternalDisplayId(), | 825 display_manager()->SetDisplayRotation(display::Display::InternalDisplayId(), |
| 826 display::Display::ROTATE_0, | 826 display::Display::ROTATE_0, |
| 827 display::Display::ROTATION_SOURCE_USER); | 827 display::Display::ROTATION_SOURCE_USER); |
| 828 | 828 |
| 829 // Open up 270 degrees to trigger maximize mode | 829 // Open up 270 degrees to trigger tablet mode |
| 830 scoped_refptr<chromeos::AccelerometerUpdate> update( | 830 scoped_refptr<chromeos::AccelerometerUpdate> update( |
| 831 new chromeos::AccelerometerUpdate()); | 831 new chromeos::AccelerometerUpdate()); |
| 832 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f, | 832 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f, |
| 833 kMeanGravity); | 833 kMeanGravity); |
| 834 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f); | 834 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f); |
| 835 ash::MaximizeModeController* controller = | 835 ash::TabletModeController* controller = |
| 836 ash::Shell::Get()->maximize_mode_controller(); | 836 ash::Shell::Get()->tablet_mode_controller(); |
| 837 controller->OnAccelerometerUpdated(update); | 837 controller->OnAccelerometerUpdated(update); |
| 838 EXPECT_TRUE(controller->IsMaximizeModeWindowManagerEnabled()); | 838 EXPECT_TRUE(controller->IsTabletModeWindowManagerEnabled()); |
| 839 | 839 |
| 840 // Trigger 90 degree rotation | 840 // Trigger 90 degree rotation |
| 841 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, -kMeanGravity, | 841 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, -kMeanGravity, |
| 842 0.0f, 0.0f); | 842 0.0f, 0.0f); |
| 843 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, -kMeanGravity, 0.0f, 0.0f); | 843 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, -kMeanGravity, 0.0f, 0.0f); |
| 844 controller->OnAccelerometerUpdated(update); | 844 controller->OnAccelerometerUpdated(update); |
| 845 shell->screen_orientation_controller()->OnAccelerometerUpdated(update); | 845 shell->screen_orientation_controller()->OnAccelerometerUpdated(update); |
| 846 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); | 846 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); |
| 847 | 847 |
| 848 const base::DictionaryValue* properties = | 848 const base::DictionaryValue* properties = |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 EXPECT_EQ(current_rotation_lock, rotation_lock); | 931 EXPECT_EQ(current_rotation_lock, rotation_lock); |
| 932 | 932 |
| 933 int orientation; | 933 int orientation; |
| 934 display::Display::Rotation current_rotation = | 934 display::Display::Rotation current_rotation = |
| 935 GetCurrentInternalDisplayRotation(); | 935 GetCurrentInternalDisplayRotation(); |
| 936 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); | 936 EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); |
| 937 EXPECT_EQ(current_rotation, orientation); | 937 EXPECT_EQ(current_rotation, orientation); |
| 938 } | 938 } |
| 939 | 939 |
| 940 // Tests that rotation state is loaded without a user being logged in, and that | 940 // Tests that rotation state is loaded without a user being logged in, and that |
| 941 // entering maximize mode applies the state. | 941 // entering tablet mode applies the state. |
| 942 TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) { | 942 TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) { |
| 943 display::Display::SetInternalDisplayId( | 943 display::Display::SetInternalDisplayId( |
| 944 display::Screen::GetScreen()->GetPrimaryDisplay().id()); | 944 display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 945 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 945 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 946 | 946 |
| 947 bool initial_rotation_lock = IsRotationLocked(); | 947 bool initial_rotation_lock = IsRotationLocked(); |
| 948 ASSERT_FALSE(initial_rotation_lock); | 948 ASSERT_FALSE(initial_rotation_lock); |
| 949 display::Display::Rotation initial_rotation = | 949 display::Display::Rotation initial_rotation = |
| 950 GetCurrentInternalDisplayRotation(); | 950 GetCurrentInternalDisplayRotation(); |
| 951 ASSERT_EQ(display::Display::ROTATE_0, initial_rotation); | 951 ASSERT_EQ(display::Display::ROTATE_0, initial_rotation); |
| 952 | 952 |
| 953 StoreDisplayRotationPrefs(initial_rotation_lock); | 953 StoreDisplayRotationPrefs(initial_rotation_lock); |
| 954 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 954 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 955 | 955 |
| 956 StoreDisplayRotationPrefsForTest(true, display::Display::ROTATE_90); | 956 StoreDisplayRotationPrefsForTest(true, display::Display::ROTATE_90); |
| 957 LoadDisplayPreferences(false); | 957 LoadDisplayPreferences(false); |
| 958 | 958 |
| 959 bool display_rotation_lock = | 959 bool display_rotation_lock = |
| 960 display_manager()->registered_internal_display_rotation_lock(); | 960 display_manager()->registered_internal_display_rotation_lock(); |
| 961 bool display_rotation = | 961 bool display_rotation = |
| 962 display_manager()->registered_internal_display_rotation(); | 962 display_manager()->registered_internal_display_rotation(); |
| 963 EXPECT_TRUE(display_rotation_lock); | 963 EXPECT_TRUE(display_rotation_lock); |
| 964 EXPECT_EQ(display::Display::ROTATE_90, display_rotation); | 964 EXPECT_EQ(display::Display::ROTATE_90, display_rotation); |
| 965 | 965 |
| 966 bool rotation_lock = IsRotationLocked(); | 966 bool rotation_lock = IsRotationLocked(); |
| 967 display::Display::Rotation before_maximize_mode_rotation = | 967 display::Display::Rotation before_tablet_mode_rotation = |
| 968 GetCurrentInternalDisplayRotation(); | 968 GetCurrentInternalDisplayRotation(); |
| 969 | 969 |
| 970 // Settings should not be applied until maximize mode activates | 970 // Settings should not be applied until tablet mode activates |
| 971 EXPECT_FALSE(rotation_lock); | 971 EXPECT_FALSE(rotation_lock); |
| 972 EXPECT_EQ(display::Display::ROTATE_0, before_maximize_mode_rotation); | 972 EXPECT_EQ(display::Display::ROTATE_0, before_tablet_mode_rotation); |
| 973 | 973 |
| 974 // Open up 270 degrees to trigger maximize mode | 974 // Open up 270 degrees to trigger tablet mode |
| 975 scoped_refptr<chromeos::AccelerometerUpdate> update( | 975 scoped_refptr<chromeos::AccelerometerUpdate> update( |
| 976 new chromeos::AccelerometerUpdate()); | 976 new chromeos::AccelerometerUpdate()); |
| 977 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f, | 977 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f, |
| 978 kMeanGravity); | 978 kMeanGravity); |
| 979 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f); | 979 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f); |
| 980 ash::MaximizeModeController* maximize_mode_controller = | 980 ash::TabletModeController* tablet_mode_controller = |
| 981 ash::Shell::Get()->maximize_mode_controller(); | 981 ash::Shell::Get()->tablet_mode_controller(); |
| 982 maximize_mode_controller->OnAccelerometerUpdated(update); | 982 tablet_mode_controller->OnAccelerometerUpdated(update); |
| 983 EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); | 983 EXPECT_TRUE(tablet_mode_controller->IsTabletModeWindowManagerEnabled()); |
| 984 bool screen_orientation_rotation_lock = IsRotationLocked(); | 984 bool screen_orientation_rotation_lock = IsRotationLocked(); |
| 985 display::Display::Rotation maximize_mode_rotation = | 985 display::Display::Rotation tablet_mode_rotation = |
| 986 GetCurrentInternalDisplayRotation(); | 986 GetCurrentInternalDisplayRotation(); |
| 987 EXPECT_TRUE(screen_orientation_rotation_lock); | 987 EXPECT_TRUE(screen_orientation_rotation_lock); |
| 988 EXPECT_EQ(display::Display::ROTATE_90, maximize_mode_rotation); | 988 EXPECT_EQ(display::Display::ROTATE_90, tablet_mode_rotation); |
| 989 } | 989 } |
| 990 | 990 |
| 991 // Tests that rotation lock being set causes the rotation state to be saved. | 991 // Tests that rotation lock being set causes the rotation state to be saved. |
| 992 TEST_F(DisplayPreferencesTest, RotationLockTriggersStore) { | 992 TEST_F(DisplayPreferencesTest, RotationLockTriggersStore) { |
| 993 display::Display::SetInternalDisplayId( | 993 display::Display::SetInternalDisplayId( |
| 994 display::Screen::GetScreen()->GetPrimaryDisplay().id()); | 994 display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 995 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 995 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
| 996 | 996 |
| 997 ash::Shell::Get()->screen_orientation_controller()->ToggleUserRotationLock(); | 997 ash::Shell::Get()->screen_orientation_controller()->ToggleUserRotationLock(); |
| 998 | 998 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 | 1149 |
| 1150 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), | 1150 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), |
| 1151 display_manager()->GetDisplayForId(list[0]).bounds()); | 1151 display_manager()->GetDisplayForId(list[0]).bounds()); |
| 1152 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200), | 1152 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200), |
| 1153 display_manager()->GetDisplayForId(list[1]).bounds()); | 1153 display_manager()->GetDisplayForId(list[1]).bounds()); |
| 1154 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300), | 1154 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300), |
| 1155 display_manager()->GetDisplayForId(list[2]).bounds()); | 1155 display_manager()->GetDisplayForId(list[2]).bounds()); |
| 1156 } | 1156 } |
| 1157 | 1157 |
| 1158 } // namespace chromeos | 1158 } // namespace chromeos |
| OLD | NEW |