| 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/display/resolution_notification_controller.h" | 10 #include "ash/display/resolution_notification_controller.h" |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after 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. | 234 // Internal display never registered the resolution. |
| 235 int width = 0, height = 0; | 235 int width = 0, height = 0; |
| 236 EXPECT_FALSE(property->GetInteger("width", &width)); | 236 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 237 EXPECT_FALSE(property->GetInteger("height", &height)); | 237 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 238 | 238 |
| 239 int top = 0, left = 0, bottom = 0, right = 0; | 239 int top = 0, left = 0, bottom = 0, right = 0; |
| 240 EXPECT_TRUE(property->GetInteger("insets_top", &top)); | 240 EXPECT_TRUE(property->GetInteger("insets_top", &top)); |
| 241 EXPECT_TRUE(property->GetInteger("insets_left", &left)); | 241 EXPECT_TRUE(property->GetInteger("insets_left", &left)); |
| 242 EXPECT_TRUE(property->GetInteger("insets_bottom", &bottom)); | 242 EXPECT_TRUE(property->GetInteger("insets_bottom", &bottom)); |
| 243 EXPECT_TRUE(property->GetInteger("insets_right", &right)); | 243 EXPECT_TRUE(property->GetInteger("insets_right", &right)); |
| 244 EXPECT_EQ(10, top); | 244 EXPECT_EQ(10, top); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 264 EXPECT_FALSE(property->GetInteger("width", &width)); | 264 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 265 EXPECT_FALSE(property->GetInteger("height", &height)); | 265 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 266 | 266 |
| 267 display_manager->SetDisplayResolution(id2, gfx::Size(300, 200)); | 267 display_manager->SetDisplayResolution(id2, gfx::Size(300, 200)); |
| 268 | 268 |
| 269 display_controller->SetPrimaryDisplayId(id2); | 269 display_controller->SetPrimaryDisplayId(id2); |
| 270 | 270 |
| 271 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); | 271 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); |
| 272 width = 0; | 272 width = 0; |
| 273 height = 0; | 273 height = 0; |
| 274 // Internal dispaly shouldn't store its resolution. | 274 // Internal display shouldn't store its resolution. |
| 275 EXPECT_FALSE(property->GetInteger("width", &width)); | 275 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 276 EXPECT_FALSE(property->GetInteger("height", &height)); | 276 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 277 | 277 |
| 278 // External dispaly's resolution must be stored this time because | 278 // External display's resolution must be stored this time because |
| 279 // it's not best. | 279 // it's not best. |
| 280 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 280 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 281 EXPECT_TRUE(property->GetInteger("width", &width)); | 281 EXPECT_TRUE(property->GetInteger("width", &width)); |
| 282 EXPECT_TRUE(property->GetInteger("height", &height)); | 282 EXPECT_TRUE(property->GetInteger("height", &height)); |
| 283 EXPECT_EQ(300, width); | 283 EXPECT_EQ(300, width); |
| 284 EXPECT_EQ(200, height); | 284 EXPECT_EQ(200, height); |
| 285 | 285 |
| 286 // The layout remains the same. | 286 // The layout remains the same. |
| 287 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 287 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
| 288 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*layout_value, | 288 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*layout_value, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 313 mirrored = false; | 313 mirrored = false; |
| 314 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); | 314 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
| 315 EXPECT_TRUE(mirrored); | 315 EXPECT_TRUE(mirrored); |
| 316 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); | 316 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
| 317 EXPECT_EQ(base::Int64ToString(id2), primary_id_str); | 317 EXPECT_EQ(base::Int64ToString(id2), primary_id_str); |
| 318 | 318 |
| 319 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); | 319 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); |
| 320 EXPECT_FALSE(property->GetInteger("width", &width)); | 320 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 321 EXPECT_FALSE(property->GetInteger("height", &height)); | 321 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 322 | 322 |
| 323 // External dispaly's selected resolution must not change | 323 // External display's selected resolution must not change |
| 324 // by mirroring. | 324 // by mirroring. |
| 325 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 325 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 326 EXPECT_TRUE(property->GetInteger("width", &width)); | 326 EXPECT_TRUE(property->GetInteger("width", &width)); |
| 327 EXPECT_TRUE(property->GetInteger("height", &height)); | 327 EXPECT_TRUE(property->GetInteger("height", &height)); |
| 328 EXPECT_EQ(300, width); | 328 EXPECT_EQ(300, width); |
| 329 EXPECT_EQ(200, height); | 329 EXPECT_EQ(200, height); |
| 330 | 330 |
| 331 // Set new display's selected resolution. | 331 // Set new display's selected resolution. |
| 332 display_manager->RegisterDisplayProperty(id2 + 1, | 332 display_manager->RegisterDisplayProperty( |
| 333 gfx::Display::ROTATE_0, | 333 id2 + 1, gfx::Display::ROTATE_0, 1.0f, NULL, gfx::Size(500, 400)); |
| 334 1.0f, | |
| 335 NULL, | |
| 336 gfx::Size(500, 400)); | |
| 337 | 334 |
| 338 UpdateDisplay("200x200*2, 600x500#600x500|500x400"); | 335 UpdateDisplay("200x200*2, 600x500#600x500|500x400"); |
| 339 | 336 |
| 340 // Update key as the 2nd display gets new id. | 337 // Update key as the 2nd display gets new id. |
| 341 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 338 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 342 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 339 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
| 343 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 340 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
| 344 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); | 341 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); |
| 345 EXPECT_EQ("right", position); | 342 EXPECT_EQ("right", position); |
| 346 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); | 343 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); |
| 347 EXPECT_EQ(0, offset); | 344 EXPECT_EQ(0, offset); |
| 348 mirrored = true; | 345 mirrored = true; |
| 349 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); | 346 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
| 350 EXPECT_FALSE(mirrored); | 347 EXPECT_FALSE(mirrored); |
| 351 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); | 348 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
| 352 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); | 349 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); |
| 353 | 350 |
| 354 // Best resolution should not be saved. | 351 // Best resolution should not be saved. |
| 355 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 352 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 356 EXPECT_FALSE(property->GetInteger("width", &width)); | 353 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 357 EXPECT_FALSE(property->GetInteger("height", &height)); | 354 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 358 | 355 |
| 359 // Set yet another new display's selected resolution. | 356 // Set yet another new display's selected resolution. |
| 360 display_manager->RegisterDisplayProperty(id2 + 1, | 357 display_manager->RegisterDisplayProperty( |
| 361 gfx::Display::ROTATE_0, | 358 id2 + 1, gfx::Display::ROTATE_0, 1.0f, NULL, gfx::Size(500, 400)); |
| 362 1.0f, | |
| 363 NULL, | |
| 364 gfx::Size(500, 400)); | |
| 365 // Disconnect 2nd display first to generate new id for external display. | 359 // Disconnect 2nd display first to generate new id for external display. |
| 366 UpdateDisplay("200x200*2"); | 360 UpdateDisplay("200x200*2"); |
| 367 UpdateDisplay("200x200*2, 500x400#600x500|500x400"); | 361 UpdateDisplay("200x200*2, 500x400#600x500|500x400%60.0f"); |
| 368 // Update key as the 2nd display gets new id. | 362 // Update key as the 2nd display gets new id. |
| 369 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 363 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 370 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 364 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
| 371 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 365 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
| 372 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); | 366 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); |
| 373 EXPECT_EQ("right", position); | 367 EXPECT_EQ("right", position); |
| 374 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); | 368 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); |
| 375 EXPECT_EQ(0, offset); | 369 EXPECT_EQ(0, offset); |
| 376 mirrored = true; | 370 mirrored = true; |
| 377 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); | 371 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
| 378 EXPECT_FALSE(mirrored); | 372 EXPECT_FALSE(mirrored); |
| 379 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); | 373 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
| 380 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); | 374 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); |
| 381 | 375 |
| 382 // External dispaly's selected resolution must be updated. | 376 // External display's selected resolution must be updated. |
| 383 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 377 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 384 EXPECT_TRUE(property->GetInteger("width", &width)); | 378 EXPECT_TRUE(property->GetInteger("width", &width)); |
| 385 EXPECT_TRUE(property->GetInteger("height", &height)); | 379 EXPECT_TRUE(property->GetInteger("height", &height)); |
| 386 EXPECT_EQ(500, width); | 380 EXPECT_EQ(500, width); |
| 387 EXPECT_EQ(400, height); | 381 EXPECT_EQ(400, height); |
| 388 } | 382 } |
| 389 | 383 |
| 390 TEST_F(DisplayPreferencesTest, PreventStore) { | 384 TEST_F(DisplayPreferencesTest, PreventStore) { |
| 391 ResolutionNotificationController::SuppressTimerForTest(); | 385 ResolutionNotificationController::SuppressTimerForTest(); |
| 392 LoggedInAsUser(); | 386 LoggedInAsUser(); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 local_state()->GetString(prefs::kDisplayPowerState)); | 555 local_state()->GetString(prefs::kDisplayPowerState)); |
| 562 | 556 |
| 563 // Don't try to load | 557 // Don't try to load |
| 564 local_state()->SetString(prefs::kDisplayPowerState, "all_off"); | 558 local_state()->SetString(prefs::kDisplayPowerState, "all_off"); |
| 565 LoadDisplayPreferences(false); | 559 LoadDisplayPreferences(false); |
| 566 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, | 560 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
| 567 shell->output_configurator()->power_state()); | 561 shell->output_configurator()->power_state()); |
| 568 } | 562 } |
| 569 | 563 |
| 570 } // namespace chromeos | 564 } // namespace chromeos |
| OLD | NEW |