diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-21 06:42:39 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-21 06:42:39 +0000 |
commit | 945ece96bfd8a4d239f967d329bfd6a102659c66 (patch) | |
tree | 2e74c8a932f04cd833bd5d439ef225d4ec63d4db /chrome/browser/chromeos/display/display_preferences_unittest.cc | |
parent | ea367c52cfaf6bfa3e96caa61de556471cbd08c9 (diff) | |
download | chromium_src-945ece96bfd8a4d239f967d329bfd6a102659c66.zip chromium_src-945ece96bfd8a4d239f967d329bfd6a102659c66.tar.gz chromium_src-945ece96bfd8a4d239f967d329bfd6a102659c66.tar.bz2 |
Refactor DisplayPreference
- Use ash::DisplayController::Observer to save preference
- DisplayLayout::FromInets to eliminate conversions
- Create OutputConfiguratorAnimation on desktop, except for test.
This is necessary to get options page working on desktop.
- Store default only when a user modified the layout. I think this matches
the user's expectation better.
Other cleanups:
- Removed unused declaration Shell::InitLayoutManagersForPrimaryDisplay
BUG=196818
TEST=covered by test
Review URL: https://codereview.chromium.org/12843008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@189538 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/display/display_preferences_unittest.cc')
-rw-r--r-- | chrome/browser/chromeos/display/display_preferences_unittest.cc | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/chrome/browser/chromeos/display/display_preferences_unittest.cc b/chrome/browser/chromeos/display/display_preferences_unittest.cc index 31242cb..43c0b8b 100644 --- a/chrome/browser/chromeos/display/display_preferences_unittest.cc +++ b/chrome/browser/chromeos/display/display_preferences_unittest.cc @@ -11,6 +11,7 @@ #include "base/prefs/testing_pref_service.h" #include "base/strings/string_number_conversions.h" #include "base/values.h" +#include "chrome/browser/chromeos/display/display_configuration_observer.h" #include "chrome/browser/chromeos/login/mock_user_manager.h" #include "chrome/browser/chromeos/login/user_manager.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" @@ -20,6 +21,10 @@ namespace chromeos { namespace { +ash::DisplayController* GetDisplayController() { + return ash::Shell::GetInstance()->display_controller(); +} + class DisplayPreferencesTest : public ash::test::AshTestBase { protected: DisplayPreferencesTest() : ash::test::AshTestBase() {} @@ -29,9 +34,11 @@ class DisplayPreferencesTest : public ash::test::AshTestBase { ash::test::AshTestBase::SetUp(); RegisterDisplayLocalStatePrefs(local_state_.registry()); TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); + observer_.reset(new DisplayConfigurationObserver()); } virtual void TearDown() OVERRIDE { + observer_.reset(); TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); ash::test::AshTestBase::TearDown(); } @@ -131,6 +138,7 @@ class DisplayPreferencesTest : public ash::test::AshTestBase { private: ScopedMockUserManagerEnabler mock_user_manager_; TestingPrefServiceSimple local_state_; + scoped_ptr<DisplayConfigurationObserver> observer_; DISALLOW_COPY_AND_ASSIGN(DisplayPreferencesTest); }; @@ -201,10 +209,13 @@ TEST_F(DisplayPreferencesTest, BasicStores) { LoggedInAsUser(); ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); - SetAndStoreDisplayLayoutPref(static_cast<int>(layout.position), - layout.offset); - StoreDisplayLayoutPref(id1, dummy_id, ash::DisplayLayout::LEFT, 20); - SetAndStorePrimaryDisplayIDPref(dummy_id); + SetCurrentAndDefaultDisplayLayout(layout); + StoreDisplayLayoutPrefForTest( + id1, dummy_id, ash::DisplayLayout(ash::DisplayLayout::LEFT, 20)); + // Can't switch to a display that does not exist. + GetDisplayController()->SetPrimaryDisplayId(dummy_id); + EXPECT_NE(dummy_id, local_state()->GetInt64(prefs::kPrimaryDisplayID)); + SetAndStoreDisplayOverscan( ash::ScreenAsh::GetNativeScreen()->GetPrimaryDisplay(), gfx::Insets(10, 11, 12, 13)); @@ -222,10 +233,10 @@ TEST_F(DisplayPreferencesTest, BasicStores) { EXPECT_TRUE(serialized_value->Equals(display_layout)); // The default value is set for the last call of - // StoreDisplayLayoutPref() - EXPECT_EQ(ash::DisplayLayout::LEFT, + // SetCurrentAndDefaultDisplayLayout + EXPECT_EQ(ash::DisplayLayout::TOP, local_state()->GetInteger(prefs::kSecondaryDisplayLayout)); - EXPECT_EQ(20, local_state()->GetInteger(prefs::kSecondaryDisplayOffset)); + EXPECT_EQ(10, local_state()->GetInteger(prefs::kSecondaryDisplayOffset)); const base::DictionaryValue* overscans = local_state()->GetDictionary(prefs::kDisplayOverscans); @@ -240,7 +251,23 @@ TEST_F(DisplayPreferencesTest, BasicStores) { EXPECT_EQ(11, left); EXPECT_EQ(12, bottom); EXPECT_EQ(13, right); - EXPECT_EQ(dummy_id, local_state()->GetInt64(prefs::kPrimaryDisplayID)); + + GetDisplayController()->SetPrimaryDisplayId(id2); + EXPECT_EQ(id2, local_state()->GetInt64(prefs::kPrimaryDisplayID)); + // The layout remains the same. + EXPECT_TRUE(displays->GetDictionary(key, &display_layout)); + EXPECT_TRUE(serialized_value->Equals(display_layout)); + // Default value should changte. + EXPECT_EQ(ash::DisplayLayout::TOP, + local_state()->GetInteger(prefs::kSecondaryDisplayLayout)); + EXPECT_EQ(10, local_state()->GetInteger(prefs::kSecondaryDisplayOffset)); + + SetCurrentAndDefaultDisplayLayout( + ash::DisplayLayout(ash::DisplayLayout::BOTTOM, 20)); + // Displays are swapped, so does the default layout. + EXPECT_EQ(ash::DisplayLayout::TOP, + local_state()->GetInteger(prefs::kSecondaryDisplayLayout)); + EXPECT_EQ(-20, local_state()->GetInteger(prefs::kSecondaryDisplayOffset)); } TEST_F(DisplayPreferencesTest, StoreForSwappedDisplay) { @@ -255,8 +282,8 @@ TEST_F(DisplayPreferencesTest, StoreForSwappedDisplay) { LoggedInAsUser(); ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); - SetAndStoreDisplayLayoutPref(static_cast<int>(layout.position), - layout.offset); + SetCurrentAndDefaultDisplayLayout(layout); + layout = layout.Invert(); scoped_ptr<base::DictionaryValue> layout_value( new base::DictionaryValue()); @@ -280,9 +307,8 @@ TEST_F(DisplayPreferencesTest, DontStoreInGuestMode) { LoggedInAsGuest(); int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); - SetAndStoreDisplayLayoutPref(static_cast<int>(layout.position), - layout.offset); - SetAndStorePrimaryDisplayIDPref(id2); + SetCurrentAndDefaultDisplayLayout(layout); + GetDisplayController()->SetPrimaryDisplayId(id2); SetAndStoreDisplayOverscan( ash::ScreenAsh::GetNativeScreen()->GetPrimaryDisplay(), gfx::Insets(10, 11, 12, 13)); |