| OLD | NEW |
| 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 <map> | 5 #include <map> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // We didn't change the default so look for it. | 112 // We didn't change the default so look for it. |
| 113 AddExpectation(kAccountsPrefAllowGuest, | 113 AddExpectation(kAccountsPrefAllowGuest, |
| 114 base::Value::CreateBooleanValue(true)); | 114 base::Value::CreateBooleanValue(true)); |
| 115 FetchPref(kAccountsPrefAllowGuest); | 115 FetchPref(kAccountsPrefAllowGuest); |
| 116 } | 116 } |
| 117 | 117 |
| 118 TEST_F(CrosSettingsTest, SetWhitelist) { | 118 TEST_F(CrosSettingsTest, SetWhitelist) { |
| 119 // Setting the whitelist should also switch the value of | 119 // Setting the whitelist should also switch the value of |
| 120 // kAccountsPrefAllowNewUser to false. | 120 // kAccountsPrefAllowNewUser to false. |
| 121 base::ListValue whitelist; | 121 base::ListValue whitelist; |
| 122 whitelist.Append(base::Value::CreateStringValue("me@owner")); | 122 whitelist.Append(new base::StringValue("me@owner")); |
| 123 AddExpectation(kAccountsPrefAllowNewUser, | 123 AddExpectation(kAccountsPrefAllowNewUser, |
| 124 base::Value::CreateBooleanValue(false)); | 124 base::Value::CreateBooleanValue(false)); |
| 125 AddExpectation(kAccountsPrefUsers, whitelist.DeepCopy()); | 125 AddExpectation(kAccountsPrefUsers, whitelist.DeepCopy()); |
| 126 SetPref(kAccountsPrefUsers, &whitelist); | 126 SetPref(kAccountsPrefUsers, &whitelist); |
| 127 FetchPref(kAccountsPrefAllowNewUser); | 127 FetchPref(kAccountsPrefAllowNewUser); |
| 128 FetchPref(kAccountsPrefUsers); | 128 FetchPref(kAccountsPrefUsers); |
| 129 } | 129 } |
| 130 | 130 |
| 131 TEST_F(CrosSettingsTest, SetWhitelistWithListOps) { | 131 TEST_F(CrosSettingsTest, SetWhitelistWithListOps) { |
| 132 base::ListValue* whitelist = new base::ListValue(); | 132 base::ListValue* whitelist = new base::ListValue(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 SetPref(kAccountsPrefUsers, &whitelist); | 172 SetPref(kAccountsPrefUsers, &whitelist); |
| 173 SetPref(kAccountsPrefAllowNewUser, &disallow_new); | 173 SetPref(kAccountsPrefAllowNewUser, &disallow_new); |
| 174 FetchPref(kAccountsPrefAllowNewUser); | 174 FetchPref(kAccountsPrefAllowNewUser); |
| 175 FetchPref(kAccountsPrefUsers); | 175 FetchPref(kAccountsPrefUsers); |
| 176 } | 176 } |
| 177 | 177 |
| 178 TEST_F(CrosSettingsTest, SetWhitelistAndNoNewUsers) { | 178 TEST_F(CrosSettingsTest, SetWhitelistAndNoNewUsers) { |
| 179 // Setting the whitelist should allow us to set kAccountsPrefAllowNewUser to | 179 // Setting the whitelist should allow us to set kAccountsPrefAllowNewUser to |
| 180 // false (which is the implicit value too). | 180 // false (which is the implicit value too). |
| 181 base::ListValue whitelist; | 181 base::ListValue whitelist; |
| 182 whitelist.Append(base::Value::CreateStringValue("me@owner")); | 182 whitelist.Append(new base::StringValue("me@owner")); |
| 183 AddExpectation(kAccountsPrefUsers, whitelist.DeepCopy()); | 183 AddExpectation(kAccountsPrefUsers, whitelist.DeepCopy()); |
| 184 AddExpectation(kAccountsPrefAllowNewUser, | 184 AddExpectation(kAccountsPrefAllowNewUser, |
| 185 base::Value::CreateBooleanValue(false)); | 185 base::Value::CreateBooleanValue(false)); |
| 186 SetPref(kAccountsPrefUsers, &whitelist); | 186 SetPref(kAccountsPrefUsers, &whitelist); |
| 187 SetPref(kAccountsPrefAllowNewUser, | 187 SetPref(kAccountsPrefAllowNewUser, |
| 188 expected_props_[kAccountsPrefAllowNewUser]); | 188 expected_props_[kAccountsPrefAllowNewUser]); |
| 189 FetchPref(kAccountsPrefAllowNewUser); | 189 FetchPref(kAccountsPrefAllowNewUser); |
| 190 FetchPref(kAccountsPrefUsers); | 190 FetchPref(kAccountsPrefUsers); |
| 191 } | 191 } |
| 192 | 192 |
| 193 TEST_F(CrosSettingsTest, SetAllowNewUsers) { | 193 TEST_F(CrosSettingsTest, SetAllowNewUsers) { |
| 194 // Setting kAccountsPrefAllowNewUser to true with no whitelist should be ok. | 194 // Setting kAccountsPrefAllowNewUser to true with no whitelist should be ok. |
| 195 AddExpectation(kAccountsPrefAllowNewUser, | 195 AddExpectation(kAccountsPrefAllowNewUser, |
| 196 base::Value::CreateBooleanValue(true)); | 196 base::Value::CreateBooleanValue(true)); |
| 197 SetPref(kAccountsPrefAllowNewUser, | 197 SetPref(kAccountsPrefAllowNewUser, |
| 198 expected_props_[kAccountsPrefAllowNewUser]); | 198 expected_props_[kAccountsPrefAllowNewUser]); |
| 199 FetchPref(kAccountsPrefAllowNewUser); | 199 FetchPref(kAccountsPrefAllowNewUser); |
| 200 } | 200 } |
| 201 | 201 |
| 202 TEST_F(CrosSettingsTest, SetEphemeralUsersEnabled) { | 202 TEST_F(CrosSettingsTest, SetEphemeralUsersEnabled) { |
| 203 base::FundamentalValue ephemeral_users_enabled(true); | 203 base::FundamentalValue ephemeral_users_enabled(true); |
| 204 AddExpectation(kAccountsPrefEphemeralUsersEnabled, | 204 AddExpectation(kAccountsPrefEphemeralUsersEnabled, |
| 205 base::Value::CreateBooleanValue(true)); | 205 base::Value::CreateBooleanValue(true)); |
| 206 SetPref(kAccountsPrefEphemeralUsersEnabled, &ephemeral_users_enabled); | 206 SetPref(kAccountsPrefEphemeralUsersEnabled, &ephemeral_users_enabled); |
| 207 FetchPref(kAccountsPrefEphemeralUsersEnabled); | 207 FetchPref(kAccountsPrefEphemeralUsersEnabled); |
| 208 } | 208 } |
| 209 | 209 |
| 210 TEST_F(CrosSettingsTest, FindEmailInList) { | 210 TEST_F(CrosSettingsTest, FindEmailInList) { |
| 211 base::ListValue list; | 211 base::ListValue list; |
| 212 list.Append(base::Value::CreateStringValue("user@example.com")); | 212 list.Append(new base::StringValue("user@example.com")); |
| 213 list.Append(base::Value::CreateStringValue("nodomain")); | 213 list.Append(new base::StringValue("nodomain")); |
| 214 list.Append(base::Value::CreateStringValue("with.dots@gmail.com")); | 214 list.Append(new base::StringValue("with.dots@gmail.com")); |
| 215 list.Append(base::Value::CreateStringValue("Upper@example.com")); | 215 list.Append(new base::StringValue("Upper@example.com")); |
| 216 | 216 |
| 217 CrosSettings* cs = &settings_; | 217 CrosSettings* cs = &settings_; |
| 218 cs->Set(kAccountsPrefUsers, list); | 218 cs->Set(kAccountsPrefUsers, list); |
| 219 | 219 |
| 220 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "user@example.com")); | 220 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "user@example.com")); |
| 221 EXPECT_FALSE(cs->FindEmailInList(kAccountsPrefUsers, "us.er@example.com")); | 221 EXPECT_FALSE(cs->FindEmailInList(kAccountsPrefUsers, "us.er@example.com")); |
| 222 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "USER@example.com")); | 222 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "USER@example.com")); |
| 223 EXPECT_FALSE(cs->FindEmailInList(kAccountsPrefUsers, "user")); | 223 EXPECT_FALSE(cs->FindEmailInList(kAccountsPrefUsers, "user")); |
| 224 | 224 |
| 225 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "nodomain")); | 225 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "nodomain")); |
| 226 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "nodomain@gmail.com")); | 226 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "nodomain@gmail.com")); |
| 227 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "no.domain@gmail.com")); | 227 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "no.domain@gmail.com")); |
| 228 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "NO.DOMAIN")); | 228 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "NO.DOMAIN")); |
| 229 | 229 |
| 230 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "with.dots@gmail.com")); | 230 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "with.dots@gmail.com")); |
| 231 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "withdots@gmail.com")); | 231 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "withdots@gmail.com")); |
| 232 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "WITH.DOTS@gmail.com")); | 232 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "WITH.DOTS@gmail.com")); |
| 233 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "WITHDOTS")); | 233 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "WITHDOTS")); |
| 234 | 234 |
| 235 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "Upper@example.com")); | 235 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "Upper@example.com")); |
| 236 EXPECT_FALSE(cs->FindEmailInList(kAccountsPrefUsers, "U.pper@example.com")); | 236 EXPECT_FALSE(cs->FindEmailInList(kAccountsPrefUsers, "U.pper@example.com")); |
| 237 EXPECT_FALSE(cs->FindEmailInList(kAccountsPrefUsers, "Upper")); | 237 EXPECT_FALSE(cs->FindEmailInList(kAccountsPrefUsers, "Upper")); |
| 238 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "upper@example.com")); | 238 EXPECT_TRUE(cs->FindEmailInList(kAccountsPrefUsers, "upper@example.com")); |
| 239 } | 239 } |
| 240 | 240 |
| 241 } // namespace chromeos | 241 } // namespace chromeos |
| OLD | NEW |