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