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

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

Issue 2392693002: Rewrite simple uses of base::ListValue::Append(base::Value*) on CrOS. (Closed)
Patch Set: MakeUnique Created 4 years, 2 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/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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 TEST_F(CrosSettingsTest, GetPref) { 115 TEST_F(CrosSettingsTest, GetPref) {
116 // We didn't change the default so look for it. 116 // We didn't change the default so look for it.
117 AddExpectation(kAccountsPrefAllowGuest, new base::FundamentalValue(true)); 117 AddExpectation(kAccountsPrefAllowGuest, new base::FundamentalValue(true));
118 FetchPref(kAccountsPrefAllowGuest); 118 FetchPref(kAccountsPrefAllowGuest);
119 } 119 }
120 120
121 TEST_F(CrosSettingsTest, SetWhitelist) { 121 TEST_F(CrosSettingsTest, SetWhitelist) {
122 // Setting the whitelist should also switch the value of 122 // Setting the whitelist should also switch the value of
123 // kAccountsPrefAllowNewUser to false. 123 // kAccountsPrefAllowNewUser to false.
124 base::ListValue whitelist; 124 base::ListValue whitelist;
125 whitelist.Append(new base::StringValue("me@owner")); 125 whitelist.AppendString("me@owner");
126 AddExpectation(kAccountsPrefAllowNewUser, new base::FundamentalValue(false)); 126 AddExpectation(kAccountsPrefAllowNewUser, new base::FundamentalValue(false));
127 AddExpectation(kAccountsPrefUsers, whitelist.DeepCopy()); 127 AddExpectation(kAccountsPrefUsers, whitelist.DeepCopy());
128 SetPref(kAccountsPrefUsers, &whitelist); 128 SetPref(kAccountsPrefUsers, &whitelist);
129 FetchPref(kAccountsPrefAllowNewUser); 129 FetchPref(kAccountsPrefAllowNewUser);
130 FetchPref(kAccountsPrefUsers); 130 FetchPref(kAccountsPrefUsers);
131 } 131 }
132 132
133 TEST_F(CrosSettingsTest, SetWhitelistWithListOps) { 133 TEST_F(CrosSettingsTest, SetWhitelistWithListOps) {
134 base::ListValue* whitelist = new base::ListValue(); 134 base::ListValue* whitelist = new base::ListValue();
135 base::StringValue hacky_user("h@xxor"); 135 base::StringValue hacky_user("h@xxor");
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 SetPref(kAccountsPrefUsers, &whitelist); 182 SetPref(kAccountsPrefUsers, &whitelist);
183 SetPref(kAccountsPrefAllowNewUser, &disallow_new); 183 SetPref(kAccountsPrefAllowNewUser, &disallow_new);
184 FetchPref(kAccountsPrefAllowNewUser); 184 FetchPref(kAccountsPrefAllowNewUser);
185 FetchPref(kAccountsPrefUsers); 185 FetchPref(kAccountsPrefUsers);
186 } 186 }
187 187
188 TEST_F(CrosSettingsTest, SetWhitelistAndNoNewUsers) { 188 TEST_F(CrosSettingsTest, SetWhitelistAndNoNewUsers) {
189 // Setting the whitelist should allow us to set kAccountsPrefAllowNewUser to 189 // Setting the whitelist should allow us to set kAccountsPrefAllowNewUser to
190 // false (which is the implicit value too). 190 // false (which is the implicit value too).
191 base::ListValue whitelist; 191 base::ListValue whitelist;
192 whitelist.Append(new base::StringValue("me@owner")); 192 whitelist.AppendString("me@owner");
193 AddExpectation(kAccountsPrefUsers, whitelist.DeepCopy()); 193 AddExpectation(kAccountsPrefUsers, whitelist.DeepCopy());
194 AddExpectation(kAccountsPrefAllowNewUser, new base::FundamentalValue(false)); 194 AddExpectation(kAccountsPrefAllowNewUser, new base::FundamentalValue(false));
195 SetPref(kAccountsPrefUsers, &whitelist); 195 SetPref(kAccountsPrefUsers, &whitelist);
196 SetPref(kAccountsPrefAllowNewUser, 196 SetPref(kAccountsPrefAllowNewUser,
197 expected_props_[kAccountsPrefAllowNewUser]); 197 expected_props_[kAccountsPrefAllowNewUser]);
198 FetchPref(kAccountsPrefAllowNewUser); 198 FetchPref(kAccountsPrefAllowNewUser);
199 FetchPref(kAccountsPrefUsers); 199 FetchPref(kAccountsPrefUsers);
200 } 200 }
201 201
202 TEST_F(CrosSettingsTest, SetAllowNewUsers) { 202 TEST_F(CrosSettingsTest, SetAllowNewUsers) {
203 // Setting kAccountsPrefAllowNewUser to true with no whitelist should be ok. 203 // Setting kAccountsPrefAllowNewUser to true with no whitelist should be ok.
204 AddExpectation(kAccountsPrefAllowNewUser, new base::FundamentalValue(true)); 204 AddExpectation(kAccountsPrefAllowNewUser, new base::FundamentalValue(true));
205 SetPref(kAccountsPrefAllowNewUser, 205 SetPref(kAccountsPrefAllowNewUser,
206 expected_props_[kAccountsPrefAllowNewUser]); 206 expected_props_[kAccountsPrefAllowNewUser]);
207 FetchPref(kAccountsPrefAllowNewUser); 207 FetchPref(kAccountsPrefAllowNewUser);
208 } 208 }
209 209
210 TEST_F(CrosSettingsTest, SetEphemeralUsersEnabled) { 210 TEST_F(CrosSettingsTest, SetEphemeralUsersEnabled) {
211 base::FundamentalValue ephemeral_users_enabled(true); 211 base::FundamentalValue ephemeral_users_enabled(true);
212 AddExpectation(kAccountsPrefEphemeralUsersEnabled, 212 AddExpectation(kAccountsPrefEphemeralUsersEnabled,
213 new base::FundamentalValue(true)); 213 new base::FundamentalValue(true));
214 SetPref(kAccountsPrefEphemeralUsersEnabled, &ephemeral_users_enabled); 214 SetPref(kAccountsPrefEphemeralUsersEnabled, &ephemeral_users_enabled);
215 FetchPref(kAccountsPrefEphemeralUsersEnabled); 215 FetchPref(kAccountsPrefEphemeralUsersEnabled);
216 } 216 }
217 217
218 TEST_F(CrosSettingsTest, FindEmailInList) { 218 TEST_F(CrosSettingsTest, FindEmailInList) {
219 base::ListValue list; 219 base::ListValue list;
220 list.Append(new base::StringValue("user@example.com")); 220 list.AppendString("user@example.com");
221 list.Append(new base::StringValue("nodomain")); 221 list.AppendString("nodomain");
222 list.Append(new base::StringValue("with.dots@gmail.com")); 222 list.AppendString("with.dots@gmail.com");
223 list.Append(new base::StringValue("Upper@example.com")); 223 list.AppendString("Upper@example.com");
224 224
225 CrosSettings* cs = &settings_; 225 CrosSettings* cs = &settings_;
226 cs->Set(kAccountsPrefUsers, list); 226 cs->Set(kAccountsPrefUsers, list);
227 227
228 EXPECT_TRUE(IsWhitelisted(cs, "user@example.com")); 228 EXPECT_TRUE(IsWhitelisted(cs, "user@example.com"));
229 EXPECT_FALSE(IsWhitelisted(cs, "us.er@example.com")); 229 EXPECT_FALSE(IsWhitelisted(cs, "us.er@example.com"));
230 EXPECT_TRUE(IsWhitelisted(cs, "USER@example.com")); 230 EXPECT_TRUE(IsWhitelisted(cs, "USER@example.com"));
231 EXPECT_FALSE(IsWhitelisted(cs, "user")); 231 EXPECT_FALSE(IsWhitelisted(cs, "user"));
232 232
233 EXPECT_TRUE(IsWhitelisted(cs, "nodomain")); 233 EXPECT_TRUE(IsWhitelisted(cs, "nodomain"));
234 EXPECT_TRUE(IsWhitelisted(cs, "nodomain@gmail.com")); 234 EXPECT_TRUE(IsWhitelisted(cs, "nodomain@gmail.com"));
235 EXPECT_TRUE(IsWhitelisted(cs, "no.domain@gmail.com")); 235 EXPECT_TRUE(IsWhitelisted(cs, "no.domain@gmail.com"));
236 EXPECT_TRUE(IsWhitelisted(cs, "NO.DOMAIN")); 236 EXPECT_TRUE(IsWhitelisted(cs, "NO.DOMAIN"));
237 237
238 EXPECT_TRUE(IsWhitelisted(cs, "with.dots@gmail.com")); 238 EXPECT_TRUE(IsWhitelisted(cs, "with.dots@gmail.com"));
239 EXPECT_TRUE(IsWhitelisted(cs, "withdots@gmail.com")); 239 EXPECT_TRUE(IsWhitelisted(cs, "withdots@gmail.com"));
240 EXPECT_TRUE(IsWhitelisted(cs, "WITH.DOTS@gmail.com")); 240 EXPECT_TRUE(IsWhitelisted(cs, "WITH.DOTS@gmail.com"));
241 EXPECT_TRUE(IsWhitelisted(cs, "WITHDOTS")); 241 EXPECT_TRUE(IsWhitelisted(cs, "WITHDOTS"));
242 242
243 EXPECT_TRUE(IsWhitelisted(cs, "Upper@example.com")); 243 EXPECT_TRUE(IsWhitelisted(cs, "Upper@example.com"));
244 EXPECT_FALSE(IsWhitelisted(cs, "U.pper@example.com")); 244 EXPECT_FALSE(IsWhitelisted(cs, "U.pper@example.com"));
245 EXPECT_FALSE(IsWhitelisted(cs, "Upper")); 245 EXPECT_FALSE(IsWhitelisted(cs, "Upper"));
246 EXPECT_TRUE(IsWhitelisted(cs, "upper@example.com")); 246 EXPECT_TRUE(IsWhitelisted(cs, "upper@example.com"));
247 } 247 }
248 248
249 TEST_F(CrosSettingsTest, FindEmailInListWildcard) { 249 TEST_F(CrosSettingsTest, FindEmailInListWildcard) {
250 base::ListValue list; 250 base::ListValue list;
251 list.Append(new base::StringValue("user@example.com")); 251 list.AppendString("user@example.com");
252 list.Append(new base::StringValue("*@example.com")); 252 list.AppendString("*@example.com");
253 253
254 CrosSettings* cs = &settings_; 254 CrosSettings* cs = &settings_;
255 cs->Set(kAccountsPrefUsers, list); 255 cs->Set(kAccountsPrefUsers, list);
256 256
257 bool wildcard_match = false; 257 bool wildcard_match = false;
258 EXPECT_TRUE(cs->FindEmailInList( 258 EXPECT_TRUE(cs->FindEmailInList(
259 kAccountsPrefUsers, "test@example.com", &wildcard_match)); 259 kAccountsPrefUsers, "test@example.com", &wildcard_match));
260 EXPECT_TRUE(wildcard_match); 260 EXPECT_TRUE(wildcard_match);
261 EXPECT_TRUE(cs->FindEmailInList( 261 EXPECT_TRUE(cs->FindEmailInList(
262 kAccountsPrefUsers, "user@example.com", &wildcard_match)); 262 kAccountsPrefUsers, "user@example.com", &wildcard_match));
263 EXPECT_FALSE(wildcard_match); 263 EXPECT_FALSE(wildcard_match);
264 EXPECT_TRUE(cs->FindEmailInList( 264 EXPECT_TRUE(cs->FindEmailInList(
265 kAccountsPrefUsers, "*@example.com", &wildcard_match)); 265 kAccountsPrefUsers, "*@example.com", &wildcard_match));
266 EXPECT_TRUE(wildcard_match); 266 EXPECT_TRUE(wildcard_match);
267 } 267 }
268 268
269 } // namespace chromeos 269 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/proxy_cros_settings_parser.cc ('k') | chrome/browser/chromeos/settings/device_settings_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698