Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/chromeos/display/display_preferences_unittest.cc

Issue 2355063002: Separate ash::test::DisplayManagerTestApi from ash (Closed)
Patch Set: review comment Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" 13 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
14 #include "ash/common/wm_shell.h" 14 #include "ash/common/wm_shell.h"
15 #include "ash/display/display_manager.h" 15 #include "ash/display/display_manager.h"
16 #include "ash/display/display_util.h" 16 #include "ash/display/display_util.h"
17 #include "ash/display/json_converter.h" 17 #include "ash/display/json_converter.h"
18 #include "ash/display/resolution_notification_controller.h" 18 #include "ash/display/resolution_notification_controller.h"
19 #include "ash/display/screen_orientation_controller_chromeos.h" 19 #include "ash/display/screen_orientation_controller_chromeos.h"
20 #include "ash/display/window_tree_host_manager.h" 20 #include "ash/display/window_tree_host_manager.h"
21 #include "ash/screen_util.h" 21 #include "ash/shell.h"
22 #include "ash/shell.h" 22 #include "ash/shell.h"
23 #include "ash/test/ash_test_base.h" 23 #include "ash/test/ash_test_base.h"
24 #include "ash/test/display_manager_test_api.h" 24 #include "ash/test/display_manager_test_api.h"
25 #include "base/macros.h" 25 #include "base/macros.h"
26 #include "base/memory/ptr_util.h" 26 #include "base/memory/ptr_util.h"
27 #include "base/memory/ref_counted.h" 27 #include "base/memory/ref_counted.h"
28 #include "base/strings/string_number_conversions.h" 28 #include "base/strings/string_number_conversions.h"
29 #include "base/values.h" 29 #include "base/values.h"
30 #include "chrome/browser/chromeos/display/display_configuration_observer.h" 30 #include "chrome/browser/chromeos/display/display_configuration_observer.h"
31 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" 31 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 TestingPrefServiceSimple local_state_; 213 TestingPrefServiceSimple local_state_;
214 std::unique_ptr<DisplayConfigurationObserver> observer_; 214 std::unique_ptr<DisplayConfigurationObserver> observer_;
215 215
216 DISALLOW_COPY_AND_ASSIGN(DisplayPreferencesTest); 216 DISALLOW_COPY_AND_ASSIGN(DisplayPreferencesTest);
217 }; 217 };
218 218
219 } // namespace 219 } // namespace
220 220
221 TEST_F(DisplayPreferencesTest, ListedLayoutOverrides) { 221 TEST_F(DisplayPreferencesTest, ListedLayoutOverrides) {
222 UpdateDisplay("100x100,200x200"); 222 UpdateDisplay("100x100,200x200");
223 ash::DisplayManager* display_manager =
224 ash::Shell::GetInstance()->display_manager();
225 223
226 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); 224 display::DisplayIdList list = display_manager()->GetCurrentDisplayIdList();
227 display::DisplayIdList dummy_list = 225 display::DisplayIdList dummy_list =
228 ash::test::CreateDisplayIdList2(list[0], list[1] + 1); 226 ash::test::CreateDisplayIdList2(list[0], list[1] + 1);
229 ASSERT_NE(list[0], dummy_list[1]); 227 ASSERT_NE(list[0], dummy_list[1]);
230 228
231 StoreDisplayLayoutPrefForList(list, display::DisplayPlacement::TOP, 20); 229 StoreDisplayLayoutPrefForList(list, display::DisplayPlacement::TOP, 20);
232 StoreDisplayLayoutPrefForList(dummy_list, display::DisplayPlacement::LEFT, 230 StoreDisplayLayoutPrefForList(dummy_list, display::DisplayPlacement::LEFT,
233 30); 231 30);
234 StoreDisplayPowerStateForTest( 232 StoreDisplayPowerStateForTest(
235 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON); 233 chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON);
236 234
(...skipping 16 matching lines...) Expand all
253 .ToString()); 251 .ToString());
254 EXPECT_EQ("id=2200000001, parent=2200000000, top, 20", 252 EXPECT_EQ("id=2200000001, parent=2200000000, top, 20",
255 GetRegisteredDisplayPlacementStr(list)); 253 GetRegisteredDisplayPlacementStr(list));
256 EXPECT_EQ("id=2200000002, parent=2200000000, left, 30", 254 EXPECT_EQ("id=2200000002, parent=2200000000, left, 30",
257 GetRegisteredDisplayPlacementStr(dummy_list)); 255 GetRegisteredDisplayPlacementStr(dummy_list));
258 } 256 }
259 257
260 TEST_F(DisplayPreferencesTest, BasicStores) { 258 TEST_F(DisplayPreferencesTest, BasicStores) {
261 ash::WindowTreeHostManager* window_tree_host_manager = 259 ash::WindowTreeHostManager* window_tree_host_manager =
262 ash::Shell::GetInstance()->window_tree_host_manager(); 260 ash::Shell::GetInstance()->window_tree_host_manager();
263 ash::DisplayManager* display_manager =
264 ash::Shell::GetInstance()->display_manager();
265 261
266 UpdateDisplay("200x200*2, 400x300#400x400|300x200*1.25"); 262 UpdateDisplay("200x200*2, 400x300#400x400|300x200*1.25");
267 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 263 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id();
268 ash::test::ScopedSetInternalDisplayId set_internal(id1); 264 ash::test::ScopedSetInternalDisplayId set_internal(display_manager(), id1);
269 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); 265 int64_t id2 = display_manager()->GetSecondaryDisplay().id();
270 int64_t dummy_id = id2 + 1; 266 int64_t dummy_id = id2 + 1;
271 ASSERT_NE(id1, dummy_id); 267 ASSERT_NE(id1, dummy_id);
272 std::vector<ui::ColorCalibrationProfile> profiles; 268 std::vector<ui::ColorCalibrationProfile> profiles;
273 profiles.push_back(ui::COLOR_PROFILE_STANDARD); 269 profiles.push_back(ui::COLOR_PROFILE_STANDARD);
274 profiles.push_back(ui::COLOR_PROFILE_DYNAMIC); 270 profiles.push_back(ui::COLOR_PROFILE_DYNAMIC);
275 profiles.push_back(ui::COLOR_PROFILE_MOVIE); 271 profiles.push_back(ui::COLOR_PROFILE_MOVIE);
276 profiles.push_back(ui::COLOR_PROFILE_READING); 272 profiles.push_back(ui::COLOR_PROFILE_READING);
277 // Allows only |id1|. 273 // Allows only |id1|.
278 ash::test::DisplayManagerTestApi().SetAvailableColorProfiles(id1, profiles); 274 ash::test::DisplayManagerTestApi(display_manager())
279 display_manager->SetColorCalibrationProfile(id1, ui::COLOR_PROFILE_DYNAMIC); 275 .SetAvailableColorProfiles(id1, profiles);
280 display_manager->SetColorCalibrationProfile(id2, ui::COLOR_PROFILE_DYNAMIC); 276 display_manager()->SetColorCalibrationProfile(id1, ui::COLOR_PROFILE_DYNAMIC);
277 display_manager()->SetColorCalibrationProfile(id2, ui::COLOR_PROFILE_DYNAMIC);
281 278
282 LoggedInAsUser(); 279 LoggedInAsUser();
283 280
284 display_manager->SetLayoutForCurrentDisplays( 281 display_manager()->SetLayoutForCurrentDisplays(ash::test::CreateDisplayLayout(
285 ash::test::CreateDisplayLayout(display::DisplayPlacement::TOP, 10)); 282 display_manager(), display::DisplayPlacement::TOP, 10));
286 const display::DisplayLayout& layout = 283 const display::DisplayLayout& layout =
287 display_manager->GetCurrentDisplayLayout(); 284 display_manager()->GetCurrentDisplayLayout();
288 EXPECT_EQ(display::DisplayPlacement::TOP, layout.placement_list[0].position); 285 EXPECT_EQ(display::DisplayPlacement::TOP, layout.placement_list[0].position);
289 EXPECT_EQ(10, layout.placement_list[0].offset); 286 EXPECT_EQ(10, layout.placement_list[0].offset);
290 287
291 display::DisplayLayoutBuilder dummy_layout_builder(id1); 288 display::DisplayLayoutBuilder dummy_layout_builder(id1);
292 dummy_layout_builder.SetSecondaryPlacement( 289 dummy_layout_builder.SetSecondaryPlacement(
293 dummy_id, display::DisplayPlacement::LEFT, 20); 290 dummy_id, display::DisplayPlacement::LEFT, 20);
294 std::unique_ptr<display::DisplayLayout> dummy_layout( 291 std::unique_ptr<display::DisplayLayout> dummy_layout(
295 dummy_layout_builder.Build()); 292 dummy_layout_builder.Build());
296 display::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, dummy_id); 293 display::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, dummy_id);
297 StoreDisplayLayoutPrefForTest(list, *dummy_layout); 294 StoreDisplayLayoutPrefForTest(list, *dummy_layout);
298 295
299 // Can't switch to a display that does not exist. 296 // Can't switch to a display that does not exist.
300 window_tree_host_manager->SetPrimaryDisplayId(dummy_id); 297 window_tree_host_manager->SetPrimaryDisplayId(dummy_id);
301 EXPECT_NE(dummy_id, display::Screen::GetScreen()->GetPrimaryDisplay().id()); 298 EXPECT_NE(dummy_id, display::Screen::GetScreen()->GetPrimaryDisplay().id());
302 299
303 window_tree_host_manager->SetOverscanInsets(id1, gfx::Insets(10, 11, 12, 13)); 300 window_tree_host_manager->SetOverscanInsets(id1, gfx::Insets(10, 11, 12, 13));
304 display_manager->SetDisplayRotation(id1, display::Display::ROTATE_90, 301 display_manager()->SetDisplayRotation(id1, display::Display::ROTATE_90,
305 display::Display::ROTATION_SOURCE_USER); 302 display::Display::ROTATION_SOURCE_USER);
306 EXPECT_TRUE(display_manager->SetDisplayUIScale(id1, 1.25f)); 303 EXPECT_TRUE(display_manager()->SetDisplayUIScale(id1, 1.25f));
307 EXPECT_FALSE(display_manager->SetDisplayUIScale(id2, 1.25f)); 304 EXPECT_FALSE(display_manager()->SetDisplayUIScale(id2, 1.25f));
308 305
309 const base::DictionaryValue* displays = 306 const base::DictionaryValue* displays =
310 local_state()->GetDictionary(prefs::kSecondaryDisplays); 307 local_state()->GetDictionary(prefs::kSecondaryDisplays);
311 const base::DictionaryValue* layout_value = nullptr; 308 const base::DictionaryValue* layout_value = nullptr;
312 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); 309 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2);
313 std::string dummy_key = 310 std::string dummy_key =
314 base::Int64ToString(id1) + "," + base::Int64ToString(dummy_id); 311 base::Int64ToString(id1) + "," + base::Int64ToString(dummy_id);
315 EXPECT_TRUE(displays->GetDictionary(dummy_key, &layout_value)); 312 EXPECT_TRUE(displays->GetDictionary(dummy_key, &layout_value));
316 313
317 display::DisplayLayout stored_layout; 314 display::DisplayLayout stored_layout;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 // by DisplayManager::SetDisplayMode 373 // by DisplayManager::SetDisplayMode
377 width = 0; 374 width = 0;
378 height = 0; 375 height = 0;
379 EXPECT_FALSE(property->GetInteger("width", &width)); 376 EXPECT_FALSE(property->GetInteger("width", &width));
380 EXPECT_FALSE(property->GetInteger("height", &height)); 377 EXPECT_FALSE(property->GetInteger("height", &height));
381 378
382 scoped_refptr<display::ManagedDisplayMode> mode( 379 scoped_refptr<display::ManagedDisplayMode> mode(
383 new display::ManagedDisplayMode(gfx::Size(300, 200), 60.0f, false, true, 380 new display::ManagedDisplayMode(gfx::Size(300, 200), 60.0f, false, true,
384 1.0 /* ui_scale */, 381 1.0 /* ui_scale */,
385 1.25f /* device_scale_factor */)); 382 1.25f /* device_scale_factor */));
386 display_manager->SetDisplayMode(id2, mode); 383 display_manager()->SetDisplayMode(id2, mode);
387 384
388 window_tree_host_manager->SetPrimaryDisplayId(id2); 385 window_tree_host_manager->SetPrimaryDisplayId(id2);
389 386
390 EXPECT_EQ(id2, display::Screen::GetScreen()->GetPrimaryDisplay().id()); 387 EXPECT_EQ(id2, display::Screen::GetScreen()->GetPrimaryDisplay().id());
391 388
392 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); 389 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property));
393 width = 0; 390 width = 0;
394 height = 0; 391 height = 0;
395 // Internal display shouldn't store its resolution. 392 // Internal display shouldn't store its resolution.
396 EXPECT_FALSE(property->GetInteger("width", &width)); 393 EXPECT_FALSE(property->GetInteger("width", &width));
(...skipping 27 matching lines...) Expand all
424 if (true) 421 if (true)
425 return; 422 return;
426 423
427 mirrored = true; 424 mirrored = true;
428 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); 425 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored));
429 EXPECT_FALSE(mirrored); 426 EXPECT_FALSE(mirrored);
430 std::string primary_id_str; 427 std::string primary_id_str;
431 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); 428 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str));
432 EXPECT_EQ(base::Int64ToString(id2), primary_id_str); 429 EXPECT_EQ(base::Int64ToString(id2), primary_id_str);
433 430
434 display_manager->SetLayoutForCurrentDisplays( 431 display_manager()->SetLayoutForCurrentDisplays(ash::test::CreateDisplayLayout(
435 ash::test::CreateDisplayLayout(display::DisplayPlacement::BOTTOM, 20)); 432 ash::Shell::GetInstance()->display_manager(),
433 display::DisplayPlacement::BOTTOM, 20));
436 434
437 UpdateDisplay("1+0-200x200*2,1+0-200x200"); 435 UpdateDisplay("1+0-200x200*2,1+0-200x200");
438 // Mirrored. 436 // Mirrored.
439 int offset = 0; 437 int offset = 0;
440 std::string position; 438 std::string position;
441 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); 439 EXPECT_TRUE(displays->GetDictionary(key, &layout_value));
442 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); 440 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position));
443 EXPECT_EQ("bottom", position); 441 EXPECT_EQ("bottom", position);
444 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); 442 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset));
445 EXPECT_EQ(20, offset); 443 EXPECT_EQ(20, offset);
(...skipping 15 matching lines...) Expand all
461 459
462 // External display's selected resolution must not change 460 // External display's selected resolution must not change
463 // by mirroring. 461 // by mirroring.
464 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); 462 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property));
465 EXPECT_TRUE(property->GetInteger("width", &width)); 463 EXPECT_TRUE(property->GetInteger("width", &width));
466 EXPECT_TRUE(property->GetInteger("height", &height)); 464 EXPECT_TRUE(property->GetInteger("height", &height));
467 EXPECT_EQ(300, width); 465 EXPECT_EQ(300, width);
468 EXPECT_EQ(200, height); 466 EXPECT_EQ(200, height);
469 467
470 // Set new display's selected resolution. 468 // Set new display's selected resolution.
471 display_manager->RegisterDisplayProperty(id2 + 1, display::Display::ROTATE_0, 469 display_manager()->RegisterDisplayProperty(
472 1.0f, nullptr, gfx::Size(500, 400), 470 id2 + 1, display::Display::ROTATE_0, 1.0f, nullptr, gfx::Size(500, 400),
473 1.0f, ui::COLOR_PROFILE_STANDARD); 471 1.0f, ui::COLOR_PROFILE_STANDARD);
474 472
475 UpdateDisplay("200x200*2, 600x500#600x500|500x400"); 473 UpdateDisplay("200x200*2, 600x500#600x500|500x400");
476 474
477 // Update key as the 2nd display gets new id. 475 // Update key as the 2nd display gets new id.
478 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); 476 id2 = display_manager()->GetSecondaryDisplay().id();
479 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); 477 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2);
480 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); 478 EXPECT_TRUE(displays->GetDictionary(key, &layout_value));
481 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); 479 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position));
482 EXPECT_EQ("right", position); 480 EXPECT_EQ("right", position);
483 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); 481 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset));
484 EXPECT_EQ(0, offset); 482 EXPECT_EQ(0, offset);
485 mirrored = true; 483 mirrored = true;
486 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); 484 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored));
487 EXPECT_FALSE(mirrored); 485 EXPECT_FALSE(mirrored);
488 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); 486 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str));
489 EXPECT_EQ(base::Int64ToString(id1), primary_id_str); 487 EXPECT_EQ(base::Int64ToString(id1), primary_id_str);
490 488
491 // Best resolution should not be saved. 489 // Best resolution should not be saved.
492 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property)); 490 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id2), &property));
493 EXPECT_FALSE(property->GetInteger("width", &width)); 491 EXPECT_FALSE(property->GetInteger("width", &width));
494 EXPECT_FALSE(property->GetInteger("height", &height)); 492 EXPECT_FALSE(property->GetInteger("height", &height));
495 493
496 // Set yet another new display's selected resolution. 494 // Set yet another new display's selected resolution.
497 display_manager->RegisterDisplayProperty(id2 + 1, display::Display::ROTATE_0, 495 display_manager()->RegisterDisplayProperty(
498 1.0f, nullptr, gfx::Size(500, 400), 496 id2 + 1, display::Display::ROTATE_0, 1.0f, nullptr, gfx::Size(500, 400),
499 1.0f, ui::COLOR_PROFILE_STANDARD); 497 1.0f, ui::COLOR_PROFILE_STANDARD);
500 // Disconnect 2nd display first to generate new id for external display. 498 // Disconnect 2nd display first to generate new id for external display.
501 UpdateDisplay("200x200*2"); 499 UpdateDisplay("200x200*2");
502 UpdateDisplay("200x200*2, 500x400#600x500|500x400%60.0f"); 500 UpdateDisplay("200x200*2, 500x400#600x500|500x400%60.0f");
503 // Update key as the 2nd display gets new id. 501 // Update key as the 2nd display gets new id.
504 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); 502 id2 = display_manager()->GetSecondaryDisplay().id();
505 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); 503 key = base::Int64ToString(id1) + "," + base::Int64ToString(id2);
506 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); 504 EXPECT_TRUE(displays->GetDictionary(key, &layout_value));
507 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position)); 505 EXPECT_TRUE(layout_value->GetString(kPositionKey, &position));
508 EXPECT_EQ("right", position); 506 EXPECT_EQ("right", position);
509 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset)); 507 EXPECT_TRUE(layout_value->GetInteger(kOffsetKey, &offset));
510 EXPECT_EQ(0, offset); 508 EXPECT_EQ(0, offset);
511 mirrored = true; 509 mirrored = true;
512 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); 510 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored));
513 EXPECT_FALSE(mirrored); 511 EXPECT_FALSE(mirrored);
514 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str)); 512 EXPECT_TRUE(layout_value->GetString(kPrimaryIdKey, &primary_id_str));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id), &property)); 566 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id), &property));
569 EXPECT_TRUE(property->GetInteger("width", &width)); 567 EXPECT_TRUE(property->GetInteger("width", &width));
570 EXPECT_TRUE(property->GetInteger("height", &height)); 568 EXPECT_TRUE(property->GetInteger("height", &height));
571 EXPECT_EQ(300, width); 569 EXPECT_EQ(300, width);
572 EXPECT_EQ(200, height); 570 EXPECT_EQ(200, height);
573 } 571 }
574 572
575 TEST_F(DisplayPreferencesTest, StoreForSwappedDisplay) { 573 TEST_F(DisplayPreferencesTest, StoreForSwappedDisplay) {
576 UpdateDisplay("100x100,200x200"); 574 UpdateDisplay("100x100,200x200");
577 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 575 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id();
578 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); 576 int64_t id2 = display_manager()->GetSecondaryDisplay().id();
579 577
580 LoggedInAsUser(); 578 LoggedInAsUser();
581 579
582 ash::test::SwapPrimaryDisplay(); 580 SwapPrimaryDisplay();
583 ASSERT_EQ(id1, ash::ScreenUtil::GetSecondaryDisplay().id()); 581 ASSERT_EQ(id1, display_manager()->GetSecondaryDisplay().id());
584 582
585 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); 583 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2);
586 const base::DictionaryValue* displays = 584 const base::DictionaryValue* displays =
587 local_state()->GetDictionary(prefs::kSecondaryDisplays); 585 local_state()->GetDictionary(prefs::kSecondaryDisplays);
588 // Initial saved value is swapped. 586 // Initial saved value is swapped.
589 { 587 {
590 const base::DictionaryValue* new_value = nullptr; 588 const base::DictionaryValue* new_value = nullptr;
591 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); 589 EXPECT_TRUE(displays->GetDictionary(key, &new_value));
592 display::DisplayLayout stored_layout; 590 display::DisplayLayout stored_layout;
593 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 591 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
594 ASSERT_EQ(1u, stored_layout.placement_list.size()); 592 ASSERT_EQ(1u, stored_layout.placement_list.size());
595 const display::DisplayPlacement& stored_placement = 593 const display::DisplayPlacement& stored_placement =
596 stored_layout.placement_list[0]; 594 stored_layout.placement_list[0];
597 EXPECT_EQ(display::DisplayPlacement::LEFT, stored_placement.position); 595 EXPECT_EQ(display::DisplayPlacement::LEFT, stored_placement.position);
598 EXPECT_EQ(0, stored_placement.offset); 596 EXPECT_EQ(0, stored_placement.offset);
599 EXPECT_EQ(id1, stored_placement.display_id); 597 EXPECT_EQ(id1, stored_placement.display_id);
600 EXPECT_EQ(id2, stored_placement.parent_display_id); 598 EXPECT_EQ(id2, stored_placement.parent_display_id);
601 EXPECT_EQ(id2, stored_layout.primary_id); 599 EXPECT_EQ(id2, stored_layout.primary_id);
602 } 600 }
603 601
604 // Updating layout with primary swapped should save the correct value. 602 // Updating layout with primary swapped should save the correct value.
605 { 603 {
606 ash::Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays( 604 display_manager()->SetLayoutForCurrentDisplays(
607 ash::test::CreateDisplayLayout(display::DisplayPlacement::TOP, 10)); 605 ash::test::CreateDisplayLayout(display_manager(),
606 display::DisplayPlacement::TOP, 10));
608 const base::DictionaryValue* new_value = nullptr; 607 const base::DictionaryValue* new_value = nullptr;
609 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); 608 EXPECT_TRUE(displays->GetDictionary(key, &new_value));
610 display::DisplayLayout stored_layout; 609 display::DisplayLayout stored_layout;
611 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 610 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
612 ASSERT_EQ(1u, stored_layout.placement_list.size()); 611 ASSERT_EQ(1u, stored_layout.placement_list.size());
613 const display::DisplayPlacement& stored_placement = 612 const display::DisplayPlacement& stored_placement =
614 stored_layout.placement_list[0]; 613 stored_layout.placement_list[0];
615 EXPECT_EQ(display::DisplayPlacement::TOP, stored_placement.position); 614 EXPECT_EQ(display::DisplayPlacement::TOP, stored_placement.position);
616 EXPECT_EQ(10, stored_placement.offset); 615 EXPECT_EQ(10, stored_placement.offset);
617 EXPECT_EQ(id1, stored_placement.display_id); 616 EXPECT_EQ(id1, stored_placement.display_id);
618 EXPECT_EQ(id2, stored_placement.parent_display_id); 617 EXPECT_EQ(id2, stored_placement.parent_display_id);
619 EXPECT_EQ(id2, stored_layout.primary_id); 618 EXPECT_EQ(id2, stored_layout.primary_id);
620 } 619 }
621 620
622 // Swapping primary will save the swapped value. 621 // Swapping primary will save the swapped value.
623 { 622 {
624 ash::test::SwapPrimaryDisplay(); 623 SwapPrimaryDisplay();
625 const base::DictionaryValue* new_value = nullptr; 624 const base::DictionaryValue* new_value = nullptr;
626 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); 625 EXPECT_TRUE(displays->GetDictionary(key, &new_value));
627 display::DisplayLayout stored_layout; 626 display::DisplayLayout stored_layout;
628 627
629 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); 628 EXPECT_TRUE(displays->GetDictionary(key, &new_value));
630 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 629 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
631 ASSERT_EQ(1u, stored_layout.placement_list.size()); 630 ASSERT_EQ(1u, stored_layout.placement_list.size());
632 const display::DisplayPlacement& stored_placement = 631 const display::DisplayPlacement& stored_placement =
633 stored_layout.placement_list[0]; 632 stored_layout.placement_list[0];
634 EXPECT_EQ(display::DisplayPlacement::BOTTOM, stored_placement.position); 633 EXPECT_EQ(display::DisplayPlacement::BOTTOM, stored_placement.position);
635 EXPECT_EQ(-10, stored_placement.offset); 634 EXPECT_EQ(-10, stored_placement.offset);
636 EXPECT_EQ(id2, stored_placement.display_id); 635 EXPECT_EQ(id2, stored_placement.display_id);
637 EXPECT_EQ(id1, stored_placement.parent_display_id); 636 EXPECT_EQ(id1, stored_placement.parent_display_id);
638 EXPECT_EQ(id1, stored_layout.primary_id); 637 EXPECT_EQ(id1, stored_layout.primary_id);
639 } 638 }
640 } 639 }
641 640
642 TEST_F(DisplayPreferencesTest, RestoreColorProfiles) { 641 TEST_F(DisplayPreferencesTest, RestoreColorProfiles) {
643 ash::DisplayManager* display_manager =
644 ash::Shell::GetInstance()->display_manager();
645
646 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 642 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id();
647 643
648 StoreColorProfile(id1, "dynamic"); 644 StoreColorProfile(id1, "dynamic");
649 645
650 LoggedInAsUser(); 646 LoggedInAsUser();
651 LoadDisplayPreferences(false); 647 LoadDisplayPreferences(false);
652 648
653 // id1's available color profiles list is empty, means somehow the color 649 // id1's available color profiles list is empty, means somehow the color
654 // profile suport is temporary in trouble. 650 // profile suport is temporary in trouble.
655 EXPECT_NE(ui::COLOR_PROFILE_DYNAMIC, 651 EXPECT_NE(ui::COLOR_PROFILE_DYNAMIC,
656 display_manager->GetDisplayInfo(id1).color_profile()); 652 display_manager()->GetDisplayInfo(id1).color_profile());
657 653
658 // Once the profile is supported, the color profile should be restored. 654 // Once the profile is supported, the color profile should be restored.
659 std::vector<ui::ColorCalibrationProfile> profiles; 655 std::vector<ui::ColorCalibrationProfile> profiles;
660 profiles.push_back(ui::COLOR_PROFILE_STANDARD); 656 profiles.push_back(ui::COLOR_PROFILE_STANDARD);
661 profiles.push_back(ui::COLOR_PROFILE_DYNAMIC); 657 profiles.push_back(ui::COLOR_PROFILE_DYNAMIC);
662 profiles.push_back(ui::COLOR_PROFILE_MOVIE); 658 profiles.push_back(ui::COLOR_PROFILE_MOVIE);
663 profiles.push_back(ui::COLOR_PROFILE_READING); 659 profiles.push_back(ui::COLOR_PROFILE_READING);
664 ash::test::DisplayManagerTestApi().SetAvailableColorProfiles(id1, profiles); 660 ash::test::DisplayManagerTestApi(ash::Shell::GetInstance()->display_manager())
661 .SetAvailableColorProfiles(id1, profiles);
665 662
666 LoadDisplayPreferences(false); 663 LoadDisplayPreferences(false);
667 EXPECT_EQ(ui::COLOR_PROFILE_DYNAMIC, 664 EXPECT_EQ(ui::COLOR_PROFILE_DYNAMIC,
668 display_manager->GetDisplayInfo(id1).color_profile()); 665 display_manager()->GetDisplayInfo(id1).color_profile());
669 } 666 }
670 667
671 TEST_F(DisplayPreferencesTest, DontStoreInGuestMode) { 668 TEST_F(DisplayPreferencesTest, DontStoreInGuestMode) {
672 ash::WindowTreeHostManager* window_tree_host_manager = 669 ash::WindowTreeHostManager* window_tree_host_manager =
673 ash::Shell::GetInstance()->window_tree_host_manager(); 670 ash::Shell::GetInstance()->window_tree_host_manager();
674 671
675 UpdateDisplay("200x200*2,200x200"); 672 UpdateDisplay("200x200*2,200x200");
676 673
677 LoggedInAsGuest(); 674 LoggedInAsGuest();
678 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 675 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id();
679 ash::test::ScopedSetInternalDisplayId set_internal(id1); 676 ash::test::ScopedSetInternalDisplayId set_internal(
680 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); 677 ash::Shell::GetInstance()->display_manager(), id1);
681 ash::DisplayManager* display_manager = 678 int64_t id2 = display_manager()->GetSecondaryDisplay().id();
682 ash::Shell::GetInstance()->display_manager(); 679 display_manager()->SetLayoutForCurrentDisplays(ash::test::CreateDisplayLayout(
683 display_manager->SetLayoutForCurrentDisplays( 680 display_manager(), display::DisplayPlacement::TOP, 10));
684 ash::test::CreateDisplayLayout(display::DisplayPlacement::TOP, 10)); 681 display_manager()->SetDisplayUIScale(id1, 1.25f);
685 display_manager->SetDisplayUIScale(id1, 1.25f);
686 window_tree_host_manager->SetPrimaryDisplayId(id2); 682 window_tree_host_manager->SetPrimaryDisplayId(id2);
687 int64_t new_primary = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 683 int64_t new_primary = display::Screen::GetScreen()->GetPrimaryDisplay().id();
688 window_tree_host_manager->SetOverscanInsets(new_primary, 684 window_tree_host_manager->SetOverscanInsets(new_primary,
689 gfx::Insets(10, 11, 12, 13)); 685 gfx::Insets(10, 11, 12, 13));
690 display_manager->SetDisplayRotation(new_primary, display::Display::ROTATE_90, 686 display_manager()->SetDisplayRotation(new_primary,
691 display::Display::ROTATION_SOURCE_USER); 687 display::Display::ROTATE_90,
688 display::Display::ROTATION_SOURCE_USER);
692 689
693 // Does not store the preferences locally. 690 // Does not store the preferences locally.
694 EXPECT_FALSE(local_state()->FindPreference( 691 EXPECT_FALSE(local_state()->FindPreference(
695 prefs::kSecondaryDisplays)->HasUserSetting()); 692 prefs::kSecondaryDisplays)->HasUserSetting());
696 EXPECT_FALSE(local_state()->FindPreference( 693 EXPECT_FALSE(local_state()->FindPreference(
697 prefs::kDisplayProperties)->HasUserSetting()); 694 prefs::kDisplayProperties)->HasUserSetting());
698 695
699 // Settings are still notified to the system. 696 // Settings are still notified to the system.
700 display::Screen* screen = display::Screen::GetScreen(); 697 display::Screen* screen = display::Screen::GetScreen();
701 EXPECT_EQ(id2, screen->GetPrimaryDisplay().id()); 698 EXPECT_EQ(id2, screen->GetPrimaryDisplay().id());
702 const display::DisplayPlacement& placement = 699 const display::DisplayPlacement& placement =
703 display_manager->GetCurrentDisplayLayout().placement_list[0]; 700 display_manager()->GetCurrentDisplayLayout().placement_list[0];
704 EXPECT_EQ(display::DisplayPlacement::BOTTOM, placement.position); 701 EXPECT_EQ(display::DisplayPlacement::BOTTOM, placement.position);
705 EXPECT_EQ(-10, placement.offset); 702 EXPECT_EQ(-10, placement.offset);
706 const display::Display& primary_display = screen->GetPrimaryDisplay(); 703 const display::Display& primary_display = screen->GetPrimaryDisplay();
707 EXPECT_EQ("178x176", primary_display.bounds().size().ToString()); 704 EXPECT_EQ("178x176", primary_display.bounds().size().ToString());
708 EXPECT_EQ(display::Display::ROTATE_90, primary_display.rotation()); 705 EXPECT_EQ(display::Display::ROTATE_90, primary_display.rotation());
709 706
710 const display::ManagedDisplayInfo& info1 = 707 const display::ManagedDisplayInfo& info1 =
711 display_manager->GetDisplayInfo(id1); 708 display_manager()->GetDisplayInfo(id1);
712 EXPECT_EQ(1.25f, info1.configured_ui_scale()); 709 EXPECT_EQ(1.25f, info1.configured_ui_scale());
713 710
714 const display::ManagedDisplayInfo& info_primary = 711 const display::ManagedDisplayInfo& info_primary =
715 display_manager->GetDisplayInfo(new_primary); 712 display_manager()->GetDisplayInfo(new_primary);
716 EXPECT_EQ(display::Display::ROTATE_90, info_primary.GetActiveRotation()); 713 EXPECT_EQ(display::Display::ROTATE_90, info_primary.GetActiveRotation());
717 EXPECT_EQ(1.0f, info_primary.configured_ui_scale()); 714 EXPECT_EQ(1.0f, info_primary.configured_ui_scale());
718 } 715 }
719 716
720 TEST_F(DisplayPreferencesTest, StorePowerStateNoLogin) { 717 TEST_F(DisplayPreferencesTest, StorePowerStateNoLogin) {
721 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); 718 EXPECT_FALSE(local_state()->HasPrefPath(prefs::kDisplayPowerState));
722 719
723 // Stores display prefs without login, which still stores the power state. 720 // Stores display prefs without login, which still stores the power state.
724 StoreDisplayPrefs(); 721 StoreDisplayPrefs();
725 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayPowerState)); 722 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayPowerState));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, 769 EXPECT_EQ(chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON,
773 shell->display_configurator()->requested_power_state()); 770 shell->display_configurator()->requested_power_state());
774 } 771 }
775 772
776 // Tests that display configuration changes caused by MaximizeModeController 773 // Tests that display configuration changes caused by MaximizeModeController
777 // are not saved. 774 // are not saved.
778 TEST_F(DisplayPreferencesTest, DontSaveMaximizeModeControllerRotations) { 775 TEST_F(DisplayPreferencesTest, DontSaveMaximizeModeControllerRotations) {
779 ash::Shell* shell = ash::Shell::GetInstance(); 776 ash::Shell* shell = ash::Shell::GetInstance();
780 display::Display::SetInternalDisplayId( 777 display::Display::SetInternalDisplayId(
781 display::Screen::GetScreen()->GetPrimaryDisplay().id()); 778 display::Screen::GetScreen()->GetPrimaryDisplay().id());
782 ash::DisplayManager* display_manager = shell->display_manager();
783 LoggedInAsUser(); 779 LoggedInAsUser();
784 // Populate the properties. 780 // Populate the properties.
785 display_manager->SetDisplayRotation(display::Display::InternalDisplayId(), 781 display_manager()->SetDisplayRotation(display::Display::InternalDisplayId(),
786 display::Display::ROTATE_180, 782 display::Display::ROTATE_180,
787 display::Display::ROTATION_SOURCE_USER); 783 display::Display::ROTATION_SOURCE_USER);
788 // Reset property to avoid rotation lock 784 // Reset property to avoid rotation lock
789 display_manager->SetDisplayRotation(display::Display::InternalDisplayId(), 785 display_manager()->SetDisplayRotation(display::Display::InternalDisplayId(),
790 display::Display::ROTATE_0, 786 display::Display::ROTATE_0,
791 display::Display::ROTATION_SOURCE_USER); 787 display::Display::ROTATION_SOURCE_USER);
792 788
793 // Open up 270 degrees to trigger maximize mode 789 // Open up 270 degrees to trigger maximize mode
794 scoped_refptr<chromeos::AccelerometerUpdate> update( 790 scoped_refptr<chromeos::AccelerometerUpdate> update(
795 new chromeos::AccelerometerUpdate()); 791 new chromeos::AccelerometerUpdate());
796 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f, 792 update->Set(chromeos::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD, 0.0f, 0.0f,
797 kMeanGravity); 793 kMeanGravity);
798 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f); 794 update->Set(chromeos::ACCELEROMETER_SOURCE_SCREEN, 0.0f, -kMeanGravity, 0.0f);
799 ash::MaximizeModeController* controller = 795 ash::MaximizeModeController* controller =
800 ash::WmShell::Get()->maximize_mode_controller(); 796 ash::WmShell::Get()->maximize_mode_controller();
801 controller->OnAccelerometerUpdated(update); 797 controller->OnAccelerometerUpdated(update);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 EXPECT_EQ(current_rotation, orientation); 897 EXPECT_EQ(current_rotation, orientation);
902 } 898 }
903 899
904 // Tests that rotation state is loaded without a user being logged in, and that 900 // Tests that rotation state is loaded without a user being logged in, and that
905 // entering maximize mode applies the state. 901 // entering maximize mode applies the state.
906 TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) { 902 TEST_F(DisplayPreferencesTest, LoadRotationNoLogin) {
907 display::Display::SetInternalDisplayId( 903 display::Display::SetInternalDisplayId(
908 display::Screen::GetScreen()->GetPrimaryDisplay().id()); 904 display::Screen::GetScreen()->GetPrimaryDisplay().id());
909 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); 905 ASSERT_FALSE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
910 906
911 ash::Shell* shell = ash::Shell::GetInstance();
912 bool initial_rotation_lock = IsRotationLocked(); 907 bool initial_rotation_lock = IsRotationLocked();
913 ASSERT_FALSE(initial_rotation_lock); 908 ASSERT_FALSE(initial_rotation_lock);
914 ash::DisplayManager* display_manager = shell->display_manager();
915 display::Display::Rotation initial_rotation = 909 display::Display::Rotation initial_rotation =
916 GetCurrentInternalDisplayRotation(); 910 GetCurrentInternalDisplayRotation();
917 ASSERT_EQ(display::Display::ROTATE_0, initial_rotation); 911 ASSERT_EQ(display::Display::ROTATE_0, initial_rotation);
918 912
919 StoreDisplayRotationPrefs(initial_rotation_lock); 913 StoreDisplayRotationPrefs(initial_rotation_lock);
920 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); 914 ASSERT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
921 915
922 StoreDisplayRotationPrefsForTest(true, display::Display::ROTATE_90); 916 StoreDisplayRotationPrefsForTest(true, display::Display::ROTATE_90);
923 LoadDisplayPreferences(false); 917 LoadDisplayPreferences(false);
924 918
925 bool display_rotation_lock = 919 bool display_rotation_lock =
926 display_manager->registered_internal_display_rotation_lock(); 920 display_manager()->registered_internal_display_rotation_lock();
927 bool display_rotation = 921 bool display_rotation =
928 display_manager->registered_internal_display_rotation(); 922 display_manager()->registered_internal_display_rotation();
929 EXPECT_TRUE(display_rotation_lock); 923 EXPECT_TRUE(display_rotation_lock);
930 EXPECT_EQ(display::Display::ROTATE_90, display_rotation); 924 EXPECT_EQ(display::Display::ROTATE_90, display_rotation);
931 925
932 bool rotation_lock = IsRotationLocked(); 926 bool rotation_lock = IsRotationLocked();
933 display::Display::Rotation before_maximize_mode_rotation = 927 display::Display::Rotation before_maximize_mode_rotation =
934 GetCurrentInternalDisplayRotation(); 928 GetCurrentInternalDisplayRotation();
935 929
936 // Settings should not be applied until maximize mode activates 930 // Settings should not be applied until maximize mode activates
937 EXPECT_FALSE(rotation_lock); 931 EXPECT_FALSE(rotation_lock);
938 EXPECT_EQ(display::Display::ROTATE_0, before_maximize_mode_rotation); 932 EXPECT_EQ(display::Display::ROTATE_0, before_maximize_mode_rotation);
(...skipping 26 matching lines...) Expand all
965 959
966 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock)); 960 EXPECT_TRUE(local_state()->HasPrefPath(prefs::kDisplayRotationLock));
967 961
968 const base::DictionaryValue* properties = 962 const base::DictionaryValue* properties =
969 local_state()->GetDictionary(prefs::kDisplayRotationLock); 963 local_state()->GetDictionary(prefs::kDisplayRotationLock);
970 bool rotation_lock; 964 bool rotation_lock;
971 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock)); 965 EXPECT_TRUE(properties->GetBoolean("lock", &rotation_lock));
972 } 966 }
973 967
974 TEST_F(DisplayPreferencesTest, SaveUnifiedMode) { 968 TEST_F(DisplayPreferencesTest, SaveUnifiedMode) {
975
976 LoggedInAsUser(); 969 LoggedInAsUser();
977 ash::DisplayManager* display_manager = 970 display_manager()->SetUnifiedDesktopEnabled(true);
978 ash::Shell::GetInstance()->display_manager();
979 display_manager->SetUnifiedDesktopEnabled(true);
980 971
981 UpdateDisplay("200x200,100x100"); 972 UpdateDisplay("200x200,100x100");
982 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); 973 display::DisplayIdList list = display_manager()->GetCurrentDisplayIdList();
983 EXPECT_EQ( 974 EXPECT_EQ(
984 "400x200", 975 "400x200",
985 display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString()); 976 display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString());
986 977
987 const base::DictionaryValue* secondary_displays = 978 const base::DictionaryValue* secondary_displays =
988 local_state()->GetDictionary(prefs::kSecondaryDisplays); 979 local_state()->GetDictionary(prefs::kSecondaryDisplays);
989 const base::DictionaryValue* new_value = nullptr; 980 const base::DictionaryValue* new_value = nullptr;
990 EXPECT_TRUE(secondary_displays->GetDictionary( 981 EXPECT_TRUE(secondary_displays->GetDictionary(
991 display::DisplayIdListToString(list), &new_value)); 982 display::DisplayIdListToString(list), &new_value));
992 983
993 display::DisplayLayout stored_layout; 984 display::DisplayLayout stored_layout;
994 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 985 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
995 EXPECT_TRUE(stored_layout.default_unified); 986 EXPECT_TRUE(stored_layout.default_unified);
996 EXPECT_FALSE(stored_layout.mirrored); 987 EXPECT_FALSE(stored_layout.mirrored);
997 988
998 const base::DictionaryValue* displays = 989 const base::DictionaryValue* displays =
999 local_state()->GetDictionary(prefs::kDisplayProperties); 990 local_state()->GetDictionary(prefs::kDisplayProperties);
1000 int64_t unified_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 991 int64_t unified_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
1001 EXPECT_FALSE( 992 EXPECT_FALSE(
1002 displays->GetDictionary(base::Int64ToString(unified_id), &new_value)); 993 displays->GetDictionary(base::Int64ToString(unified_id), &new_value));
1003 994
1004 ash::test::SetDisplayResolution(unified_id, gfx::Size(200, 100)); 995 ash::test::SetDisplayResolution(display_manager(), unified_id,
996 gfx::Size(200, 100));
1005 EXPECT_EQ( 997 EXPECT_EQ(
1006 "200x100", 998 "200x100",
1007 display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString()); 999 display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString());
1008 EXPECT_FALSE( 1000 EXPECT_FALSE(
1009 displays->GetDictionary(base::Int64ToString(unified_id), &new_value)); 1001 displays->GetDictionary(base::Int64ToString(unified_id), &new_value));
1010 1002
1011 // Mirror mode should remember if the default mode was unified. 1003 // Mirror mode should remember if the default mode was unified.
1012 display_manager->SetMirrorMode(true); 1004 display_manager()->SetMirrorMode(true);
1013 ASSERT_TRUE(secondary_displays->GetDictionary( 1005 ASSERT_TRUE(secondary_displays->GetDictionary(
1014 display::DisplayIdListToString(list), &new_value)); 1006 display::DisplayIdListToString(list), &new_value));
1015 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 1007 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
1016 EXPECT_TRUE(stored_layout.default_unified); 1008 EXPECT_TRUE(stored_layout.default_unified);
1017 EXPECT_TRUE(stored_layout.mirrored); 1009 EXPECT_TRUE(stored_layout.mirrored);
1018 1010
1019 display_manager->SetMirrorMode(false); 1011 display_manager()->SetMirrorMode(false);
1020 ASSERT_TRUE(secondary_displays->GetDictionary( 1012 ASSERT_TRUE(secondary_displays->GetDictionary(
1021 display::DisplayIdListToString(list), &new_value)); 1013 display::DisplayIdListToString(list), &new_value));
1022 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 1014 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
1023 EXPECT_TRUE(stored_layout.default_unified); 1015 EXPECT_TRUE(stored_layout.default_unified);
1024 EXPECT_FALSE(stored_layout.mirrored); 1016 EXPECT_FALSE(stored_layout.mirrored);
1025 1017
1026 // Exit unified mode. 1018 // Exit unified mode.
1027 display_manager->SetDefaultMultiDisplayModeForCurrentDisplays( 1019 display_manager()->SetDefaultMultiDisplayModeForCurrentDisplays(
1028 ash::DisplayManager::EXTENDED); 1020 ash::DisplayManager::EXTENDED);
1029 ASSERT_TRUE(secondary_displays->GetDictionary( 1021 ASSERT_TRUE(secondary_displays->GetDictionary(
1030 display::DisplayIdListToString(list), &new_value)); 1022 display::DisplayIdListToString(list), &new_value));
1031 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 1023 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
1032 EXPECT_FALSE(stored_layout.default_unified); 1024 EXPECT_FALSE(stored_layout.default_unified);
1033 EXPECT_FALSE(stored_layout.mirrored); 1025 EXPECT_FALSE(stored_layout.mirrored);
1034 } 1026 }
1035 1027
1036 TEST_F(DisplayPreferencesTest, RestoreUnifiedMode) { 1028 TEST_F(DisplayPreferencesTest, RestoreUnifiedMode) {
1037 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 1029 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id();
1038 display::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, id1 + 1); 1030 display::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, id1 + 1);
1039 StoreDisplayBoolPropertyForList(list, "default_unified", true); 1031 StoreDisplayBoolPropertyForList(list, "default_unified", true);
1040 StoreDisplayPropertyForList( 1032 StoreDisplayPropertyForList(
1041 list, "primary-id", 1033 list, "primary-id",
1042 base::MakeUnique<base::StringValue>(base::Int64ToString(id1))); 1034 base::MakeUnique<base::StringValue>(base::Int64ToString(id1)));
1043 LoadDisplayPreferences(false); 1035 LoadDisplayPreferences(false);
1044 1036
1045 // Should not restore to unified unless unified desktop is enabled. 1037 // Should not restore to unified unless unified desktop is enabled.
1046 UpdateDisplay("100x100,200x200"); 1038 UpdateDisplay("100x100,200x200");
1047 ash::DisplayManager* display_manager = 1039 EXPECT_FALSE(display_manager()->IsInUnifiedMode());
1048 ash::Shell::GetInstance()->display_manager();
1049 EXPECT_FALSE(display_manager->IsInUnifiedMode());
1050 1040
1051 // Restored to unified. 1041 // Restored to unified.
1052 display_manager->SetUnifiedDesktopEnabled(true); 1042 display_manager()->SetUnifiedDesktopEnabled(true);
1053 StoreDisplayBoolPropertyForList(list, "default_unified", true); 1043 StoreDisplayBoolPropertyForList(list, "default_unified", true);
1054 LoadDisplayPreferences(false); 1044 LoadDisplayPreferences(false);
1055 UpdateDisplay("100x100,200x200"); 1045 UpdateDisplay("100x100,200x200");
1056 EXPECT_TRUE(display_manager->IsInUnifiedMode()); 1046 EXPECT_TRUE(display_manager()->IsInUnifiedMode());
1057 1047
1058 // Restored to mirror, then unified. 1048 // Restored to mirror, then unified.
1059 StoreDisplayBoolPropertyForList(list, "mirrored", true); 1049 StoreDisplayBoolPropertyForList(list, "mirrored", true);
1060 StoreDisplayBoolPropertyForList(list, "default_unified", true); 1050 StoreDisplayBoolPropertyForList(list, "default_unified", true);
1061 LoadDisplayPreferences(false); 1051 LoadDisplayPreferences(false);
1062 UpdateDisplay("100x100,200x200"); 1052 UpdateDisplay("100x100,200x200");
1063 EXPECT_TRUE(display_manager->IsInMirrorMode()); 1053 EXPECT_TRUE(display_manager()->IsInMirrorMode());
1064 1054
1065 display_manager->SetMirrorMode(false); 1055 display_manager()->SetMirrorMode(false);
1066 EXPECT_TRUE(display_manager->IsInUnifiedMode()); 1056 EXPECT_TRUE(display_manager()->IsInUnifiedMode());
1067 1057
1068 // Sanity check. Restore to extended. 1058 // Sanity check. Restore to extended.
1069 StoreDisplayBoolPropertyForList(list, "default_unified", false); 1059 StoreDisplayBoolPropertyForList(list, "default_unified", false);
1070 StoreDisplayBoolPropertyForList(list, "mirrored", false); 1060 StoreDisplayBoolPropertyForList(list, "mirrored", false);
1071 LoadDisplayPreferences(false); 1061 LoadDisplayPreferences(false);
1072 UpdateDisplay("100x100,200x200"); 1062 UpdateDisplay("100x100,200x200");
1073 EXPECT_FALSE(display_manager->IsInMirrorMode()); 1063 EXPECT_FALSE(display_manager()->IsInMirrorMode());
1074 EXPECT_FALSE(display_manager->IsInUnifiedMode()); 1064 EXPECT_FALSE(display_manager()->IsInUnifiedMode());
1075 } 1065 }
1076 1066
1077 TEST_F(DisplayPreferencesTest, SaveThreeDisplays) { 1067 TEST_F(DisplayPreferencesTest, SaveThreeDisplays) {
1078 LoggedInAsUser(); 1068 LoggedInAsUser();
1079 ash::DisplayManager* display_manager =
1080 ash::Shell::GetInstance()->display_manager();
1081 UpdateDisplay("200x200,200x200,300x300"); 1069 UpdateDisplay("200x200,200x200,300x300");
1082 1070
1083 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); 1071 display::DisplayIdList list = display_manager()->GetCurrentDisplayIdList();
1084 ASSERT_EQ(3u, list.size()); 1072 ASSERT_EQ(3u, list.size());
1085 1073
1086 display::DisplayLayoutBuilder builder(list[0]); 1074 display::DisplayLayoutBuilder builder(list[0]);
1087 builder.AddDisplayPlacement(list[1], list[0], 1075 builder.AddDisplayPlacement(list[1], list[0],
1088 display::DisplayPlacement::RIGHT, 0); 1076 display::DisplayPlacement::RIGHT, 0);
1089 builder.AddDisplayPlacement(list[2], list[0], 1077 builder.AddDisplayPlacement(list[2], list[0],
1090 display::DisplayPlacement::BOTTOM, 100); 1078 display::DisplayPlacement::BOTTOM, 100);
1091 display_manager->SetLayoutForCurrentDisplays(builder.Build()); 1079 display_manager()->SetLayoutForCurrentDisplays(builder.Build());
1092 1080
1093 const base::DictionaryValue* secondary_displays = 1081 const base::DictionaryValue* secondary_displays =
1094 local_state()->GetDictionary(prefs::kSecondaryDisplays); 1082 local_state()->GetDictionary(prefs::kSecondaryDisplays);
1095 const base::DictionaryValue* new_value = nullptr; 1083 const base::DictionaryValue* new_value = nullptr;
1096 EXPECT_TRUE(secondary_displays->GetDictionary( 1084 EXPECT_TRUE(secondary_displays->GetDictionary(
1097 display::DisplayIdListToString(list), &new_value)); 1085 display::DisplayIdListToString(list), &new_value));
1098 } 1086 }
1099 1087
1100 TEST_F(DisplayPreferencesTest, RestoreThreeDisplays) { 1088 TEST_F(DisplayPreferencesTest, RestoreThreeDisplays) {
1101 LoggedInAsUser(); 1089 LoggedInAsUser();
1102 ash::DisplayManager* display_manager =
1103 ash::Shell::GetInstance()->display_manager();
1104 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 1090 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id();
1105 display::DisplayIdList list = 1091 display::DisplayIdList list =
1106 ash::test::CreateDisplayIdListN(3, id1, id1 + 1, id1 + 2); 1092 ash::test::CreateDisplayIdListN(3, id1, id1 + 1, id1 + 2);
1107 1093
1108 display::DisplayLayoutBuilder builder(list[0]); 1094 display::DisplayLayoutBuilder builder(list[0]);
1109 builder.AddDisplayPlacement(list[1], list[0], display::DisplayPlacement::LEFT, 1095 builder.AddDisplayPlacement(list[1], list[0], display::DisplayPlacement::LEFT,
1110 0); 1096 0);
1111 builder.AddDisplayPlacement(list[2], list[1], 1097 builder.AddDisplayPlacement(list[2], list[1],
1112 display::DisplayPlacement::BOTTOM, 100); 1098 display::DisplayPlacement::BOTTOM, 100);
1113 StoreDisplayLayoutPrefForTest(list, *builder.Build()); 1099 StoreDisplayLayoutPrefForTest(list, *builder.Build());
1114 LoadDisplayPreferences(false); 1100 LoadDisplayPreferences(false);
1115 1101
1116 UpdateDisplay("200x200,200x200,300x300"); 1102 UpdateDisplay("200x200,200x200,300x300");
1117 display::DisplayIdList new_list = display_manager->GetCurrentDisplayIdList(); 1103 display::DisplayIdList new_list =
1104 display_manager()->GetCurrentDisplayIdList();
1118 ASSERT_EQ(3u, list.size()); 1105 ASSERT_EQ(3u, list.size());
1119 ASSERT_EQ(list[0], new_list[0]); 1106 ASSERT_EQ(list[0], new_list[0]);
1120 ASSERT_EQ(list[1], new_list[1]); 1107 ASSERT_EQ(list[1], new_list[1]);
1121 ASSERT_EQ(list[2], new_list[2]); 1108 ASSERT_EQ(list[2], new_list[2]);
1122 1109
1123 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), 1110 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
1124 display_manager->GetDisplayForId(list[0]).bounds()); 1111 display_manager()->GetDisplayForId(list[0]).bounds());
1125 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200), 1112 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200),
1126 display_manager->GetDisplayForId(list[1]).bounds()); 1113 display_manager()->GetDisplayForId(list[1]).bounds());
1127 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300), 1114 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300),
1128 display_manager->GetDisplayForId(list[2]).bounds()); 1115 display_manager()->GetDisplayForId(list[2]).bounds());
1129 } 1116 }
1130 1117
1131 } // namespace chromeos 1118 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698