| 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 EXPECT_EQ("top, 20", GetRegisteredDisplayLayoutStr(id1, id2)); | 183 EXPECT_EQ("top, 20", GetRegisteredDisplayLayoutStr(id1, id2)); |
| 184 EXPECT_EQ("left, 30", GetRegisteredDisplayLayoutStr(id1, dummy_id)); | 184 EXPECT_EQ("left, 30", GetRegisteredDisplayLayoutStr(id1, dummy_id)); |
| 185 } | 185 } |
| 186 | 186 |
| 187 TEST_F(DisplayPreferencesTest, BasicStores) { | 187 TEST_F(DisplayPreferencesTest, BasicStores) { |
| 188 ash::DisplayController* display_controller = | 188 ash::DisplayController* display_controller = |
| 189 ash::Shell::GetInstance()->display_controller(); | 189 ash::Shell::GetInstance()->display_controller(); |
| 190 ash::internal::DisplayManager* display_manager = | 190 ash::internal::DisplayManager* display_manager = |
| 191 ash::Shell::GetInstance()->display_manager(); | 191 ash::Shell::GetInstance()->display_manager(); |
| 192 | 192 |
| 193 UpdateDisplay("200x200*2,400x300"); | 193 UpdateDisplay("200x200*2, 400x300#400x400|300x200"); |
| 194 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); | 194 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); |
| 195 gfx::Display::SetInternalDisplayId(id1); | 195 gfx::Display::SetInternalDisplayId(id1); |
| 196 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); | 196 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); |
| 197 int64 dummy_id = id2 + 1; | 197 int64 dummy_id = id2 + 1; |
| 198 ASSERT_NE(id1, dummy_id); | 198 ASSERT_NE(id1, dummy_id); |
| 199 | 199 |
| 200 LoggedInAsUser(); | 200 LoggedInAsUser(); |
| 201 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); | 201 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); |
| 202 SetCurrentDisplayLayout(layout); | 202 SetCurrentDisplayLayout(layout); |
| 203 StoreDisplayLayoutPrefForTest( | 203 StoreDisplayLayoutPrefForTest( |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 EXPECT_FALSE(property->GetInteger("insets_bottom", &bottom)); | 264 EXPECT_FALSE(property->GetInteger("insets_bottom", &bottom)); |
| 265 EXPECT_FALSE(property->GetInteger("insets_right", &right)); | 265 EXPECT_FALSE(property->GetInteger("insets_right", &right)); |
| 266 | 266 |
| 267 // Resolution is saved only when the resolution is set | 267 // Resolution is saved only when the resolution is set |
| 268 // by DisplayManager::SetDisplayResolution | 268 // by DisplayManager::SetDisplayResolution |
| 269 width = 0; | 269 width = 0; |
| 270 height = 0; | 270 height = 0; |
| 271 EXPECT_FALSE(property->GetInteger("width", &width)); | 271 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 272 EXPECT_FALSE(property->GetInteger("height", &height)); | 272 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 273 | 273 |
| 274 display_manager->SetDisplayResolution(id2, gfx::Size(400, 300)); | 274 display_manager->SetDisplayResolution(id2, gfx::Size(300, 200)); |
| 275 | 275 |
| 276 display_controller->SetPrimaryDisplayId(id2); | 276 display_controller->SetPrimaryDisplayId(id2); |
| 277 | 277 |
| 278 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); | 278 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); |
| 279 width = 0; | 279 width = 0; |
| 280 height = 0; | 280 height = 0; |
| 281 // Internal dispaly shouldn't store its resolution. | 281 // Internal dispaly shouldn't store its resolution. |
| 282 EXPECT_FALSE(property->GetInteger("width", &width)); | 282 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 283 EXPECT_FALSE(property->GetInteger("height", &height)); | 283 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 284 | 284 |
| 285 // External dispaly's resolution must be stored this time. | 285 // External dispaly's resolution must be stored this time because |
| 286 // it's not best. |
| 286 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 287 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 287 EXPECT_TRUE(property->GetInteger("width", &width)); | 288 EXPECT_TRUE(property->GetInteger("width", &width)); |
| 288 EXPECT_TRUE(property->GetInteger("height", &height)); | 289 EXPECT_TRUE(property->GetInteger("height", &height)); |
| 289 EXPECT_EQ(400, width); | 290 EXPECT_EQ(300, width); |
| 290 EXPECT_EQ(300, height); | 291 EXPECT_EQ(200, height); |
| 291 | 292 |
| 292 // The layout remains the same. | 293 // The layout remains the same. |
| 293 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 294 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
| 294 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*layout_value, | 295 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*layout_value, |
| 295 &stored_layout)); | 296 &stored_layout)); |
| 296 EXPECT_EQ(layout.position, stored_layout.position); | 297 EXPECT_EQ(layout.position, stored_layout.position); |
| 297 EXPECT_EQ(layout.offset, stored_layout.offset); | 298 EXPECT_EQ(layout.offset, stored_layout.offset); |
| 298 EXPECT_EQ(id2, stored_layout.primary_id); | 299 EXPECT_EQ(id2, stored_layout.primary_id); |
| 299 | 300 |
| 300 mirrored = true; | 301 mirrored = true; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 324 | 325 |
| 325 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); | 326 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); |
| 326 EXPECT_FALSE(property->GetInteger("width", &width)); | 327 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 327 EXPECT_FALSE(property->GetInteger("height", &height)); | 328 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 328 | 329 |
| 329 // External dispaly's selected resolution must not change | 330 // External dispaly's selected resolution must not change |
| 330 // by mirroring. | 331 // by mirroring. |
| 331 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 332 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 332 EXPECT_TRUE(property->GetInteger("width", &width)); | 333 EXPECT_TRUE(property->GetInteger("width", &width)); |
| 333 EXPECT_TRUE(property->GetInteger("height", &height)); | 334 EXPECT_TRUE(property->GetInteger("height", &height)); |
| 334 EXPECT_EQ(400, width); | 335 EXPECT_EQ(300, width); |
| 335 EXPECT_EQ(300, height); | 336 EXPECT_EQ(200, height); |
| 336 | 337 |
| 337 // Set new display's selected resolution. | 338 // Set new display's selected resolution. |
| 338 display_manager->SetDisplayResolution(id2 + 1, gfx::Size(500, 400)); | 339 display_manager->RegisterDisplayProperty(id2 + 1, |
| 339 UpdateDisplay("200x200*2,500x400"); | 340 gfx::Display::ROTATE_0, |
| 341 1.0f, |
| 342 NULL, |
| 343 gfx::Size(500, 400)); |
| 344 |
| 345 UpdateDisplay("200x200*2, 600x500#600x500|500x400"); |
| 346 |
| 340 // Update key as the 2nd display gets new id. | 347 // Update key as the 2nd display gets new id. |
| 341 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); | 348 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); |
| 342 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 349 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
| 343 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 350 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
| 344 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); | 351 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); |
| 345 EXPECT_EQ("right", position); | 352 EXPECT_EQ("right", position); |
| 346 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); | 353 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); |
| 347 EXPECT_EQ(0, offset); | 354 EXPECT_EQ(0, offset); |
| 348 mirrored = true; | 355 mirrored = true; |
| 349 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); | 356 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
| 350 EXPECT_FALSE(mirrored); | 357 EXPECT_FALSE(mirrored); |
| 351 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); | 358 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
| 352 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); | 359 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); |
| 353 | 360 |
| 354 // External dispaly's selected resolution must be updated. | 361 // External dispaly's selected resolution must be updated. |
| 355 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 362 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 356 EXPECT_TRUE(property->GetInteger("width", &width)); | 363 EXPECT_TRUE(property->GetInteger("width", &width)); |
| 357 EXPECT_TRUE(property->GetInteger("height", &height)); | 364 EXPECT_TRUE(property->GetInteger("height", &height)); |
| 358 EXPECT_EQ(500, width); | 365 EXPECT_EQ(500, width); |
| 359 EXPECT_EQ(400, height); | 366 EXPECT_EQ(400, height); |
| 360 } | 367 } |
| 361 | 368 |
| 362 TEST_F(DisplayPreferencesTest, PreventStore) { | 369 TEST_F(DisplayPreferencesTest, PreventStore) { |
| 363 ResolutionNotificationController::SuppressTimerForTest(); | 370 ResolutionNotificationController::SuppressTimerForTest(); |
| 364 LoggedInAsUser(); | 371 LoggedInAsUser(); |
| 365 UpdateDisplay("400x300"); | 372 UpdateDisplay("400x300#500x400|400x300|300x200"); |
| 366 int64 id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); | 373 int64 id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); |
| 367 // Set display's resolution in single display. It creates the notification and | 374 // Set display's resolution in single display. It creates the notification and |
| 368 // display preferences should not stored meanwhile. | 375 // display preferences should not stored meanwhile. |
| 369 ash::Shell::GetInstance()->resolution_notification_controller()-> | 376 ash::Shell::GetInstance()->resolution_notification_controller()-> |
| 370 SetDisplayResolutionAndNotify( | 377 SetDisplayResolutionAndNotify( |
| 371 id, gfx::Size(400, 300), gfx::Size(500, 400), base::Closure()); | 378 id, gfx::Size(400, 300), gfx::Size(500, 400), base::Closure()); |
| 372 UpdateDisplay("500x400"); | 379 UpdateDisplay("500x400#500x400|400x300|300x200"); |
| 373 | 380 |
| 374 const base::DictionaryValue* properties = | 381 const base::DictionaryValue* properties = |
| 375 local_state()->GetDictionary(prefs::kDisplayProperties); | 382 local_state()->GetDictionary(prefs::kDisplayProperties); |
| 376 const base::DictionaryValue* property = NULL; | 383 const base::DictionaryValue* property = NULL; |
| 377 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id), &property)); | 384 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id), &property)); |
| 378 int width = 0, height = 0; | 385 int width = 0, height = 0; |
| 379 EXPECT_FALSE(property->GetInteger("width", &width)); | 386 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 380 EXPECT_FALSE(property->GetInteger("height", &height)); | 387 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 381 | 388 |
| 382 // Revert the change. When timeout, 2nd button is revert. | 389 // Revert the change. When timeout, 2nd button is revert. |
| 383 message_center::MessageCenter::Get()->ClickOnNotificationButton( | 390 message_center::MessageCenter::Get()->ClickOnNotificationButton( |
| 384 ResolutionNotificationController::kNotificationId, 1); | 391 ResolutionNotificationController::kNotificationId, 1); |
| 385 RunAllPendingInMessageLoop(); | 392 RunAllPendingInMessageLoop(); |
| 386 EXPECT_FALSE(message_center::MessageCenter::Get()->HasNotification( | 393 EXPECT_FALSE(message_center::MessageCenter::Get()->HasNotification( |
| 387 ResolutionNotificationController::kNotificationId)); | 394 ResolutionNotificationController::kNotificationId)); |
| 388 | 395 |
| 389 // Once the notification is removed, the specified resolution will be stored | 396 // Once the notification is removed, the specified resolution will be stored |
| 390 // by SetDisplayResolution. | 397 // by SetDisplayResolution. |
| 391 ash::Shell::GetInstance()->display_manager()->SetDisplayResolution( | 398 ash::Shell::GetInstance()->display_manager()->SetDisplayResolution( |
| 392 id, gfx::Size(300, 200)); | 399 id, gfx::Size(300, 200)); |
| 393 UpdateDisplay("300x200"); | 400 UpdateDisplay("300x200#500x400|400x300|300x200"); |
| 394 | 401 |
| 395 property = NULL; | 402 property = NULL; |
| 396 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id), &property)); | 403 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id), &property)); |
| 397 EXPECT_TRUE(property->GetInteger("width", &width)); | 404 EXPECT_TRUE(property->GetInteger("width", &width)); |
| 398 EXPECT_TRUE(property->GetInteger("height", &height)); | 405 EXPECT_TRUE(property->GetInteger("height", &height)); |
| 399 EXPECT_EQ(300, width); | 406 EXPECT_EQ(300, width); |
| 400 EXPECT_EQ(200, height); | 407 EXPECT_EQ(200, height); |
| 401 } | 408 } |
| 402 | 409 |
| 403 TEST_F(DisplayPreferencesTest, StoreForSwappedDisplay) { | 410 TEST_F(DisplayPreferencesTest, StoreForSwappedDisplay) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 TEST_F(DisplayPreferencesTest, DisplayPowerStateAfterRestart) { | 494 TEST_F(DisplayPreferencesTest, DisplayPowerStateAfterRestart) { |
| 488 StoreDisplayPowerStateForTest( | 495 StoreDisplayPowerStateForTest( |
| 489 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); | 496 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); |
| 490 LoadDisplayPreferences(false); | 497 LoadDisplayPreferences(false); |
| 491 EXPECT_EQ( | 498 EXPECT_EQ( |
| 492 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, | 499 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
| 493 ash::Shell::GetInstance()->output_configurator()->power_state()); | 500 ash::Shell::GetInstance()->output_configurator()->power_state()); |
| 494 } | 501 } |
| 495 | 502 |
| 496 } // namespace chromeos | 503 } // namespace chromeos |
| OLD | NEW |