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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/display/display_preferences.h"
7 #include "ash/display/display_controller.h"
8 #include "ash/display/display_layout_store.h"
9 #include "ash/display/display_manager.h"
10 #include "ash/display/resolution_notification_controller.h"
11 #include "ash/screen_util.h"
12 #include "ash/shell.h"
13 #include "ash/test/ash_test_base.h"
14 #include "base/prefs/scoped_user_pref_update.h"
15 #include "base/prefs/testing_pref_service.h"
16 #include "base/strings/string_number_conversions.h"
17 #include "base/values.h"
18 #include "chrome/browser/chromeos/display/display_configuration_observer.h"
19 #include "chrome/browser/chromeos/login/mock_user_manager.h"
20 #include "chrome/browser/chromeos/login/user_manager.h"
21 #include "chrome/common/pref_names.h"
22 #include "chrome/test/base/testing_browser_process.h"
23 #include "chromeos/display/output_configurator.h"
24 #include "ui/message_center/message_center.h"
26 using ash::internal::ResolutionNotificationController
;
30 const char kPrimaryIdKey
[] = "primary-id";
31 const char kMirroredKey
[] = "mirrored";
32 const char kPositionKey
[] = "position";
33 const char kOffsetKey
[] = "offset";
35 class DisplayPreferencesTest
: public ash::test::AshTestBase
{
37 DisplayPreferencesTest()
38 : mock_user_manager_(new MockUserManager
),
39 user_manager_enabler_(mock_user_manager_
) {
42 virtual ~DisplayPreferencesTest() {}
44 virtual void SetUp() OVERRIDE
{
45 EXPECT_CALL(*mock_user_manager_
, IsUserLoggedIn())
46 .WillRepeatedly(testing::Return(false));
47 EXPECT_CALL(*mock_user_manager_
, Shutdown());
48 ash::test::AshTestBase::SetUp();
49 RegisterDisplayLocalStatePrefs(local_state_
.registry());
50 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_
);
51 observer_
.reset(new DisplayConfigurationObserver());
54 virtual void TearDown() OVERRIDE
{
56 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL
);
57 ash::test::AshTestBase::TearDown();
60 void LoggedInAsUser() {
61 EXPECT_CALL(*mock_user_manager_
, IsUserLoggedIn())
62 .WillRepeatedly(testing::Return(true));
63 EXPECT_CALL(*mock_user_manager_
, IsLoggedInAsRegularUser())
64 .WillRepeatedly(testing::Return(true));
67 void LoggedInAsGuest() {
68 EXPECT_CALL(*mock_user_manager_
, IsUserLoggedIn())
69 .WillRepeatedly(testing::Return(true));
70 EXPECT_CALL(*mock_user_manager_
, IsLoggedInAsRegularUser())
71 .WillRepeatedly(testing::Return(false));
72 EXPECT_CALL(*mock_user_manager_
, IsLoggedInAsLocallyManagedUser())
73 .WillRepeatedly(testing::Return(false));
76 // Do not use the implementation of display_preferences.cc directly to avoid
77 // notifying the update to the system.
78 void StoreDisplayLayoutPrefForName(const std::string
& name
,
79 ash::DisplayLayout::Position layout
,
82 DictionaryPrefUpdate
update(&local_state_
, prefs::kSecondaryDisplays
);
83 ash::DisplayLayout
display_layout(layout
, offset
);
84 display_layout
.primary_id
= primary_id
;
86 DCHECK(!name
.empty());
88 base::DictionaryValue
* pref_data
= update
.Get();
89 scoped_ptr
<base::Value
>layout_value(new base::DictionaryValue());
90 if (pref_data
->HasKey(name
)) {
91 base::Value
* value
= NULL
;
92 if (pref_data
->Get(name
, &value
) && value
!= NULL
)
93 layout_value
.reset(value
->DeepCopy());
95 if (ash::DisplayLayout::ConvertToValue(display_layout
, layout_value
.get()))
96 pref_data
->Set(name
, layout_value
.release());
99 void StoreDisplayLayoutPrefForPair(int64 id1
,
101 ash::DisplayLayout::Position layout
,
103 StoreDisplayLayoutPrefForName(
104 base::Int64ToString(id1
) + "," + base::Int64ToString(id2
),
105 layout
, offset
, id1
);
108 void StoreDisplayLayoutPrefForSecondary(int64 id
,
109 ash::DisplayLayout::Position layout
,
112 StoreDisplayLayoutPrefForName(
113 base::Int64ToString(id
), layout
, offset
, primary_id
);
116 void StoreDisplayOverscan(int64 id
, const gfx::Insets
& insets
) {
117 DictionaryPrefUpdate
update(&local_state_
, prefs::kDisplayProperties
);
118 const std::string name
= base::Int64ToString(id
);
120 base::DictionaryValue
* pref_data
= update
.Get();
121 base::DictionaryValue
* insets_value
= new base::DictionaryValue();
122 insets_value
->SetInteger("insets_top", insets
.top());
123 insets_value
->SetInteger("insets_left", insets
.left());
124 insets_value
->SetInteger("insets_bottom", insets
.bottom());
125 insets_value
->SetInteger("insets_right", insets
.right());
126 pref_data
->Set(name
, insets_value
);
129 std::string
GetRegisteredDisplayLayoutStr(int64 id1
, int64 id2
) {
130 ash::DisplayIdPair pair
;
133 return ash::Shell::GetInstance()->display_manager()->layout_store()->
134 GetRegisteredDisplayLayout(pair
).ToString();
137 PrefService
* local_state() { return &local_state_
; }
140 MockUserManager
* mock_user_manager_
; // Not owned.
141 ScopedUserManagerEnabler user_manager_enabler_
;
142 TestingPrefServiceSimple local_state_
;
143 scoped_ptr
<DisplayConfigurationObserver
> observer_
;
145 DISALLOW_COPY_AND_ASSIGN(DisplayPreferencesTest
);
150 TEST_F(DisplayPreferencesTest
, PairedLayoutOverrides
) {
151 UpdateDisplay("100x100,200x200");
152 int64 id1
= gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id();
153 int64 id2
= ash::ScreenUtil::GetSecondaryDisplay().id();
154 int64 dummy_id
= id2
+ 1;
155 ASSERT_NE(id1
, dummy_id
);
157 StoreDisplayLayoutPrefForPair(id1
, id2
, ash::DisplayLayout::TOP
, 20);
158 StoreDisplayLayoutPrefForPair(id1
, dummy_id
, ash::DisplayLayout::LEFT
, 30);
159 StoreDisplayPowerStateForTest(
160 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON
);
162 ash::Shell
* shell
= ash::Shell::GetInstance();
164 LoadDisplayPreferences(true);
165 // DisplayPowerState should be ignored at boot.
166 EXPECT_EQ(chromeos::DISPLAY_POWER_ALL_ON
,
167 shell
->output_configurator()->power_state());
169 shell
->display_manager()->UpdateDisplays();
170 // Check if the layout settings are notified to the system properly.
171 // The paired layout overrides old layout.
172 // Inverted one of for specified pair (id1, id2). Not used for the pair
173 // (id1, dummy_id) since dummy_id is not connected right now.
175 shell
->display_manager()->GetCurrentDisplayLayout().ToString());
176 EXPECT_EQ("top, 20", GetRegisteredDisplayLayoutStr(id1
, id2
));
177 EXPECT_EQ("left, 30", GetRegisteredDisplayLayoutStr(id1
, dummy_id
));
180 TEST_F(DisplayPreferencesTest
, BasicStores
) {
181 ash::DisplayController
* display_controller
=
182 ash::Shell::GetInstance()->display_controller();
183 ash::internal::DisplayManager
* display_manager
=
184 ash::Shell::GetInstance()->display_manager();
186 UpdateDisplay("200x200*2, 400x300#400x400|300x200");
187 int64 id1
= gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id();
188 gfx::Display::SetInternalDisplayId(id1
);
189 int64 id2
= ash::ScreenUtil::GetSecondaryDisplay().id();
190 int64 dummy_id
= id2
+ 1;
191 ASSERT_NE(id1
, dummy_id
);
194 ash::DisplayLayout
layout(ash::DisplayLayout::TOP
, 10);
195 SetCurrentDisplayLayout(layout
);
196 StoreDisplayLayoutPrefForTest(
197 id1
, dummy_id
, ash::DisplayLayout(ash::DisplayLayout::LEFT
, 20));
198 // Can't switch to a display that does not exist.
199 display_controller
->SetPrimaryDisplayId(dummy_id
);
200 EXPECT_NE(dummy_id
, ash::Shell::GetScreen()->GetPrimaryDisplay().id());
202 display_controller
->SetOverscanInsets(id1
, gfx::Insets(10, 11, 12, 13));
203 display_manager
->SetDisplayRotation(id1
, gfx::Display::ROTATE_90
);
204 display_manager
->SetDisplayUIScale(id1
, 1.25f
);
205 display_manager
->SetDisplayUIScale(id2
, 1.25f
);
207 const base::DictionaryValue
* displays
=
208 local_state()->GetDictionary(prefs::kSecondaryDisplays
);
209 const base::DictionaryValue
* layout_value
= NULL
;
210 std::string key
= base::Int64ToString(id1
) + "," + base::Int64ToString(id2
);
211 EXPECT_TRUE(displays
->GetDictionary(key
, &layout_value
));
213 ash::DisplayLayout stored_layout
;
214 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*layout_value
,
216 EXPECT_EQ(layout
.position
, stored_layout
.position
);
217 EXPECT_EQ(layout
.offset
, stored_layout
.offset
);
219 bool mirrored
= true;
220 EXPECT_TRUE(layout_value
->GetBoolean(kMirroredKey
, &mirrored
));
221 EXPECT_FALSE(mirrored
);
223 const base::DictionaryValue
* properties
=
224 local_state()->GetDictionary(prefs::kDisplayProperties
);
225 const base::DictionaryValue
* property
= NULL
;
226 EXPECT_TRUE(properties
->GetDictionary(base::Int64ToString(id1
), &property
));
229 EXPECT_TRUE(property
->GetInteger("rotation", &rotation
));
230 EXPECT_TRUE(property
->GetInteger("ui-scale", &ui_scale
));
231 EXPECT_EQ(1, rotation
);
232 EXPECT_EQ(1250, ui_scale
);
234 // Internal display never registere the resolution.
235 int width
= 0, height
= 0;
236 EXPECT_FALSE(property
->GetInteger("width", &width
));
237 EXPECT_FALSE(property
->GetInteger("height", &height
));
239 int top
= 0, left
= 0, bottom
= 0, right
= 0;
240 EXPECT_TRUE(property
->GetInteger("insets_top", &top
));
241 EXPECT_TRUE(property
->GetInteger("insets_left", &left
));
242 EXPECT_TRUE(property
->GetInteger("insets_bottom", &bottom
));
243 EXPECT_TRUE(property
->GetInteger("insets_right", &right
));
246 EXPECT_EQ(12, bottom
);
247 EXPECT_EQ(13, right
);
249 EXPECT_TRUE(properties
->GetDictionary(base::Int64ToString(id2
), &property
));
250 EXPECT_TRUE(property
->GetInteger("rotation", &rotation
));
251 EXPECT_TRUE(property
->GetInteger("ui-scale", &ui_scale
));
252 EXPECT_EQ(0, rotation
);
253 // ui_scale works only on 2x scale factor/1st display.
254 EXPECT_EQ(1000, ui_scale
);
255 EXPECT_FALSE(property
->GetInteger("insets_top", &top
));
256 EXPECT_FALSE(property
->GetInteger("insets_left", &left
));
257 EXPECT_FALSE(property
->GetInteger("insets_bottom", &bottom
));
258 EXPECT_FALSE(property
->GetInteger("insets_right", &right
));
260 // Resolution is saved only when the resolution is set
261 // by DisplayManager::SetDisplayResolution
264 EXPECT_FALSE(property
->GetInteger("width", &width
));
265 EXPECT_FALSE(property
->GetInteger("height", &height
));
267 display_manager
->SetDisplayResolution(id2
, gfx::Size(300, 200));
269 display_controller
->SetPrimaryDisplayId(id2
);
271 EXPECT_TRUE(properties
->GetDictionary(base::Int64ToString(id1
), &property
));
274 // Internal dispaly shouldn't store its resolution.
275 EXPECT_FALSE(property
->GetInteger("width", &width
));
276 EXPECT_FALSE(property
->GetInteger("height", &height
));
278 // External dispaly's resolution must be stored this time because
280 EXPECT_TRUE(properties
->GetDictionary(base::Int64ToString(id2
), &property
));
281 EXPECT_TRUE(property
->GetInteger("width", &width
));
282 EXPECT_TRUE(property
->GetInteger("height", &height
));
283 EXPECT_EQ(300, width
);
284 EXPECT_EQ(200, height
);
286 // The layout remains the same.
287 EXPECT_TRUE(displays
->GetDictionary(key
, &layout_value
));
288 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*layout_value
,
290 EXPECT_EQ(layout
.position
, stored_layout
.position
);
291 EXPECT_EQ(layout
.offset
, stored_layout
.offset
);
292 EXPECT_EQ(id2
, stored_layout
.primary_id
);
295 EXPECT_TRUE(layout_value
->GetBoolean(kMirroredKey
, &mirrored
));
296 EXPECT_FALSE(mirrored
);
297 std::string primary_id_str
;
298 EXPECT_TRUE(layout_value
->GetString(kPrimaryIdKey
, &primary_id_str
));
299 EXPECT_EQ(base::Int64ToString(id2
), primary_id_str
);
301 SetCurrentDisplayLayout(
302 ash::DisplayLayout(ash::DisplayLayout::BOTTOM
, 20));
304 UpdateDisplay("1+0-200x200*2,1+0-200x200");
307 std::string position
;
308 EXPECT_TRUE(displays
->GetDictionary(key
, &layout_value
));
309 EXPECT_TRUE(layout_value
->GetString(kPositionKey
, &position
));
310 EXPECT_EQ("top", position
);
311 EXPECT_TRUE(layout_value
->GetInteger(kOffsetKey
, &offset
));
312 EXPECT_EQ(-20, offset
);
314 EXPECT_TRUE(layout_value
->GetBoolean(kMirroredKey
, &mirrored
));
315 EXPECT_TRUE(mirrored
);
316 EXPECT_TRUE(layout_value
->GetString(kPrimaryIdKey
, &primary_id_str
));
317 EXPECT_EQ(base::Int64ToString(id2
), primary_id_str
);
319 EXPECT_TRUE(properties
->GetDictionary(base::Int64ToString(id1
), &property
));
320 EXPECT_FALSE(property
->GetInteger("width", &width
));
321 EXPECT_FALSE(property
->GetInteger("height", &height
));
323 // External dispaly's selected resolution must not change
325 EXPECT_TRUE(properties
->GetDictionary(base::Int64ToString(id2
), &property
));
326 EXPECT_TRUE(property
->GetInteger("width", &width
));
327 EXPECT_TRUE(property
->GetInteger("height", &height
));
328 EXPECT_EQ(300, width
);
329 EXPECT_EQ(200, height
);
331 // Set new display's selected resolution.
332 display_manager
->RegisterDisplayProperty(id2
+ 1,
333 gfx::Display::ROTATE_0
,
336 gfx::Size(500, 400));
338 UpdateDisplay("200x200*2, 600x500#600x500|500x400");
340 // Update key as the 2nd display gets new id.
341 id2
= ash::ScreenUtil::GetSecondaryDisplay().id();
342 key
= base::Int64ToString(id1
) + "," + base::Int64ToString(id2
);
343 EXPECT_TRUE(displays
->GetDictionary(key
, &layout_value
));
344 EXPECT_TRUE(layout_value
->GetString(kPositionKey
, &position
));
345 EXPECT_EQ("right", position
);
346 EXPECT_TRUE(layout_value
->GetInteger(kOffsetKey
, &offset
));
347 EXPECT_EQ(0, offset
);
349 EXPECT_TRUE(layout_value
->GetBoolean(kMirroredKey
, &mirrored
));
350 EXPECT_FALSE(mirrored
);
351 EXPECT_TRUE(layout_value
->GetString(kPrimaryIdKey
, &primary_id_str
));
352 EXPECT_EQ(base::Int64ToString(id1
), primary_id_str
);
354 // Best resolution should not be saved.
355 EXPECT_TRUE(properties
->GetDictionary(base::Int64ToString(id2
), &property
));
356 EXPECT_FALSE(property
->GetInteger("width", &width
));
357 EXPECT_FALSE(property
->GetInteger("height", &height
));
359 // Set yet another new display's selected resolution.
360 display_manager
->RegisterDisplayProperty(id2
+ 1,
361 gfx::Display::ROTATE_0
,
364 gfx::Size(500, 400));
365 // Disconnect 2nd display first to generate new id for external display.
366 UpdateDisplay("200x200*2");
367 UpdateDisplay("200x200*2, 500x400#600x500|500x400");
368 // Update key as the 2nd display gets new id.
369 id2
= ash::ScreenUtil::GetSecondaryDisplay().id();
370 key
= base::Int64ToString(id1
) + "," + base::Int64ToString(id2
);
371 EXPECT_TRUE(displays
->GetDictionary(key
, &layout_value
));
372 EXPECT_TRUE(layout_value
->GetString(kPositionKey
, &position
));
373 EXPECT_EQ("right", position
);
374 EXPECT_TRUE(layout_value
->GetInteger(kOffsetKey
, &offset
));
375 EXPECT_EQ(0, offset
);
377 EXPECT_TRUE(layout_value
->GetBoolean(kMirroredKey
, &mirrored
));
378 EXPECT_FALSE(mirrored
);
379 EXPECT_TRUE(layout_value
->GetString(kPrimaryIdKey
, &primary_id_str
));
380 EXPECT_EQ(base::Int64ToString(id1
), primary_id_str
);
382 // External dispaly's selected resolution must be updated.
383 EXPECT_TRUE(properties
->GetDictionary(base::Int64ToString(id2
), &property
));
384 EXPECT_TRUE(property
->GetInteger("width", &width
));
385 EXPECT_TRUE(property
->GetInteger("height", &height
));
386 EXPECT_EQ(500, width
);
387 EXPECT_EQ(400, height
);
390 TEST_F(DisplayPreferencesTest
, PreventStore
) {
391 ResolutionNotificationController::SuppressTimerForTest();
393 UpdateDisplay("400x300#500x400|400x300|300x200");
394 int64 id
= ash::Shell::GetScreen()->GetPrimaryDisplay().id();
395 // Set display's resolution in single display. It creates the notification and
396 // display preferences should not stored meanwhile.
397 ash::Shell::GetInstance()->resolution_notification_controller()->
398 SetDisplayResolutionAndNotify(
399 id
, gfx::Size(400, 300), gfx::Size(500, 400), base::Closure());
400 UpdateDisplay("500x400#500x400|400x300|300x200");
402 const base::DictionaryValue
* properties
=
403 local_state()->GetDictionary(prefs::kDisplayProperties
);
404 const base::DictionaryValue
* property
= NULL
;
405 EXPECT_TRUE(properties
->GetDictionary(base::Int64ToString(id
), &property
));
406 int width
= 0, height
= 0;
407 EXPECT_FALSE(property
->GetInteger("width", &width
));
408 EXPECT_FALSE(property
->GetInteger("height", &height
));
410 // Revert the change. When timeout, 2nd button is revert.
411 message_center::MessageCenter::Get()->ClickOnNotificationButton(
412 ResolutionNotificationController::kNotificationId
, 1);
413 RunAllPendingInMessageLoop();
414 EXPECT_FALSE(message_center::MessageCenter::Get()->HasNotification(
415 ResolutionNotificationController::kNotificationId
));
417 // Once the notification is removed, the specified resolution will be stored
418 // by SetDisplayResolution.
419 ash::Shell::GetInstance()->display_manager()->SetDisplayResolution(
420 id
, gfx::Size(300, 200));
421 UpdateDisplay("300x200#500x400|400x300|300x200");
424 EXPECT_TRUE(properties
->GetDictionary(base::Int64ToString(id
), &property
));
425 EXPECT_TRUE(property
->GetInteger("width", &width
));
426 EXPECT_TRUE(property
->GetInteger("height", &height
));
427 EXPECT_EQ(300, width
);
428 EXPECT_EQ(200, height
);
431 TEST_F(DisplayPreferencesTest
, StoreForSwappedDisplay
) {
432 UpdateDisplay("100x100,200x200");
433 int64 id1
= gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id();
434 int64 id2
= ash::ScreenUtil::GetSecondaryDisplay().id();
436 ash::DisplayController
* display_controller
=
437 ash::Shell::GetInstance()->display_controller();
438 display_controller
->SwapPrimaryDisplay();
439 ASSERT_EQ(id1
, ash::ScreenUtil::GetSecondaryDisplay().id());
442 ash::DisplayLayout
layout(ash::DisplayLayout::TOP
, 10);
443 SetCurrentDisplayLayout(layout
);
444 layout
= layout
.Invert();
446 const base::DictionaryValue
* displays
=
447 local_state()->GetDictionary(prefs::kSecondaryDisplays
);
448 const base::DictionaryValue
* new_value
= NULL
;
449 std::string key
= base::Int64ToString(id1
) + "," + base::Int64ToString(id2
);
450 EXPECT_TRUE(displays
->GetDictionary(key
, &new_value
));
452 ash::DisplayLayout stored_layout
;
453 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*new_value
, &stored_layout
));
454 EXPECT_EQ(layout
.position
, stored_layout
.position
);
455 EXPECT_EQ(layout
.offset
, stored_layout
.offset
);
456 EXPECT_EQ(id2
, stored_layout
.primary_id
);
458 display_controller
->SwapPrimaryDisplay();
459 EXPECT_TRUE(displays
->GetDictionary(key
, &new_value
));
460 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*new_value
, &stored_layout
));
461 EXPECT_EQ(layout
.position
, stored_layout
.position
);
462 EXPECT_EQ(layout
.offset
, stored_layout
.offset
);
463 EXPECT_EQ(id1
, stored_layout
.primary_id
);
466 TEST_F(DisplayPreferencesTest
, DontStoreInGuestMode
) {
467 ash::DisplayController
* display_controller
=
468 ash::Shell::GetInstance()->display_controller();
469 ash::internal::DisplayManager
* display_manager
=
470 ash::Shell::GetInstance()->display_manager();
472 UpdateDisplay("200x200*2,200x200");
475 int64 id1
= ash::Shell::GetScreen()->GetPrimaryDisplay().id();
476 gfx::Display::SetInternalDisplayId(id1
);
477 int64 id2
= ash::ScreenUtil::GetSecondaryDisplay().id();
478 ash::DisplayLayout
layout(ash::DisplayLayout::TOP
, 10);
479 SetCurrentDisplayLayout(layout
);
480 display_manager
->SetDisplayUIScale(id1
, 1.25f
);
481 display_controller
->SetPrimaryDisplayId(id2
);
482 int64 new_primary
= ash::Shell::GetScreen()->GetPrimaryDisplay().id();
483 display_controller
->SetOverscanInsets(
485 gfx::Insets(10, 11, 12, 13));
486 display_manager
->SetDisplayRotation(new_primary
, gfx::Display::ROTATE_90
);
488 // Does not store the preferences locally.
489 EXPECT_FALSE(local_state()->FindPreference(
490 prefs::kSecondaryDisplays
)->HasUserSetting());
491 EXPECT_FALSE(local_state()->FindPreference(
492 prefs::kDisplayProperties
)->HasUserSetting());
494 // Settings are still notified to the system.
495 gfx::Screen
* screen
= gfx::Screen::GetNativeScreen();
496 EXPECT_EQ(id2
, screen
->GetPrimaryDisplay().id());
497 EXPECT_EQ(ash::DisplayLayout::BOTTOM
,
498 display_manager
->GetCurrentDisplayLayout().position
);
499 EXPECT_EQ(-10, display_manager
->GetCurrentDisplayLayout().offset
);
500 const gfx::Display
& primary_display
= screen
->GetPrimaryDisplay();
501 EXPECT_EQ("178x176", primary_display
.bounds().size().ToString());
502 EXPECT_EQ(gfx::Display::ROTATE_90
, primary_display
.rotation());
504 const ash::internal::DisplayInfo
& info1
=
505 display_manager
->GetDisplayInfo(id1
);
506 EXPECT_EQ(1.25f
, info1
.configured_ui_scale());
508 const ash::internal::DisplayInfo
& info_primary
=
509 display_manager
->GetDisplayInfo(new_primary
);
510 EXPECT_EQ(gfx::Display::ROTATE_90
, info_primary
.rotation());
511 EXPECT_EQ(1.0f
, info_primary
.configured_ui_scale());
514 TEST_F(DisplayPreferencesTest
, StorePowerStateNoLogin
) {
515 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState
));
517 // Stores display prefs without login, which still stores the power state.
519 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayPowerState
));
522 TEST_F(DisplayPreferencesTest
, StorePowerStateGuest
) {
523 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState
));
527 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayPowerState
));
530 TEST_F(DisplayPreferencesTest
, StorePowerStateNormalUser
) {
531 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState
));
535 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayPowerState
));
538 TEST_F(DisplayPreferencesTest
, DisplayPowerStateAfterRestart
) {
539 StoreDisplayPowerStateForTest(
540 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON
);
541 LoadDisplayPreferences(false);
543 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON
,
544 ash::Shell::GetInstance()->output_configurator()->power_state());
547 TEST_F(DisplayPreferencesTest
, DontSaveAndRestoreAllOff
) {
548 ash::Shell
* shell
= ash::Shell::GetInstance();
549 StoreDisplayPowerStateForTest(
550 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON
);
551 LoadDisplayPreferences(false);
552 // DisplayPowerState should be ignored at boot.
553 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON
,
554 shell
->output_configurator()->power_state());
556 StoreDisplayPowerStateForTest(
557 chromeos::DISPLAY_POWER_ALL_OFF
);
558 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON
,
559 shell
->output_configurator()->power_state());
560 EXPECT_EQ("internal_off_external_on",
561 local_state()->GetString(prefs::kDisplayPowerState
));
564 local_state()->SetString(prefs::kDisplayPowerState
, "all_off");
565 LoadDisplayPreferences(false);
566 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON
,
567 shell
->output_configurator()->power_state());
570 } // namespace chromeos