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 "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
8 #include "ash/display/display_layout_store.h" | 8 #include "ash/display/display_layout_store.h" |
9 #include "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
10 #include "ash/screen_ash.h" | 10 #include "ash/screen_ash.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 EXPECT_EQ("top, 20", GetRegisteredDisplayLayoutStr(id1, id2)); | 176 EXPECT_EQ("top, 20", GetRegisteredDisplayLayoutStr(id1, id2)); |
177 EXPECT_EQ("left, 30", GetRegisteredDisplayLayoutStr(id1, dummy_id)); | 177 EXPECT_EQ("left, 30", GetRegisteredDisplayLayoutStr(id1, dummy_id)); |
178 } | 178 } |
179 | 179 |
180 TEST_F(DisplayPreferencesTest, BasicStores) { | 180 TEST_F(DisplayPreferencesTest, BasicStores) { |
181 ash::DisplayController* display_controller = | 181 ash::DisplayController* display_controller = |
182 ash::Shell::GetInstance()->display_controller(); | 182 ash::Shell::GetInstance()->display_controller(); |
183 ash::internal::DisplayManager* display_manager = | 183 ash::internal::DisplayManager* display_manager = |
184 ash::Shell::GetInstance()->display_manager(); | 184 ash::Shell::GetInstance()->display_manager(); |
185 | 185 |
186 UpdateDisplay("200x200*2,200x200"); | 186 UpdateDisplay("200x200*2,400x300"); |
187 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); | 187 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); |
188 gfx::Display::SetInternalDisplayId(id1); | 188 gfx::Display::SetInternalDisplayId(id1); |
189 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); | 189 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); |
190 int64 dummy_id = id2 + 1; | 190 int64 dummy_id = id2 + 1; |
191 ASSERT_NE(id1, dummy_id); | 191 ASSERT_NE(id1, dummy_id); |
192 | 192 |
193 LoggedInAsUser(); | 193 LoggedInAsUser(); |
194 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); | 194 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); |
195 SetCurrentDisplayLayout(layout); | 195 SetCurrentDisplayLayout(layout); |
196 StoreDisplayLayoutPrefForTest( | 196 StoreDisplayLayoutPrefForTest( |
(...skipping 27 matching lines...) Expand all Loading... |
224 local_state()->GetDictionary(prefs::kDisplayProperties); | 224 local_state()->GetDictionary(prefs::kDisplayProperties); |
225 const base::DictionaryValue* property = NULL; | 225 const base::DictionaryValue* property = NULL; |
226 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); | 226 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); |
227 int ui_scale = 0; | 227 int ui_scale = 0; |
228 int rotation = 0; | 228 int rotation = 0; |
229 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); | 229 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); |
230 EXPECT_TRUE(property->GetInteger("ui-scale", &ui_scale)); | 230 EXPECT_TRUE(property->GetInteger("ui-scale", &ui_scale)); |
231 EXPECT_EQ(1, rotation); | 231 EXPECT_EQ(1, rotation); |
232 EXPECT_EQ(1250, ui_scale); | 232 EXPECT_EQ(1250, ui_scale); |
233 | 233 |
| 234 // Internal display never registere the resolution. |
| 235 int width = 0, height = 0; |
| 236 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 237 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 238 |
234 int top = 0, left = 0, bottom = 0, right = 0; | 239 int top = 0, left = 0, bottom = 0, right = 0; |
235 EXPECT_TRUE(property->GetInteger("insets_top", &top)); | 240 EXPECT_TRUE(property->GetInteger("insets_top", &top)); |
236 EXPECT_TRUE(property->GetInteger("insets_left", &left)); | 241 EXPECT_TRUE(property->GetInteger("insets_left", &left)); |
237 EXPECT_TRUE(property->GetInteger("insets_bottom", &bottom)); | 242 EXPECT_TRUE(property->GetInteger("insets_bottom", &bottom)); |
238 EXPECT_TRUE(property->GetInteger("insets_right", &right)); | 243 EXPECT_TRUE(property->GetInteger("insets_right", &right)); |
239 EXPECT_EQ(10, top); | 244 EXPECT_EQ(10, top); |
240 EXPECT_EQ(11, left); | 245 EXPECT_EQ(11, left); |
241 EXPECT_EQ(12, bottom); | 246 EXPECT_EQ(12, bottom); |
242 EXPECT_EQ(13, right); | 247 EXPECT_EQ(13, right); |
243 | 248 |
244 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 249 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
245 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); | 250 EXPECT_TRUE(property->GetInteger("rotation", &rotation)); |
246 EXPECT_TRUE(property->GetInteger("ui-scale", &ui_scale)); | 251 EXPECT_TRUE(property->GetInteger("ui-scale", &ui_scale)); |
247 EXPECT_EQ(0, rotation); | 252 EXPECT_EQ(0, rotation); |
248 // ui_scale works only on 2x scale factor/1st display. | 253 // ui_scale works only on 2x scale factor/1st display. |
249 EXPECT_EQ(1000, ui_scale); | 254 EXPECT_EQ(1000, ui_scale); |
250 EXPECT_FALSE(property->GetInteger("insets_top", &top)); | 255 EXPECT_FALSE(property->GetInteger("insets_top", &top)); |
251 EXPECT_FALSE(property->GetInteger("insets_left", &left)); | 256 EXPECT_FALSE(property->GetInteger("insets_left", &left)); |
252 EXPECT_FALSE(property->GetInteger("insets_bottom", &bottom)); | 257 EXPECT_FALSE(property->GetInteger("insets_bottom", &bottom)); |
253 EXPECT_FALSE(property->GetInteger("insets_right", &right)); | 258 EXPECT_FALSE(property->GetInteger("insets_right", &right)); |
254 | 259 |
| 260 // Resolution is saved only when the resolution is set |
| 261 // by DisplayManager::SetDisplayResolution |
| 262 width = 0; |
| 263 height = 0; |
| 264 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 265 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 266 |
| 267 display_manager->SetDisplayResolution(id2, gfx::Size(400, 300)); |
| 268 |
255 display_controller->SetPrimaryDisplayId(id2); | 269 display_controller->SetPrimaryDisplayId(id2); |
256 | 270 |
| 271 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); |
| 272 width = 0; |
| 273 height = 0; |
| 274 // Internal dispaly shouldn't store its resolution. |
| 275 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 276 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 277 |
| 278 // External dispaly's resolution must be stored this time. |
| 279 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 280 EXPECT_TRUE(property->GetInteger("width", &width)); |
| 281 EXPECT_TRUE(property->GetInteger("height", &height)); |
| 282 EXPECT_EQ(400, width); |
| 283 EXPECT_EQ(300, height); |
| 284 |
257 // The layout remains the same. | 285 // The layout remains the same. |
258 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 286 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
259 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*layout_value, | 287 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*layout_value, |
260 &stored_layout)); | 288 &stored_layout)); |
261 EXPECT_EQ(layout.position, stored_layout.position); | 289 EXPECT_EQ(layout.position, stored_layout.position); |
262 EXPECT_EQ(layout.offset, stored_layout.offset); | 290 EXPECT_EQ(layout.offset, stored_layout.offset); |
263 EXPECT_EQ(id2, stored_layout.primary_id); | 291 EXPECT_EQ(id2, stored_layout.primary_id); |
264 | 292 |
265 mirrored = true; | 293 mirrored = true; |
266 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); | 294 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
(...skipping 13 matching lines...) Expand all Loading... |
280 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); | 308 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); |
281 EXPECT_EQ("top", position); | 309 EXPECT_EQ("top", position); |
282 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); | 310 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); |
283 EXPECT_EQ(-20, offset); | 311 EXPECT_EQ(-20, offset); |
284 mirrored = false; | 312 mirrored = false; |
285 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); | 313 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
286 EXPECT_TRUE(mirrored); | 314 EXPECT_TRUE(mirrored); |
287 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); | 315 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
288 EXPECT_EQ(base::Int64ToString(id2), primary_id_str); | 316 EXPECT_EQ(base::Int64ToString(id2), primary_id_str); |
289 | 317 |
290 UpdateDisplay("200x200*2,200x200"); | 318 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); |
| 319 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 320 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 321 |
| 322 // External dispaly's selected resolution must not change |
| 323 // by mirroring. |
| 324 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 325 EXPECT_TRUE(property->GetInteger("width", &width)); |
| 326 EXPECT_TRUE(property->GetInteger("height", &height)); |
| 327 EXPECT_EQ(400, width); |
| 328 EXPECT_EQ(300, height); |
| 329 |
| 330 // Set new display's selected resolution. |
| 331 display_manager->SetDisplayResolution(id2 + 1, gfx::Size(500, 400)); |
| 332 UpdateDisplay("200x200*2,500x400"); |
291 // Update key as the 2nd display gets new id. | 333 // Update key as the 2nd display gets new id. |
292 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); | 334 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); |
293 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 335 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
294 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 336 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
295 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); | 337 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); |
296 EXPECT_EQ("right", position); | 338 EXPECT_EQ("right", position); |
297 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); | 339 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); |
298 EXPECT_EQ(0, offset); | 340 EXPECT_EQ(0, offset); |
299 mirrored = true; | 341 mirrored = true; |
300 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); | 342 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
301 EXPECT_FALSE(mirrored); | 343 EXPECT_FALSE(mirrored); |
302 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); | 344 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
303 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); | 345 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); |
| 346 |
| 347 // External dispaly's selected resolution must be updated. |
| 348 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 349 EXPECT_TRUE(property->GetInteger("width", &width)); |
| 350 EXPECT_TRUE(property->GetInteger("height", &height)); |
| 351 EXPECT_EQ(500, width); |
| 352 EXPECT_EQ(400, height); |
304 } | 353 } |
305 | 354 |
306 TEST_F(DisplayPreferencesTest, StoreForSwappedDisplay) { | 355 TEST_F(DisplayPreferencesTest, StoreForSwappedDisplay) { |
307 UpdateDisplay("100x100,200x200"); | 356 UpdateDisplay("100x100,200x200"); |
308 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); | 357 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); |
309 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); | 358 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); |
310 | 359 |
311 ash::DisplayController* display_controller = | 360 ash::DisplayController* display_controller = |
312 ash::Shell::GetInstance()->display_controller(); | 361 ash::Shell::GetInstance()->display_controller(); |
313 display_controller->SwapPrimaryDisplay(); | 362 display_controller->SwapPrimaryDisplay(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 StoreDisplayPowerStateForTest( | 440 StoreDisplayPowerStateForTest( |
392 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); | 441 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); |
393 LoadDisplayPreferences(false); | 442 LoadDisplayPreferences(false); |
394 EXPECT_EQ( | 443 EXPECT_EQ( |
395 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, | 444 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
396 ash::Shell::GetInstance()->output_configurator()->power_state()); | 445 ash::Shell::GetInstance()->output_configurator()->power_state()); |
397 } | 446 } |
398 | 447 |
399 } // namespace | 448 } // namespace |
400 } // namespace chromeos | 449 } // namespace chromeos |
OLD | NEW |