Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(919)

Side by Side Diff: chrome/browser/chromeos/display/display_preferences_unittest.cc

Issue 12505005: Store rotation/ui scale to local state. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "ash/display/display_controller.h" 7 #include "ash/display/display_controller.h"
8 #include "ash/screen_ash.h" 8 #include "ash/screen_ash.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 local_state_.SetInteger( 106 local_state_.SetInteger(
107 prefs::kSecondaryDisplayLayout, static_cast<int>(layout)); 107 prefs::kSecondaryDisplayLayout, static_cast<int>(layout));
108 local_state_.SetInteger(prefs::kSecondaryDisplayOffset, offset); 108 local_state_.SetInteger(prefs::kSecondaryDisplayOffset, offset);
109 } 109 }
110 110
111 void StorePrimaryDisplayId(int64 display_id) { 111 void StorePrimaryDisplayId(int64 display_id) {
112 local_state_.SetInt64(prefs::kPrimaryDisplayID, display_id); 112 local_state_.SetInt64(prefs::kPrimaryDisplayID, display_id);
113 } 113 }
114 114
115 void StoreDisplayOverscan(int64 id, const gfx::Insets& insets) { 115 void StoreDisplayOverscan(int64 id, const gfx::Insets& insets) {
116 DictionaryPrefUpdate update(&local_state_, prefs::kDisplayOverscans); 116 DictionaryPrefUpdate update(&local_state_, prefs::kDisplayProperties);
117 const std::string name = base::Int64ToString(id); 117 const std::string name = base::Int64ToString(id);
118 118
119 base::DictionaryValue* pref_data = update.Get(); 119 base::DictionaryValue* pref_data = update.Get();
120 base::DictionaryValue* insets_value = new base::DictionaryValue(); 120 base::DictionaryValue* insets_value = new base::DictionaryValue();
121 insets_value->SetInteger("top", insets.top()); 121 insets_value->SetInteger("insets_top", insets.top());
122 insets_value->SetInteger("left", insets.left()); 122 insets_value->SetInteger("insets_left", insets.left());
123 insets_value->SetInteger("bottom", insets.bottom()); 123 insets_value->SetInteger("insets_bottom", insets.bottom());
124 insets_value->SetInteger("right", insets.right()); 124 insets_value->SetInteger("insets_right", insets.right());
125 pref_data->Set(name, insets_value); 125 pref_data->Set(name, insets_value);
126 } 126 }
127 127
128 std::string GetRegisteredDisplayLayoutStr(int64 id1, int64 id2) { 128 std::string GetRegisteredDisplayLayoutStr(int64 id1, int64 id2) {
129 ash::DisplayIdPair pair; 129 ash::DisplayIdPair pair;
130 pair.first = id1; 130 pair.first = id1;
131 pair.second = id2; 131 pair.second = id2;
132 return ash::Shell::GetInstance()->display_controller()-> 132 return ash::Shell::GetInstance()->display_controller()->
133 GetRegisteredDisplayLayout(pair).ToString(); 133 GetRegisteredDisplayLayout(pair).ToString();
134 } 134 }
(...skipping 15 matching lines...) Expand all
150 int64 dummy_id = id2 + 1; 150 int64 dummy_id = id2 + 1;
151 ASSERT_NE(id1, dummy_id); 151 ASSERT_NE(id1, dummy_id);
152 152
153 StoreDisplayLayoutPrefForSecondary(id2, ash::DisplayLayout::BOTTOM, 20); 153 StoreDisplayLayoutPrefForSecondary(id2, ash::DisplayLayout::BOTTOM, 20);
154 StoreDisplayLayoutPrefForSecondary(dummy_id, ash::DisplayLayout::TOP, -10); 154 StoreDisplayLayoutPrefForSecondary(dummy_id, ash::DisplayLayout::TOP, -10);
155 StoreDefaultLayoutPref(ash::DisplayLayout::LEFT, 50); 155 StoreDefaultLayoutPref(ash::DisplayLayout::LEFT, 50);
156 StorePrimaryDisplayId(id2); 156 StorePrimaryDisplayId(id2);
157 StoreDisplayOverscan(id1, gfx::Insets(10, 10, 10, 10)); 157 StoreDisplayOverscan(id1, gfx::Insets(10, 10, 10, 10));
158 StoreDisplayOverscan(id2, gfx::Insets(20, 20, 20, 20)); 158 StoreDisplayOverscan(id2, gfx::Insets(20, 20, 20, 20));
159 159
160 NotifyDisplayLocalStatePrefChanged(); 160 LoadDisplayPreferences();
161 // Check if the layout settings are notified to the system properly. 161 // Check if the layout settings are notified to the system properly.
162 ash::DisplayController* display_controller = 162 ash::DisplayController* display_controller =
163 ash::Shell::GetInstance()->display_controller(); 163 ash::Shell::GetInstance()->display_controller();
164 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); 164 gfx::Screen* screen = gfx::Screen::GetNativeScreen();
165 EXPECT_EQ(id2, screen->GetPrimaryDisplay().id()); 165 EXPECT_EQ(id2, screen->GetPrimaryDisplay().id());
166 // Display was swapped, so the layout was inverted. 166 // Display was swapped, so the layout was inverted.
167 EXPECT_EQ("top, -20", 167 EXPECT_EQ("top, -20",
168 display_controller->GetCurrentDisplayLayout().ToString()); 168 display_controller->GetCurrentDisplayLayout().ToString());
169 169
170 EXPECT_EQ("bottom, 20", GetRegisteredDisplayLayoutStr(id1, id2)); 170 EXPECT_EQ("bottom, 20", GetRegisteredDisplayLayoutStr(id1, id2));
171 EXPECT_EQ("top, -10", GetRegisteredDisplayLayoutStr(id1, dummy_id)); 171 EXPECT_EQ("top, -10", GetRegisteredDisplayLayoutStr(id1, dummy_id));
172 EXPECT_EQ("left, 50", 172 EXPECT_EQ("left, 50",
173 display_controller->default_display_layout().ToString()); 173 display_controller->default_display_layout().ToString());
174 EXPECT_EQ("160x160", screen->GetPrimaryDisplay().bounds().size().ToString()); 174 EXPECT_EQ("160x160", screen->GetPrimaryDisplay().bounds().size().ToString());
175 EXPECT_EQ("80x80", 175 EXPECT_EQ("80x80",
176 ash::ScreenAsh::GetSecondaryDisplay().bounds().size().ToString()); 176 ash::ScreenAsh::GetSecondaryDisplay().bounds().size().ToString());
177 } 177 }
178 178
179 TEST_F(DisplayPreferencesTest, PairedLayoutOverrides) { 179 TEST_F(DisplayPreferencesTest, PairedLayoutOverrides) {
180 UpdateDisplay("100x100,200x200"); 180 UpdateDisplay("100x100,200x200");
181 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); 181 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id();
182 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); 182 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id();
183 int64 dummy_id = id2 + 1; 183 int64 dummy_id = id2 + 1;
184 ASSERT_NE(id1, dummy_id); 184 ASSERT_NE(id1, dummy_id);
185 185
186 StoreDisplayLayoutPrefForPair(id1, id2, ash::DisplayLayout::TOP, 20); 186 StoreDisplayLayoutPrefForPair(id1, id2, ash::DisplayLayout::TOP, 20);
187 StoreDisplayLayoutPrefForPair(id1, dummy_id, ash::DisplayLayout::LEFT, 30); 187 StoreDisplayLayoutPrefForPair(id1, dummy_id, ash::DisplayLayout::LEFT, 30);
188 StoreDefaultLayoutPref(ash::DisplayLayout::LEFT, 50); 188 StoreDefaultLayoutPref(ash::DisplayLayout::LEFT, 50);
189 189
190 NotifyDisplayLocalStatePrefChanged(); 190 LoadDisplayPreferences();
191 // Check if the layout settings are notified to the system properly. 191 // Check if the layout settings are notified to the system properly.
192 // The paired layout overrides old layout. 192 // The paired layout overrides old layout.
193 ash::DisplayController* display_controller = 193 ash::DisplayController* display_controller =
194 ash::Shell::GetInstance()->display_controller(); 194 ash::Shell::GetInstance()->display_controller();
195 // Inverted one of for specified pair (id1, id2). Not used for the pair 195 // Inverted one of for specified pair (id1, id2). Not used for the pair
196 // (id1, dummy_id) since dummy_id is not connected right now. 196 // (id1, dummy_id) since dummy_id is not connected right now.
197 EXPECT_EQ("top, 20", 197 EXPECT_EQ("top, 20",
198 display_controller->GetCurrentDisplayLayout().ToString()); 198 display_controller->GetCurrentDisplayLayout().ToString());
199 EXPECT_EQ("top, 20", GetRegisteredDisplayLayoutStr(id1, id2)); 199 EXPECT_EQ("top, 20", GetRegisteredDisplayLayoutStr(id1, id2));
200 EXPECT_EQ("left, 30", GetRegisteredDisplayLayoutStr(id1, dummy_id)); 200 EXPECT_EQ("left, 30", GetRegisteredDisplayLayoutStr(id1, dummy_id));
201 } 201 }
202 202
203 TEST_F(DisplayPreferencesTest, BasicStores) { 203 TEST_F(DisplayPreferencesTest, BasicStores) {
204 UpdateDisplay("100x100,200x200"); 204 UpdateDisplay("100x100,200x200");
205 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); 205 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id();
206 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); 206 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id();
207 int64 dummy_id = id2 + 1; 207 int64 dummy_id = id2 + 1;
208 ASSERT_NE(id1, dummy_id); 208 ASSERT_NE(id1, dummy_id);
209 209
210 LoggedInAsUser(); 210 LoggedInAsUser();
211 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); 211 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10);
212 SetCurrentAndDefaultDisplayLayout(layout); 212 SetCurrentAndDefaultDisplayLayout(layout);
213 StoreDisplayLayoutPrefForTest( 213 StoreDisplayLayoutPrefForTest(
214 id1, dummy_id, ash::DisplayLayout(ash::DisplayLayout::LEFT, 20)); 214 id1, dummy_id, ash::DisplayLayout(ash::DisplayLayout::LEFT, 20));
215 // Can't switch to a display that does not exist. 215 // Can't switch to a display that does not exist.
216 GetDisplayController()->SetPrimaryDisplayId(dummy_id); 216 GetDisplayController()->SetPrimaryDisplayId(dummy_id);
217 EXPECT_NE(dummy_id, local_state()->GetInt64(prefs::kPrimaryDisplayID)); 217 EXPECT_NE(dummy_id, local_state()->GetInt64(prefs::kPrimaryDisplayID));
218 218
219 SetAndStoreDisplayOverscan( 219 ash::Shell::GetInstance()->display_controller()->SetOverscanInsets(
220 ash::ScreenAsh::GetNativeScreen()->GetPrimaryDisplay(), 220 ash::ScreenAsh::GetNativeScreen()->GetPrimaryDisplay().id(),
221 gfx::Insets(10, 11, 12, 13)); 221 gfx::Insets(10, 11, 12, 13));
222 222
223 scoped_ptr<base::DictionaryValue> serialized_value( 223 scoped_ptr<base::DictionaryValue> serialized_value(
224 new base::DictionaryValue()); 224 new base::DictionaryValue());
225 ASSERT_TRUE(ash::DisplayLayout::ConvertToValue(layout, 225 ASSERT_TRUE(ash::DisplayLayout::ConvertToValue(layout,
226 serialized_value.get())); 226 serialized_value.get()));
227 227
228 const base::DictionaryValue* displays = 228 const base::DictionaryValue* displays =
229 local_state()->GetDictionary(prefs::kSecondaryDisplays); 229 local_state()->GetDictionary(prefs::kSecondaryDisplays);
230 const base::DictionaryValue* display_layout = NULL; 230 const base::DictionaryValue* display_layout = NULL;
231 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); 231 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2);
232 EXPECT_TRUE(displays->GetDictionary(key, &display_layout)); 232 EXPECT_TRUE(displays->GetDictionary(key, &display_layout));
233 EXPECT_TRUE(serialized_value->Equals(display_layout)); 233 EXPECT_TRUE(serialized_value->Equals(display_layout));
234 234
235 // The default value is set for the last call of 235 // The default value is set for the last call of
236 // SetCurrentAndDefaultDisplayLayout 236 // SetCurrentAndDefaultDisplayLayout
237 EXPECT_EQ(ash::DisplayLayout::TOP, 237 EXPECT_EQ(ash::DisplayLayout::TOP,
238 local_state()->GetInteger(prefs::kSecondaryDisplayLayout)); 238 local_state()->GetInteger(prefs::kSecondaryDisplayLayout));
239 EXPECT_EQ(10, local_state()->GetInteger(prefs::kSecondaryDisplayOffset)); 239 EXPECT_EQ(10, local_state()->GetInteger(prefs::kSecondaryDisplayOffset));
240 240
241 const base::DictionaryValue* overscans = 241 const base::DictionaryValue* overscans =
242 local_state()->GetDictionary(prefs::kDisplayOverscans); 242 local_state()->GetDictionary(prefs::kDisplayProperties);
243 const base::DictionaryValue* overscan = NULL; 243 const base::DictionaryValue* overscan = NULL;
244 EXPECT_TRUE(overscans->GetDictionary(base::Int64ToString(id1), &overscan)); 244 EXPECT_TRUE(overscans->GetDictionary(base::Int64ToString(id1), &overscan));
245 int top = 0, left = 0, bottom = 0, right = 0; 245 int top = 0, left = 0, bottom = 0, right = 0;
246 EXPECT_TRUE(overscan->GetInteger("top", &top)); 246 EXPECT_TRUE(overscan->GetInteger("insets_top", &top));
247 EXPECT_TRUE(overscan->GetInteger("left", &left)); 247 EXPECT_TRUE(overscan->GetInteger("insets_left", &left));
248 EXPECT_TRUE(overscan->GetInteger("bottom", &bottom)); 248 EXPECT_TRUE(overscan->GetInteger("insets_bottom", &bottom));
249 EXPECT_TRUE(overscan->GetInteger("right", &right)); 249 EXPECT_TRUE(overscan->GetInteger("insets_right", &right));
250 EXPECT_EQ(10, top); 250 EXPECT_EQ(10, top);
251 EXPECT_EQ(11, left); 251 EXPECT_EQ(11, left);
252 EXPECT_EQ(12, bottom); 252 EXPECT_EQ(12, bottom);
253 EXPECT_EQ(13, right); 253 EXPECT_EQ(13, right);
254 254
255 GetDisplayController()->SetPrimaryDisplayId(id2); 255 GetDisplayController()->SetPrimaryDisplayId(id2);
256 EXPECT_EQ(id2, local_state()->GetInt64(prefs::kPrimaryDisplayID)); 256 EXPECT_EQ(id2, local_state()->GetInt64(prefs::kPrimaryDisplayID));
257 // The layout remains the same. 257 // The layout remains the same.
258 EXPECT_TRUE(displays->GetDictionary(key, &display_layout)); 258 EXPECT_TRUE(displays->GetDictionary(key, &display_layout));
259 EXPECT_TRUE(serialized_value->Equals(display_layout)); 259 EXPECT_TRUE(serialized_value->Equals(display_layout));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 } 302 }
303 303
304 TEST_F(DisplayPreferencesTest, DontStoreInGuestMode) { 304 TEST_F(DisplayPreferencesTest, DontStoreInGuestMode) {
305 UpdateDisplay("100x100,200x200"); 305 UpdateDisplay("100x100,200x200");
306 306
307 LoggedInAsGuest(); 307 LoggedInAsGuest();
308 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); 308 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id();
309 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); 309 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10);
310 SetCurrentAndDefaultDisplayLayout(layout); 310 SetCurrentAndDefaultDisplayLayout(layout);
311 GetDisplayController()->SetPrimaryDisplayId(id2); 311 GetDisplayController()->SetPrimaryDisplayId(id2);
312 SetAndStoreDisplayOverscan( 312 ash::Shell::GetInstance()->display_controller()->SetOverscanInsets(
313 ash::ScreenAsh::GetNativeScreen()->GetPrimaryDisplay(), 313 ash::ScreenAsh::GetNativeScreen()->GetPrimaryDisplay().id(),
314 gfx::Insets(10, 11, 12, 13)); 314 gfx::Insets(10, 11, 12, 13));
315 315
316 // Does not store the preferences locally. 316 // Does not store the preferences locally.
317 EXPECT_FALSE(local_state()->FindPreference( 317 EXPECT_FALSE(local_state()->FindPreference(
318 prefs::kSecondaryDisplays)->HasUserSetting()); 318 prefs::kSecondaryDisplays)->HasUserSetting());
319 EXPECT_FALSE(local_state()->FindPreference( 319 EXPECT_FALSE(local_state()->FindPreference(
320 prefs::kSecondaryDisplayLayout)->HasUserSetting()); 320 prefs::kSecondaryDisplayLayout)->HasUserSetting());
321 EXPECT_FALSE(local_state()->FindPreference( 321 EXPECT_FALSE(local_state()->FindPreference(
322 prefs::kSecondaryDisplayOffset)->HasUserSetting()); 322 prefs::kSecondaryDisplayOffset)->HasUserSetting());
323 EXPECT_FALSE(local_state()->FindPreference( 323 EXPECT_FALSE(local_state()->FindPreference(
324 prefs::kPrimaryDisplayID)->HasUserSetting()); 324 prefs::kPrimaryDisplayID)->HasUserSetting());
325 EXPECT_FALSE(local_state()->FindPreference( 325 EXPECT_FALSE(local_state()->FindPreference(
326 prefs::kDisplayOverscans)->HasUserSetting()); 326 prefs::kDisplayProperties)->HasUserSetting());
327 327
328 // Settings are still notified to the system. 328 // Settings are still notified to the system.
329 ash::DisplayController* display_controller = 329 ash::DisplayController* display_controller =
330 ash::Shell::GetInstance()->display_controller(); 330 ash::Shell::GetInstance()->display_controller();
331 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); 331 gfx::Screen* screen = gfx::Screen::GetNativeScreen();
332 EXPECT_EQ(id2, screen->GetPrimaryDisplay().id()); 332 EXPECT_EQ(id2, screen->GetPrimaryDisplay().id());
333 EXPECT_EQ(ash::DisplayLayout::BOTTOM, 333 EXPECT_EQ(ash::DisplayLayout::BOTTOM,
334 display_controller->GetCurrentDisplayLayout().position); 334 display_controller->GetCurrentDisplayLayout().position);
335 EXPECT_EQ(-10, display_controller->GetCurrentDisplayLayout().offset); 335 EXPECT_EQ(-10, display_controller->GetCurrentDisplayLayout().offset);
336 EXPECT_EQ("176x178", screen->GetPrimaryDisplay().bounds().size().ToString()); 336 EXPECT_EQ("176x178", screen->GetPrimaryDisplay().bounds().size().ToString());
337 } 337 }
338 338
339 } // namespace 339 } // namespace
340 } // namespace chromeos 340 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698