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

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

Powered by Google App Engine
This is Rietveld 408576698