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

Side by Side Diff: chrome/browser/chromeos/settings/cros_settings_unittest.cc

Issue 2476493003: Remove FundamentalValue
Patch Set: Fix Created 4 years, 1 month 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/settings/cros_settings.h" 5 #include "chrome/browser/chromeos/settings/cros_settings.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 ScopedDeviceSettingsTestHelper device_settings_test_helper_; 97 ScopedDeviceSettingsTestHelper device_settings_test_helper_;
98 CrosSettings settings_; 98 CrosSettings settings_;
99 99
100 std::map<std::string, std::unique_ptr<base::Value>> expected_props_; 100 std::map<std::string, std::unique_ptr<base::Value>> expected_props_;
101 101
102 base::WeakPtrFactory<CrosSettingsTest> weak_factory_; 102 base::WeakPtrFactory<CrosSettingsTest> weak_factory_;
103 }; 103 };
104 104
105 TEST_F(CrosSettingsTest, SetPref) { 105 TEST_F(CrosSettingsTest, SetPref) {
106 // Change to something that is not the default. 106 // Change to something that is not the default.
107 AddExpectation(kAccountsPrefAllowGuest, 107 AddExpectation(kAccountsPrefAllowGuest, base::MakeUnique<base::Value>(false));
108 base::MakeUnique<base::FundamentalValue>(false));
109 SetPref(kAccountsPrefAllowGuest, 108 SetPref(kAccountsPrefAllowGuest,
110 expected_props_[kAccountsPrefAllowGuest].get()); 109 expected_props_[kAccountsPrefAllowGuest].get());
111 FetchPref(kAccountsPrefAllowGuest); 110 FetchPref(kAccountsPrefAllowGuest);
112 ASSERT_TRUE(expected_props_.empty()); 111 ASSERT_TRUE(expected_props_.empty());
113 } 112 }
114 113
115 TEST_F(CrosSettingsTest, GetPref) { 114 TEST_F(CrosSettingsTest, GetPref) {
116 // We didn't change the default so look for it. 115 // We didn't change the default so look for it.
117 AddExpectation(kAccountsPrefAllowGuest, 116 AddExpectation(kAccountsPrefAllowGuest, base::MakeUnique<base::Value>(true));
118 base::MakeUnique<base::FundamentalValue>(true));
119 FetchPref(kAccountsPrefAllowGuest); 117 FetchPref(kAccountsPrefAllowGuest);
120 } 118 }
121 119
122 TEST_F(CrosSettingsTest, SetWhitelist) { 120 TEST_F(CrosSettingsTest, SetWhitelist) {
123 // Setting the whitelist should also switch the value of 121 // Setting the whitelist should also switch the value of
124 // kAccountsPrefAllowNewUser to false. 122 // kAccountsPrefAllowNewUser to false.
125 base::ListValue whitelist; 123 base::ListValue whitelist;
126 whitelist.AppendString("me@owner"); 124 whitelist.AppendString("me@owner");
127 AddExpectation(kAccountsPrefAllowNewUser, 125 AddExpectation(kAccountsPrefAllowNewUser,
128 base::MakeUnique<base::FundamentalValue>(false)); 126 base::MakeUnique<base::Value>(false));
129 AddExpectation(kAccountsPrefUsers, whitelist.CreateDeepCopy()); 127 AddExpectation(kAccountsPrefUsers, whitelist.CreateDeepCopy());
130 SetPref(kAccountsPrefUsers, &whitelist); 128 SetPref(kAccountsPrefUsers, &whitelist);
131 FetchPref(kAccountsPrefAllowNewUser); 129 FetchPref(kAccountsPrefAllowNewUser);
132 FetchPref(kAccountsPrefUsers); 130 FetchPref(kAccountsPrefUsers);
133 } 131 }
134 132
135 TEST_F(CrosSettingsTest, SetWhitelistWithListOps) { 133 TEST_F(CrosSettingsTest, SetWhitelistWithListOps) {
136 std::unique_ptr<base::ListValue> whitelist = 134 std::unique_ptr<base::ListValue> whitelist =
137 base::MakeUnique<base::ListValue>(); 135 base::MakeUnique<base::ListValue>();
138 base::StringValue hacky_user("h@xxor"); 136 base::StringValue hacky_user("h@xxor");
139 whitelist->Append(hacky_user.CreateDeepCopy()); 137 whitelist->Append(hacky_user.CreateDeepCopy());
140 AddExpectation(kAccountsPrefAllowNewUser, 138 AddExpectation(kAccountsPrefAllowNewUser,
141 base::MakeUnique<base::FundamentalValue>(false)); 139 base::MakeUnique<base::Value>(false));
142 AddExpectation(kAccountsPrefUsers, std::move(whitelist)); 140 AddExpectation(kAccountsPrefUsers, std::move(whitelist));
143 // Add some user to the whitelist. 141 // Add some user to the whitelist.
144 settings_.AppendToList(kAccountsPrefUsers, &hacky_user); 142 settings_.AppendToList(kAccountsPrefUsers, &hacky_user);
145 FetchPref(kAccountsPrefAllowNewUser); 143 FetchPref(kAccountsPrefAllowNewUser);
146 FetchPref(kAccountsPrefUsers); 144 FetchPref(kAccountsPrefUsers);
147 } 145 }
148 146
149 TEST_F(CrosSettingsTest, SetWhitelistWithListOps2) { 147 TEST_F(CrosSettingsTest, SetWhitelistWithListOps2) {
150 base::ListValue whitelist; 148 base::ListValue whitelist;
151 base::StringValue hacky_user("h@xxor"); 149 base::StringValue hacky_user("h@xxor");
152 base::StringValue lamy_user("l@mer"); 150 base::StringValue lamy_user("l@mer");
153 whitelist.Append(hacky_user.CreateDeepCopy()); 151 whitelist.Append(hacky_user.CreateDeepCopy());
154 std::unique_ptr<base::ListValue> expected_list = whitelist.CreateDeepCopy(); 152 std::unique_ptr<base::ListValue> expected_list = whitelist.CreateDeepCopy();
155 whitelist.Append(lamy_user.CreateDeepCopy()); 153 whitelist.Append(lamy_user.CreateDeepCopy());
156 AddExpectation(kAccountsPrefAllowNewUser, 154 AddExpectation(kAccountsPrefAllowNewUser,
157 base::MakeUnique<base::FundamentalValue>(false)); 155 base::MakeUnique<base::Value>(false));
158 AddExpectation(kAccountsPrefUsers, whitelist.CreateDeepCopy()); 156 AddExpectation(kAccountsPrefUsers, whitelist.CreateDeepCopy());
159 SetPref(kAccountsPrefUsers, &whitelist); 157 SetPref(kAccountsPrefUsers, &whitelist);
160 FetchPref(kAccountsPrefAllowNewUser); 158 FetchPref(kAccountsPrefAllowNewUser);
161 FetchPref(kAccountsPrefUsers); 159 FetchPref(kAccountsPrefUsers);
162 ASSERT_TRUE(expected_props_.empty()); 160 ASSERT_TRUE(expected_props_.empty());
163 // Now try to remove one element from that list. 161 // Now try to remove one element from that list.
164 AddExpectation(kAccountsPrefUsers, std::move(expected_list)); 162 AddExpectation(kAccountsPrefUsers, std::move(expected_list));
165 settings_.RemoveFromList(kAccountsPrefUsers, &lamy_user); 163 settings_.RemoveFromList(kAccountsPrefUsers, &lamy_user);
166 FetchPref(kAccountsPrefAllowNewUser); 164 FetchPref(kAccountsPrefAllowNewUser);
167 FetchPref(kAccountsPrefUsers); 165 FetchPref(kAccountsPrefUsers);
168 } 166 }
169 167
170 TEST_F(CrosSettingsTest, SetEmptyWhitelist) { 168 TEST_F(CrosSettingsTest, SetEmptyWhitelist) {
171 // Setting the whitelist empty should switch the value of 169 // Setting the whitelist empty should switch the value of
172 // kAccountsPrefAllowNewUser to true. 170 // kAccountsPrefAllowNewUser to true.
173 base::ListValue whitelist; 171 base::ListValue whitelist;
174 AddExpectation(kAccountsPrefAllowNewUser, 172 AddExpectation(kAccountsPrefAllowNewUser,
175 base::MakeUnique<base::FundamentalValue>(true)); 173 base::MakeUnique<base::Value>(true));
176 SetPref(kAccountsPrefUsers, &whitelist); 174 SetPref(kAccountsPrefUsers, &whitelist);
177 FetchPref(kAccountsPrefAllowNewUser); 175 FetchPref(kAccountsPrefAllowNewUser);
178 FetchPref(kAccountsPrefUsers); 176 FetchPref(kAccountsPrefUsers);
179 } 177 }
180 178
181 TEST_F(CrosSettingsTest, SetEmptyWhitelistAndNoNewUsers) { 179 TEST_F(CrosSettingsTest, SetEmptyWhitelistAndNoNewUsers) {
182 // Setting the whitelist empty and disallowing new users should result in no 180 // Setting the whitelist empty and disallowing new users should result in no
183 // new users allowed. 181 // new users allowed.
184 base::ListValue whitelist; 182 base::ListValue whitelist;
185 base::FundamentalValue disallow_new(false); 183 base::Value disallow_new(false);
186 AddExpectation(kAccountsPrefUsers, whitelist.CreateDeepCopy()); 184 AddExpectation(kAccountsPrefUsers, whitelist.CreateDeepCopy());
187 AddExpectation(kAccountsPrefAllowNewUser, 185 AddExpectation(kAccountsPrefAllowNewUser,
188 base::MakeUnique<base::FundamentalValue>(false)); 186 base::MakeUnique<base::Value>(false));
189 SetPref(kAccountsPrefUsers, &whitelist); 187 SetPref(kAccountsPrefUsers, &whitelist);
190 SetPref(kAccountsPrefAllowNewUser, &disallow_new); 188 SetPref(kAccountsPrefAllowNewUser, &disallow_new);
191 FetchPref(kAccountsPrefAllowNewUser); 189 FetchPref(kAccountsPrefAllowNewUser);
192 FetchPref(kAccountsPrefUsers); 190 FetchPref(kAccountsPrefUsers);
193 } 191 }
194 192
195 TEST_F(CrosSettingsTest, SetWhitelistAndNoNewUsers) { 193 TEST_F(CrosSettingsTest, SetWhitelistAndNoNewUsers) {
196 // Setting the whitelist should allow us to set kAccountsPrefAllowNewUser to 194 // Setting the whitelist should allow us to set kAccountsPrefAllowNewUser to
197 // false (which is the implicit value too). 195 // false (which is the implicit value too).
198 base::ListValue whitelist; 196 base::ListValue whitelist;
199 whitelist.AppendString("me@owner"); 197 whitelist.AppendString("me@owner");
200 AddExpectation(kAccountsPrefUsers, whitelist.CreateDeepCopy()); 198 AddExpectation(kAccountsPrefUsers, whitelist.CreateDeepCopy());
201 AddExpectation(kAccountsPrefAllowNewUser, 199 AddExpectation(kAccountsPrefAllowNewUser,
202 base::MakeUnique<base::FundamentalValue>(false)); 200 base::MakeUnique<base::Value>(false));
203 SetPref(kAccountsPrefUsers, &whitelist); 201 SetPref(kAccountsPrefUsers, &whitelist);
204 SetPref(kAccountsPrefAllowNewUser, 202 SetPref(kAccountsPrefAllowNewUser,
205 expected_props_[kAccountsPrefAllowNewUser].get()); 203 expected_props_[kAccountsPrefAllowNewUser].get());
206 FetchPref(kAccountsPrefAllowNewUser); 204 FetchPref(kAccountsPrefAllowNewUser);
207 FetchPref(kAccountsPrefUsers); 205 FetchPref(kAccountsPrefUsers);
208 } 206 }
209 207
210 TEST_F(CrosSettingsTest, SetAllowNewUsers) { 208 TEST_F(CrosSettingsTest, SetAllowNewUsers) {
211 // Setting kAccountsPrefAllowNewUser to true with no whitelist should be ok. 209 // Setting kAccountsPrefAllowNewUser to true with no whitelist should be ok.
212 AddExpectation(kAccountsPrefAllowNewUser, 210 AddExpectation(kAccountsPrefAllowNewUser,
213 base::MakeUnique<base::FundamentalValue>(true)); 211 base::MakeUnique<base::Value>(true));
214 SetPref(kAccountsPrefAllowNewUser, 212 SetPref(kAccountsPrefAllowNewUser,
215 expected_props_[kAccountsPrefAllowNewUser].get()); 213 expected_props_[kAccountsPrefAllowNewUser].get());
216 FetchPref(kAccountsPrefAllowNewUser); 214 FetchPref(kAccountsPrefAllowNewUser);
217 } 215 }
218 216
219 TEST_F(CrosSettingsTest, SetEphemeralUsersEnabled) { 217 TEST_F(CrosSettingsTest, SetEphemeralUsersEnabled) {
220 base::FundamentalValue ephemeral_users_enabled(true); 218 base::Value ephemeral_users_enabled(true);
221 AddExpectation(kAccountsPrefEphemeralUsersEnabled, 219 AddExpectation(kAccountsPrefEphemeralUsersEnabled,
222 base::MakeUnique<base::FundamentalValue>(true)); 220 base::MakeUnique<base::Value>(true));
223 SetPref(kAccountsPrefEphemeralUsersEnabled, &ephemeral_users_enabled); 221 SetPref(kAccountsPrefEphemeralUsersEnabled, &ephemeral_users_enabled);
224 FetchPref(kAccountsPrefEphemeralUsersEnabled); 222 FetchPref(kAccountsPrefEphemeralUsersEnabled);
225 } 223 }
226 224
227 TEST_F(CrosSettingsTest, FindEmailInList) { 225 TEST_F(CrosSettingsTest, FindEmailInList) {
228 base::ListValue list; 226 base::ListValue list;
229 list.AppendString("user@example.com"); 227 list.AppendString("user@example.com");
230 list.AppendString("nodomain"); 228 list.AppendString("nodomain");
231 list.AppendString("with.dots@gmail.com"); 229 list.AppendString("with.dots@gmail.com");
232 list.AppendString("Upper@example.com"); 230 list.AppendString("Upper@example.com");
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 EXPECT_TRUE(wildcard_match); 267 EXPECT_TRUE(wildcard_match);
270 EXPECT_TRUE(cs->FindEmailInList( 268 EXPECT_TRUE(cs->FindEmailInList(
271 kAccountsPrefUsers, "user@example.com", &wildcard_match)); 269 kAccountsPrefUsers, "user@example.com", &wildcard_match));
272 EXPECT_FALSE(wildcard_match); 270 EXPECT_FALSE(wildcard_match);
273 EXPECT_TRUE(cs->FindEmailInList( 271 EXPECT_TRUE(cs->FindEmailInList(
274 kAccountsPrefUsers, "*@example.com", &wildcard_match)); 272 kAccountsPrefUsers, "*@example.com", &wildcard_match));
275 EXPECT_TRUE(wildcard_match); 273 EXPECT_TRUE(wildcard_match);
276 } 274 }
277 275
278 } // namespace chromeos 276 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698