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

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

Issue 1808253004: Refactor JSONValueConverter Out of DisplayLayout (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up some Includes 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
« no previous file with comments | « chrome/browser/chromeos/display/display_preferences.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
11 11
12 #include "ash/display/display_layout_builder.h" 12 #include "ash/display/display_layout_builder.h"
13 #include "ash/display/display_layout_store.h" 13 #include "ash/display/display_layout_store.h"
14 #include "ash/display/display_manager.h" 14 #include "ash/display/display_manager.h"
15 #include "ash/display/display_util.h" 15 #include "ash/display/display_util.h"
16 #include "ash/display/json_converter.h"
16 #include "ash/display/resolution_notification_controller.h" 17 #include "ash/display/resolution_notification_controller.h"
17 #include "ash/display/screen_orientation_controller_chromeos.h" 18 #include "ash/display/screen_orientation_controller_chromeos.h"
18 #include "ash/display/window_tree_host_manager.h" 19 #include "ash/display/window_tree_host_manager.h"
19 #include "ash/screen_util.h" 20 #include "ash/screen_util.h"
20 #include "ash/shell.h" 21 #include "ash/shell.h"
21 #include "ash/test/ash_test_base.h" 22 #include "ash/test/ash_test_base.h"
22 #include "ash/test/display_manager_test_api.h" 23 #include "ash/test/display_manager_test_api.h"
23 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 24 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
24 #include "base/macros.h" 25 #include "base/macros.h"
25 #include "base/memory/ref_counted.h" 26 #include "base/memory/ref_counted.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 114
114 DCHECK(!name.empty()); 115 DCHECK(!name.empty());
115 116
116 base::DictionaryValue* pref_data = update.Get(); 117 base::DictionaryValue* pref_data = update.Get();
117 scoped_ptr<base::Value>layout_value(new base::DictionaryValue()); 118 scoped_ptr<base::Value>layout_value(new base::DictionaryValue());
118 if (pref_data->HasKey(name)) { 119 if (pref_data->HasKey(name)) {
119 base::Value* value = nullptr; 120 base::Value* value = nullptr;
120 if (pref_data->Get(name, &value) && value != nullptr) 121 if (pref_data->Get(name, &value) && value != nullptr)
121 layout_value.reset(value->DeepCopy()); 122 layout_value.reset(value->DeepCopy());
122 } 123 }
123 if (ash::DisplayLayout::ConvertToValue(display_layout, layout_value.get())) 124 if (ash::DisplayLayoutToJson(display_layout, layout_value.get()))
124 pref_data->Set(name, layout_value.release()); 125 pref_data->Set(name, layout_value.release());
125 } 126 }
126 127
127 void StoreDisplayPropertyForList(const ash::DisplayIdList& list, 128 void StoreDisplayPropertyForList(const ash::DisplayIdList& list,
128 std::string key, 129 std::string key,
129 scoped_ptr<base::Value> value) { 130 scoped_ptr<base::Value> value) {
130 std::string name = ash::DisplayIdListToString(list); 131 std::string name = ash::DisplayIdListToString(list);
131 132
132 DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays); 133 DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays);
133 base::DictionaryValue* pref_data = update.Get(); 134 base::DictionaryValue* pref_data = update.Get();
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 300
300 const base::DictionaryValue* displays = 301 const base::DictionaryValue* displays =
301 local_state()->GetDictionary(prefs::kSecondaryDisplays); 302 local_state()->GetDictionary(prefs::kSecondaryDisplays);
302 const base::DictionaryValue* layout_value = nullptr; 303 const base::DictionaryValue* layout_value = nullptr;
303 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); 304 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2);
304 std::string dummy_key = 305 std::string dummy_key =
305 base::Int64ToString(id1) + "," + base::Int64ToString(dummy_id); 306 base::Int64ToString(id1) + "," + base::Int64ToString(dummy_id);
306 EXPECT_TRUE(displays->GetDictionary(dummy_key, &layout_value)); 307 EXPECT_TRUE(displays->GetDictionary(dummy_key, &layout_value));
307 308
308 ash::DisplayLayout stored_layout; 309 ash::DisplayLayout stored_layout;
309 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*layout_value, 310 EXPECT_TRUE(ash::JsonToDisplayLayout(*layout_value, &stored_layout));
310 &stored_layout));
311 ASSERT_EQ(1u, stored_layout.placement_list.size()); 311 ASSERT_EQ(1u, stored_layout.placement_list.size());
312 312
313 EXPECT_EQ(dummy_layout->placement_list[0]->position, 313 EXPECT_EQ(dummy_layout->placement_list[0]->position,
314 stored_layout.placement_list[0]->position); 314 stored_layout.placement_list[0]->position);
315 EXPECT_EQ(dummy_layout->placement_list[0]->offset, 315 EXPECT_EQ(dummy_layout->placement_list[0]->offset,
316 stored_layout.placement_list[0]->offset); 316 stored_layout.placement_list[0]->offset);
317 317
318 bool mirrored = true; 318 bool mirrored = true;
319 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored)); 319 EXPECT_TRUE(layout_value->GetBoolean(kMirroredKey, &mirrored));
320 EXPECT_FALSE(mirrored); 320 EXPECT_FALSE(mirrored);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 EXPECT_TRUE(property->GetInteger("height", &height)); 394 EXPECT_TRUE(property->GetInteger("height", &height));
395 EXPECT_TRUE(property->GetInteger( 395 EXPECT_TRUE(property->GetInteger(
396 "device-scale-factor", &device_scale_factor)); 396 "device-scale-factor", &device_scale_factor));
397 EXPECT_EQ(300, width); 397 EXPECT_EQ(300, width);
398 EXPECT_EQ(200, height); 398 EXPECT_EQ(200, height);
399 EXPECT_EQ(1250, device_scale_factor); 399 EXPECT_EQ(1250, device_scale_factor);
400 400
401 // The layout is swapped. 401 // The layout is swapped.
402 EXPECT_TRUE(displays->GetDictionary(key, &layout_value)); 402 EXPECT_TRUE(displays->GetDictionary(key, &layout_value));
403 403
404 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*layout_value, 404 EXPECT_TRUE(ash::JsonToDisplayLayout(*layout_value, &stored_layout));
405 &stored_layout));
406 ASSERT_EQ(1u, stored_layout.placement_list.size()); 405 ASSERT_EQ(1u, stored_layout.placement_list.size());
407 const ash::DisplayPlacement& stored_placement = 406 const ash::DisplayPlacement& stored_placement =
408 *stored_layout.placement_list[0]; 407 *stored_layout.placement_list[0];
409 EXPECT_EQ(ash::DisplayPlacement::BOTTOM, stored_placement.position); 408 EXPECT_EQ(ash::DisplayPlacement::BOTTOM, stored_placement.position);
410 EXPECT_EQ(-10, stored_placement.offset); 409 EXPECT_EQ(-10, stored_placement.offset);
411 EXPECT_EQ(id1, stored_placement.display_id); 410 EXPECT_EQ(id1, stored_placement.display_id);
412 EXPECT_EQ(id2, stored_placement.parent_display_id); 411 EXPECT_EQ(id2, stored_placement.parent_display_id);
413 EXPECT_EQ(id2, stored_layout.primary_id); 412 EXPECT_EQ(id2, stored_layout.primary_id);
414 413
415 if (true) 414 if (true)
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 ASSERT_EQ(id1, ash::ScreenUtil::GetSecondaryDisplay().id()); 571 ASSERT_EQ(id1, ash::ScreenUtil::GetSecondaryDisplay().id());
573 572
574 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2); 573 std::string key = base::Int64ToString(id1) + "," + base::Int64ToString(id2);
575 const base::DictionaryValue* displays = 574 const base::DictionaryValue* displays =
576 local_state()->GetDictionary(prefs::kSecondaryDisplays); 575 local_state()->GetDictionary(prefs::kSecondaryDisplays);
577 // Initial saved value is swapped. 576 // Initial saved value is swapped.
578 { 577 {
579 const base::DictionaryValue* new_value = nullptr; 578 const base::DictionaryValue* new_value = nullptr;
580 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); 579 EXPECT_TRUE(displays->GetDictionary(key, &new_value));
581 ash::DisplayLayout stored_layout; 580 ash::DisplayLayout stored_layout;
582 EXPECT_TRUE( 581 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
583 ash::DisplayLayout::ConvertFromValue(*new_value, &stored_layout));
584 ASSERT_EQ(1u, stored_layout.placement_list.size()); 582 ASSERT_EQ(1u, stored_layout.placement_list.size());
585 const ash::DisplayPlacement& stored_placement = 583 const ash::DisplayPlacement& stored_placement =
586 *stored_layout.placement_list[0]; 584 *stored_layout.placement_list[0];
587 EXPECT_EQ(ash::DisplayPlacement::LEFT, stored_placement.position); 585 EXPECT_EQ(ash::DisplayPlacement::LEFT, stored_placement.position);
588 EXPECT_EQ(0, stored_placement.offset); 586 EXPECT_EQ(0, stored_placement.offset);
589 EXPECT_EQ(id1, stored_placement.display_id); 587 EXPECT_EQ(id1, stored_placement.display_id);
590 EXPECT_EQ(id2, stored_placement.parent_display_id); 588 EXPECT_EQ(id2, stored_placement.parent_display_id);
591 EXPECT_EQ(id2, stored_layout.primary_id); 589 EXPECT_EQ(id2, stored_layout.primary_id);
592 } 590 }
593 591
594 // Updating layout with primary swapped should save the correct value. 592 // Updating layout with primary swapped should save the correct value.
595 { 593 {
596 ash::Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays( 594 ash::Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
597 ash::test::CreateDisplayLayout(ash::DisplayPlacement::TOP, 10)); 595 ash::test::CreateDisplayLayout(ash::DisplayPlacement::TOP, 10));
598 const base::DictionaryValue* new_value = nullptr; 596 const base::DictionaryValue* new_value = nullptr;
599 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); 597 EXPECT_TRUE(displays->GetDictionary(key, &new_value));
600 ash::DisplayLayout stored_layout; 598 ash::DisplayLayout stored_layout;
601 EXPECT_TRUE( 599 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
602 ash::DisplayLayout::ConvertFromValue(*new_value, &stored_layout));
603 ASSERT_EQ(1u, stored_layout.placement_list.size()); 600 ASSERT_EQ(1u, stored_layout.placement_list.size());
604 const ash::DisplayPlacement& stored_placement = 601 const ash::DisplayPlacement& stored_placement =
605 *stored_layout.placement_list[0]; 602 *stored_layout.placement_list[0];
606 EXPECT_EQ(ash::DisplayPlacement::TOP, stored_placement.position); 603 EXPECT_EQ(ash::DisplayPlacement::TOP, stored_placement.position);
607 EXPECT_EQ(10, stored_placement.offset); 604 EXPECT_EQ(10, stored_placement.offset);
608 EXPECT_EQ(id1, stored_placement.display_id); 605 EXPECT_EQ(id1, stored_placement.display_id);
609 EXPECT_EQ(id2, stored_placement.parent_display_id); 606 EXPECT_EQ(id2, stored_placement.parent_display_id);
610 EXPECT_EQ(id2, stored_layout.primary_id); 607 EXPECT_EQ(id2, stored_layout.primary_id);
611 } 608 }
612 609
613 // Swapping primary will save the swapped value. 610 // Swapping primary will save the swapped value.
614 { 611 {
615 ash::test::SwapPrimaryDisplay(); 612 ash::test::SwapPrimaryDisplay();
616 const base::DictionaryValue* new_value = nullptr; 613 const base::DictionaryValue* new_value = nullptr;
617 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); 614 EXPECT_TRUE(displays->GetDictionary(key, &new_value));
618 ash::DisplayLayout stored_layout; 615 ash::DisplayLayout stored_layout;
619 616
620 EXPECT_TRUE(displays->GetDictionary(key, &new_value)); 617 EXPECT_TRUE(displays->GetDictionary(key, &new_value));
621 EXPECT_TRUE( 618 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
622 ash::DisplayLayout::ConvertFromValue(*new_value, &stored_layout));
623 ASSERT_EQ(1u, stored_layout.placement_list.size()); 619 ASSERT_EQ(1u, stored_layout.placement_list.size());
624 const ash::DisplayPlacement& stored_placement = 620 const ash::DisplayPlacement& stored_placement =
625 *stored_layout.placement_list[0]; 621 *stored_layout.placement_list[0];
626 EXPECT_EQ(ash::DisplayPlacement::BOTTOM, stored_placement.position); 622 EXPECT_EQ(ash::DisplayPlacement::BOTTOM, stored_placement.position);
627 EXPECT_EQ(-10, stored_placement.offset); 623 EXPECT_EQ(-10, stored_placement.offset);
628 EXPECT_EQ(id2, stored_placement.display_id); 624 EXPECT_EQ(id2, stored_placement.display_id);
629 EXPECT_EQ(id1, stored_placement.parent_display_id); 625 EXPECT_EQ(id1, stored_placement.parent_display_id);
630 EXPECT_EQ(id1, stored_layout.primary_id); 626 EXPECT_EQ(id1, stored_layout.primary_id);
631 } 627 }
632 } 628 }
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 EXPECT_EQ("400x200", 965 EXPECT_EQ("400x200",
970 gfx::Screen::GetScreen()->GetPrimaryDisplay().size().ToString()); 966 gfx::Screen::GetScreen()->GetPrimaryDisplay().size().ToString());
971 967
972 const base::DictionaryValue* secondary_displays = 968 const base::DictionaryValue* secondary_displays =
973 local_state()->GetDictionary(prefs::kSecondaryDisplays); 969 local_state()->GetDictionary(prefs::kSecondaryDisplays);
974 const base::DictionaryValue* new_value = nullptr; 970 const base::DictionaryValue* new_value = nullptr;
975 EXPECT_TRUE(secondary_displays->GetDictionary( 971 EXPECT_TRUE(secondary_displays->GetDictionary(
976 ash::DisplayIdListToString(list), &new_value)); 972 ash::DisplayIdListToString(list), &new_value));
977 973
978 ash::DisplayLayout stored_layout; 974 ash::DisplayLayout stored_layout;
979 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*new_value, &stored_layout)); 975 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
980 EXPECT_TRUE(stored_layout.default_unified); 976 EXPECT_TRUE(stored_layout.default_unified);
981 EXPECT_FALSE(stored_layout.mirrored); 977 EXPECT_FALSE(stored_layout.mirrored);
982 978
983 const base::DictionaryValue* displays = 979 const base::DictionaryValue* displays =
984 local_state()->GetDictionary(prefs::kDisplayProperties); 980 local_state()->GetDictionary(prefs::kDisplayProperties);
985 int64_t unified_id = gfx::Screen::GetScreen()->GetPrimaryDisplay().id(); 981 int64_t unified_id = gfx::Screen::GetScreen()->GetPrimaryDisplay().id();
986 EXPECT_FALSE( 982 EXPECT_FALSE(
987 displays->GetDictionary(base::Int64ToString(unified_id), &new_value)); 983 displays->GetDictionary(base::Int64ToString(unified_id), &new_value));
988 984
989 ash::test::SetDisplayResolution(unified_id, gfx::Size(200, 100)); 985 ash::test::SetDisplayResolution(unified_id, gfx::Size(200, 100));
990 EXPECT_EQ("200x100", 986 EXPECT_EQ("200x100",
991 gfx::Screen::GetScreen()->GetPrimaryDisplay().size().ToString()); 987 gfx::Screen::GetScreen()->GetPrimaryDisplay().size().ToString());
992 EXPECT_FALSE( 988 EXPECT_FALSE(
993 displays->GetDictionary(base::Int64ToString(unified_id), &new_value)); 989 displays->GetDictionary(base::Int64ToString(unified_id), &new_value));
994 990
995 // Mirror mode should remember if the default mode was unified. 991 // Mirror mode should remember if the default mode was unified.
996 display_manager->SetMirrorMode(true); 992 display_manager->SetMirrorMode(true);
997 ASSERT_TRUE(secondary_displays->GetDictionary( 993 ASSERT_TRUE(secondary_displays->GetDictionary(
998 ash::DisplayIdListToString(list), &new_value)); 994 ash::DisplayIdListToString(list), &new_value));
999 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*new_value, &stored_layout)); 995 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
1000 EXPECT_TRUE(stored_layout.default_unified); 996 EXPECT_TRUE(stored_layout.default_unified);
1001 EXPECT_TRUE(stored_layout.mirrored); 997 EXPECT_TRUE(stored_layout.mirrored);
1002 998
1003 display_manager->SetMirrorMode(false); 999 display_manager->SetMirrorMode(false);
1004 ASSERT_TRUE(secondary_displays->GetDictionary( 1000 ASSERT_TRUE(secondary_displays->GetDictionary(
1005 ash::DisplayIdListToString(list), &new_value)); 1001 ash::DisplayIdListToString(list), &new_value));
1006 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*new_value, &stored_layout)); 1002 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
1007 EXPECT_TRUE(stored_layout.default_unified); 1003 EXPECT_TRUE(stored_layout.default_unified);
1008 EXPECT_FALSE(stored_layout.mirrored); 1004 EXPECT_FALSE(stored_layout.mirrored);
1009 1005
1010 // Exit unified mode. 1006 // Exit unified mode.
1011 display_manager->SetDefaultMultiDisplayModeForCurrentDisplays( 1007 display_manager->SetDefaultMultiDisplayModeForCurrentDisplays(
1012 ash::DisplayManager::EXTENDED); 1008 ash::DisplayManager::EXTENDED);
1013 ASSERT_TRUE(secondary_displays->GetDictionary( 1009 ASSERT_TRUE(secondary_displays->GetDictionary(
1014 ash::DisplayIdListToString(list), &new_value)); 1010 ash::DisplayIdListToString(list), &new_value));
1015 EXPECT_TRUE(ash::DisplayLayout::ConvertFromValue(*new_value, &stored_layout)); 1011 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
1016 EXPECT_FALSE(stored_layout.default_unified); 1012 EXPECT_FALSE(stored_layout.default_unified);
1017 EXPECT_FALSE(stored_layout.mirrored); 1013 EXPECT_FALSE(stored_layout.mirrored);
1018 } 1014 }
1019 1015
1020 TEST_F(DisplayPreferencesTest, RestoreUnifiedMode) { 1016 TEST_F(DisplayPreferencesTest, RestoreUnifiedMode) {
1021 int64_t id1 = gfx::Screen::GetScreen()->GetPrimaryDisplay().id(); 1017 int64_t id1 = gfx::Screen::GetScreen()->GetPrimaryDisplay().id();
1022 ash::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, id1 + 1); 1018 ash::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, id1 + 1);
1023 StoreDisplayBoolPropertyForList(list, "default_unified", true); 1019 StoreDisplayBoolPropertyForList(list, "default_unified", true);
1024 StoreDisplayPropertyForList( 1020 StoreDisplayPropertyForList(
1025 list, "primary-id", 1021 list, "primary-id",
(...skipping 26 matching lines...) Expand all
1052 // Sanity check. Restore to extended. 1048 // Sanity check. Restore to extended.
1053 StoreDisplayBoolPropertyForList(list, "default_unified", false); 1049 StoreDisplayBoolPropertyForList(list, "default_unified", false);
1054 StoreDisplayBoolPropertyForList(list, "mirrored", false); 1050 StoreDisplayBoolPropertyForList(list, "mirrored", false);
1055 LoadDisplayPreferences(false); 1051 LoadDisplayPreferences(false);
1056 UpdateDisplay("100x100,200x200"); 1052 UpdateDisplay("100x100,200x200");
1057 EXPECT_FALSE(display_manager->IsInMirrorMode()); 1053 EXPECT_FALSE(display_manager->IsInMirrorMode());
1058 EXPECT_FALSE(display_manager->IsInUnifiedMode()); 1054 EXPECT_FALSE(display_manager->IsInUnifiedMode());
1059 } 1055 }
1060 1056
1061 } // namespace chromeos 1057 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/display/display_preferences.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698