| 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_util.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 "ash/test/display_manager_test_api.h" | 14 #include "ash/test/display_manager_test_api.h" |
| 15 #include "base/prefs/scoped_user_pref_update.h" | 15 #include "base/prefs/scoped_user_pref_update.h" |
| 16 #include "base/prefs/testing_pref_service.h" | 16 #include "base/prefs/testing_pref_service.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/chromeos/display/display_configuration_observer.h" | 19 #include "chrome/browser/chromeos/display/display_configuration_observer.h" |
| 20 #include "chrome/browser/chromeos/login/mock_user_manager.h" | 20 #include "chrome/browser/chromeos/login/mock_user_manager.h" |
| 21 #include "chrome/browser/chromeos/login/user_manager.h" | 21 #include "chrome/browser/chromeos/login/user_manager.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/test/base/testing_browser_process.h" | 23 #include "chrome/test/base/testing_browser_process.h" |
| 24 #include "ui/display/chromeos/output_configurator.h" | 24 #include "ui/display/chromeos/output_configurator.h" |
| 25 #include "ui/message_center/message_center.h" | 25 #include "ui/message_center/message_center.h" |
| 26 | 26 |
| 27 using ash::internal::ResolutionNotificationController; | 27 using ash::ResolutionNotificationController; |
| 28 | 28 |
| 29 namespace chromeos { | 29 namespace chromeos { |
| 30 namespace { | 30 namespace { |
| 31 const char kPrimaryIdKey[] = "primary-id"; | 31 const char kPrimaryIdKey[] = "primary-id"; |
| 32 const char kMirroredKey[] = "mirrored"; | 32 const char kMirroredKey[] = "mirrored"; |
| 33 const char kPositionKey[] = "position"; | 33 const char kPositionKey[] = "position"; |
| 34 const char kOffsetKey[] = "offset"; | 34 const char kOffsetKey[] = "offset"; |
| 35 | 35 |
| 36 class DisplayPreferencesTest : public ash::test::AshTestBase { | 36 class DisplayPreferencesTest : public ash::test::AshTestBase { |
| 37 protected: | 37 protected: |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 // (id1, dummy_id) since dummy_id is not connected right now. | 184 // (id1, dummy_id) since dummy_id is not connected right now. |
| 185 EXPECT_EQ("top, 20", | 185 EXPECT_EQ("top, 20", |
| 186 shell->display_manager()->GetCurrentDisplayLayout().ToString()); | 186 shell->display_manager()->GetCurrentDisplayLayout().ToString()); |
| 187 EXPECT_EQ("top, 20", GetRegisteredDisplayLayoutStr(id1, id2)); | 187 EXPECT_EQ("top, 20", GetRegisteredDisplayLayoutStr(id1, id2)); |
| 188 EXPECT_EQ("left, 30", GetRegisteredDisplayLayoutStr(id1, dummy_id)); | 188 EXPECT_EQ("left, 30", GetRegisteredDisplayLayoutStr(id1, dummy_id)); |
| 189 } | 189 } |
| 190 | 190 |
| 191 TEST_F(DisplayPreferencesTest, BasicStores) { | 191 TEST_F(DisplayPreferencesTest, BasicStores) { |
| 192 ash::DisplayController* display_controller = | 192 ash::DisplayController* display_controller = |
| 193 ash::Shell::GetInstance()->display_controller(); | 193 ash::Shell::GetInstance()->display_controller(); |
| 194 ash::internal::DisplayManager* display_manager = | 194 ash::DisplayManager* display_manager = |
| 195 ash::Shell::GetInstance()->display_manager(); | 195 ash::Shell::GetInstance()->display_manager(); |
| 196 | 196 |
| 197 UpdateDisplay("200x200*2, 400x300#400x400|300x200"); | 197 UpdateDisplay("200x200*2, 400x300#400x400|300x200"); |
| 198 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); | 198 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); |
| 199 gfx::Display::SetInternalDisplayId(id1); | 199 gfx::Display::SetInternalDisplayId(id1); |
| 200 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 200 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 201 int64 dummy_id = id2 + 1; | 201 int64 dummy_id = id2 + 1; |
| 202 ASSERT_NE(id1, dummy_id); | 202 ASSERT_NE(id1, dummy_id); |
| 203 std::vector<ui::ColorCalibrationProfile> profiles; | 203 std::vector<ui::ColorCalibrationProfile> profiles; |
| 204 profiles.push_back(ui::COLOR_PROFILE_STANDARD); | 204 profiles.push_back(ui::COLOR_PROFILE_STANDARD); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 | 482 |
| 483 display_controller->SwapPrimaryDisplay(); | 483 display_controller->SwapPrimaryDisplay(); |
| 484 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); | 484 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); |
| 485 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*new_value, &stored_layout)); | 485 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*new_value, &stored_layout)); |
| 486 EXPECT_EQ(layout.position, stored_layout.position); | 486 EXPECT_EQ(layout.position, stored_layout.position); |
| 487 EXPECT_EQ(layout.offset, stored_layout.offset); | 487 EXPECT_EQ(layout.offset, stored_layout.offset); |
| 488 EXPECT_EQ(id1, stored_layout.primary_id); | 488 EXPECT_EQ(id1, stored_layout.primary_id); |
| 489 } | 489 } |
| 490 | 490 |
| 491 TEST_F(DisplayPreferencesTest, RestoreColorProfiles) { | 491 TEST_F(DisplayPreferencesTest, RestoreColorProfiles) { |
| 492 ash::internal::DisplayManager* display_manager = | 492 ash::DisplayManager* display_manager = |
| 493 ash::Shell::GetInstance()->display_manager(); | 493 ash::Shell::GetInstance()->display_manager(); |
| 494 | 494 |
| 495 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); | 495 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); |
| 496 | 496 |
| 497 StoreColorProfile(id1, "dynamic"); | 497 StoreColorProfile(id1, "dynamic"); |
| 498 | 498 |
| 499 LoggedInAsUser(); | 499 LoggedInAsUser(); |
| 500 LoadDisplayPreferences(false); | 500 LoadDisplayPreferences(false); |
| 501 | 501 |
| 502 // id1's available color profiles list is empty, means somehow the color | 502 // id1's available color profiles list is empty, means somehow the color |
| (...skipping 11 matching lines...) Expand all Loading... |
| 514 test_api.SetAvailableColorProfiles(id1, profiles); | 514 test_api.SetAvailableColorProfiles(id1, profiles); |
| 515 | 515 |
| 516 LoadDisplayPreferences(false); | 516 LoadDisplayPreferences(false); |
| 517 EXPECT_EQ(ui::COLOR_PROFILE_DYNAMIC, | 517 EXPECT_EQ(ui::COLOR_PROFILE_DYNAMIC, |
| 518 display_manager->GetDisplayInfo(id1).color_profile()); | 518 display_manager->GetDisplayInfo(id1).color_profile()); |
| 519 } | 519 } |
| 520 | 520 |
| 521 TEST_F(DisplayPreferencesTest, DontStoreInGuestMode) { | 521 TEST_F(DisplayPreferencesTest, DontStoreInGuestMode) { |
| 522 ash::DisplayController* display_controller = | 522 ash::DisplayController* display_controller = |
| 523 ash::Shell::GetInstance()->display_controller(); | 523 ash::Shell::GetInstance()->display_controller(); |
| 524 ash::internal::DisplayManager* display_manager = | 524 ash::DisplayManager* display_manager = |
| 525 ash::Shell::GetInstance()->display_manager(); | 525 ash::Shell::GetInstance()->display_manager(); |
| 526 | 526 |
| 527 UpdateDisplay("200x200*2,200x200"); | 527 UpdateDisplay("200x200*2,200x200"); |
| 528 | 528 |
| 529 LoggedInAsGuest(); | 529 LoggedInAsGuest(); |
| 530 int64 id1 = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); | 530 int64 id1 = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); |
| 531 gfx::Display::SetInternalDisplayId(id1); | 531 gfx::Display::SetInternalDisplayId(id1); |
| 532 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 532 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 533 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); | 533 ash::DisplayLayout layout(ash::DisplayLayout::TOP, 10); |
| 534 SetCurrentDisplayLayout(layout); | 534 SetCurrentDisplayLayout(layout); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 549 // Settings are still notified to the system. | 549 // Settings are still notified to the system. |
| 550 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); | 550 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); |
| 551 EXPECT_EQ(id2, screen->GetPrimaryDisplay().id()); | 551 EXPECT_EQ(id2, screen->GetPrimaryDisplay().id()); |
| 552 EXPECT_EQ(ash::DisplayLayout::BOTTOM, | 552 EXPECT_EQ(ash::DisplayLayout::BOTTOM, |
| 553 display_manager->GetCurrentDisplayLayout().position); | 553 display_manager->GetCurrentDisplayLayout().position); |
| 554 EXPECT_EQ(-10, display_manager->GetCurrentDisplayLayout().offset); | 554 EXPECT_EQ(-10, display_manager->GetCurrentDisplayLayout().offset); |
| 555 const gfx::Display& primary_display = screen->GetPrimaryDisplay(); | 555 const gfx::Display& primary_display = screen->GetPrimaryDisplay(); |
| 556 EXPECT_EQ("178x176", primary_display.bounds().size().ToString()); | 556 EXPECT_EQ("178x176", primary_display.bounds().size().ToString()); |
| 557 EXPECT_EQ(gfx::Display::ROTATE_90, primary_display.rotation()); | 557 EXPECT_EQ(gfx::Display::ROTATE_90, primary_display.rotation()); |
| 558 | 558 |
| 559 const ash::internal::DisplayInfo& info1 = | 559 const ash::DisplayInfo& info1 = display_manager->GetDisplayInfo(id1); |
| 560 display_manager->GetDisplayInfo(id1); | |
| 561 EXPECT_EQ(1.25f, info1.configured_ui_scale()); | 560 EXPECT_EQ(1.25f, info1.configured_ui_scale()); |
| 562 | 561 |
| 563 const ash::internal::DisplayInfo& info_primary = | 562 const ash::DisplayInfo& info_primary = |
| 564 display_manager->GetDisplayInfo(new_primary); | 563 display_manager->GetDisplayInfo(new_primary); |
| 565 EXPECT_EQ(gfx::Display::ROTATE_90, info_primary.rotation()); | 564 EXPECT_EQ(gfx::Display::ROTATE_90, info_primary.rotation()); |
| 566 EXPECT_EQ(1.0f, info_primary.configured_ui_scale()); | 565 EXPECT_EQ(1.0f, info_primary.configured_ui_scale()); |
| 567 } | 566 } |
| 568 | 567 |
| 569 TEST_F(DisplayPreferencesTest, StorePowerStateNoLogin) { | 568 TEST_F(DisplayPreferencesTest, StorePowerStateNoLogin) { |
| 570 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); | 569 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); |
| 571 | 570 |
| 572 // Stores display prefs without login, which still stores the power state. | 571 // Stores display prefs without login, which still stores the power state. |
| 573 StoreDisplayPrefs(); | 572 StoreDisplayPrefs(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 local_state()->GetString(prefs::kDisplayPowerState)); | 615 local_state()->GetString(prefs::kDisplayPowerState)); |
| 617 | 616 |
| 618 // Don't try to load | 617 // Don't try to load |
| 619 local_state()->SetString(prefs::kDisplayPowerState, "all_off"); | 618 local_state()->SetString(prefs::kDisplayPowerState, "all_off"); |
| 620 LoadDisplayPreferences(false); | 619 LoadDisplayPreferences(false); |
| 621 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, | 620 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
| 622 shell->output_configurator()->power_state()); | 621 shell->output_configurator()->power_state()); |
| 623 } | 622 } |
| 624 | 623 |
| 625 } // namespace chromeos | 624 } // namespace chromeos |
| OLD | NEW |