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/screen_ash.h" | 11 #include "ash/screen_ash.h" |
11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
12 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
13 #include "base/prefs/testing_pref_service.h" | 14 #include "base/prefs/testing_pref_service.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/values.h" | 16 #include "base/values.h" |
16 #include "chrome/browser/chromeos/display/display_configuration_observer.h" | 17 #include "chrome/browser/chromeos/display/display_configuration_observer.h" |
17 #include "chrome/browser/chromeos/login/mock_user_manager.h" | 18 #include "chrome/browser/chromeos/login/mock_user_manager.h" |
18 #include "chrome/browser/chromeos/login/user_manager.h" | 19 #include "chrome/browser/chromeos/login/user_manager.h" |
19 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 20 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
21 #include "chrome/test/base/testing_browser_process.h" | 22 #include "chrome/test/base/testing_browser_process.h" |
22 #include "chromeos/display/output_configurator.h" | 23 #include "chromeos/display/output_configurator.h" |
| 24 #include "ui/message_center/message_center.h" |
| 25 |
| 26 using ash::internal::ResolutionNotificationController; |
23 | 27 |
24 namespace chromeos { | 28 namespace chromeos { |
25 namespace { | 29 namespace { |
26 const char kPrimaryIdKey[] = "primary-id"; | 30 const char kPrimaryIdKey[] = "primary-id"; |
27 const char kMirroredKey[] = "mirrored"; | 31 const char kMirroredKey[] = "mirrored"; |
28 const char kPositionKey[] = "position"; | 32 const char kPositionKey[] = "position"; |
29 const char kOffsetKey[] = "offset"; | 33 const char kOffsetKey[] = "offset"; |
30 | 34 |
31 class DisplayPreferencesTest : public ash::test::AshTestBase { | 35 class DisplayPreferencesTest : public ash::test::AshTestBase { |
32 protected: | 36 protected: |
33 DisplayPreferencesTest() : ash::test::AshTestBase(), | 37 DisplayPreferencesTest() : ash::test::AshTestBase(), |
34 mock_user_manager_(new MockUserManager), | 38 mock_user_manager_(new MockUserManager), |
35 user_manager_enabler_(mock_user_manager_) { | 39 user_manager_enabler_(mock_user_manager_) { |
36 } | 40 } |
37 | 41 |
38 virtual ~DisplayPreferencesTest() {} | 42 virtual ~DisplayPreferencesTest() {} |
39 | 43 |
40 virtual void SetUp() OVERRIDE { | 44 virtual void SetUp() OVERRIDE { |
41 EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn()) | 45 EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn()) |
42 .WillRepeatedly(testing::Return(false)); | 46 .WillRepeatedly(testing::Return(false)); |
| 47 EXPECT_CALL(*mock_user_manager_, Shutdown()); |
43 ash::test::AshTestBase::SetUp(); | 48 ash::test::AshTestBase::SetUp(); |
44 RegisterDisplayLocalStatePrefs(local_state_.registry()); | 49 RegisterDisplayLocalStatePrefs(local_state_.registry()); |
45 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); | 50 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); |
46 observer_.reset(new DisplayConfigurationObserver()); | 51 observer_.reset(new DisplayConfigurationObserver()); |
47 } | 52 } |
48 | 53 |
49 virtual void TearDown() OVERRIDE { | 54 virtual void TearDown() OVERRIDE { |
50 observer_.reset(); | 55 observer_.reset(); |
51 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); | 56 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); |
52 ash::test::AshTestBase::TearDown(); | 57 ash::test::AshTestBase::TearDown(); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 144 |
140 private: | 145 private: |
141 MockUserManager* mock_user_manager_; // Not owned. | 146 MockUserManager* mock_user_manager_; // Not owned. |
142 ScopedUserManagerEnabler user_manager_enabler_; | 147 ScopedUserManagerEnabler user_manager_enabler_; |
143 TestingPrefServiceSimple local_state_; | 148 TestingPrefServiceSimple local_state_; |
144 scoped_ptr<DisplayConfigurationObserver> observer_; | 149 scoped_ptr<DisplayConfigurationObserver> observer_; |
145 | 150 |
146 DISALLOW_COPY_AND_ASSIGN(DisplayPreferencesTest); | 151 DISALLOW_COPY_AND_ASSIGN(DisplayPreferencesTest); |
147 }; | 152 }; |
148 | 153 |
| 154 } // namespace |
| 155 |
149 TEST_F(DisplayPreferencesTest, PairedLayoutOverrides) { | 156 TEST_F(DisplayPreferencesTest, PairedLayoutOverrides) { |
150 UpdateDisplay("100x100,200x200"); | 157 UpdateDisplay("100x100,200x200"); |
151 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); | 158 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); |
152 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); | 159 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); |
153 int64 dummy_id = id2 + 1; | 160 int64 dummy_id = id2 + 1; |
154 ASSERT_NE(id1, dummy_id); | 161 ASSERT_NE(id1, dummy_id); |
155 | 162 |
156 StoreDisplayLayoutPrefForPair(id1, id2, ash::DisplayLayout::TOP, 20); | 163 StoreDisplayLayoutPrefForPair(id1, id2, ash::DisplayLayout::TOP, 20); |
157 StoreDisplayLayoutPrefForPair(id1, dummy_id, ash::DisplayLayout::LEFT, 30); | 164 StoreDisplayLayoutPrefForPair(id1, dummy_id, ash::DisplayLayout::LEFT, 30); |
158 StoreDisplayPowerStateForTest( | 165 StoreDisplayPowerStateForTest( |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); | 352 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); |
346 | 353 |
347 // External dispaly's selected resolution must be updated. | 354 // External dispaly's selected resolution must be updated. |
348 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); | 355 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); |
349 EXPECT_TRUE(property->GetInteger("width", &width)); | 356 EXPECT_TRUE(property->GetInteger("width", &width)); |
350 EXPECT_TRUE(property->GetInteger("height", &height)); | 357 EXPECT_TRUE(property->GetInteger("height", &height)); |
351 EXPECT_EQ(500, width); | 358 EXPECT_EQ(500, width); |
352 EXPECT_EQ(400, height); | 359 EXPECT_EQ(400, height); |
353 } | 360 } |
354 | 361 |
| 362 TEST_F(DisplayPreferencesTest, PreventStore) { |
| 363 ResolutionNotificationController::SuppressTimerForTest(); |
| 364 LoggedInAsUser(); |
| 365 UpdateDisplay("400x300"); |
| 366 int64 id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); |
| 367 // Set display's resolution in single display. It creates the notification and |
| 368 // display preferences should not stored meanwhile. |
| 369 ash::Shell::GetInstance()->resolution_notification_controller()-> |
| 370 SetDisplayResolutionAndNotify( |
| 371 id, gfx::Size(400, 300), gfx::Size(500, 400), base::Closure()); |
| 372 UpdateDisplay("500x400"); |
| 373 |
| 374 const base::DictionaryValue* properties = |
| 375 local_state()->GetDictionary(prefs::kDisplayProperties); |
| 376 const base::DictionaryValue* property = NULL; |
| 377 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id), &property)); |
| 378 int width = 0, height = 0; |
| 379 EXPECT_FALSE(property->GetInteger("width", &width)); |
| 380 EXPECT_FALSE(property->GetInteger("height", &height)); |
| 381 |
| 382 // Revert the change. When timeout, 2nd button is revert. |
| 383 message_center::MessageCenter::Get()->ClickOnNotificationButton( |
| 384 ResolutionNotificationController::kNotificationId, 1); |
| 385 RunAllPendingInMessageLoop(); |
| 386 EXPECT_FALSE(message_center::MessageCenter::Get()->HasNotification( |
| 387 ResolutionNotificationController::kNotificationId)); |
| 388 |
| 389 // Once the notification is removed, the specified resolution will be stored |
| 390 // by SetDisplayResolution. |
| 391 ash::Shell::GetInstance()->display_manager()->SetDisplayResolution( |
| 392 id, gfx::Size(300, 200)); |
| 393 UpdateDisplay("300x200"); |
| 394 |
| 395 property = NULL; |
| 396 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id), &property)); |
| 397 EXPECT_TRUE(property->GetInteger("width", &width)); |
| 398 EXPECT_TRUE(property->GetInteger("height", &height)); |
| 399 EXPECT_EQ(300, width); |
| 400 EXPECT_EQ(200, height); |
| 401 } |
| 402 |
355 TEST_F(DisplayPreferencesTest, StoreForSwappedDisplay) { | 403 TEST_F(DisplayPreferencesTest, StoreForSwappedDisplay) { |
356 UpdateDisplay("100x100,200x200"); | 404 UpdateDisplay("100x100,200x200"); |
357 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); | 405 int64 id1 = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id(); |
358 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); | 406 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); |
359 | 407 |
360 ash::DisplayController* display_controller = | 408 ash::DisplayController* display_controller = |
361 ash::Shell::GetInstance()->display_controller(); | 409 ash::Shell::GetInstance()->display_controller(); |
362 display_controller->SwapPrimaryDisplay(); | 410 display_controller->SwapPrimaryDisplay(); |
363 ASSERT_EQ(id1, ash::ScreenAsh::GetSecondaryDisplay().id()); | 411 ASSERT_EQ(id1, ash::ScreenAsh::GetSecondaryDisplay().id()); |
364 | 412 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 | 486 |
439 TEST_F(DisplayPreferencesTest, DisplayPowerStateAfterRestart) { | 487 TEST_F(DisplayPreferencesTest, DisplayPowerStateAfterRestart) { |
440 StoreDisplayPowerStateForTest( | 488 StoreDisplayPowerStateForTest( |
441 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); | 489 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); |
442 LoadDisplayPreferences(false); | 490 LoadDisplayPreferences(false); |
443 EXPECT_EQ( | 491 EXPECT_EQ( |
444 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, | 492 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
445 ash::Shell::GetInstance()->output_configurator()->power_state()); | 493 ash::Shell::GetInstance()->output_configurator()->power_state()); |
446 } | 494 } |
447 | 495 |
448 } // namespace | |
449 } // namespace chromeos | 496 } // namespace chromeos |
OLD | NEW |