| 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" |
| 11 #include "ash/screen_ash.h" | 11 #include "ash/screen_util.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
| 14 #include "base/prefs/scoped_user_pref_update.h" | 14 #include "base/prefs/scoped_user_pref_update.h" |
| 15 #include "base/prefs/testing_pref_service.h" | 15 #include "base/prefs/testing_pref_service.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/chromeos/display/display_configuration_observer.h" | 18 #include "chrome/browser/chromeos/display/display_configuration_observer.h" |
| 19 #include "chrome/browser/chromeos/login/mock_user_manager.h" | 19 #include "chrome/browser/chromeos/login/mock_user_manager.h" |
| 20 #include "chrome/browser/chromeos/login/user_manager.h" | 20 #include "chrome/browser/chromeos/login/user_manager.h" |
| 21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 scoped_ptr<DisplayConfigurationObserver> observer_; | 143 scoped_ptr<DisplayConfigurationObserver> observer_; |
| 144 | 144 |
| 145 DISALLOW_COPY_AND_ASSIGN(DisplayPreferencesTest); | 145 DISALLOW_COPY_AND_ASSIGN(DisplayPreferencesTest); |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 } // namespace | 148 } // namespace |
| 149 | 149 |
| 150 TEST_F(DisplayPreferencesTest, PairedLayoutOverrides) { | 150 TEST_F(DisplayPreferencesTest, PairedLayoutOverrides) { |
| 151 UpdateDisplay("100x100,200x200"); | 151 UpdateDisplay("100x100,200x200"); |
| 152 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); | 152 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); |
| 153 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); | 153 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 154 int64 dummy_id = id2 + 1; | 154 int64 dummy_id = id2 + 1; |
| 155 ASSERT_NE(id1, dummy_id); | 155 ASSERT_NE(id1, dummy_id); |
| 156 | 156 |
| 157 StoreDisplayLayoutPrefForPair(id1, id2, ash::DisplayLayout::TOP, 20); | 157 StoreDisplayLayoutPrefForPair(id1, id2, ash::DisplayLayout::TOP, 20); |
| 158 StoreDisplayLayoutPrefForPair(id1, dummy_id, ash::DisplayLayout::LEFT, 30); | 158 StoreDisplayLayoutPrefForPair(id1, dummy_id, ash::DisplayLayout::LEFT, 30); |
| 159 StoreDisplayPowerStateForTest( | 159 StoreDisplayPowerStateForTest( |
| 160 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); | 160 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); |
| 161 | 161 |
| 162 ash::Shell* shell = ash::Shell::GetInstance(); | 162 ash::Shell* shell = ash::Shell::GetInstance(); |
| 163 | 163 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 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, 400x300#400x400|300x200"); | 186 UpdateDisplay("200x200*2, 400x300#400x400|300x200"); |
| 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::ScreenUtil::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( |
| 197 id1, dummy_id, ash::DisplayLayout(ash::DisplayLayout::LEFT, 20)); | 197 id1, dummy_id, ash::DisplayLayout(ash::DisplayLayout::LEFT, 20)); |
| 198 // Can't switch to a display that does not exist. | 198 // Can't switch to a display that does not exist. |
| 199 display_controller->SetPrimaryDisplayId(dummy_id); | 199 display_controller->SetPrimaryDisplayId(dummy_id); |
| 200 EXPECT_NE(dummy_id, display_controller->GetPrimaryDisplay().id()); | 200 EXPECT_NE(dummy_id, ash::Shell::GetScreen()->GetPrimaryDisplay().id()); |
| 201 | 201 |
| 202 display_controller->SetOverscanInsets(id1, gfx::Insets(10, 11, 12, 13)); | 202 display_controller->SetOverscanInsets(id1, gfx::Insets(10, 11, 12, 13)); |
| 203 display_manager->SetDisplayRotation(id1, gfx::Display::ROTATE_90); | 203 display_manager->SetDisplayRotation(id1, gfx::Display::ROTATE_90); |
| 204 display_manager->SetDisplayUIScale(id1, 1.25f); | 204 display_manager->SetDisplayUIScale(id1, 1.25f); |
| 205 display_manager->SetDisplayUIScale(id2, 1.25f); | 205 display_manager->SetDisplayUIScale(id2, 1.25f); |
| 206 | 206 |
| 207 const base::DictionaryValue* displays = | 207 const base::DictionaryValue* displays = |
| 208 local_state()->GetDictionary(prefs::kSecondaryDisplays); | 208 local_state()->GetDictionary(prefs::kSecondaryDisplays); |
| 209 const base::DictionaryValue* layout_value = NULL; | 209 const base::DictionaryValue* layout_value = NULL; |
| 210 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 210 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 // Set new display's selected resolution. | 331 // Set new display's selected resolution. |
| 332 display_manager->RegisterDisplayProperty(id2 + 1, | 332 display_manager->RegisterDisplayProperty(id2 + 1, |
| 333 gfx::Display::ROTATE_0, | 333 gfx::Display::ROTATE_0, |
| 334 1.0f, | 334 1.0f, |
| 335 NULL, | 335 NULL, |
| 336 gfx::Size(500, 400)); | 336 gfx::Size(500, 400)); |
| 337 | 337 |
| 338 UpdateDisplay("200x200*2, 600x500#600x500|500x400"); | 338 UpdateDisplay("200x200*2, 600x500#600x500|500x400"); |
| 339 | 339 |
| 340 // Update key as the 2nd display gets new id. | 340 // Update key as the 2nd display gets new id. |
| 341 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); | 341 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 342 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 342 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
| 343 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 343 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
| 344 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); | 344 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); |
| 345 EXPECT_EQ("right", position); | 345 EXPECT_EQ("right", position); |
| 346 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); | 346 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); |
| 347 EXPECT_EQ(0, offset); | 347 EXPECT_EQ(0, offset); |
| 348 mirrored = true; | 348 mirrored = true; |
| 349 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); | 349 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
| 350 EXPECT_FALSE(mirrored); | 350 EXPECT_FALSE(mirrored); |
| 351 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); | 351 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
| 352 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); | 352 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); |
| 353 | 353 |
| 354 // Best resolution should not be saved. | 354 // Best resolution should not be saved. |
| 355 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 355 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
| 356 EXPECT_FALSE(property->GetInteger("width", &width)); | 356 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 357 EXPECT_FALSE(property->GetInteger("height", &height)); | 357 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 358 | 358 |
| 359 // Set yet another new display's selected resolution. | 359 // Set yet another new display's selected resolution. |
| 360 display_manager->RegisterDisplayProperty(id2 + 1, | 360 display_manager->RegisterDisplayProperty(id2 + 1, |
| 361 gfx::Display::ROTATE_0, | 361 gfx::Display::ROTATE_0, |
| 362 1.0f, | 362 1.0f, |
| 363 NULL, | 363 NULL, |
| 364 gfx::Size(500, 400)); | 364 gfx::Size(500, 400)); |
| 365 // Disconnect 2nd display first to generate new id for external display. | 365 // Disconnect 2nd display first to generate new id for external display. |
| 366 UpdateDisplay("200x200*2"); | 366 UpdateDisplay("200x200*2"); |
| 367 UpdateDisplay("200x200*2, 500x400#600x500|500x400"); | 367 UpdateDisplay("200x200*2, 500x400#600x500|500x400"); |
| 368 // Update key as the 2nd display gets new id. | 368 // Update key as the 2nd display gets new id. |
| 369 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); | 369 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 370 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 370 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
| 371 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); | 371 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); |
| 372 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); | 372 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); |
| 373 EXPECT_EQ("right", position); | 373 EXPECT_EQ("right", position); |
| 374 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); | 374 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); |
| 375 EXPECT_EQ(0, offset); | 375 EXPECT_EQ(0, offset); |
| 376 mirrored = true; | 376 mirrored = true; |
| 377 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); | 377 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); |
| 378 EXPECT_FALSE(mirrored); | 378 EXPECT_FALSE(mirrored); |
| 379 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); | 379 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id), &property)); | 424 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id), &property)); |
| 425 EXPECT_TRUE(property->GetInteger("width", &width)); | 425 EXPECT_TRUE(property->GetInteger("width", &width)); |
| 426 EXPECT_TRUE(property->GetInteger("height", &height)); | 426 EXPECT_TRUE(property->GetInteger("height", &height)); |
| 427 EXPECT_EQ(300, width); | 427 EXPECT_EQ(300, width); |
| 428 EXPECT_EQ(200, height); | 428 EXPECT_EQ(200, height); |
| 429 } | 429 } |
| 430 | 430 |
| 431 TEST_F(DisplayPreferencesTest, StoreForSwappedDisplay) { | 431 TEST_F(DisplayPreferencesTest, StoreForSwappedDisplay) { |
| 432 UpdateDisplay("100x100,200x200"); | 432 UpdateDisplay("100x100,200x200"); |
| 433 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); | 433 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); |
| 434 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); | 434 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 435 | 435 |
| 436 ash::DisplayController* display_controller = | 436 ash::DisplayController* display_controller = |
| 437 ash::Shell::GetInstance()->display_controller(); | 437 ash::Shell::GetInstance()->display_controller(); |
| 438 display_controller->SwapPrimaryDisplay(); | 438 display_controller->SwapPrimaryDisplay(); |
| 439 ASSERT_EQ(id1, ash::ScreenAsh::GetSecondaryDisplay().id()); | 439 ASSERT_EQ(id1, ash::ScreenUtil::GetSecondaryDisplay().id()); |
| 440 | 440 |
| 441 LoggedInAsUser(); | 441 LoggedInAsUser(); |
| 442 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); | 442 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); |
| 443 SetCurrentDisplayLayout(layout); | 443 SetCurrentDisplayLayout(layout); |
| 444 layout = layout.Invert(); | 444 layout = layout.Invert(); |
| 445 | 445 |
| 446 const base::DictionaryValue* displays = | 446 const base::DictionaryValue* displays = |
| 447 local_state()->GetDictionary(prefs::kSecondaryDisplays); | 447 local_state()->GetDictionary(prefs::kSecondaryDisplays); |
| 448 const base::DictionaryValue* new_value = NULL; | 448 const base::DictionaryValue* new_value = NULL; |
| 449 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); | 449 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 465 | 465 |
| 466 TEST_F(DisplayPreferencesTest, DontStoreInGuestMode) { | 466 TEST_F(DisplayPreferencesTest, DontStoreInGuestMode) { |
| 467 ash::DisplayController* display_controller = | 467 ash::DisplayController* display_controller = |
| 468 ash::Shell::GetInstance()->display_controller(); | 468 ash::Shell::GetInstance()->display_controller(); |
| 469 ash::internal::DisplayManager* display_manager = | 469 ash::internal::DisplayManager* display_manager = |
| 470 ash::Shell::GetInstance()->display_manager(); | 470 ash::Shell::GetInstance()->display_manager(); |
| 471 | 471 |
| 472 UpdateDisplay("200x200*2,200x200"); | 472 UpdateDisplay("200x200*2,200x200"); |
| 473 | 473 |
| 474 LoggedInAsGuest(); | 474 LoggedInAsGuest(); |
| 475 int64 id1 = ash::ScreenAsh::GetNativeScreen()->GetPrimaryDisplay().id(); | 475 int64 id1 = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); |
| 476 gfx::Display::SetInternalDisplayId(id1); | 476 gfx::Display::SetInternalDisplayId(id1); |
| 477 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); | 477 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 478 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); | 478 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); |
| 479 SetCurrentDisplayLayout(layout); | 479 SetCurrentDisplayLayout(layout); |
| 480 display_manager->SetDisplayUIScale(id1, 1.25f); | 480 display_manager->SetDisplayUIScale(id1, 1.25f); |
| 481 display_controller->SetPrimaryDisplayId(id2); | 481 display_controller->SetPrimaryDisplayId(id2); |
| 482 int64 new_primary = | 482 int64 new_primary = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); |
| 483 ash::ScreenAsh::GetNativeScreen()->GetPrimaryDisplay().id(); | |
| 484 display_controller->SetOverscanInsets( | 483 display_controller->SetOverscanInsets( |
| 485 new_primary, | 484 new_primary, |
| 486 gfx::Insets(10, 11, 12, 13)); | 485 gfx::Insets(10, 11, 12, 13)); |
| 487 display_manager->SetDisplayRotation(new_primary, gfx::Display::ROTATE_90); | 486 display_manager->SetDisplayRotation(new_primary, gfx::Display::ROTATE_90); |
| 488 | 487 |
| 489 // Does not store the preferences locally. | 488 // Does not store the preferences locally. |
| 490 EXPECT_FALSE(local_state()->FindPreference( | 489 EXPECT_FALSE(local_state()->FindPreference( |
| 491 prefs::kSecondaryDisplays)->HasUserSetting()); | 490 prefs::kSecondaryDisplays)->HasUserSetting()); |
| 492 EXPECT_FALSE(local_state()->FindPreference( | 491 EXPECT_FALSE(local_state()->FindPreference( |
| 493 prefs::kDisplayProperties)->HasUserSetting()); | 492 prefs::kDisplayProperties)->HasUserSetting()); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 local_state()->GetString(prefs::kDisplayPowerState)); | 561 local_state()->GetString(prefs::kDisplayPowerState)); |
| 563 | 562 |
| 564 // Don't try to load | 563 // Don't try to load |
| 565 local_state()->SetString(prefs::kDisplayPowerState, "all_off"); | 564 local_state()->SetString(prefs::kDisplayPowerState, "all_off"); |
| 566 LoadDisplayPreferences(false); | 565 LoadDisplayPreferences(false); |
| 567 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, | 566 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
| 568 shell->output_configurator()->power_state()); | 567 shell->output_configurator()->power_state()); |
| 569 } | 568 } |
| 570 | 569 |
| 571 } // namespace chromeos | 570 } // namespace chromeos |
| OLD | NEW |