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/content/display/screen_orientation_controller_chromeos.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 // The mean acceleration due to gravity on Earth in m/s^2. | 43 // The mean acceleration due to gravity on Earth in m/s^2. |
44 const float kMeanGravity = 9.80665f; | 44 const float kMeanGravity = 9.80665f; |
45 | 45 |
46 bool IsRotationLocked() { | 46 bool IsRotationLocked() { |
47 return ash::Shell::GetInstance() | 47 return ash::Shell::GetInstance() |
48 ->screen_orientation_controller() | 48 ->screen_orientation_controller() |
49 ->rotation_locked(); | 49 ->rotation_locked(); |
50 } | 50 } |
51 | 51 |
| 52 std::string ToPairString(const ash::DisplayIdPair& pair) { |
| 53 return base::Int64ToString(pair.first) + "," + |
| 54 base::Int64ToString(pair.second); |
| 55 } |
| 56 |
52 class DisplayPreferencesTest : public ash::test::AshTestBase { | 57 class DisplayPreferencesTest : public ash::test::AshTestBase { |
53 protected: | 58 protected: |
54 DisplayPreferencesTest() | 59 DisplayPreferencesTest() |
55 : mock_user_manager_(new MockUserManager), | 60 : mock_user_manager_(new MockUserManager), |
56 user_manager_enabler_(mock_user_manager_) { | 61 user_manager_enabler_(mock_user_manager_) { |
57 } | 62 } |
58 | 63 |
59 ~DisplayPreferencesTest() override {} | 64 ~DisplayPreferencesTest() override {} |
60 | 65 |
61 void SetUp() override { | 66 void SetUp() override { |
(...skipping 23 matching lines...) Expand all Loading... |
85 EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn()) | 90 EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn()) |
86 .WillRepeatedly(testing::Return(true)); | 91 .WillRepeatedly(testing::Return(true)); |
87 EXPECT_CALL(*mock_user_manager_, IsLoggedInAsUserWithGaiaAccount()) | 92 EXPECT_CALL(*mock_user_manager_, IsLoggedInAsUserWithGaiaAccount()) |
88 .WillRepeatedly(testing::Return(false)); | 93 .WillRepeatedly(testing::Return(false)); |
89 EXPECT_CALL(*mock_user_manager_, IsLoggedInAsSupervisedUser()) | 94 EXPECT_CALL(*mock_user_manager_, IsLoggedInAsSupervisedUser()) |
90 .WillRepeatedly(testing::Return(false)); | 95 .WillRepeatedly(testing::Return(false)); |
91 } | 96 } |
92 | 97 |
93 // Do not use the implementation of display_preferences.cc directly to avoid | 98 // Do not use the implementation of display_preferences.cc directly to avoid |
94 // notifying the update to the system. | 99 // notifying the update to the system. |
95 void StoreDisplayLayoutPrefForName(const std::string& name, | 100 void StoreDisplayLayoutPrefForPair(const ash::DisplayIdPair& pair, |
96 ash::DisplayLayout::Position layout, | 101 ash::DisplayLayout::Position layout, |
97 int offset, | 102 int offset, |
98 int64 primary_id) { | 103 int64 primary_id) { |
| 104 std::string name = ToPairString(pair); |
99 DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays); | 105 DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays); |
100 ash::DisplayLayout display_layout(layout, offset); | 106 ash::DisplayLayout display_layout(layout, offset); |
101 display_layout.primary_id = primary_id; | 107 display_layout.primary_id = primary_id; |
102 | 108 |
103 DCHECK(!name.empty()); | 109 DCHECK(!name.empty()); |
104 | 110 |
105 base::DictionaryValue* pref_data = update.Get(); | 111 base::DictionaryValue* pref_data = update.Get(); |
106 scoped_ptr<base::Value>layout_value(new base::DictionaryValue()); | 112 scoped_ptr<base::Value>layout_value(new base::DictionaryValue()); |
107 if (pref_data->HasKey(name)) { | 113 if (pref_data->HasKey(name)) { |
108 base::Value* value = NULL; | 114 base::Value* value = NULL; |
109 if (pref_data->Get(name, &value) && value != NULL) | 115 if (pref_data->Get(name, &value) && value != NULL) |
110 layout_value.reset(value->DeepCopy()); | 116 layout_value.reset(value->DeepCopy()); |
111 } | 117 } |
112 if (ash::DisplayLayout::ConvertToValue(display_layout, layout_value.get())) | 118 if (ash::DisplayLayout::ConvertToValue(display_layout, layout_value.get())) |
113 pref_data->Set(name, layout_value.release()); | 119 pref_data->Set(name, layout_value.release()); |
114 } | 120 } |
115 | 121 |
116 void StoreDisplayLayoutPrefForPair(int64 id1, | 122 void StoreDisplayPropertyForPair(const ash::DisplayIdPair& pair, |
117 int64 id2, | 123 std::string key, |
| 124 base::Value* value) { |
| 125 std::string name = ToPairString(pair); |
| 126 |
| 127 DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays); |
| 128 base::DictionaryValue* pref_data = update.Get(); |
| 129 |
| 130 if (pref_data->HasKey(name)) { |
| 131 base::Value* layout_value = NULL; |
| 132 pref_data->Get(name, &layout_value); |
| 133 if (layout_value) |
| 134 static_cast<base::DictionaryValue*>(layout_value)->Set(key, value); |
| 135 } else { |
| 136 scoped_ptr<base::DictionaryValue> layout_value( |
| 137 new base::DictionaryValue()); |
| 138 layout_value->SetBoolean(key, value); |
| 139 pref_data->Set(name, layout_value.release()); |
| 140 } |
| 141 } |
| 142 |
| 143 void StoreDisplayBoolPropertyForPair(const ash::DisplayIdPair& pair, |
| 144 const std::string& key, |
| 145 bool value) { |
| 146 StoreDisplayPropertyForPair(pair, key, new base::FundamentalValue(value)); |
| 147 } |
| 148 |
| 149 void StoreDisplayLayoutPrefForPair(const ash::DisplayIdPair& pair, |
118 ash::DisplayLayout::Position layout, | 150 ash::DisplayLayout::Position layout, |
119 int offset) { | 151 int offset) { |
120 StoreDisplayLayoutPrefForName( | 152 StoreDisplayLayoutPrefForPair(pair, layout, offset, pair.first); |
121 base::Int64ToString(id1) + "," + base::Int64ToString(id2), | |
122 layout, offset, id1); | |
123 } | |
124 | |
125 void StoreDisplayLayoutPrefForSecondary(int64 id, | |
126 ash::DisplayLayout::Position layout, | |
127 int offset, | |
128 int64 primary_id) { | |
129 StoreDisplayLayoutPrefForName( | |
130 base::Int64ToString(id), layout, offset, primary_id); | |
131 } | 153 } |
132 | 154 |
133 void StoreDisplayOverscan(int64 id, const gfx::Insets& insets) { | 155 void StoreDisplayOverscan(int64 id, const gfx::Insets& insets) { |
134 DictionaryPrefUpdate update(&local_state_, prefs::kDisplayProperties); | 156 DictionaryPrefUpdate update(&local_state_, prefs::kDisplayProperties); |
135 const std::string name = base::Int64ToString(id); | 157 const std::string name = base::Int64ToString(id); |
136 | 158 |
137 base::DictionaryValue* pref_data = update.Get(); | 159 base::DictionaryValue* pref_data = update.Get(); |
138 base::DictionaryValue* insets_value = new base::DictionaryValue(); | 160 base::DictionaryValue* insets_value = new base::DictionaryValue(); |
139 insets_value->SetInteger("insets_top", insets.top()); | 161 insets_value->SetInteger("insets_top", insets.top()); |
140 insets_value->SetInteger("insets_left", insets.left()); | 162 insets_value->SetInteger("insets_left", insets.left()); |
(...skipping 13 matching lines...) Expand all Loading... |
154 } | 176 } |
155 | 177 |
156 void StoreDisplayRotationPrefsForTest(bool rotation_lock, | 178 void StoreDisplayRotationPrefsForTest(bool rotation_lock, |
157 gfx::Display::Rotation rotation) { | 179 gfx::Display::Rotation rotation) { |
158 DictionaryPrefUpdate update(local_state(), prefs::kDisplayRotationLock); | 180 DictionaryPrefUpdate update(local_state(), prefs::kDisplayRotationLock); |
159 base::DictionaryValue* pref_data = update.Get(); | 181 base::DictionaryValue* pref_data = update.Get(); |
160 pref_data->SetBoolean("lock", rotation_lock); | 182 pref_data->SetBoolean("lock", rotation_lock); |
161 pref_data->SetInteger("orientation", static_cast<int>(rotation)); | 183 pref_data->SetInteger("orientation", static_cast<int>(rotation)); |
162 } | 184 } |
163 | 185 |
164 std::string GetRegisteredDisplayLayoutStr(int64 id1, int64 id2) { | 186 std::string GetRegisteredDisplayLayoutStr(const ash::DisplayIdPair& pair) { |
165 ash::DisplayIdPair pair; | |
166 pair.first = id1; | |
167 pair.second = id2; | |
168 return ash::Shell::GetInstance()->display_manager()->layout_store()-> | 187 return ash::Shell::GetInstance()->display_manager()->layout_store()-> |
169 GetRegisteredDisplayLayout(pair).ToString(); | 188 GetRegisteredDisplayLayout(pair).ToString(); |
170 } | 189 } |
171 | 190 |
172 PrefService* local_state() { return &local_state_; } | 191 PrefService* local_state() { return &local_state_; } |
173 | 192 |
174 private: | 193 private: |
175 MockUserManager* mock_user_manager_; // Not owned. | 194 MockUserManager* mock_user_manager_; // Not owned. |
176 ScopedUserManagerEnabler user_manager_enabler_; | 195 ScopedUserManagerEnabler user_manager_enabler_; |
177 TestingPrefServiceSimple local_state_; | 196 TestingPrefServiceSimple local_state_; |
178 scoped_ptr<DisplayConfigurationObserver> observer_; | 197 scoped_ptr<DisplayConfigurationObserver> observer_; |
179 | 198 |
180 DISALLOW_COPY_AND_ASSIGN(DisplayPreferencesTest); | 199 DISALLOW_COPY_AND_ASSIGN(DisplayPreferencesTest); |
181 }; | 200 }; |
182 | 201 |
183 } // namespace | 202 } // namespace |
184 | 203 |
185 TEST_F(DisplayPreferencesTest, PairedLayoutOverrides) { | 204 TEST_F(DisplayPreferencesTest, PairedLayoutOverrides) { |
186 UpdateDisplay("100x100,200x200"); | 205 UpdateDisplay("100x100,200x200"); |
187 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); | 206 ash::DisplayManager* display_manager = |
188 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 207 ash::Shell::GetInstance()->display_manager(); |
189 int64 dummy_id = id2 + 1; | |
190 ASSERT_NE(id1, dummy_id); | |
191 | 208 |
192 StoreDisplayLayoutPrefForPair(id1, id2, ash::DisplayLayout::TOP, 20); | 209 ash::DisplayIdPair pair = display_manager->GetCurrentDisplayIdPair(); |
193 StoreDisplayLayoutPrefForPair(id1, dummy_id, ash::DisplayLayout::LEFT, 30); | 210 ash::DisplayIdPair dummy_pair = std::make_pair(pair.first, pair.second + 1); |
| 211 ASSERT_NE(pair.first, dummy_pair.second); |
| 212 |
| 213 StoreDisplayLayoutPrefForPair(pair, ash::DisplayLayout::TOP, 20); |
| 214 StoreDisplayLayoutPrefForPair(dummy_pair, ash::DisplayLayout::LEFT, 30); |
194 StoreDisplayPowerStateForTest( | 215 StoreDisplayPowerStateForTest( |
195 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); | 216 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); |
196 | 217 |
197 ash::Shell* shell = ash::Shell::GetInstance(); | 218 ash::Shell* shell = ash::Shell::GetInstance(); |
198 | 219 |
199 LoadDisplayPreferences(true); | 220 LoadDisplayPreferences(true); |
200 // DisplayPowerState should be ignored at boot. | 221 // DisplayPowerState should be ignored at boot. |
201 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON, | 222 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON, |
202 shell->display_configurator()->requested_power_state()); | 223 shell->display_configurator()->requested_power_state()); |
203 | 224 |
204 shell->display_manager()->UpdateDisplays(); | 225 shell->display_manager()->UpdateDisplays(); |
205 // Check if the layout settings are notified to the system properly. | 226 // Check if the layout settings are notified to the system properly. |
206 // The paired layout overrides old layout. | 227 // The paired layout overrides old layout. |
207 // Inverted one of for specified pair (id1, id2). Not used for the pair | 228 // Inverted one of for specified pair (id1, id2). Not used for the pair |
208 // (id1, dummy_id) since dummy_id is not connected right now. | 229 // (id1, dummy_id) since dummy_id is not connected right now. |
209 EXPECT_EQ("top, 20", | 230 EXPECT_EQ("top, 20", |
210 shell->display_manager()->GetCurrentDisplayLayout().ToString()); | 231 shell->display_manager()->GetCurrentDisplayLayout().ToString()); |
211 EXPECT_EQ("top, 20", GetRegisteredDisplayLayoutStr(id1, id2)); | 232 EXPECT_EQ("top, 20", GetRegisteredDisplayLayoutStr(pair)); |
212 EXPECT_EQ("left, 30", GetRegisteredDisplayLayoutStr(id1, dummy_id)); | 233 EXPECT_EQ("left, 30", GetRegisteredDisplayLayoutStr(dummy_pair)); |
213 } | 234 } |
214 | 235 |
215 TEST_F(DisplayPreferencesTest, BasicStores) { | 236 TEST_F(DisplayPreferencesTest, BasicStores) { |
216 ash::DisplayController* display_controller = | 237 ash::DisplayController* display_controller = |
217 ash::Shell::GetInstance()->display_controller(); | 238 ash::Shell::GetInstance()->display_controller(); |
218 ash::DisplayManager* display_manager = | 239 ash::DisplayManager* display_manager = |
219 ash::Shell::GetInstance()->display_manager(); | 240 ash::Shell::GetInstance()->display_manager(); |
220 | 241 |
221 UpdateDisplay("200x200*2, 400x300#400x400|300x200*1.25"); | 242 UpdateDisplay("200x200*2, 400x300#400x400|300x200*1.25"); |
222 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); | 243 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 true); | 868 true); |
848 | 869 |
849 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); | 870 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); |
850 | 871 |
851 const base::DictionaryValue* properties = | 872 const base::DictionaryValue* properties = |
852 local_state()->GetDictionary(prefs::kDisplayRotationLock); | 873 local_state()->GetDictionary(prefs::kDisplayRotationLock); |
853 bool rotation_lock; | 874 bool rotation_lock; |
854 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); | 875 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); |
855 } | 876 } |
856 | 877 |
| 878 TEST_F(DisplayPreferencesTest, SaveUnifiedMode) { |
| 879 UpdateDisplay("100x100,200x200"); |
| 880 LoggedInAsUser(); |
| 881 ash::DisplayManager* display_manager = |
| 882 ash::Shell::GetInstance()->display_manager(); |
| 883 ash::DisplayIdPair pair = display_manager->GetCurrentDisplayIdPair(); |
| 884 std::string pair_key = ToPairString(pair); |
| 885 |
| 886 // Unified mode should be recorded. |
| 887 display_manager->SetDefaultMultiDisplayMode(ash::DisplayManager::UNIFIED); |
| 888 display_manager->ReconfigureDisplays(); |
| 889 |
| 890 const base::DictionaryValue* displays = |
| 891 local_state()->GetDictionary(prefs::kSecondaryDisplays); |
| 892 const base::DictionaryValue* new_value = NULL; |
| 893 EXPECT_TRUE(displays->GetDictionary(ToPairString(pair), &new_value)); |
| 894 |
| 895 ash::DisplayLayout stored_layout; |
| 896 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*new_value, &stored_layout)); |
| 897 EXPECT_TRUE(stored_layout.default_unified); |
| 898 EXPECT_FALSE(stored_layout.mirrored); |
| 899 |
| 900 // Mirror mode should remember if the default mode was unified. |
| 901 display_manager->SetMirrorMode(true); |
| 902 EXPECT_TRUE(displays->GetDictionary(ToPairString(pair), &new_value)); |
| 903 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*new_value, &stored_layout)); |
| 904 EXPECT_TRUE(stored_layout.default_unified); |
| 905 EXPECT_TRUE(stored_layout.mirrored); |
| 906 |
| 907 display_manager->SetMirrorMode(false); |
| 908 EXPECT_TRUE(displays->GetDictionary(ToPairString(pair), &new_value)); |
| 909 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*new_value, &stored_layout)); |
| 910 EXPECT_TRUE(stored_layout.default_unified); |
| 911 EXPECT_FALSE(stored_layout.mirrored); |
| 912 |
| 913 // Exit unified mode. |
| 914 display_manager->SetDefaultMultiDisplayMode(ash::DisplayManager::EXTENDED); |
| 915 display_manager->ReconfigureDisplays(); |
| 916 EXPECT_TRUE(displays->GetDictionary(ToPairString(pair), &new_value)); |
| 917 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*new_value, &stored_layout)); |
| 918 EXPECT_FALSE(stored_layout.default_unified); |
| 919 EXPECT_FALSE(stored_layout.mirrored); |
| 920 } |
| 921 |
| 922 TEST_F(DisplayPreferencesTest, RestoreUnifiedMode) { |
| 923 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); |
| 924 ash::DisplayIdPair pair = std::make_pair(id1, id1 + 1); |
| 925 // Restored to unified. |
| 926 StoreDisplayBoolPropertyForPair(pair, "default_unified", true); |
| 927 StoreDisplayPropertyForPair(pair, "primary-id", |
| 928 new base::StringValue(base::Int64ToString(id1))); |
| 929 LoadDisplayPreferences(false); |
| 930 UpdateDisplay("100x100,200x200"); |
| 931 ash::DisplayManager* display_manager = |
| 932 ash::Shell::GetInstance()->display_manager(); |
| 933 EXPECT_TRUE(display_manager->IsInUnifiedMode()); |
| 934 |
| 935 // Restored to mirror, then unified. |
| 936 StoreDisplayBoolPropertyForPair(pair, "mirrored", true); |
| 937 StoreDisplayBoolPropertyForPair(pair, "default_unified", true); |
| 938 LoadDisplayPreferences(false); |
| 939 UpdateDisplay("100x100,200x200"); |
| 940 EXPECT_TRUE(display_manager->IsInMirrorMode()); |
| 941 |
| 942 display_manager->SetMirrorMode(false); |
| 943 EXPECT_TRUE(display_manager->IsInUnifiedMode()); |
| 944 |
| 945 // Sanity check. Restore to extended. |
| 946 StoreDisplayBoolPropertyForPair(pair, "default_unified", false); |
| 947 StoreDisplayBoolPropertyForPair(pair, "mirrored", false); |
| 948 LoadDisplayPreferences(false); |
| 949 UpdateDisplay("100x100,200x200"); |
| 950 EXPECT_FALSE(display_manager->IsInMirrorMode()); |
| 951 EXPECT_FALSE(display_manager->IsInUnifiedMode()); |
| 952 } |
| 953 |
857 } // namespace chromeos | 954 } // namespace chromeos |
OLD | NEW |