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

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
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 = ui::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 = ui::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 832 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 978
978 UpdateDisplay("200x200,100x100"); 979 UpdateDisplay("200x200,100x100");
979 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); 980 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList();
980 EXPECT_EQ( 981 EXPECT_EQ(
981 "400x200", 982 "400x200",
982 display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString()); 983 display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString());
983 984
984 const base::DictionaryValue* secondary_displays = 985 const base::DictionaryValue* secondary_displays =
985 local_state()->GetDictionary(prefs::kSecondaryDisplays); 986 local_state()->GetDictionary(prefs::kSecondaryDisplays);
986 const base::DictionaryValue* new_value = nullptr; 987 const base::DictionaryValue* new_value = nullptr;
987 EXPECT_TRUE(secondary_displays->GetDictionary( 988 EXPECT_TRUE(secondary_displays->GetDictionary(ui::DisplayIdListToString(list),
988 ash::DisplayIdListToString(list), &new_value)); 989 &new_value));
989 990
990 display::DisplayLayout stored_layout; 991 display::DisplayLayout stored_layout;
991 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 992 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
992 EXPECT_TRUE(stored_layout.default_unified); 993 EXPECT_TRUE(stored_layout.default_unified);
993 EXPECT_FALSE(stored_layout.mirrored); 994 EXPECT_FALSE(stored_layout.mirrored);
994 995
995 const base::DictionaryValue* displays = 996 const base::DictionaryValue* displays =
996 local_state()->GetDictionary(prefs::kDisplayProperties); 997 local_state()->GetDictionary(prefs::kDisplayProperties);
997 int64_t unified_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 998 int64_t unified_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
998 EXPECT_FALSE( 999 EXPECT_FALSE(
999 displays->GetDictionary(base::Int64ToString(unified_id), &new_value)); 1000 displays->GetDictionary(base::Int64ToString(unified_id), &new_value));
1000 1001
1001 ash::test::SetDisplayResolution(unified_id, gfx::Size(200, 100)); 1002 ash::test::SetDisplayResolution(unified_id, gfx::Size(200, 100));
1002 EXPECT_EQ( 1003 EXPECT_EQ(
1003 "200x100", 1004 "200x100",
1004 display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString()); 1005 display::Screen::GetScreen()->GetPrimaryDisplay().size().ToString());
1005 EXPECT_FALSE( 1006 EXPECT_FALSE(
1006 displays->GetDictionary(base::Int64ToString(unified_id), &new_value)); 1007 displays->GetDictionary(base::Int64ToString(unified_id), &new_value));
1007 1008
1008 // Mirror mode should remember if the default mode was unified. 1009 // Mirror mode should remember if the default mode was unified.
1009 display_manager->SetMirrorMode(true); 1010 display_manager->SetMirrorMode(true);
1010 ASSERT_TRUE(secondary_displays->GetDictionary( 1011 ASSERT_TRUE(secondary_displays->GetDictionary(ui::DisplayIdListToString(list),
1011 ash::DisplayIdListToString(list), &new_value)); 1012 &new_value));
1012 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 1013 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
1013 EXPECT_TRUE(stored_layout.default_unified); 1014 EXPECT_TRUE(stored_layout.default_unified);
1014 EXPECT_TRUE(stored_layout.mirrored); 1015 EXPECT_TRUE(stored_layout.mirrored);
1015 1016
1016 display_manager->SetMirrorMode(false); 1017 display_manager->SetMirrorMode(false);
1017 ASSERT_TRUE(secondary_displays->GetDictionary( 1018 ASSERT_TRUE(secondary_displays->GetDictionary(ui::DisplayIdListToString(list),
1018 ash::DisplayIdListToString(list), &new_value)); 1019 &new_value));
1019 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 1020 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
1020 EXPECT_TRUE(stored_layout.default_unified); 1021 EXPECT_TRUE(stored_layout.default_unified);
1021 EXPECT_FALSE(stored_layout.mirrored); 1022 EXPECT_FALSE(stored_layout.mirrored);
1022 1023
1023 // Exit unified mode. 1024 // Exit unified mode.
1024 display_manager->SetDefaultMultiDisplayModeForCurrentDisplays( 1025 display_manager->SetDefaultMultiDisplayModeForCurrentDisplays(
1025 ash::DisplayManager::EXTENDED); 1026 ash::DisplayManager::EXTENDED);
1026 ASSERT_TRUE(secondary_displays->GetDictionary( 1027 ASSERT_TRUE(secondary_displays->GetDictionary(ui::DisplayIdListToString(list),
1027 ash::DisplayIdListToString(list), &new_value)); 1028 &new_value));
1028 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout)); 1029 EXPECT_TRUE(ash::JsonToDisplayLayout(*new_value, &stored_layout));
1029 EXPECT_FALSE(stored_layout.default_unified); 1030 EXPECT_FALSE(stored_layout.default_unified);
1030 EXPECT_FALSE(stored_layout.mirrored); 1031 EXPECT_FALSE(stored_layout.mirrored);
1031 } 1032 }
1032 1033
1033 TEST_F(DisplayPreferencesTest, RestoreUnifiedMode) { 1034 TEST_F(DisplayPreferencesTest, RestoreUnifiedMode) {
1034 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 1035 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id();
1035 display::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, id1 + 1); 1036 display::DisplayIdList list = ash::test::CreateDisplayIdList2(id1, id1 + 1);
1036 StoreDisplayBoolPropertyForList(list, "default_unified", true); 1037 StoreDisplayBoolPropertyForList(list, "default_unified", true);
1037 StoreDisplayPropertyForList( 1038 StoreDisplayPropertyForList(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 display::DisplayLayoutBuilder builder(list[0]); 1084 display::DisplayLayoutBuilder builder(list[0]);
1084 builder.AddDisplayPlacement(list[1], list[0], 1085 builder.AddDisplayPlacement(list[1], list[0],
1085 display::DisplayPlacement::RIGHT, 0); 1086 display::DisplayPlacement::RIGHT, 0);
1086 builder.AddDisplayPlacement(list[2], list[0], 1087 builder.AddDisplayPlacement(list[2], list[0],
1087 display::DisplayPlacement::BOTTOM, 100); 1088 display::DisplayPlacement::BOTTOM, 100);
1088 display_manager->SetLayoutForCurrentDisplays(builder.Build()); 1089 display_manager->SetLayoutForCurrentDisplays(builder.Build());
1089 1090
1090 const base::DictionaryValue* secondary_displays = 1091 const base::DictionaryValue* secondary_displays =
1091 local_state()->GetDictionary(prefs::kSecondaryDisplays); 1092 local_state()->GetDictionary(prefs::kSecondaryDisplays);
1092 const base::DictionaryValue* new_value = nullptr; 1093 const base::DictionaryValue* new_value = nullptr;
1093 EXPECT_TRUE(secondary_displays->GetDictionary( 1094 EXPECT_TRUE(secondary_displays->GetDictionary(ui::DisplayIdListToString(list),
1094 ash::DisplayIdListToString(list), &new_value)); 1095 &new_value));
1095 } 1096 }
1096 1097
1097 TEST_F(DisplayPreferencesTest, RestoreThreeDisplays) { 1098 TEST_F(DisplayPreferencesTest, RestoreThreeDisplays) {
1098 LoggedInAsUser(); 1099 LoggedInAsUser();
1099 ash::DisplayManager* display_manager = 1100 ash::DisplayManager* display_manager =
1100 ash::Shell::GetInstance()->display_manager(); 1101 ash::Shell::GetInstance()->display_manager();
1101 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 1102 int64_t id1 = display::Screen::GetScreen()->GetPrimaryDisplay().id();
1102 display::DisplayIdList list = 1103 display::DisplayIdList list =
1103 ash::test::CreateDisplayIdListN(3, id1, id1 + 1, id1 + 2); 1104 ash::test::CreateDisplayIdListN(3, id1, id1 + 1, id1 + 2);
1104 1105
(...skipping 14 matching lines...) Expand all
1119 1120
1120 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), 1121 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
1121 display_manager->GetDisplayForId(list[0]).bounds()); 1122 display_manager->GetDisplayForId(list[0]).bounds());
1122 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200), 1123 EXPECT_EQ(gfx::Rect(-200, 0, 200, 200),
1123 display_manager->GetDisplayForId(list[1]).bounds()); 1124 display_manager->GetDisplayForId(list[1]).bounds());
1124 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300), 1125 EXPECT_EQ(gfx::Rect(-100, 200, 300, 300),
1125 display_manager->GetDisplayForId(list[2]).bounds()); 1126 display_manager->GetDisplayForId(list[2]).bounds());
1126 } 1127 }
1127 1128
1128 } // namespace chromeos 1129 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698