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

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

Issue 1819533002: Convert ScopedVector<DisplayPlacement> to std::vector<DisplayPlacement> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@jsonrefactor
Patch Set: Created 4 years, 9 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 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 // Do not use the implementation of display_preferences.cc directly to avoid 102 // Do not use the implementation of display_preferences.cc directly to avoid
103 // notifying the update to the system. 103 // notifying the update to the system.
104 void StoreDisplayLayoutPrefForList(const ash::DisplayIdList& list, 104 void StoreDisplayLayoutPrefForList(const ash::DisplayIdList& list,
105 ash::DisplayPlacement::Position position, 105 ash::DisplayPlacement::Position position,
106 int offset, 106 int offset,
107 int64_t primary_id) { 107 int64_t primary_id) {
108 std::string name = ash::DisplayIdListToString(list); 108 std::string name = ash::DisplayIdListToString(list);
109 DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays); 109 DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays);
110 ash::DisplayLayout display_layout; 110 ash::DisplayLayout display_layout;
111 display_layout.placement_list.push_back( 111 display_layout.placement_list.emplace_back(position, offset);
112 new ash::DisplayPlacement(position, offset));
113 display_layout.primary_id = primary_id; 112 display_layout.primary_id = primary_id;
114 113
115 DCHECK(!name.empty()); 114 DCHECK(!name.empty());
116 115
117 base::DictionaryValue* pref_data = update.Get(); 116 base::DictionaryValue* pref_data = update.Get();
118 scoped_ptr<base::Value>layout_value(new base::DictionaryValue()); 117 scoped_ptr<base::Value>layout_value(new base::DictionaryValue());
119 if (pref_data->HasKey(name)) { 118 if (pref_data->HasKey(name)) {
120 base::Value* value = nullptr; 119 base::Value* value = nullptr;
121 if (pref_data->Get(name, &value) && value != nullptr) 120 if (pref_data->Get(name, &value) && value != nullptr)
122 layout_value.reset(value->DeepCopy()); 121 layout_value.reset(value->DeepCopy());
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 pref_data->SetBoolean("lock", rotation_lock); 189 pref_data->SetBoolean("lock", rotation_lock);
191 pref_data->SetInteger("orientation", static_cast<int>(rotation)); 190 pref_data->SetInteger("orientation", static_cast<int>(rotation));
192 } 191 }
193 192
194 std::string GetRegisteredDisplayPlacementStr(const ash::DisplayIdList& list) { 193 std::string GetRegisteredDisplayPlacementStr(const ash::DisplayIdList& list) {
195 return ash::Shell::GetInstance() 194 return ash::Shell::GetInstance()
196 ->display_manager() 195 ->display_manager()
197 ->layout_store() 196 ->layout_store()
198 ->GetRegisteredDisplayLayout(list) 197 ->GetRegisteredDisplayLayout(list)
199 .placement_list[0] 198 .placement_list[0]
200 ->ToString(); 199 .ToString();
201 } 200 }
202 201
203 PrefService* local_state() { return &local_state_; } 202 PrefService* local_state() { return &local_state_; }
204 203
205 private: 204 private:
206 MockUserManager* mock_user_manager_; // Not owned. 205 MockUserManager* mock_user_manager_; // Not owned.
207 ScopedUserManagerEnabler user_manager_enabler_; 206 ScopedUserManagerEnabler user_manager_enabler_;
208 TestingPrefServiceSimple local_state_; 207 TestingPrefServiceSimple local_state_;
209 scoped_ptr<DisplayConfigurationObserver> observer_; 208 scoped_ptr<DisplayConfigurationObserver> observer_;
210 209
(...skipping 26 matching lines...) Expand all
237 236
238 shell->display_manager()->UpdateDisplays(); 237 shell->display_manager()->UpdateDisplays();
239 // Check if the layout settings are notified to the system properly. 238 // Check if the layout settings are notified to the system properly.
240 // The new layout overrides old layout. 239 // The new layout overrides old layout.
241 // Inverted one of for specified pair (id1, id2). Not used for the list 240 // Inverted one of for specified pair (id1, id2). Not used for the list
242 // (id1, dummy_id) since dummy_id is not connected right now. 241 // (id1, dummy_id) since dummy_id is not connected right now.
243 EXPECT_EQ("id=2200000001, parent=2200000000, top, 20", 242 EXPECT_EQ("id=2200000001, parent=2200000000, top, 20",
244 shell->display_manager() 243 shell->display_manager()
245 ->GetCurrentDisplayLayout() 244 ->GetCurrentDisplayLayout()
246 .placement_list[0] 245 .placement_list[0]
247 ->ToString()); 246 .ToString());
248 EXPECT_EQ("id=2200000001, parent=2200000000, top, 20", 247 EXPECT_EQ("id=2200000001, parent=2200000000, top, 20",
249 GetRegisteredDisplayPlacementStr(list)); 248 GetRegisteredDisplayPlacementStr(list));
250 EXPECT_EQ("id=2200000002, parent=2200000000, left, 30", 249 EXPECT_EQ("id=2200000002, parent=2200000000, left, 30",
251 GetRegisteredDisplayPlacementStr(dummy_list)); 250 GetRegisteredDisplayPlacementStr(dummy_list));
252 } 251 }
253 252
254 TEST_F(DisplayPreferencesTest, BasicStores) { 253 TEST_F(DisplayPreferencesTest, BasicStores) {
255 ash::WindowTreeHostManager* window_tree_host_manager = 254 ash::WindowTreeHostManager* window_tree_host_manager =
256 ash::Shell::GetInstance()->window_tree_host_manager(); 255 ash::Shell::GetInstance()->window_tree_host_manager();
257 ash::DisplayManager* display_manager = 256 ash::DisplayManager* display_manager =
(...skipping 13 matching lines...) Expand all
271 // Allows only |id1|. 270 // Allows only |id1|.
272 ash::test::DisplayManagerTestApi().SetAvailableColorProfiles(id1, profiles); 271 ash::test::DisplayManagerTestApi().SetAvailableColorProfiles(id1, profiles);
273 display_manager->SetColorCalibrationProfile(id1, ui::COLOR_PROFILE_DYNAMIC); 272 display_manager->SetColorCalibrationProfile(id1, ui::COLOR_PROFILE_DYNAMIC);
274 display_manager->SetColorCalibrationProfile(id2, ui::COLOR_PROFILE_DYNAMIC); 273 display_manager->SetColorCalibrationProfile(id2, ui::COLOR_PROFILE_DYNAMIC);
275 274
276 LoggedInAsUser(); 275 LoggedInAsUser();
277 276
278 display_manager->SetLayoutForCurrentDisplays( 277 display_manager->SetLayoutForCurrentDisplays(
279 ash::test::CreateDisplayLayout(ash::DisplayPlacement::TOP, 10)); 278 ash::test::CreateDisplayLayout(ash::DisplayPlacement::TOP, 10));
280 const ash::DisplayLayout& layout = display_manager->GetCurrentDisplayLayout(); 279 const ash::DisplayLayout& layout = display_manager->GetCurrentDisplayLayout();
281 EXPECT_EQ(ash::DisplayPlacement::TOP, layout.placement_list[0]->position); 280 EXPECT_EQ(ash::DisplayPlacement::TOP, layout.placement_list[0].position);
282 EXPECT_EQ(10, layout.placement_list[0]->offset); 281 EXPECT_EQ(10, layout.placement_list[0].offset);
283 282
284 ash::DisplayLayoutBuilder dummy_layout_builder(id1); 283 ash::DisplayLayoutBuilder dummy_layout_builder(id1);
285 dummy_layout_builder.SetSecondaryPlacement(dummy_id, 284 dummy_layout_builder.SetSecondaryPlacement(dummy_id,
286 ash::DisplayPlacement::LEFT, 20); 285 ash::DisplayPlacement::LEFT, 20);
287 scoped_ptr<ash::DisplayLayout> dummy_layout(dummy_layout_builder.Build()); 286 scoped_ptr<ash::DisplayLayout> dummy_layout(dummy_layout_builder.Build());
288 ash::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, dummy_id); 287 ash::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, dummy_id);
289 StoreDisplayLayoutPrefForTest(list, *dummy_layout); 288 StoreDisplayLayoutPrefForTest(list, *dummy_layout);
290 289
291 // Can't switch to a display that does not exist. 290 // Can't switch to a display that does not exist.
292 window_tree_host_manager->SetPrimaryDisplayId(dummy_id); 291 window_tree_host_manager->SetPrimaryDisplayId(dummy_id);
(...skipping 10 matching lines...) Expand all
303 const base::DictionaryValue* layout_value = nullptr; 302 const base::DictionaryValue* layout_value = nullptr;
304 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); 303 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2);
305 std::string dummy_key = 304 std::string dummy_key =
306 base::Int64ToString(id1) + "," + base::Int64ToString(dummy_id); 305 base::Int64ToString(id1) + "," + base::Int64ToString(dummy_id);
307 EXPECT_TRUE(displays->GetDictionary(dummy_key, &layout_value)); 306 EXPECT_TRUE(displays->GetDictionary(dummy_key, &layout_value));
308 307
309 ash::DisplayLayout stored_layout; 308 ash::DisplayLayout stored_layout;
310 EXPECT_TRUE(ash::JsonToDisplayLayout(*layout_value, &stored_layout)); 309 EXPECT_TRUE(ash::JsonToDisplayLayout(*layout_value, &stored_layout));
311 ASSERT_EQ(1u, stored_layout.placement_list.size()); 310 ASSERT_EQ(1u, stored_layout.placement_list.size());
312 311
313 EXPECT_EQ(dummy_layout->placement_list[0]->position, 312 EXPECT_EQ(dummy_layout->placement_list[0].position,
314 stored_layout.placement_list[0]->position); 313 stored_layout.placement_list[0].position);
315 EXPECT_EQ(dummy_layout->placement_list[0]->offset, 314 EXPECT_EQ(dummy_layout->placement_list[0].offset,
316 stored_layout.placement_list[0]->offset); 315 stored_layout.placement_list[0].offset);
317 316
318 bool mirrored = true; 317 bool mirrored = true;
319 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); 318 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored));
320 EXPECT_FALSE(mirrored); 319 EXPECT_FALSE(mirrored);
321 320
322 const base::DictionaryValue* properties = 321 const base::DictionaryValue* properties =
323 local_state()->GetDictionary(prefs::kDisplayProperties); 322 local_state()->GetDictionary(prefs::kDisplayProperties);
324 const base::DictionaryValue* property = nullptr; 323 const base::DictionaryValue* property = nullptr;
325 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property)); 324 EXPECT_TRUE(properties->GetDictionary(base::Int64ToString(id1), &property));
326 int ui_scale = 0; 325 int ui_scale = 0;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 EXPECT_EQ(300, width); 396 EXPECT_EQ(300, width);
398 EXPECT_EQ(200, height); 397 EXPECT_EQ(200, height);
399 EXPECT_EQ(1250, device_scale_factor); 398 EXPECT_EQ(1250, device_scale_factor);
400 399
401 // The layout is swapped. 400 // The layout is swapped.
402 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); 401 EXPECT_TRUE(displays->GetDictionary(key, &layout_value));
403 402
404 EXPECT_TRUE(ash::JsonToDisplayLayout(*layout_value, &stored_layout)); 403 EXPECT_TRUE(ash::JsonToDisplayLayout(*layout_value, &stored_layout));
405 ASSERT_EQ(1u, stored_layout.placement_list.size()); 404 ASSERT_EQ(1u, stored_layout.placement_list.size());
406 const ash::DisplayPlacement& stored_placement = 405 const ash::DisplayPlacement& stored_placement =
407 *stored_layout.placement_list[0]; 406 stored_layout.placement_list[0];
408 EXPECT_EQ(ash::DisplayPlacement::BOTTOM, stored_placement.position); 407 EXPECT_EQ(ash::DisplayPlacement::BOTTOM, stored_placement.position);
409 EXPECT_EQ(-10, stored_placement.offset); 408 EXPECT_EQ(-10, stored_placement.offset);
410 EXPECT_EQ(id1, stored_placement.display_id); 409 EXPECT_EQ(id1, stored_placement.display_id);
411 EXPECT_EQ(id2, stored_placement.parent_display_id); 410 EXPECT_EQ(id2, stored_placement.parent_display_id);
412 EXPECT_EQ(id2, stored_layout.primary_id); 411 EXPECT_EQ(id2, stored_layout.primary_id);
413 412
414 if (true) 413 if (true)
415 return; 414 return;
416 415
417 mirrored = true; 416 mirrored = true;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 const base::DictionaryValue* displays = 573 const base::DictionaryValue* displays =
575 local_state()->GetDictionary(prefs::kSecondaryDisplays); 574 local_state()->GetDictionary(prefs::kSecondaryDisplays);
576 // Initial saved value is swapped. 575 // Initial saved value is swapped.
577 { 576 {
578 const base::DictionaryValue* new_value = nullptr; 577 const base::DictionaryValue* new_value = nullptr;
579 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); 578 EXPECT_TRUE(displays->GetDictionary(key, &new_value));
580 ash::DisplayLayout stored_layout; 579 ash::DisplayLayout stored_layout;
581 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 580 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
582 ASSERT_EQ(1u, stored_layout.placement_list.size()); 581 ASSERT_EQ(1u, stored_layout.placement_list.size());
583 const ash::DisplayPlacement& stored_placement = 582 const ash::DisplayPlacement& stored_placement =
584 *stored_layout.placement_list[0]; 583 stored_layout.placement_list[0];
585 EXPECT_EQ(ash::DisplayPlacement::LEFT, stored_placement.position); 584 EXPECT_EQ(ash::DisplayPlacement::LEFT, stored_placement.position);
586 EXPECT_EQ(0, stored_placement.offset); 585 EXPECT_EQ(0, stored_placement.offset);
587 EXPECT_EQ(id1, stored_placement.display_id); 586 EXPECT_EQ(id1, stored_placement.display_id);
588 EXPECT_EQ(id2, stored_placement.parent_display_id); 587 EXPECT_EQ(id2, stored_placement.parent_display_id);
589 EXPECT_EQ(id2, stored_layout.primary_id); 588 EXPECT_EQ(id2, stored_layout.primary_id);
590 } 589 }
591 590
592 // Updating layout with primary swapped should save the correct value. 591 // Updating layout with primary swapped should save the correct value.
593 { 592 {
594 ash::Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays( 593 ash::Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
595 ash::test::CreateDisplayLayout(ash::DisplayPlacement::TOP, 10)); 594 ash::test::CreateDisplayLayout(ash::DisplayPlacement::TOP, 10));
596 const base::DictionaryValue* new_value = nullptr; 595 const base::DictionaryValue* new_value = nullptr;
597 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); 596 EXPECT_TRUE(displays->GetDictionary(key, &new_value));
598 ash::DisplayLayout stored_layout; 597 ash::DisplayLayout stored_layout;
599 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 598 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
600 ASSERT_EQ(1u, stored_layout.placement_list.size()); 599 ASSERT_EQ(1u, stored_layout.placement_list.size());
601 const ash::DisplayPlacement& stored_placement = 600 const ash::DisplayPlacement& stored_placement =
602 *stored_layout.placement_list[0]; 601 stored_layout.placement_list[0];
603 EXPECT_EQ(ash::DisplayPlacement::TOP, stored_placement.position); 602 EXPECT_EQ(ash::DisplayPlacement::TOP, stored_placement.position);
604 EXPECT_EQ(10, stored_placement.offset); 603 EXPECT_EQ(10, stored_placement.offset);
605 EXPECT_EQ(id1, stored_placement.display_id); 604 EXPECT_EQ(id1, stored_placement.display_id);
606 EXPECT_EQ(id2, stored_placement.parent_display_id); 605 EXPECT_EQ(id2, stored_placement.parent_display_id);
607 EXPECT_EQ(id2, stored_layout.primary_id); 606 EXPECT_EQ(id2, stored_layout.primary_id);
608 } 607 }
609 608
610 // Swapping primary will save the swapped value. 609 // Swapping primary will save the swapped value.
611 { 610 {
612 ash::test::SwapPrimaryDisplay(); 611 ash::test::SwapPrimaryDisplay();
613 const base::DictionaryValue* new_value = nullptr; 612 const base::DictionaryValue* new_value = nullptr;
614 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); 613 EXPECT_TRUE(displays->GetDictionary(key, &new_value));
615 ash::DisplayLayout stored_layout; 614 ash::DisplayLayout stored_layout;
616 615
617 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); 616 EXPECT_TRUE(displays->GetDictionary(key, &new_value));
618 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 617 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
619 ASSERT_EQ(1u, stored_layout.placement_list.size()); 618 ASSERT_EQ(1u, stored_layout.placement_list.size());
620 const ash::DisplayPlacement& stored_placement = 619 const ash::DisplayPlacement& stored_placement =
621 *stored_layout.placement_list[0]; 620 stored_layout.placement_list[0];
622 EXPECT_EQ(ash::DisplayPlacement::BOTTOM, stored_placement.position); 621 EXPECT_EQ(ash::DisplayPlacement::BOTTOM, stored_placement.position);
623 EXPECT_EQ(-10, stored_placement.offset); 622 EXPECT_EQ(-10, stored_placement.offset);
624 EXPECT_EQ(id2, stored_placement.display_id); 623 EXPECT_EQ(id2, stored_placement.display_id);
625 EXPECT_EQ(id1, stored_placement.parent_display_id); 624 EXPECT_EQ(id1, stored_placement.parent_display_id);
626 EXPECT_EQ(id1, stored_layout.primary_id); 625 EXPECT_EQ(id1, stored_layout.primary_id);
627 } 626 }
628 } 627 }
629 628
630 TEST_F(DisplayPreferencesTest, RestoreColorProfiles) { 629 TEST_F(DisplayPreferencesTest, RestoreColorProfiles) {
631 ash::DisplayManager* display_manager = 630 ash::DisplayManager* display_manager =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 // Does not store the preferences locally. 680 // Does not store the preferences locally.
682 EXPECT_FALSE(local_state()->FindPreference( 681 EXPECT_FALSE(local_state()->FindPreference(
683 prefs::kSecondaryDisplays)->HasUserSetting()); 682 prefs::kSecondaryDisplays)->HasUserSetting());
684 EXPECT_FALSE(local_state()->FindPreference( 683 EXPECT_FALSE(local_state()->FindPreference(
685 prefs::kDisplayProperties)->HasUserSetting()); 684 prefs::kDisplayProperties)->HasUserSetting());
686 685
687 // Settings are still notified to the system. 686 // Settings are still notified to the system.
688 gfx::Screen* screen = gfx::Screen::GetScreen(); 687 gfx::Screen* screen = gfx::Screen::GetScreen();
689 EXPECT_EQ(id2, screen->GetPrimaryDisplay().id()); 688 EXPECT_EQ(id2, screen->GetPrimaryDisplay().id());
690 const ash::DisplayPlacement& placement = 689 const ash::DisplayPlacement& placement =
691 *display_manager->GetCurrentDisplayLayout().placement_list[0]; 690 display_manager->GetCurrentDisplayLayout().placement_list[0];
692 EXPECT_EQ(ash::DisplayPlacement::BOTTOM, placement.position); 691 EXPECT_EQ(ash::DisplayPlacement::BOTTOM, placement.position);
693 EXPECT_EQ(-10, placement.offset); 692 EXPECT_EQ(-10, placement.offset);
694 const gfx::Display& primary_display = screen->GetPrimaryDisplay(); 693 const gfx::Display& primary_display = screen->GetPrimaryDisplay();
695 EXPECT_EQ("178x176", primary_display.bounds().size().ToString()); 694 EXPECT_EQ("178x176", primary_display.bounds().size().ToString());
696 EXPECT_EQ(gfx::Display::ROTATE_90, primary_display.rotation()); 695 EXPECT_EQ(gfx::Display::ROTATE_90, primary_display.rotation());
697 696
698 const ash::DisplayInfo& info1 = display_manager->GetDisplayInfo(id1); 697 const ash::DisplayInfo& info1 = display_manager->GetDisplayInfo(id1);
699 EXPECT_EQ(1.25f, info1.configured_ui_scale()); 698 EXPECT_EQ(1.25f, info1.configured_ui_scale());
700 699
701 const ash::DisplayInfo& info_primary = 700 const ash::DisplayInfo& info_primary =
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 // Sanity check. Restore to extended. 1047 // Sanity check. Restore to extended.
1049 StoreDisplayBoolPropertyForList(list, "default_unified", false); 1048 StoreDisplayBoolPropertyForList(list, "default_unified", false);
1050 StoreDisplayBoolPropertyForList(list, "mirrored", false); 1049 StoreDisplayBoolPropertyForList(list, "mirrored", false);
1051 LoadDisplayPreferences(false); 1050 LoadDisplayPreferences(false);
1052 UpdateDisplay("100x100,200x200"); 1051 UpdateDisplay("100x100,200x200");
1053 EXPECT_FALSE(display_manager->IsInMirrorMode()); 1052 EXPECT_FALSE(display_manager->IsInMirrorMode());
1054 EXPECT_FALSE(display_manager->IsInUnifiedMode()); 1053 EXPECT_FALSE(display_manager->IsInUnifiedMode());
1055 } 1054 }
1056 1055
1057 } // namespace chromeos 1056 } // namespace chromeos
OLDNEW
« no previous file with comments | « ash/extended_desktop_unittest.cc ('k') | chrome/browser/extensions/display_info_provider_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698