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

Side by Side Diff: chrome/browser/policy/configuration_policy_pref_store_unittest.cc

Issue 6074003: Handle policy refresh internally in ConfigurationPolicyPrefStore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <gtest/gtest.h>
6
7 #include "base/file_path.h" 5 #include "base/file_path.h"
8 #include "chrome/browser/policy/configuration_policy_pref_store.h" 6 #include "chrome/browser/policy/configuration_policy_pref_store.h"
9 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 7 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
8 #include "chrome/common/chrome_switches.h"
9 #include "chrome/common/notification_service.h"
10 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
11 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/pref_store_observer_mock.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 using testing::_;
16 using testing::Mock;
12 17
13 namespace policy { 18 namespace policy {
14 19
15 // Holds a set of test parameters, consisting of pref name and policy type. 20 // Holds a set of test parameters, consisting of pref name and policy type.
16 class TypeAndName { 21 class TypeAndName {
17 public: 22 public:
18 TypeAndName(ConfigurationPolicyType type, const char* pref_name) 23 TypeAndName(ConfigurationPolicyType type, const char* pref_name)
19 : type_(type), 24 : type_(type),
20 pref_name_(pref_name) {} 25 pref_name_(pref_name) {}
21 26
22 ConfigurationPolicyType type() const { return type_; } 27 ConfigurationPolicyType type() const { return type_; }
23 const char* pref_name() const { return pref_name_; } 28 const char* pref_name() const { return pref_name_; }
24 29
25 private: 30 private:
26 ConfigurationPolicyType type_; 31 ConfigurationPolicyType type_;
27 const char* pref_name_; 32 const char* pref_name_;
28 }; 33 };
29 34
30 template<typename TESTBASE> 35 template<typename TESTBASE>
31 class ConfigurationPolicyPrefStoreTestBase : public TESTBASE { 36 class ConfigurationPolicyPrefStoreTestBase : public TESTBASE {
32 protected: 37 protected:
33 ConfigurationPolicyPrefStoreTestBase() 38 ConfigurationPolicyPrefStoreTestBase()
34 : provider_(), 39 : provider_(),
35 store_(&provider_) {} 40 store_(&provider_) {}
36 41
42 void RefreshPolicy() {
43 NotificationService::current()->Notify(
44 NotificationType::POLICY_CHANGED,
45 Source<ConfigurationPolicyProvider>(&provider_),
46 NotificationService::NoDetails());
47 }
48
37 MockConfigurationPolicyProvider provider_; 49 MockConfigurationPolicyProvider provider_;
38 ConfigurationPolicyPrefStore store_; 50 ConfigurationPolicyPrefStore store_;
39 }; 51 };
40 52
41 // Test cases for list-valued policy settings. 53 // Test cases for list-valued policy settings.
42 class ConfigurationPolicyPrefStoreListTest 54 class ConfigurationPolicyPrefStoreListTest
43 : public ConfigurationPolicyPrefStoreTestBase< 55 : public ConfigurationPolicyPrefStoreTestBase<
44 testing::TestWithParam<TypeAndName> > { 56 testing::TestWithParam<TypeAndName> > {
45 }; 57 };
46 58
47 TEST_P(ConfigurationPolicyPrefStoreListTest, GetDefault) { 59 TEST_P(ConfigurationPolicyPrefStoreListTest, GetDefault) {
48 ListValue* list = NULL; 60 EXPECT_EQ(PrefStore::READ_NO_VALUE,
49 EXPECT_FALSE(store_.prefs()->GetList(GetParam().pref_name(), &list)); 61 store_.GetValue(GetParam().pref_name(), NULL));
50 } 62 }
51 63
52 TEST_P(ConfigurationPolicyPrefStoreListTest, SetValue) { 64 TEST_P(ConfigurationPolicyPrefStoreListTest, SetValue) {
53 ListValue* in_value = new ListValue(); 65 ListValue* in_value = new ListValue();
54 in_value->Append(Value::CreateStringValue("test1")); 66 in_value->Append(Value::CreateStringValue("test1"));
55 in_value->Append(Value::CreateStringValue("test2,")); 67 in_value->Append(Value::CreateStringValue("test2,"));
56 store_.Apply(GetParam().type(), in_value); 68 provider_.AddPolicy(GetParam().type(), in_value);
57 ListValue* list = NULL; 69 RefreshPolicy();
58 EXPECT_TRUE(store_.prefs()->GetList(GetParam().pref_name(), &list)); 70 Value* value;
59 ListValue::const_iterator current(list->begin()); 71 EXPECT_EQ(PrefStore::READ_OK,
60 const ListValue::const_iterator end(list->end()); 72 store_.GetValue(GetParam().pref_name(), &value));
61 ASSERT_TRUE(current != end); 73 EXPECT_TRUE(in_value->Equals(value));
62 std::string value;
63 (*current)->GetAsString(&value);
64 EXPECT_EQ("test1", value);
65 ++current;
66 ASSERT_TRUE(current != end);
67 (*current)->GetAsString(&value);
68 EXPECT_EQ("test2,", value);
69 ++current;
70 EXPECT_TRUE(current == end);
71 } 74 }
72 75
73 INSTANTIATE_TEST_CASE_P( 76 INSTANTIATE_TEST_CASE_P(
74 ConfigurationPolicyPrefStoreListTestInstance, 77 ConfigurationPolicyPrefStoreListTestInstance,
75 ConfigurationPolicyPrefStoreListTest, 78 ConfigurationPolicyPrefStoreListTest,
76 testing::Values( 79 testing::Values(
77 TypeAndName(kPolicyURLsToRestoreOnStartup, 80 TypeAndName(kPolicyURLsToRestoreOnStartup,
78 prefs::kURLsToRestoreOnStartup), 81 prefs::kURLsToRestoreOnStartup),
79 TypeAndName(kPolicyExtensionInstallAllowList, 82 TypeAndName(kPolicyExtensionInstallAllowList,
80 prefs::kExtensionInstallAllowList), 83 prefs::kExtensionInstallAllowList),
81 TypeAndName(kPolicyExtensionInstallDenyList, 84 TypeAndName(kPolicyExtensionInstallDenyList,
82 prefs::kExtensionInstallDenyList), 85 prefs::kExtensionInstallDenyList),
83 TypeAndName(kPolicyDisabledPlugins, 86 TypeAndName(kPolicyDisabledPlugins,
84 prefs::kPluginsPluginsBlacklist))); 87 prefs::kPluginsPluginsBlacklist)));
85 88
86 // Test cases for string-valued policy settings. 89 // Test cases for string-valued policy settings.
87 class ConfigurationPolicyPrefStoreStringTest 90 class ConfigurationPolicyPrefStoreStringTest
88 : public ConfigurationPolicyPrefStoreTestBase< 91 : public ConfigurationPolicyPrefStoreTestBase<
89 testing::TestWithParam<TypeAndName> > { 92 testing::TestWithParam<TypeAndName> > {
90 }; 93 };
91 94
92 TEST_P(ConfigurationPolicyPrefStoreStringTest, GetDefault) { 95 TEST_P(ConfigurationPolicyPrefStoreStringTest, GetDefault) {
93 std::string result; 96 EXPECT_EQ(PrefStore::READ_NO_VALUE,
94 EXPECT_FALSE(store_.prefs()->GetString(GetParam().pref_name(), &result)); 97 store_.GetValue(GetParam().pref_name(), NULL));
95 } 98 }
96 99
97 TEST_P(ConfigurationPolicyPrefStoreStringTest, SetValue) { 100 TEST_P(ConfigurationPolicyPrefStoreStringTest, SetValue) {
98 store_.Apply(GetParam().type(), 101 provider_.AddPolicy(GetParam().type(),
99 Value::CreateStringValue("http://chromium.org")); 102 Value::CreateStringValue("http://chromium.org"));
103 RefreshPolicy();
104 Value* value;
105 EXPECT_EQ(PrefStore::READ_OK,
106 store_.GetValue(GetParam().pref_name(), &value));
107 ASSERT_TRUE(value);
100 std::string result; 108 std::string result;
101 EXPECT_TRUE(store_.prefs()->GetString(GetParam().pref_name(), &result)); 109 EXPECT_TRUE(value->GetAsString(&result));
102 EXPECT_EQ(result, "http://chromium.org"); 110 EXPECT_EQ(result, "http://chromium.org");
103 } 111 }
104 112
105 INSTANTIATE_TEST_CASE_P( 113 INSTANTIATE_TEST_CASE_P(
106 ConfigurationPolicyPrefStoreStringTestInstance, 114 ConfigurationPolicyPrefStoreStringTestInstance,
107 ConfigurationPolicyPrefStoreStringTest, 115 ConfigurationPolicyPrefStoreStringTest,
108 testing::Values( 116 testing::Values(
109 TypeAndName(kPolicyHomePage, 117 TypeAndName(kPolicyHomePage,
110 prefs::kHomePage), 118 prefs::kHomePage),
111 TypeAndName(kPolicyProxyServer, 119 TypeAndName(kPolicyProxyServer,
(...skipping 15 matching lines...) Expand all
127 TypeAndName(kPolicyGSSAPILibraryName, 135 TypeAndName(kPolicyGSSAPILibraryName,
128 prefs::kGSSAPILibraryName))); 136 prefs::kGSSAPILibraryName)));
129 137
130 // Test cases for boolean-valued policy settings. 138 // Test cases for boolean-valued policy settings.
131 class ConfigurationPolicyPrefStoreBooleanTest 139 class ConfigurationPolicyPrefStoreBooleanTest
132 : public ConfigurationPolicyPrefStoreTestBase< 140 : public ConfigurationPolicyPrefStoreTestBase<
133 testing::TestWithParam<TypeAndName> > { 141 testing::TestWithParam<TypeAndName> > {
134 }; 142 };
135 143
136 TEST_P(ConfigurationPolicyPrefStoreBooleanTest, GetDefault) { 144 TEST_P(ConfigurationPolicyPrefStoreBooleanTest, GetDefault) {
137 bool result = false; 145 EXPECT_EQ(PrefStore::READ_NO_VALUE,
138 EXPECT_FALSE(store_.prefs()->GetBoolean(GetParam().pref_name(), &result)); 146 store_.GetValue(GetParam().pref_name(), NULL));
139 } 147 }
140 148
141 TEST_P(ConfigurationPolicyPrefStoreBooleanTest, SetValue) { 149 TEST_P(ConfigurationPolicyPrefStoreBooleanTest, SetValue) {
142 store_.Apply(GetParam().type(), Value::CreateBooleanValue(false)); 150 provider_.AddPolicy(GetParam().type(), Value::CreateBooleanValue(false));
151 RefreshPolicy();
152 Value* value;
143 bool result = true; 153 bool result = true;
144 EXPECT_TRUE(store_.prefs()->GetBoolean(GetParam().pref_name(), &result)); 154 EXPECT_EQ(PrefStore::READ_OK,
145 EXPECT_FALSE(result); 155 store_.GetValue(GetParam().pref_name(), &value));
156 EXPECT_TRUE(FundamentalValue(false).Equals(value));
146 157
147 store_.Apply(GetParam().type(), Value::CreateBooleanValue(true)); 158 provider_.AddPolicy(GetParam().type(), Value::CreateBooleanValue(true));
159 RefreshPolicy();
148 result = false; 160 result = false;
149 EXPECT_TRUE(store_.prefs()->GetBoolean(GetParam().pref_name(), &result)); 161 EXPECT_EQ(PrefStore::READ_OK,
150 EXPECT_TRUE(result); 162 store_.GetValue(GetParam().pref_name(), &value));
163 EXPECT_TRUE(FundamentalValue(true).Equals(value));
151 } 164 }
152 165
153 INSTANTIATE_TEST_CASE_P( 166 INSTANTIATE_TEST_CASE_P(
154 ConfigurationPolicyPrefStoreBooleanTestInstance, 167 ConfigurationPolicyPrefStoreBooleanTestInstance,
155 ConfigurationPolicyPrefStoreBooleanTest, 168 ConfigurationPolicyPrefStoreBooleanTest,
156 testing::Values( 169 testing::Values(
157 TypeAndName(kPolicyHomepageIsNewTabPage, 170 TypeAndName(kPolicyHomepageIsNewTabPage,
158 prefs::kHomePageIsNewTabPage), 171 prefs::kHomePageIsNewTabPage),
159 TypeAndName(kPolicyAlternateErrorPagesEnabled, 172 TypeAndName(kPolicyAlternateErrorPagesEnabled,
160 prefs::kAlternateErrorPagesEnabled), 173 prefs::kAlternateErrorPagesEnabled),
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 prefs::kEnableScreenLock))); 211 prefs::kEnableScreenLock)));
199 #endif // defined(OS_CHROMEOS) 212 #endif // defined(OS_CHROMEOS)
200 213
201 // Test cases for integer-valued policy settings. 214 // Test cases for integer-valued policy settings.
202 class ConfigurationPolicyPrefStoreIntegerTest 215 class ConfigurationPolicyPrefStoreIntegerTest
203 : public ConfigurationPolicyPrefStoreTestBase< 216 : public ConfigurationPolicyPrefStoreTestBase<
204 testing::TestWithParam<TypeAndName> > { 217 testing::TestWithParam<TypeAndName> > {
205 }; 218 };
206 219
207 TEST_P(ConfigurationPolicyPrefStoreIntegerTest, GetDefault) { 220 TEST_P(ConfigurationPolicyPrefStoreIntegerTest, GetDefault) {
208 int result = 0; 221 EXPECT_EQ(PrefStore::READ_NO_VALUE,
209 EXPECT_FALSE(store_.prefs()->GetInteger(GetParam().pref_name(), &result)); 222 store_.GetValue(GetParam().pref_name(), NULL));
210 } 223 }
211 224
212 TEST_P(ConfigurationPolicyPrefStoreIntegerTest, SetValue) { 225 TEST_P(ConfigurationPolicyPrefStoreIntegerTest, SetValue) {
213 store_.Apply(GetParam().type(), Value::CreateIntegerValue(2)); 226 provider_.AddPolicy(GetParam().type(), Value::CreateIntegerValue(2));
214 int result = 0; 227 RefreshPolicy();
215 EXPECT_TRUE(store_.prefs()->GetInteger(GetParam().pref_name(), &result)); 228 Value* value = NULL;
216 EXPECT_EQ(result, 2); 229 EXPECT_EQ(PrefStore::READ_OK,
230 store_.GetValue(GetParam().pref_name(), &value));
231 EXPECT_TRUE(FundamentalValue(2).Equals(value));
217 } 232 }
218 233
219 INSTANTIATE_TEST_CASE_P( 234 INSTANTIATE_TEST_CASE_P(
220 ConfigurationPolicyPrefStoreIntegerTestInstance, 235 ConfigurationPolicyPrefStoreIntegerTestInstance,
221 ConfigurationPolicyPrefStoreIntegerTest, 236 ConfigurationPolicyPrefStoreIntegerTest,
222 testing::Values( 237 testing::Values(
223 TypeAndName(kPolicyRestoreOnStartup, 238 TypeAndName(kPolicyRestoreOnStartup,
224 prefs::kRestoreOnStartup))); 239 prefs::kRestoreOnStartup)));
225 240
226 // Test cases for the proxy policy settings. 241 // Test cases for the proxy policy settings.
227 class ConfigurationPolicyPrefStoreProxyTest : public testing::Test { 242 class ConfigurationPolicyPrefStoreProxyTest : public testing::Test {
228 }; 243 };
229 244
230 TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptions) { 245 TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptions) {
231 scoped_ptr<MockConfigurationPolicyProvider> provider( 246 MockConfigurationPolicyProvider provider;
232 new MockConfigurationPolicyProvider()); 247 provider.AddPolicy(kPolicyProxyBypassList,
233 provider->AddPolicy(kPolicyProxyBypassList, 248 Value::CreateStringValue("http://chromium.org/override"));
234 Value::CreateStringValue("http://chromium.org/override")); 249 provider.AddPolicy(kPolicyProxyPacUrl,
235 provider->AddPolicy(kPolicyProxyPacUrl, 250 Value::CreateStringValue("http://short.org/proxy.pac"));
236 Value::CreateStringValue("http://short.org/proxy.pac")); 251 provider.AddPolicy(kPolicyProxyServer,
237 provider->AddPolicy(kPolicyProxyServer, 252 Value::CreateStringValue("chromium.org"));
238 Value::CreateStringValue("chromium.org")); 253 provider.AddPolicy(kPolicyProxyServerMode,
239 provider->AddPolicy(kPolicyProxyServerMode, 254 Value::CreateIntegerValue(
240 Value::CreateIntegerValue( 255 kPolicyManuallyConfiguredProxyMode));
241 kPolicyManuallyConfiguredProxyMode));
242 256
243 ConfigurationPolicyPrefStore store(provider.get()); 257 ConfigurationPolicyPrefStore store(&provider);
244 258
245 std::string string_result; 259 Value* value = NULL;
246 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyBypassList, 260 EXPECT_EQ(PrefStore::READ_OK,
247 &string_result)); 261 store.GetValue(prefs::kProxyBypassList, &value));
248 EXPECT_EQ("http://chromium.org/override", string_result); 262 EXPECT_TRUE(StringValue("http://chromium.org/override").Equals(value));
249 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 263 EXPECT_EQ(PrefStore::READ_OK,
250 EXPECT_EQ("http://short.org/proxy.pac", string_result); 264 store.GetValue(prefs::kProxyPacUrl, &value));
251 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 265 EXPECT_TRUE(StringValue("http://short.org/proxy.pac").Equals(value));
252 EXPECT_EQ("chromium.org", string_result); 266 EXPECT_EQ(PrefStore::READ_OK,
253 bool bool_result; 267 store.GetValue(prefs::kProxyServer, &value));
254 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 268 EXPECT_TRUE(StringValue("chromium.org").Equals(value));
255 EXPECT_FALSE(bool_result); 269 EXPECT_EQ(PrefStore::READ_OK,
256 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result)); 270 store.GetValue(prefs::kNoProxyServer, &value));
257 EXPECT_FALSE(bool_result); 271 EXPECT_TRUE(FundamentalValue(false).Equals(value));
272 EXPECT_EQ(PrefStore::READ_OK,
273 store.GetValue(prefs::kProxyAutoDetect, &value));
274 EXPECT_TRUE(FundamentalValue(false).Equals(value));
258 } 275 }
259 276
260 TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxy) { 277 TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxy) {
261 scoped_ptr<MockConfigurationPolicyProvider> provider( 278 MockConfigurationPolicyProvider provider;
262 new MockConfigurationPolicyProvider()); 279 provider.AddPolicy(kPolicyProxyBypassList,
263 provider->AddPolicy(kPolicyProxyBypassList, 280 Value::CreateStringValue("http://chromium.org/override"));
264 Value::CreateStringValue("http://chromium.org/override")); 281 provider.AddPolicy(kPolicyProxyServerMode,
265 provider->AddPolicy(kPolicyProxyServerMode, 282 Value::CreateIntegerValue(kPolicyNoProxyServerMode));
266 Value::CreateIntegerValue(
267 kPolicyNoProxyServerMode));
268 283
269 ConfigurationPolicyPrefStore store(provider.get()); 284 ConfigurationPolicyPrefStore store(&provider);
270 285
271 std::string string_result; 286 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
272 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, 287 store.GetValue(prefs::kProxyBypassList, NULL));
273 &string_result)); 288 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
274 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 289 store.GetValue(prefs::kProxyPacUrl, NULL));
275 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 290 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
276 bool bool_result; 291 store.GetValue(prefs::kProxyServer, NULL));
277 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 292 Value* value = NULL;
278 EXPECT_TRUE(bool_result); 293 EXPECT_EQ(PrefStore::READ_OK,
279 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result)); 294 store.GetValue(prefs::kNoProxyServer, &value));
280 EXPECT_FALSE(bool_result); 295 EXPECT_TRUE(FundamentalValue(true).Equals(value));
296 EXPECT_EQ(PrefStore::READ_OK,
297 store.GetValue(prefs::kProxyAutoDetect, &value));
298 EXPECT_TRUE(FundamentalValue(false).Equals(value));
281 } 299 }
282 300
283 TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxyReversedApplyOrder) { 301 TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxyReversedApplyOrder) {
284 scoped_ptr<MockConfigurationPolicyProvider> provider( 302 MockConfigurationPolicyProvider provider;
285 new MockConfigurationPolicyProvider()); 303 provider.AddPolicy(kPolicyProxyServerMode,
286 provider->AddPolicy(kPolicyProxyServerMode, 304 Value::CreateIntegerValue(kPolicyNoProxyServerMode));
287 Value::CreateIntegerValue( 305 provider.AddPolicy(kPolicyProxyBypassList,
288 kPolicyNoProxyServerMode)); 306 Value::CreateStringValue("http://chromium.org/override"));
289 provider->AddPolicy(kPolicyProxyBypassList,
290 Value::CreateStringValue("http://chromium.org/override"));
291 307
292 ConfigurationPolicyPrefStore store(provider.get()); 308 ConfigurationPolicyPrefStore store(&provider);
293 309
294 std::string string_result; 310 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
295 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, 311 store.GetValue(prefs::kProxyBypassList, NULL));
296 &string_result)); 312 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
297 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 313 store.GetValue(prefs::kProxyPacUrl, NULL));
298 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 314 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
299 bool bool_result; 315 store.GetValue(prefs::kProxyServer, NULL));
300 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 316 Value* value = NULL;
301 EXPECT_TRUE(bool_result); 317 EXPECT_EQ(PrefStore::READ_OK,
302 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result)); 318 store.GetValue(prefs::kNoProxyServer, &value));
303 EXPECT_FALSE(bool_result); 319 EXPECT_TRUE(FundamentalValue(true).Equals(value));
320 EXPECT_EQ(PrefStore::READ_OK,
321 store.GetValue(prefs::kProxyAutoDetect, &value));
322 EXPECT_TRUE(FundamentalValue(false).Equals(value));
304 } 323 }
305 324
306 TEST_F(ConfigurationPolicyPrefStoreProxyTest, AutoDetect) { 325 TEST_F(ConfigurationPolicyPrefStoreProxyTest, AutoDetect) {
307 scoped_ptr<MockConfigurationPolicyProvider> provider( 326 MockConfigurationPolicyProvider provider;
308 new MockConfigurationPolicyProvider()); 327 provider.AddPolicy(kPolicyProxyServerMode,
309 provider->AddPolicy(kPolicyProxyServerMode, 328 Value::CreateIntegerValue(kPolicyAutoDetectProxyMode));
310 Value::CreateIntegerValue(
311 kPolicyAutoDetectProxyMode));
312 329
313 ConfigurationPolicyPrefStore store(provider.get()); 330 ConfigurationPolicyPrefStore store(&provider);
314 331
315 std::string string_result; 332 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
316 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, 333 store.GetValue(prefs::kProxyBypassList, NULL));
317 &string_result)); 334 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
318 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 335 store.GetValue(prefs::kProxyPacUrl, NULL));
319 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 336 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
320 bool bool_result; 337 store.GetValue(prefs::kProxyServer, NULL));
321 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 338 Value* value = NULL;
322 EXPECT_FALSE(bool_result); 339 EXPECT_EQ(PrefStore::READ_OK,
323 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result)); 340 store.GetValue(prefs::kNoProxyServer, &value));
324 EXPECT_TRUE(bool_result); 341 EXPECT_TRUE(FundamentalValue(false).Equals(value));
342 EXPECT_EQ(PrefStore::READ_OK,
343 store.GetValue(prefs::kProxyAutoDetect, &value));
344 EXPECT_TRUE(FundamentalValue(true).Equals(value));
325 } 345 }
326 346
327 TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystem) { 347 TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystem) {
328 scoped_ptr<MockConfigurationPolicyProvider> provider( 348 MockConfigurationPolicyProvider provider;
329 new MockConfigurationPolicyProvider()); 349 provider.AddPolicy(kPolicyProxyBypassList,
330 provider->AddPolicy(kPolicyProxyBypassList, 350 Value::CreateStringValue("http://chromium.org/override"));
331 Value::CreateStringValue("http://chromium.org/override")); 351 provider.AddPolicy(kPolicyProxyServerMode,
332 provider->AddPolicy(kPolicyProxyServerMode, 352 Value::CreateIntegerValue(kPolicyUseSystemProxyMode));
333 Value::CreateIntegerValue(
334 kPolicyUseSystemProxyMode));
335 353
336 ConfigurationPolicyPrefStore store(provider.get()); 354 ConfigurationPolicyPrefStore store(&provider);
337 355
338 std::string string_result; 356 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
339 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, 357 store.GetValue(prefs::kProxyBypassList, NULL));
340 &string_result)); 358 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
341 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 359 store.GetValue(prefs::kProxyPacUrl, NULL));
342 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 360 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
343 bool bool_result; 361 store.GetValue(prefs::kProxyServer, NULL));
344 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 362 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
345 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, 363 store.GetValue(prefs::kNoProxyServer, NULL));
346 &bool_result)); 364 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
365 store.GetValue(prefs::kProxyAutoDetect, NULL));
347 } 366 }
348 367
349 TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystemReversedApplyOrder) { 368 TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystemReversedApplyOrder) {
350 scoped_ptr<MockConfigurationPolicyProvider> provider( 369 MockConfigurationPolicyProvider provider;
351 new MockConfigurationPolicyProvider()); 370 provider.AddPolicy(kPolicyProxyServerMode,
352 provider->AddPolicy(kPolicyProxyServerMode, 371 Value::CreateIntegerValue(kPolicyUseSystemProxyMode));
353 Value::CreateIntegerValue( 372 provider.AddPolicy(kPolicyProxyBypassList,
354 kPolicyUseSystemProxyMode)); 373 Value::CreateStringValue("http://chromium.org/override"));
355 provider->AddPolicy(kPolicyProxyBypassList,
356 Value::CreateStringValue("http://chromium.org/override"));
357 374
358 ConfigurationPolicyPrefStore store(provider.get()); 375 ConfigurationPolicyPrefStore store(&provider);
359 376
360 std::string string_result; 377 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
361 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, 378 store.GetValue(prefs::kProxyBypassList, NULL));
362 &string_result)); 379 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
363 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 380 store.GetValue(prefs::kProxyPacUrl, NULL));
364 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 381 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
365 bool bool_result; 382 store.GetValue(prefs::kProxyServer, NULL));
366 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 383 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
367 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, 384 store.GetValue(prefs::kNoProxyServer, NULL));
368 &bool_result)); 385 EXPECT_EQ(PrefStore::READ_USE_DEFAULT,
386 store.GetValue(prefs::kProxyAutoDetect, NULL));
369 } 387 }
370 388
371 class ConfigurationPolicyPrefStoreDefaultSearchTest : public testing::Test { 389 class ConfigurationPolicyPrefStoreDefaultSearchTest : public testing::Test {
372 }; 390 };
373 391
374 // Checks that if the policy for default search is valid, i.e. there's a 392 // Checks that if the policy for default search is valid, i.e. there's a
375 // search URL, that all the elements have been given proper defaults. 393 // search URL, that all the elements have been given proper defaults.
376 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MinimallyDefined) { 394 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MinimallyDefined) {
377 const char* const search_url = "http://test.com/search?t={searchTerms}"; 395 const char* const search_url = "http://test.com/search?t={searchTerms}";
378 scoped_ptr<MockConfigurationPolicyProvider> provider( 396 MockConfigurationPolicyProvider provider;
379 new MockConfigurationPolicyProvider()); 397 provider.AddPolicy(kPolicyDefaultSearchProviderEnabled,
380 provider->AddPolicy( 398 Value::CreateBooleanValue(true));
381 kPolicyDefaultSearchProviderEnabled, 399 provider.AddPolicy(kPolicyDefaultSearchProviderSearchURL,
382 Value::CreateBooleanValue(true)); 400 Value::CreateStringValue(search_url));
383 provider->AddPolicy(
384 kPolicyDefaultSearchProviderSearchURL,
385 Value::CreateStringValue(search_url));
386 401
387 ConfigurationPolicyPrefStore store(provider.get()); 402 ConfigurationPolicyPrefStore store(&provider);
388 const DictionaryValue* prefs = store.prefs();
389 403
390 std::string string_result; 404 Value* value = NULL;
391 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL, 405 EXPECT_EQ(PrefStore::READ_OK,
392 &string_result)); 406 store.GetValue(prefs::kDefaultSearchProviderSearchURL, &value));
393 EXPECT_EQ(string_result, search_url); 407 EXPECT_TRUE(StringValue(search_url).Equals(value));
394 408
395 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderName, 409 EXPECT_EQ(PrefStore::READ_OK,
396 &string_result)); 410 store.GetValue(prefs::kDefaultSearchProviderName, &value));
397 EXPECT_EQ(string_result, "test.com"); 411 EXPECT_TRUE(StringValue("test.com").Equals(value));
398 412
399 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderKeyword, 413 EXPECT_EQ(PrefStore::READ_OK,
400 &string_result)); 414 store.GetValue(prefs::kDefaultSearchProviderKeyword, &value));
401 EXPECT_EQ(string_result, std::string()); 415 EXPECT_TRUE(StringValue(std::string()).Equals(value));
402 416
403 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderSuggestURL, 417 EXPECT_EQ(PrefStore::READ_OK,
404 &string_result)); 418 store.GetValue(prefs::kDefaultSearchProviderSuggestURL, &value));
405 EXPECT_EQ(string_result, std::string()); 419 EXPECT_TRUE(StringValue(std::string()).Equals(value));
406 420
407 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderIconURL, 421 EXPECT_EQ(PrefStore::READ_OK,
408 &string_result)); 422 store.GetValue(prefs::kDefaultSearchProviderIconURL, &value));
409 EXPECT_EQ(string_result, std::string()); 423 EXPECT_TRUE(StringValue(std::string()).Equals(value));
410 424
411 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderEncodings, 425 EXPECT_EQ(PrefStore::READ_OK,
412 &string_result)); 426 store.GetValue(prefs::kDefaultSearchProviderEncodings, &value));
413 EXPECT_EQ(string_result, std::string()); 427 EXPECT_TRUE(StringValue(std::string()).Equals(value));
414 } 428 }
415 429
416 // Checks that for a fully defined search policy, all elements have been 430 // Checks that for a fully defined search policy, all elements have been
417 // read properly. 431 // read properly.
418 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, FullyDefined) { 432 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, FullyDefined) {
419 const char* const search_url = "http://test.com/search?t={searchTerms}"; 433 const char* const search_url = "http://test.com/search?t={searchTerms}";
420 const char* const suggest_url = "http://test.com/sugg?={searchTerms}"; 434 const char* const suggest_url = "http://test.com/sugg?={searchTerms}";
421 const char* const icon_url = "http://test.com/icon.jpg"; 435 const char* const icon_url = "http://test.com/icon.jpg";
422 const char* const name = "MyName"; 436 const char* const name = "MyName";
423 const char* const keyword = "MyKeyword"; 437 const char* const keyword = "MyKeyword";
424 const char* const encodings = "UTF-16;UTF-8"; 438 const char* const encodings = "UTF-16;UTF-8";
425 scoped_ptr<MockConfigurationPolicyProvider> provider( 439 MockConfigurationPolicyProvider provider;
426 new MockConfigurationPolicyProvider()); 440 provider.AddPolicy(kPolicyDefaultSearchProviderEnabled,
427 provider->AddPolicy( 441 Value::CreateBooleanValue(true));
428 kPolicyDefaultSearchProviderEnabled, 442 provider.AddPolicy(kPolicyDefaultSearchProviderSearchURL,
429 Value::CreateBooleanValue(true)); 443 Value::CreateStringValue(search_url));
430 provider->AddPolicy( 444 provider.AddPolicy(kPolicyDefaultSearchProviderName,
431 kPolicyDefaultSearchProviderSearchURL, 445 Value::CreateStringValue(name));
432 Value::CreateStringValue(search_url)); 446 provider.AddPolicy(kPolicyDefaultSearchProviderKeyword,
433 provider->AddPolicy( 447 Value::CreateStringValue(keyword));
434 kPolicyDefaultSearchProviderName, 448 provider.AddPolicy(kPolicyDefaultSearchProviderSuggestURL,
435 Value::CreateStringValue(name)); 449 Value::CreateStringValue(suggest_url));
436 provider->AddPolicy( 450 provider.AddPolicy(kPolicyDefaultSearchProviderIconURL,
437 kPolicyDefaultSearchProviderKeyword, 451 Value::CreateStringValue(icon_url));
438 Value::CreateStringValue(keyword)); 452 provider.AddPolicy(kPolicyDefaultSearchProviderEncodings,
439 provider->AddPolicy( 453 Value::CreateStringValue(encodings));
440 kPolicyDefaultSearchProviderSuggestURL,
441 Value::CreateStringValue(suggest_url));
442 provider->AddPolicy(
443 kPolicyDefaultSearchProviderIconURL,
444 Value::CreateStringValue(icon_url));
445 provider->AddPolicy(
446 kPolicyDefaultSearchProviderEncodings,
447 Value::CreateStringValue(encodings));
448 454
449 ConfigurationPolicyPrefStore store(provider.get()); 455 ConfigurationPolicyPrefStore store(&provider);
450 const DictionaryValue* prefs = store.prefs();
451 456
452 std::string result_search_url; 457 Value* value = NULL;
453 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL, 458 EXPECT_EQ(PrefStore::READ_OK,
454 &result_search_url)); 459 store.GetValue(prefs::kDefaultSearchProviderSearchURL, &value));
455 EXPECT_EQ(result_search_url, search_url); 460 EXPECT_TRUE(StringValue(search_url).Equals(value));
456 461
457 std::string result_name; 462 EXPECT_EQ(PrefStore::READ_OK,
458 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderName, 463 store.GetValue(prefs::kDefaultSearchProviderName, &value));
459 &result_name)); 464 EXPECT_TRUE(StringValue(name).Equals(value));
460 EXPECT_EQ(result_name, name);
461 465
462 std::string result_keyword; 466 EXPECT_EQ(PrefStore::READ_OK,
463 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderKeyword, 467 store.GetValue(prefs::kDefaultSearchProviderKeyword, &value));
464 &result_keyword)); 468 EXPECT_TRUE(StringValue(keyword).Equals(value));
465 EXPECT_EQ(result_keyword, keyword);
466 469
467 std::string result_suggest_url; 470 EXPECT_EQ(PrefStore::READ_OK,
468 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderSuggestURL, 471 store.GetValue(prefs::kDefaultSearchProviderSuggestURL, &value));
469 &result_suggest_url)); 472 EXPECT_TRUE(StringValue(suggest_url).Equals(value));
470 EXPECT_EQ(result_suggest_url, suggest_url);
471 473
472 std::string result_icon_url; 474 EXPECT_EQ(PrefStore::READ_OK,
473 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderIconURL, 475 store.GetValue(prefs::kDefaultSearchProviderIconURL, &value));
474 &result_icon_url)); 476 EXPECT_TRUE(StringValue(icon_url).Equals(value));
475 EXPECT_EQ(result_icon_url, icon_url);
476 477
477 std::string result_encodings; 478 EXPECT_EQ(PrefStore::READ_OK,
478 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderEncodings, 479 store.GetValue(prefs::kDefaultSearchProviderEncodings, &value));
479 &result_encodings)); 480 EXPECT_TRUE(StringValue(encodings).Equals(value));
480 EXPECT_EQ(result_encodings, encodings);
481 } 481 }
482 482
483 // Checks that if the default search policy is missing, that no elements of the 483 // Checks that if the default search policy is missing, that no elements of the
484 // default search policy will be present. 484 // default search policy will be present.
485 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MissingUrl) { 485 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MissingUrl) {
486 const char* const suggest_url = "http://test.com/sugg?t={searchTerms}"; 486 const char* const suggest_url = "http://test.com/sugg?t={searchTerms}";
487 const char* const icon_url = "http://test.com/icon.jpg"; 487 const char* const icon_url = "http://test.com/icon.jpg";
488 const char* const name = "MyName"; 488 const char* const name = "MyName";
489 const char* const keyword = "MyKeyword"; 489 const char* const keyword = "MyKeyword";
490 const char* const encodings = "UTF-16;UTF-8"; 490 const char* const encodings = "UTF-16;UTF-8";
491 scoped_ptr<MockConfigurationPolicyProvider> provider( 491 MockConfigurationPolicyProvider provider;
492 new MockConfigurationPolicyProvider()); 492 provider.AddPolicy(kPolicyDefaultSearchProviderEnabled,
493 provider->AddPolicy( 493 Value::CreateBooleanValue(true));
494 kPolicyDefaultSearchProviderEnabled, 494 provider.AddPolicy(kPolicyDefaultSearchProviderName,
495 Value::CreateBooleanValue(true)); 495 Value::CreateStringValue(name));
496 provider->AddPolicy( 496 provider.AddPolicy(kPolicyDefaultSearchProviderKeyword,
497 kPolicyDefaultSearchProviderName, 497 Value::CreateStringValue(keyword));
498 Value::CreateStringValue(name)); 498 provider.AddPolicy(kPolicyDefaultSearchProviderSuggestURL,
499 provider->AddPolicy( 499 Value::CreateStringValue(suggest_url));
500 kPolicyDefaultSearchProviderKeyword, 500 provider.AddPolicy(kPolicyDefaultSearchProviderIconURL,
501 Value::CreateStringValue(keyword)); 501 Value::CreateStringValue(icon_url));
502 provider->AddPolicy( 502 provider.AddPolicy(kPolicyDefaultSearchProviderEncodings,
503 kPolicyDefaultSearchProviderSuggestURL, 503 Value::CreateStringValue(encodings));
504 Value::CreateStringValue(suggest_url));
505 provider->AddPolicy(
506 kPolicyDefaultSearchProviderIconURL,
507 Value::CreateStringValue(icon_url));
508 provider->AddPolicy(
509 kPolicyDefaultSearchProviderEncodings,
510 Value::CreateStringValue(encodings));
511 504
512 ConfigurationPolicyPrefStore store(provider.get()); 505 ConfigurationPolicyPrefStore store(&provider);
513 const DictionaryValue* prefs = store.prefs();
514 506
515 std::string string_result; 507 EXPECT_EQ(PrefStore::READ_NO_VALUE,
516 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL, 508 store.GetValue(prefs::kDefaultSearchProviderSearchURL, NULL));
517 &string_result)); 509 EXPECT_EQ(PrefStore::READ_NO_VALUE,
518 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderName, 510 store.GetValue(prefs::kDefaultSearchProviderName, NULL));
519 &string_result)); 511 EXPECT_EQ(PrefStore::READ_NO_VALUE,
520 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderKeyword, 512 store.GetValue(prefs::kDefaultSearchProviderKeyword, NULL));
521 &string_result)); 513 EXPECT_EQ(PrefStore::READ_NO_VALUE,
522 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSuggestURL, 514 store.GetValue(prefs::kDefaultSearchProviderSuggestURL, NULL));
523 &string_result)); 515 EXPECT_EQ(PrefStore::READ_NO_VALUE,
524 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderIconURL, 516 store.GetValue(prefs::kDefaultSearchProviderIconURL, NULL));
525 &string_result)); 517 EXPECT_EQ(PrefStore::READ_NO_VALUE,
526 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderEncodings, 518 store.GetValue(prefs::kDefaultSearchProviderEncodings, NULL));
527 &string_result));
528 } 519 }
529 520
530 // Checks that if the default search policy is invalid, that no elements of the 521 // Checks that if the default search policy is invalid, that no elements of the
531 // default search policy will be present. 522 // default search policy will be present.
532 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, Invalid) { 523 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, Invalid) {
533 const char* const bad_search_url = "http://test.com/noSearchTerms"; 524 const char* const bad_search_url = "http://test.com/noSearchTerms";
534 const char* const suggest_url = "http://test.com/sugg?t={searchTerms}"; 525 const char* const suggest_url = "http://test.com/sugg?t={searchTerms}";
535 const char* const icon_url = "http://test.com/icon.jpg"; 526 const char* const icon_url = "http://test.com/icon.jpg";
536 const char* const name = "MyName"; 527 const char* const name = "MyName";
537 const char* const keyword = "MyKeyword"; 528 const char* const keyword = "MyKeyword";
538 const char* const encodings = "UTF-16;UTF-8"; 529 const char* const encodings = "UTF-16;UTF-8";
539 scoped_ptr<MockConfigurationPolicyProvider> provider( 530 MockConfigurationPolicyProvider provider;
540 new MockConfigurationPolicyProvider()); 531 provider.AddPolicy(kPolicyDefaultSearchProviderEnabled,
541 provider->AddPolicy( 532 Value::CreateBooleanValue(true));
542 kPolicyDefaultSearchProviderEnabled, 533 provider.AddPolicy(kPolicyDefaultSearchProviderSearchURL,
543 Value::CreateBooleanValue(true)); 534 Value::CreateStringValue(bad_search_url));
544 provider->AddPolicy( 535 provider.AddPolicy(kPolicyDefaultSearchProviderName,
545 kPolicyDefaultSearchProviderSearchURL, 536 Value::CreateStringValue(name));
546 Value::CreateStringValue(bad_search_url)); 537 provider.AddPolicy(kPolicyDefaultSearchProviderKeyword,
547 provider->AddPolicy( 538 Value::CreateStringValue(keyword));
548 kPolicyDefaultSearchProviderName, 539 provider.AddPolicy(kPolicyDefaultSearchProviderSuggestURL,
549 Value::CreateStringValue(name)); 540 Value::CreateStringValue(suggest_url));
550 provider->AddPolicy( 541 provider.AddPolicy(kPolicyDefaultSearchProviderIconURL,
551 kPolicyDefaultSearchProviderKeyword, 542 Value::CreateStringValue(icon_url));
552 Value::CreateStringValue(keyword)); 543 provider.AddPolicy(kPolicyDefaultSearchProviderEncodings,
553 provider->AddPolicy( 544 Value::CreateStringValue(encodings));
554 kPolicyDefaultSearchProviderSuggestURL,
555 Value::CreateStringValue(suggest_url));
556 provider->AddPolicy(
557 kPolicyDefaultSearchProviderIconURL,
558 Value::CreateStringValue(icon_url));
559 provider->AddPolicy(
560 kPolicyDefaultSearchProviderEncodings,
561 Value::CreateStringValue(encodings));
562 545
563 ConfigurationPolicyPrefStore store(provider.get()); 546 ConfigurationPolicyPrefStore store(&provider);
564 const DictionaryValue* const prefs = store.prefs();
565 547
566 std::string string_result; 548 EXPECT_EQ(PrefStore::READ_NO_VALUE,
567 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderEnabled, 549 store.GetValue(prefs::kDefaultSearchProviderSearchURL, NULL));
568 &string_result)); 550 EXPECT_EQ(PrefStore::READ_NO_VALUE,
569 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL, 551 store.GetValue(prefs::kDefaultSearchProviderName, NULL));
570 &string_result)); 552 EXPECT_EQ(PrefStore::READ_NO_VALUE,
571 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderName, 553 store.GetValue(prefs::kDefaultSearchProviderKeyword, NULL));
572 &string_result)); 554 EXPECT_EQ(PrefStore::READ_NO_VALUE,
573 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderKeyword, 555 store.GetValue(prefs::kDefaultSearchProviderSuggestURL, NULL));
574 &string_result)); 556 EXPECT_EQ(PrefStore::READ_NO_VALUE,
575 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSuggestURL, 557 store.GetValue(prefs::kDefaultSearchProviderIconURL, NULL));
576 &string_result)); 558 EXPECT_EQ(PrefStore::READ_NO_VALUE,
577 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderIconURL, 559 store.GetValue(prefs::kDefaultSearchProviderEncodings, NULL));
578 &string_result));
579 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderEncodings,
580 &string_result));
581 } 560 }
582 561
583 // Test cases for the Sync policy setting. 562 // Test cases for the Sync policy setting.
584 class ConfigurationPolicyPrefStoreSyncTest 563 class ConfigurationPolicyPrefStoreSyncTest
585 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> { 564 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> {
586 }; 565 };
587 566
588 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) { 567 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) {
589 bool result = false; 568 EXPECT_EQ(PrefStore::READ_NO_VALUE,
590 EXPECT_FALSE(store_.prefs()->GetBoolean(prefs::kSyncManaged, &result)); 569 store_.GetValue(prefs::kSyncManaged, NULL));
591 } 570 }
592 571
593 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Enabled) { 572 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Enabled) {
594 store_.Apply(kPolicySyncDisabled, Value::CreateBooleanValue(false)); 573 provider_.AddPolicy(kPolicySyncDisabled, Value::CreateBooleanValue(false));
574 RefreshPolicy();
595 // Enabling Sync should not set the pref. 575 // Enabling Sync should not set the pref.
596 bool result = false; 576 EXPECT_EQ(PrefStore::READ_NO_VALUE,
597 EXPECT_FALSE(store_.prefs()->GetBoolean(prefs::kSyncManaged, &result)); 577 store_.GetValue(prefs::kSyncManaged, NULL));
598 } 578 }
599 579
600 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Disabled) { 580 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Disabled) {
601 store_.Apply(kPolicySyncDisabled, Value::CreateBooleanValue(true)); 581 provider_.AddPolicy(kPolicySyncDisabled, Value::CreateBooleanValue(true));
582 RefreshPolicy();
602 // Sync should be flagged as managed. 583 // Sync should be flagged as managed.
603 bool result = false; 584 Value* value = NULL;
604 EXPECT_TRUE(store_.prefs()->GetBoolean(prefs::kSyncManaged, &result)); 585 EXPECT_EQ(PrefStore::READ_OK, store_.GetValue(prefs::kSyncManaged, &value));
605 EXPECT_TRUE(result); 586 EXPECT_TRUE(FundamentalValue(true).Equals(value));
606 } 587 }
607 588
608 // Test cases for the AutoFill policy setting. 589 // Test cases for the AutoFill policy setting.
609 class ConfigurationPolicyPrefStoreAutoFillTest 590 class ConfigurationPolicyPrefStoreAutoFillTest
610 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> { 591 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> {
611 }; 592 };
612 593
613 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Default) { 594 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Default) {
614 bool result = false; 595 EXPECT_EQ(PrefStore::READ_NO_VALUE,
615 EXPECT_FALSE(store_.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result)); 596 store_.GetValue(prefs::kSyncManaged, NULL));
616 } 597 }
617 598
618 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Enabled) { 599 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Enabled) {
619 store_.Apply(kPolicyAutoFillEnabled, Value::CreateBooleanValue(true)); 600 provider_.AddPolicy(kPolicyAutoFillEnabled, Value::CreateBooleanValue(true));
601 RefreshPolicy();
620 // Enabling AutoFill should not set the pref. 602 // Enabling AutoFill should not set the pref.
621 bool result = false; 603 EXPECT_EQ(PrefStore::READ_NO_VALUE,
622 EXPECT_FALSE(store_.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result)); 604 store_.GetValue(prefs::kSyncManaged, NULL));
623 } 605 }
624 606
625 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Disabled) { 607 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Disabled) {
626 store_.Apply(kPolicyAutoFillEnabled, Value::CreateBooleanValue(false)); 608 provider_.AddPolicy(kPolicyAutoFillEnabled, Value::CreateBooleanValue(false));
609 RefreshPolicy();
627 // Disabling AutoFill should switch the pref to managed. 610 // Disabling AutoFill should switch the pref to managed.
628 bool result = true; 611 Value* value = NULL;
629 EXPECT_TRUE(store_.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result)); 612 EXPECT_EQ(PrefStore::READ_OK,
630 EXPECT_FALSE(result); 613 store_.GetValue(prefs::kAutoFillEnabled, &value));
614 EXPECT_TRUE(FundamentalValue(false).Equals(value));
615 }
616
617 // Exercises the policy refresh mechanism.
618 class ConfigurationPolicyPrefStoreRefreshTest
619 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> {
620 protected:
621 virtual void SetUp() {
622 store_.AddObserver(&observer_);
623 }
624
625 virtual void TearDown() {
626 store_.RemoveObserver(&observer_);
627 }
628
629 PrefStoreObserverMock observer_;
630 };
631
632 TEST_F(ConfigurationPolicyPrefStoreRefreshTest, Refresh) {
633 Value* value = NULL;
634 EXPECT_EQ(PrefStore::READ_NO_VALUE,
635 store_.GetValue(prefs::kHomePage, NULL));
636
637 EXPECT_CALL(observer_, OnPrefValueChanged(prefs::kHomePage)).Times(1);
638 provider_.AddPolicy(kPolicyHomePage,
639 Value::CreateStringValue("http://www.chromium.org"));
640 RefreshPolicy();
641 Mock::VerifyAndClearExpectations(&observer_);
642 EXPECT_EQ(PrefStore::READ_OK,
643 store_.GetValue(prefs::kHomePage, &value));
644 EXPECT_TRUE(StringValue("http://www.chromium.org").Equals(value));
645
646 EXPECT_CALL(observer_, OnPrefValueChanged(_)).Times(0);
647 RefreshPolicy();
648 Mock::VerifyAndClearExpectations(&observer_);
649
650 EXPECT_CALL(observer_, OnPrefValueChanged(prefs::kHomePage)).Times(1);
651 provider_.RemovePolicy(kPolicyHomePage);
652 RefreshPolicy();
653 Mock::VerifyAndClearExpectations(&observer_);
654 EXPECT_EQ(PrefStore::READ_NO_VALUE,
655 store_.GetValue(prefs::kHomePage, NULL));
656 }
657
658 TEST_F(ConfigurationPolicyPrefStoreRefreshTest, Initialization) {
659 EXPECT_FALSE(store_.IsInitializationComplete());
660
661 EXPECT_CALL(observer_, OnInitializationCompleted()).Times(1);
662
663 provider_.SetInitializationComplete(true);
664 EXPECT_FALSE(store_.IsInitializationComplete());
665
666 RefreshPolicy();
667 Mock::VerifyAndClearExpectations(&observer_);
668 EXPECT_TRUE(store_.IsInitializationComplete());
631 } 669 }
632 670
633 } // namespace policy 671 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698