X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fchrome%2Fbrowser%2Fchromeos%2Fdisplay%2Fdisplay_preferences_unittest.cc;h=4c63885fab6fb8b18728a45ff6318b1ee1e7a7a0;hb=3545e9f2671f595d2a2f3ee75ca0393b01e35ef6;hp=658ec54197be7a406b2f62e6cc030e105d28d1fb;hpb=7d210d4c7e9ba36e635eabc5b5780495f8a63292;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/chrome/browser/chromeos/display/display_preferences_unittest.cc b/src/chrome/browser/chromeos/display/display_preferences_unittest.cc index 658ec54..4c63885 100644 --- a/src/chrome/browser/chromeos/display/display_preferences_unittest.cc +++ b/src/chrome/browser/chromeos/display/display_preferences_unittest.cc @@ -38,6 +38,9 @@ const char kMirroredKey[] = "mirrored"; const char kPositionKey[] = "position"; const char kOffsetKey[] = "offset"; +// The mean acceleration due to gravity on Earth in m/s^2. +const float kMeanGravity = 9.80665f; + class DisplayPreferencesTest : public ash::test::AshTestBase { protected: DisplayPreferencesTest() @@ -142,6 +145,14 @@ class DisplayPreferencesTest : public ash::test::AshTestBase { pref_data->Set(name, property); } + void StoreDisplayRotationPrefsForTest(bool rotation_lock, + gfx::Display::Rotation rotation) { + DictionaryPrefUpdate update(local_state(), prefs::kDisplayRotationLock); + base::DictionaryValue* pref_data = update.Get(); + pref_data->SetBoolean("lock", rotation_lock); + pref_data->SetInteger("orientation", static_cast(rotation)); + } + std::string GetRegisteredDisplayLayoutStr(int64 id1, int64 id2) { ash::DisplayIdPair pair; pair.first = id1; @@ -180,7 +191,7 @@ TEST_F(DisplayPreferencesTest, PairedLayoutOverrides) { LoadDisplayPreferences(true); // DisplayPowerState should be ignored at boot. EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON, - shell->display_configurator()->power_state()); + shell->display_configurator()->requested_power_state()); shell->display_manager()->UpdateDisplays(); // Check if the layout settings are notified to the system properly. @@ -612,7 +623,8 @@ TEST_F(DisplayPreferencesTest, DisplayPowerStateAfterRestart) { chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); LoadDisplayPreferences(false); EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, - ash::Shell::GetInstance()->display_configurator()->power_state()); + ash::Shell::GetInstance()->display_configurator()-> + requested_power_state()); } TEST_F(DisplayPreferencesTest, DontSaveAndRestoreAllOff) { @@ -622,12 +634,12 @@ TEST_F(DisplayPreferencesTest, DontSaveAndRestoreAllOff) { LoadDisplayPreferences(false); // DisplayPowerState should be ignored at boot. EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, - shell->display_configurator()->power_state()); + shell->display_configurator()->requested_power_state()); StoreDisplayPowerStateForTest( chromeos::DISPLAY_POWER_ALL_OFF); EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, - shell->display_configurator()->power_state()); + shell->display_configurator()->requested_power_state()); EXPECT_EQ("internal_off_external_on", local_state()->GetString(prefs::kDisplayPowerState)); @@ -635,7 +647,7 @@ TEST_F(DisplayPreferencesTest, DontSaveAndRestoreAllOff) { local_state()->SetString(prefs::kDisplayPowerState, "all_off"); LoadDisplayPreferences(false); EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, - shell->display_configurator()->power_state()); + shell->display_configurator()->requested_power_state()); } // Tests that display configuration changes caused by MaximizeModeController @@ -655,13 +667,20 @@ TEST_F(DisplayPreferencesTest, DontSaveMaximizeModeControllerRotations) { gfx::Display::ROTATE_0); // Open up 270 degrees to trigger maximize mode - controller->OnAccelerometerUpdated(gfx::Vector3dF(0.0f, 0.0f, -1.0f), - gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); + ui::AccelerometerUpdate update; + update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, + 0.0f, 0.0f, kMeanGravity); + update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, + 0.0f, -kMeanGravity, 0.0f); + controller->OnAccelerometerUpdated(update); EXPECT_TRUE(controller->IsMaximizeModeWindowManagerEnabled()); // Trigger 90 degree rotation - controller->OnAccelerometerUpdated(gfx::Vector3dF(0.0f, 1.0f, 0.0f), - gfx::Vector3dF(0.0f, 1.0f, 0.0f)); + update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, + -kMeanGravity, 0.0f, 0.0f); + update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, + -kMeanGravity, 0.0f, 0.0f); + controller->OnAccelerometerUpdated(update); EXPECT_EQ(gfx::Display::ROTATE_90, display_manager-> GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation()); @@ -675,4 +694,187 @@ TEST_F(DisplayPreferencesTest, DontSaveMaximizeModeControllerRotations) { EXPECT_EQ(gfx::Display::ROTATE_0, rotation); } +// Tests that the rotation state is saved without a user being logged in. +TEST_F(DisplayPreferencesTest, StoreRotationStateNoLogin) { + gfx::Display::SetInternalDisplayId( + gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); + EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); + + bool current_rotation_lock = + ash::Shell::GetInstance()->maximize_mode_controller()->rotation_locked(); + StoreDisplayRotationPrefs(current_rotation_lock); + EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); + + const base::DictionaryValue* properties = + local_state()->GetDictionary(prefs::kDisplayRotationLock); + bool rotation_lock; + EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); + EXPECT_EQ(current_rotation_lock, rotation_lock); + + int orientation; + gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> + display_manager()-> + GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); + EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); + EXPECT_EQ(current_rotation, orientation); +} + +// Tests that the rotation state is saved when a guest is logged in. +TEST_F(DisplayPreferencesTest, StoreRotationStateGuest) { + gfx::Display::SetInternalDisplayId( + gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); + EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); + LoggedInAsGuest(); + + bool current_rotation_lock = + ash::Shell::GetInstance()->maximize_mode_controller()->rotation_locked(); + StoreDisplayRotationPrefs(current_rotation_lock); + EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); + + const base::DictionaryValue* properties = + local_state()->GetDictionary(prefs::kDisplayRotationLock); + bool rotation_lock; + EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); + EXPECT_EQ(current_rotation_lock, rotation_lock); + + int orientation; + gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> + display_manager()-> + GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); + EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); + EXPECT_EQ(current_rotation, orientation); +} + +// Tests that the rotation state is saved when a normal user is logged in. +TEST_F(DisplayPreferencesTest, StoreRotationStateNormalUser) { + gfx::Display::SetInternalDisplayId( + gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); + EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); + LoggedInAsGuest(); + + bool current_rotation_lock = + ash::Shell::GetInstance()->maximize_mode_controller()->rotation_locked(); + StoreDisplayRotationPrefs(current_rotation_lock); + EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); + + const base::DictionaryValue* properties = + local_state()->GetDictionary(prefs::kDisplayRotationLock); + bool rotation_lock; + EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); + EXPECT_EQ(current_rotation_lock, rotation_lock); + + int orientation; + gfx::Display::Rotation current_rotation = ash::Shell::GetInstance()-> + display_manager()-> + GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); + EXPECT_TRUE(properties->GetInteger("orientation", &orientation)); + EXPECT_EQ(current_rotation, orientation); +} + +// Tests that rotation state is loaded without a user being logged in, and that +// entering maximize mode applies the state. +TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) { + gfx::Display::SetInternalDisplayId( + gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); + ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); + + ash::Shell* shell = ash::Shell::GetInstance(); + ash::MaximizeModeController* maximize_mode_controller = + shell->maximize_mode_controller(); + bool initial_rotation_lock = maximize_mode_controller->rotation_locked(); + ASSERT_FALSE(initial_rotation_lock); + ash::DisplayManager* display_manager = shell->display_manager(); + gfx::Display::Rotation initial_rotation = display_manager-> + GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); + ASSERT_EQ(gfx::Display::ROTATE_0, initial_rotation); + + StoreDisplayRotationPrefs(initial_rotation_lock); + ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); + + StoreDisplayRotationPrefsForTest(true, gfx::Display::ROTATE_90); + LoadDisplayPreferences(false); + + bool display_rotation_lock = + display_manager->registered_internal_display_rotation_lock(); + bool display_rotation = + display_manager->registered_internal_display_rotation(); + EXPECT_TRUE(display_rotation_lock); + EXPECT_EQ(gfx::Display::ROTATE_90, display_rotation); + + bool rotation_lock = maximize_mode_controller->rotation_locked(); + gfx::Display::Rotation before_maximize_mode_rotation = display_manager-> + GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); + + // Settings should not be applied until maximize mode activates + EXPECT_FALSE(rotation_lock); + EXPECT_EQ(gfx::Display::ROTATE_0, before_maximize_mode_rotation); + + // Open up 270 degrees to trigger maximize mode + ui::AccelerometerUpdate update; + update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, + 0.0f, 0.0f, kMeanGravity); + update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, + 0.0f, -kMeanGravity, 0.0f); + maximize_mode_controller->OnAccelerometerUpdated(update); + EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); + bool maximize_mode_rotation_lock = + maximize_mode_controller->rotation_locked(); + gfx::Display::Rotation maximize_mode_rotation = display_manager-> + GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); + EXPECT_TRUE(maximize_mode_rotation_lock); + EXPECT_EQ(gfx::Display::ROTATE_90, maximize_mode_rotation); +} + +// Tests that loaded rotation state is ignored if the device starts in normal +// mode, and that they are not applied upon first entering maximize mode. +TEST_F(DisplayPreferencesTest, LoadRotationIgnoredInNormalMode) { + gfx::Display::SetInternalDisplayId( + gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); + ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); + StoreDisplayRotationPrefs(false /* rotation_lock*/); + ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); + + StoreDisplayRotationPrefsForTest(true, gfx::Display::ROTATE_90); + LoadDisplayPreferences(false); + + ash::MaximizeModeController* maximize_mode_controller = + ash::Shell::GetInstance()->maximize_mode_controller(); + // Lid open to 90 degrees + ui::AccelerometerUpdate update; + update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, + -kMeanGravity, 0.0f, 0.0f); + update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, + -kMeanGravity, 0.0f, 0.0f); + maximize_mode_controller->OnAccelerometerUpdated(update); + EXPECT_FALSE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); + EXPECT_FALSE(maximize_mode_controller->rotation_locked()); + + // Open up 270 degrees to trigger maximize mode + update.Set(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, + 0.0f, 0.0f, kMeanGravity); + update.Set(ui::ACCELEROMETER_SOURCE_SCREEN, + 0.0f, -kMeanGravity, 0.0f); + maximize_mode_controller->OnAccelerometerUpdated(update); + EXPECT_TRUE(maximize_mode_controller->IsMaximizeModeWindowManagerEnabled()); + EXPECT_FALSE(maximize_mode_controller->rotation_locked()); +} + +// Tests that rotation lock being set causes the rotation state to be saved. +TEST_F(DisplayPreferencesTest, RotationLockTriggersStore) { + gfx::Display::SetInternalDisplayId( + gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id()); + ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); + + ash::MaximizeModeController* maximize_mode_controller = + ash::Shell::GetInstance()->maximize_mode_controller(); + maximize_mode_controller->SetRotationLocked(true); + + EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); + + const base::DictionaryValue* properties = + local_state()->GetDictionary(prefs::kDisplayRotationLock); + bool rotation_lock; + EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); +} + } // namespace chromeos