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

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

Issue 2286523002: Relocate reuseable portions of ash/display/display_util.* (Closed)
Patch Set: fixed ozone build Created 4 years, 3 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') | ui/display/BUILD.gn » ('j') | 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 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 19 matching lines...) Expand all
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"
32 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 32 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
33 #include "chrome/common/pref_names.h" 33 #include "chrome/common/pref_names.h"
34 #include "chrome/test/base/testing_browser_process.h" 34 #include "chrome/test/base/testing_browser_process.h"
35 #include "components/prefs/scoped_user_pref_update.h" 35 #include "components/prefs/scoped_user_pref_update.h"
36 #include "components/prefs/testing_pref_service.h" 36 #include "components/prefs/testing_pref_service.h"
37 #include "ui/display/chromeos/display_configurator.h" 37 #include "ui/display/chromeos/display_configurator.h"
38 #include "ui/display/manager/display_layout_builder.h" 38 #include "ui/display/manager/display_layout_builder.h"
39 #include "ui/display/manager/display_layout_store.h" 39 #include "ui/display/manager/display_layout_store.h"
40 #include "ui/display/manager/display_manager_utilities.h"
40 #include "ui/display/screen.h" 41 #include "ui/display/screen.h"
41 #include "ui/gfx/geometry/vector3d_f.h" 42 #include "ui/gfx/geometry/vector3d_f.h"
42 #include "ui/message_center/message_center.h" 43 #include "ui/message_center/message_center.h"
43 44
44 using ash::ResolutionNotificationController; 45 using ash::ResolutionNotificationController;
45 46
46 namespace chromeos { 47 namespace chromeos {
47 namespace { 48 namespace {
48 const char kPrimaryIdKey[] = "primary-id"; 49 const char kPrimaryIdKey[] = "primary-id";
49 const char kMirroredKey[] = "mirrored"; 50 const char kMirroredKey[] = "mirrored";
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 .WillRepeatedly(testing::Return(false)); 103 .WillRepeatedly(testing::Return(false));
103 } 104 }
104 105
105 // Do not use the implementation of display_preferences.cc directly to avoid 106 // Do not use the implementation of display_preferences.cc directly to avoid
106 // notifying the update to the system. 107 // notifying the update to the system.
107 void StoreDisplayLayoutPrefForList( 108 void StoreDisplayLayoutPrefForList(
108 const display::DisplayIdList& list, 109 const display::DisplayIdList& list,
109 display::DisplayPlacement::Position position, 110 display::DisplayPlacement::Position position,
110 int offset, 111 int offset,
111 int64_t primary_id) { 112 int64_t primary_id) {
112 std::string name = ash::DisplayIdListToString(list); 113 std::string name = display::DisplayIdListToString(list);
113 DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays); 114 DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays);
114 display::DisplayLayout display_layout; 115 display::DisplayLayout display_layout;
115 display_layout.placement_list.emplace_back(position, offset); 116 display_layout.placement_list.emplace_back(position, offset);
116 display_layout.primary_id = primary_id; 117 display_layout.primary_id = primary_id;
117 118
118 DCHECK(!name.empty()); 119 DCHECK(!name.empty());
119 120
120 base::DictionaryValue* pref_data = update.Get(); 121 base::DictionaryValue* pref_data = update.Get();
121 std::unique_ptr<base::Value> layout_value(new base::DictionaryValue()); 122 std::unique_ptr<base::Value> layout_value(new base::DictionaryValue());
122 if (pref_data->HasKey(name)) { 123 if (pref_data->HasKey(name)) {
123 base::Value* value = nullptr; 124 base::Value* value = nullptr;
124 if (pref_data->Get(name, &value) && value != nullptr) 125 if (pref_data->Get(name, &value) && value != nullptr)
125 layout_value.reset(value->DeepCopy()); 126 layout_value.reset(value->DeepCopy());
126 } 127 }
127 if (ash::DisplayLayoutToJson(display_layout, layout_value.get())) 128 if (ash::DisplayLayoutToJson(display_layout, layout_value.get()))
128 pref_data->Set(name, layout_value.release()); 129 pref_data->Set(name, layout_value.release());
129 } 130 }
130 131
131 void StoreDisplayPropertyForList(const display::DisplayIdList& list, 132 void StoreDisplayPropertyForList(const display::DisplayIdList& list,
132 std::string key, 133 std::string key,
133 std::unique_ptr<base::Value> value) { 134 std::unique_ptr<base::Value> value) {
134 std::string name = ash::DisplayIdListToString(list); 135 std::string name = display::DisplayIdListToString(list);
135 136
136 DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays); 137 DictionaryPrefUpdate update(&local_state_, prefs::kSecondaryDisplays);
137 base::DictionaryValue* pref_data = update.Get(); 138 base::DictionaryValue* pref_data = update.Get();
138 139
139 if (pref_data->HasKey(name)) { 140 if (pref_data->HasKey(name)) {
140 base::Value* layout_value = nullptr; 141 base::Value* layout_value = nullptr;
141 pref_data->Get(name, &layout_value); 142 pref_data->Get(name, &layout_value);
142 if (layout_value) 143 if (layout_value)
143 static_cast<base::DictionaryValue*>(layout_value) 144 static_cast<base::DictionaryValue*>(layout_value)
144 ->Set(key, std::move(value)); 145 ->Set(key, std::move(value));
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 UpdateDisplay("200x200,100x100"); 981 UpdateDisplay("200x200,100x100");
981 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); 982 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList();
982 EXPECT_EQ( 983 EXPECT_EQ(
983 "400x200", 984 "400x200",
984 display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString()); 985 display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString());
985 986
986 const base::DictionaryValue* secondary_displays = 987 const base::DictionaryValue* secondary_displays =
987 local_state()->GetDictionary(prefs::kSecondaryDisplays); 988 local_state()->GetDictionary(prefs::kSecondaryDisplays);
988 const base::DictionaryValue* new_value = nullptr; 989 const base::DictionaryValue* new_value = nullptr;
989 EXPECT_TRUE(secondary_displays->GetDictionary( 990 EXPECT_TRUE(secondary_displays->GetDictionary(
990 ash::DisplayIdListToString(list), &new_value)); 991 display::DisplayIdListToString(list), &new_value));
991 992
992 display::DisplayLayout stored_layout; 993 display::DisplayLayout stored_layout;
993 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 994 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
994 EXPECT_TRUE(stored_layout.default_unified); 995 EXPECT_TRUE(stored_layout.default_unified);
995 EXPECT_FALSE(stored_layout.mirrored); 996 EXPECT_FALSE(stored_layout.mirrored);
996 997
997 const base::DictionaryValue* displays = 998 const base::DictionaryValue* displays =
998 local_state()->GetDictionary(prefs::kDisplayProperties); 999 local_state()->GetDictionary(prefs::kDisplayProperties);
999 int64_t unified_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 1000 int64_t unified_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
1000 EXPECT_FALSE( 1001 EXPECT_FALSE(
1001 displays->GetDictionary(base::Int64ToString(unified_id), &new_value)); 1002 displays->GetDictionary(base::Int64ToString(unified_id), &new_value));
1002 1003
1003 ash::test::SetDisplayResolution(unified_id, gfx::Size(200, 100)); 1004 ash::test::SetDisplayResolution(unified_id, gfx::Size(200, 100));
1004 EXPECT_EQ( 1005 EXPECT_EQ(
1005 "200x100", 1006 "200x100",
1006 display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString()); 1007 display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString());
1007 EXPECT_FALSE( 1008 EXPECT_FALSE(
1008 displays->GetDictionary(base::Int64ToString(unified_id), &new_value)); 1009 displays->GetDictionary(base::Int64ToString(unified_id), &new_value));
1009 1010
1010 // Mirror mode should remember if the default mode was unified. 1011 // Mirror mode should remember if the default mode was unified.
1011 display_manager->SetMirrorMode(true); 1012 display_manager->SetMirrorMode(true);
1012 ASSERT_TRUE(secondary_displays->GetDictionary( 1013 ASSERT_TRUE(secondary_displays->GetDictionary(
1013 ash::DisplayIdListToString(list), &new_value)); 1014 display::DisplayIdListToString(list), &new_value));
1014 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 1015 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
1015 EXPECT_TRUE(stored_layout.default_unified); 1016 EXPECT_TRUE(stored_layout.default_unified);
1016 EXPECT_TRUE(stored_layout.mirrored); 1017 EXPECT_TRUE(stored_layout.mirrored);
1017 1018
1018 display_manager->SetMirrorMode(false); 1019 display_manager->SetMirrorMode(false);
1019 ASSERT_TRUE(secondary_displays->GetDictionary( 1020 ASSERT_TRUE(secondary_displays->GetDictionary(
1020 ash::DisplayIdListToString(list), &new_value)); 1021 display::DisplayIdListToString(list), &new_value));
1021 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 1022 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
1022 EXPECT_TRUE(stored_layout.default_unified); 1023 EXPECT_TRUE(stored_layout.default_unified);
1023 EXPECT_FALSE(stored_layout.mirrored); 1024 EXPECT_FALSE(stored_layout.mirrored);
1024 1025
1025 // Exit unified mode. 1026 // Exit unified mode.
1026 display_manager->SetDefaultMultiDisplayModeForCurrentDisplays( 1027 display_manager->SetDefaultMultiDisplayModeForCurrentDisplays(
1027 ash::DisplayManager::EXTENDED); 1028 ash::DisplayManager::EXTENDED);
1028 ASSERT_TRUE(secondary_displays->GetDictionary( 1029 ASSERT_TRUE(secondary_displays->GetDictionary(
1029 ash::DisplayIdListToString(list), &new_value)); 1030 display::DisplayIdListToString(list), &new_value));
1030 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 1031 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
1031 EXPECT_FALSE(stored_layout.default_unified); 1032 EXPECT_FALSE(stored_layout.default_unified);
1032 EXPECT_FALSE(stored_layout.mirrored); 1033 EXPECT_FALSE(stored_layout.mirrored);
1033 } 1034 }
1034 1035
1035 TEST_F(DisplayPreferencesTest, RestoreUnifiedMode) { 1036 TEST_F(DisplayPreferencesTest, RestoreUnifiedMode) {
1036 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 1037 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id();
1037 display::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, id1 + 1); 1038 display::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, id1 + 1);
1038 StoreDisplayBoolPropertyForList(list, "default_unified", true); 1039 StoreDisplayBoolPropertyForList(list, "default_unified", true);
1039 StoreDisplayPropertyForList( 1040 StoreDisplayPropertyForList(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 builder.AddDisplayPlacement(list[1], list[0], 1087 builder.AddDisplayPlacement(list[1], list[0],
1087 display::DisplayPlacement::RIGHT, 0); 1088 display::DisplayPlacement::RIGHT, 0);
1088 builder.AddDisplayPlacement(list[2], list[0], 1089 builder.AddDisplayPlacement(list[2], list[0],
1089 display::DisplayPlacement::BOTTOM, 100); 1090 display::DisplayPlacement::BOTTOM, 100);
1090 display_manager->SetLayoutForCurrentDisplays(builder.Build()); 1091 display_manager->SetLayoutForCurrentDisplays(builder.Build());
1091 1092
1092 const base::DictionaryValue* secondary_displays = 1093 const base::DictionaryValue* secondary_displays =
1093 local_state()->GetDictionary(prefs::kSecondaryDisplays); 1094 local_state()->GetDictionary(prefs::kSecondaryDisplays);
1094 const base::DictionaryValue* new_value = nullptr; 1095 const base::DictionaryValue* new_value = nullptr;
1095 EXPECT_TRUE(secondary_displays->GetDictionary( 1096 EXPECT_TRUE(secondary_displays->GetDictionary(
1096 ash::DisplayIdListToString(list), &new_value)); 1097 display::DisplayIdListToString(list), &new_value));
1097 } 1098 }
1098 1099
1099 TEST_F(DisplayPreferencesTest, RestoreThreeDisplays) { 1100 TEST_F(DisplayPreferencesTest, RestoreThreeDisplays) {
1100 LoggedInAsUser(); 1101 LoggedInAsUser();
1101 ash::DisplayManager* display_manager = 1102 ash::DisplayManager* display_manager =
1102 ash::Shell::GetInstance()->display_manager(); 1103 ash::Shell::GetInstance()->display_manager();
1103 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 1104 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id();
1104 display::DisplayIdList list = 1105 display::DisplayIdList list =
1105 ash::test::CreateDisplayIdListN(3, id1, id1 + 1, id1 + 2); 1106 ash::test::CreateDisplayIdListN(3, id1, id1 + 1, id1 + 2);
1106 1107
(...skipping 14 matching lines...) Expand all
1121 1122
1122 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), 1123 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
1123 display_manager->GetDisplayForId(list[0]).bounds()); 1124 display_manager->GetDisplayForId(list[0]).bounds());
1124 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200), 1125 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200),
1125 display_manager->GetDisplayForId(list[1]).bounds()); 1126 display_manager->GetDisplayForId(list[1]).bounds());
1126 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300), 1127 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300),
1127 display_manager->GetDisplayForId(list[2]).bounds()); 1128 display_manager->GetDisplayForId(list[2]).bounds());
1128 } 1129 }
1129 1130
1130 } // namespace chromeos 1131 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/display/display_preferences.cc ('k') | ui/display/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698