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

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

Issue 5915004: Introduce incognito preference settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Whitespaces + fixes for trybot 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> 5 #include <gtest/gtest.h>
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/ref_counted.h"
8 #include "chrome/browser/policy/configuration_policy_pref_store.h" 9 #include "chrome/browser/policy/configuration_policy_pref_store.h"
9 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 10 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
10 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
11 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
12 13
13 namespace policy { 14 namespace policy {
14 15
15 // Holds a set of test parameters, consisting of pref name and policy type. 16 // Holds a set of test parameters, consisting of pref name and policy type.
16 class TypeAndName { 17 class TypeAndName {
17 public: 18 public:
18 TypeAndName(ConfigurationPolicyType type, const char* pref_name) 19 TypeAndName(ConfigurationPolicyType type, const char* pref_name)
19 : type_(type), 20 : type_(type),
20 pref_name_(pref_name) {} 21 pref_name_(pref_name) {}
21 22
22 ConfigurationPolicyType type() const { return type_; } 23 ConfigurationPolicyType type() const { return type_; }
23 const char* pref_name() const { return pref_name_; } 24 const char* pref_name() const { return pref_name_; }
24 25
25 private: 26 private:
26 ConfigurationPolicyType type_; 27 ConfigurationPolicyType type_;
27 const char* pref_name_; 28 const char* pref_name_;
28 }; 29 };
29 30
30 template<typename TESTBASE> 31 template<typename TESTBASE>
31 class ConfigurationPolicyPrefStoreTestBase : public TESTBASE { 32 class ConfigurationPolicyPrefStoreTestBase : public TESTBASE {
32 protected: 33 protected:
33 ConfigurationPolicyPrefStoreTestBase() 34 ConfigurationPolicyPrefStoreTestBase()
34 : provider_(), 35 : provider_(),
35 store_(&provider_) {} 36 store_(new ConfigurationPolicyPrefStore(&provider_)) {}
36 37
37 MockConfigurationPolicyProvider provider_; 38 MockConfigurationPolicyProvider provider_;
38 ConfigurationPolicyPrefStore store_; 39 scoped_refptr<ConfigurationPolicyPrefStore> store_;
39 }; 40 };
40 41
41 // Test cases for list-valued policy settings. 42 // Test cases for list-valued policy settings.
42 class ConfigurationPolicyPrefStoreListTest 43 class ConfigurationPolicyPrefStoreListTest
43 : public ConfigurationPolicyPrefStoreTestBase< 44 : public ConfigurationPolicyPrefStoreTestBase<
44 testing::TestWithParam<TypeAndName> > { 45 testing::TestWithParam<TypeAndName> > {
45 }; 46 };
46 47
47 TEST_P(ConfigurationPolicyPrefStoreListTest, GetDefault) { 48 TEST_P(ConfigurationPolicyPrefStoreListTest, GetDefault) {
48 ListValue* list = NULL; 49 ListValue* list = NULL;
49 EXPECT_FALSE(store_.prefs()->GetList(GetParam().pref_name(), &list)); 50 EXPECT_FALSE(store_->prefs()->GetList(GetParam().pref_name(), &list));
50 } 51 }
51 52
52 TEST_P(ConfigurationPolicyPrefStoreListTest, SetValue) { 53 TEST_P(ConfigurationPolicyPrefStoreListTest, SetValue) {
53 ListValue* in_value = new ListValue(); 54 ListValue* in_value = new ListValue();
54 in_value->Append(Value::CreateStringValue("test1")); 55 in_value->Append(Value::CreateStringValue("test1"));
55 in_value->Append(Value::CreateStringValue("test2,")); 56 in_value->Append(Value::CreateStringValue("test2,"));
56 store_.Apply(GetParam().type(), in_value); 57 store_->Apply(GetParam().type(), in_value);
57 ListValue* list = NULL; 58 ListValue* list = NULL;
58 EXPECT_TRUE(store_.prefs()->GetList(GetParam().pref_name(), &list)); 59 EXPECT_TRUE(store_->prefs()->GetList(GetParam().pref_name(), &list));
59 ListValue::const_iterator current(list->begin()); 60 ListValue::const_iterator current(list->begin());
60 const ListValue::const_iterator end(list->end()); 61 const ListValue::const_iterator end(list->end());
61 ASSERT_TRUE(current != end); 62 ASSERT_TRUE(current != end);
62 std::string value; 63 std::string value;
63 (*current)->GetAsString(&value); 64 (*current)->GetAsString(&value);
64 EXPECT_EQ("test1", value); 65 EXPECT_EQ("test1", value);
65 ++current; 66 ++current;
66 ASSERT_TRUE(current != end); 67 ASSERT_TRUE(current != end);
67 (*current)->GetAsString(&value); 68 (*current)->GetAsString(&value);
68 EXPECT_EQ("test2,", value); 69 EXPECT_EQ("test2,", value);
(...skipping 15 matching lines...) Expand all
84 prefs::kPluginsPluginsBlacklist))); 85 prefs::kPluginsPluginsBlacklist)));
85 86
86 // Test cases for string-valued policy settings. 87 // Test cases for string-valued policy settings.
87 class ConfigurationPolicyPrefStoreStringTest 88 class ConfigurationPolicyPrefStoreStringTest
88 : public ConfigurationPolicyPrefStoreTestBase< 89 : public ConfigurationPolicyPrefStoreTestBase<
89 testing::TestWithParam<TypeAndName> > { 90 testing::TestWithParam<TypeAndName> > {
90 }; 91 };
91 92
92 TEST_P(ConfigurationPolicyPrefStoreStringTest, GetDefault) { 93 TEST_P(ConfigurationPolicyPrefStoreStringTest, GetDefault) {
93 std::string result; 94 std::string result;
94 EXPECT_FALSE(store_.prefs()->GetString(GetParam().pref_name(), &result)); 95 EXPECT_FALSE(store_->prefs()->GetString(GetParam().pref_name(), &result));
95 } 96 }
96 97
97 TEST_P(ConfigurationPolicyPrefStoreStringTest, SetValue) { 98 TEST_P(ConfigurationPolicyPrefStoreStringTest, SetValue) {
98 store_.Apply(GetParam().type(), 99 store_->Apply(GetParam().type(),
99 Value::CreateStringValue("http://chromium.org")); 100 Value::CreateStringValue("http://chromium.org"));
100 std::string result; 101 std::string result;
101 EXPECT_TRUE(store_.prefs()->GetString(GetParam().pref_name(), &result)); 102 EXPECT_TRUE(store_->prefs()->GetString(GetParam().pref_name(), &result));
102 EXPECT_EQ(result, "http://chromium.org"); 103 EXPECT_EQ(result, "http://chromium.org");
103 } 104 }
104 105
105 INSTANTIATE_TEST_CASE_P( 106 INSTANTIATE_TEST_CASE_P(
106 ConfigurationPolicyPrefStoreStringTestInstance, 107 ConfigurationPolicyPrefStoreStringTestInstance,
107 ConfigurationPolicyPrefStoreStringTest, 108 ConfigurationPolicyPrefStoreStringTest,
108 testing::Values( 109 testing::Values(
109 TypeAndName(kPolicyHomePage, 110 TypeAndName(kPolicyHomePage,
110 prefs::kHomePage), 111 prefs::kHomePage),
111 TypeAndName(kPolicyProxyServer, 112 TypeAndName(kPolicyProxyServer,
(...skipping 16 matching lines...) Expand all
128 prefs::kGSSAPILibraryName))); 129 prefs::kGSSAPILibraryName)));
129 130
130 // Test cases for boolean-valued policy settings. 131 // Test cases for boolean-valued policy settings.
131 class ConfigurationPolicyPrefStoreBooleanTest 132 class ConfigurationPolicyPrefStoreBooleanTest
132 : public ConfigurationPolicyPrefStoreTestBase< 133 : public ConfigurationPolicyPrefStoreTestBase<
133 testing::TestWithParam<TypeAndName> > { 134 testing::TestWithParam<TypeAndName> > {
134 }; 135 };
135 136
136 TEST_P(ConfigurationPolicyPrefStoreBooleanTest, GetDefault) { 137 TEST_P(ConfigurationPolicyPrefStoreBooleanTest, GetDefault) {
137 bool result = false; 138 bool result = false;
138 EXPECT_FALSE(store_.prefs()->GetBoolean(GetParam().pref_name(), &result)); 139 EXPECT_FALSE(store_->prefs()->GetBoolean(GetParam().pref_name(), &result));
139 } 140 }
140 141
141 TEST_P(ConfigurationPolicyPrefStoreBooleanTest, SetValue) { 142 TEST_P(ConfigurationPolicyPrefStoreBooleanTest, SetValue) {
142 store_.Apply(GetParam().type(), Value::CreateBooleanValue(false)); 143 store_->Apply(GetParam().type(), Value::CreateBooleanValue(false));
143 bool result = true; 144 bool result = true;
144 EXPECT_TRUE(store_.prefs()->GetBoolean(GetParam().pref_name(), &result)); 145 EXPECT_TRUE(store_->prefs()->GetBoolean(GetParam().pref_name(), &result));
145 EXPECT_FALSE(result); 146 EXPECT_FALSE(result);
146 147
147 store_.Apply(GetParam().type(), Value::CreateBooleanValue(true)); 148 store_->Apply(GetParam().type(), Value::CreateBooleanValue(true));
148 result = false; 149 result = false;
149 EXPECT_TRUE(store_.prefs()->GetBoolean(GetParam().pref_name(), &result)); 150 EXPECT_TRUE(store_->prefs()->GetBoolean(GetParam().pref_name(), &result));
150 EXPECT_TRUE(result); 151 EXPECT_TRUE(result);
151 } 152 }
152 153
153 INSTANTIATE_TEST_CASE_P( 154 INSTANTIATE_TEST_CASE_P(
154 ConfigurationPolicyPrefStoreBooleanTestInstance, 155 ConfigurationPolicyPrefStoreBooleanTestInstance,
155 ConfigurationPolicyPrefStoreBooleanTest, 156 ConfigurationPolicyPrefStoreBooleanTest,
156 testing::Values( 157 testing::Values(
157 TypeAndName(kPolicyHomepageIsNewTabPage, 158 TypeAndName(kPolicyHomepageIsNewTabPage,
158 prefs::kHomePageIsNewTabPage), 159 prefs::kHomePageIsNewTabPage),
159 TypeAndName(kPolicyAlternateErrorPagesEnabled, 160 TypeAndName(kPolicyAlternateErrorPagesEnabled,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 #endif // defined(OS_CHROMEOS) 198 #endif // defined(OS_CHROMEOS)
198 199
199 // Test cases for integer-valued policy settings. 200 // Test cases for integer-valued policy settings.
200 class ConfigurationPolicyPrefStoreIntegerTest 201 class ConfigurationPolicyPrefStoreIntegerTest
201 : public ConfigurationPolicyPrefStoreTestBase< 202 : public ConfigurationPolicyPrefStoreTestBase<
202 testing::TestWithParam<TypeAndName> > { 203 testing::TestWithParam<TypeAndName> > {
203 }; 204 };
204 205
205 TEST_P(ConfigurationPolicyPrefStoreIntegerTest, GetDefault) { 206 TEST_P(ConfigurationPolicyPrefStoreIntegerTest, GetDefault) {
206 int result = 0; 207 int result = 0;
207 EXPECT_FALSE(store_.prefs()->GetInteger(GetParam().pref_name(), &result)); 208 EXPECT_FALSE(store_->prefs()->GetInteger(GetParam().pref_name(), &result));
208 } 209 }
209 210
210 TEST_P(ConfigurationPolicyPrefStoreIntegerTest, SetValue) { 211 TEST_P(ConfigurationPolicyPrefStoreIntegerTest, SetValue) {
211 store_.Apply(GetParam().type(), Value::CreateIntegerValue(2)); 212 store_->Apply(GetParam().type(), Value::CreateIntegerValue(2));
212 int result = 0; 213 int result = 0;
213 EXPECT_TRUE(store_.prefs()->GetInteger(GetParam().pref_name(), &result)); 214 EXPECT_TRUE(store_->prefs()->GetInteger(GetParam().pref_name(), &result));
214 EXPECT_EQ(result, 2); 215 EXPECT_EQ(result, 2);
215 } 216 }
216 217
217 INSTANTIATE_TEST_CASE_P( 218 INSTANTIATE_TEST_CASE_P(
218 ConfigurationPolicyPrefStoreIntegerTestInstance, 219 ConfigurationPolicyPrefStoreIntegerTestInstance,
219 ConfigurationPolicyPrefStoreIntegerTest, 220 ConfigurationPolicyPrefStoreIntegerTest,
220 testing::Values( 221 testing::Values(
221 TypeAndName(kPolicyRestoreOnStartup, 222 TypeAndName(kPolicyRestoreOnStartup,
222 prefs::kRestoreOnStartup))); 223 prefs::kRestoreOnStartup)));
223 224
224 // Test cases for the proxy policy settings. 225 // Test cases for the proxy policy settings.
225 class ConfigurationPolicyPrefStoreProxyTest : public testing::Test { 226 class ConfigurationPolicyPrefStoreProxyTest : public testing::Test {
226 }; 227 };
227 228
228 TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptions) { 229 TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptions) {
229 scoped_ptr<MockConfigurationPolicyProvider> provider( 230 scoped_ptr<MockConfigurationPolicyProvider> provider(
230 new MockConfigurationPolicyProvider()); 231 new MockConfigurationPolicyProvider());
231 provider->AddPolicy(kPolicyProxyBypassList, 232 provider->AddPolicy(kPolicyProxyBypassList,
232 Value::CreateStringValue("http://chromium.org/override")); 233 Value::CreateStringValue("http://chromium.org/override"));
233 provider->AddPolicy(kPolicyProxyPacUrl, 234 provider->AddPolicy(kPolicyProxyPacUrl,
234 Value::CreateStringValue("http://short.org/proxy.pac")); 235 Value::CreateStringValue("http://short.org/proxy.pac"));
235 provider->AddPolicy(kPolicyProxyServer, 236 provider->AddPolicy(kPolicyProxyServer,
236 Value::CreateStringValue("chromium.org")); 237 Value::CreateStringValue("chromium.org"));
237 provider->AddPolicy(kPolicyProxyServerMode, 238 provider->AddPolicy(kPolicyProxyServerMode,
238 Value::CreateIntegerValue( 239 Value::CreateIntegerValue(
239 kPolicyManuallyConfiguredProxyMode)); 240 kPolicyManuallyConfiguredProxyMode));
240 241
241 ConfigurationPolicyPrefStore store(provider.get()); 242 scoped_refptr<ConfigurationPolicyPrefStore> store(
243 new ConfigurationPolicyPrefStore(provider.get()));
242 244
243 std::string string_result; 245 std::string string_result;
244 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyBypassList, 246 EXPECT_TRUE(store->prefs()->GetString(prefs::kProxyBypassList,
245 &string_result)); 247 &string_result));
246 EXPECT_EQ("http://chromium.org/override", string_result); 248 EXPECT_EQ("http://chromium.org/override", string_result);
247 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 249 EXPECT_TRUE(store->prefs()->GetString(prefs::kProxyPacUrl, &string_result));
248 EXPECT_EQ("http://short.org/proxy.pac", string_result); 250 EXPECT_EQ("http://short.org/proxy.pac", string_result);
249 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 251 EXPECT_TRUE(store->prefs()->GetString(prefs::kProxyServer, &string_result));
250 EXPECT_EQ("chromium.org", string_result); 252 EXPECT_EQ("chromium.org", string_result);
251 bool bool_result; 253 bool bool_result;
252 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 254 EXPECT_TRUE(store->prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
253 EXPECT_FALSE(bool_result); 255 EXPECT_FALSE(bool_result);
254 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result)); 256 EXPECT_TRUE(store->prefs()->GetBoolean(prefs::kProxyAutoDetect,
257 &bool_result));
255 EXPECT_FALSE(bool_result); 258 EXPECT_FALSE(bool_result);
256 } 259 }
257 260
258 TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxy) { 261 TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxy) {
259 scoped_ptr<MockConfigurationPolicyProvider> provider( 262 scoped_ptr<MockConfigurationPolicyProvider> provider(
260 new MockConfigurationPolicyProvider()); 263 new MockConfigurationPolicyProvider());
261 provider->AddPolicy(kPolicyProxyBypassList, 264 provider->AddPolicy(kPolicyProxyBypassList,
262 Value::CreateStringValue("http://chromium.org/override")); 265 Value::CreateStringValue("http://chromium.org/override"));
263 provider->AddPolicy(kPolicyProxyServerMode, 266 provider->AddPolicy(kPolicyProxyServerMode,
264 Value::CreateIntegerValue( 267 Value::CreateIntegerValue(
265 kPolicyNoProxyServerMode)); 268 kPolicyNoProxyServerMode));
266 269
267 ConfigurationPolicyPrefStore store(provider.get()); 270 scoped_refptr<ConfigurationPolicyPrefStore> store(
271 new ConfigurationPolicyPrefStore(provider.get()));
268 272
269 std::string string_result; 273 std::string string_result;
270 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, 274 EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyBypassList,
271 &string_result)); 275 &string_result));
272 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 276 EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyPacUrl, &string_result));
273 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 277 EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyServer, &string_result));
274 bool bool_result; 278 bool bool_result;
275 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 279 EXPECT_TRUE(store->prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
276 EXPECT_TRUE(bool_result); 280 EXPECT_TRUE(bool_result);
277 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result)); 281 EXPECT_TRUE(store->prefs()->GetBoolean(prefs::kProxyAutoDetect,
282 &bool_result));
278 EXPECT_FALSE(bool_result); 283 EXPECT_FALSE(bool_result);
279 } 284 }
280 285
281 TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxyReversedApplyOrder) { 286 TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxyReversedApplyOrder) {
282 scoped_ptr<MockConfigurationPolicyProvider> provider( 287 scoped_ptr<MockConfigurationPolicyProvider> provider(
283 new MockConfigurationPolicyProvider()); 288 new MockConfigurationPolicyProvider());
284 provider->AddPolicy(kPolicyProxyServerMode, 289 provider->AddPolicy(kPolicyProxyServerMode,
285 Value::CreateIntegerValue( 290 Value::CreateIntegerValue(
286 kPolicyNoProxyServerMode)); 291 kPolicyNoProxyServerMode));
287 provider->AddPolicy(kPolicyProxyBypassList, 292 provider->AddPolicy(kPolicyProxyBypassList,
288 Value::CreateStringValue("http://chromium.org/override")); 293 Value::CreateStringValue("http://chromium.org/override"));
289 294
290 ConfigurationPolicyPrefStore store(provider.get()); 295 scoped_refptr<ConfigurationPolicyPrefStore> store(
296 new ConfigurationPolicyPrefStore(provider.get()));
291 297
292 std::string string_result; 298 std::string string_result;
293 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, 299 EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyBypassList,
294 &string_result)); 300 &string_result));
295 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 301 EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyPacUrl, &string_result));
296 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 302 EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyServer, &string_result));
297 bool bool_result; 303 bool bool_result;
298 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 304 EXPECT_TRUE(store->prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
299 EXPECT_TRUE(bool_result); 305 EXPECT_TRUE(bool_result);
300 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result)); 306 EXPECT_TRUE(store->prefs()->GetBoolean(prefs::kProxyAutoDetect,
307 &bool_result));
301 EXPECT_FALSE(bool_result); 308 EXPECT_FALSE(bool_result);
302 } 309 }
303 310
304 TEST_F(ConfigurationPolicyPrefStoreProxyTest, AutoDetect) { 311 TEST_F(ConfigurationPolicyPrefStoreProxyTest, AutoDetect) {
305 scoped_ptr<MockConfigurationPolicyProvider> provider( 312 scoped_ptr<MockConfigurationPolicyProvider> provider(
306 new MockConfigurationPolicyProvider()); 313 new MockConfigurationPolicyProvider());
307 provider->AddPolicy(kPolicyProxyServerMode, 314 provider->AddPolicy(kPolicyProxyServerMode,
308 Value::CreateIntegerValue( 315 Value::CreateIntegerValue(
309 kPolicyAutoDetectProxyMode)); 316 kPolicyAutoDetectProxyMode));
310 317
311 ConfigurationPolicyPrefStore store(provider.get()); 318 scoped_refptr<ConfigurationPolicyPrefStore> store(
319 new ConfigurationPolicyPrefStore(provider.get()));
312 320
313 std::string string_result; 321 std::string string_result;
314 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, 322 EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyBypassList,
315 &string_result)); 323 &string_result));
316 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 324 EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyPacUrl, &string_result));
317 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 325 EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyServer, &string_result));
318 bool bool_result; 326 bool bool_result;
319 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 327 EXPECT_TRUE(store->prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
320 EXPECT_FALSE(bool_result); 328 EXPECT_FALSE(bool_result);
321 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result)); 329 EXPECT_TRUE(store->prefs()->GetBoolean(prefs::kProxyAutoDetect,
330 &bool_result));
322 EXPECT_TRUE(bool_result); 331 EXPECT_TRUE(bool_result);
323 } 332 }
324 333
325 TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystem) { 334 TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystem) {
326 scoped_ptr<MockConfigurationPolicyProvider> provider( 335 scoped_ptr<MockConfigurationPolicyProvider> provider(
327 new MockConfigurationPolicyProvider()); 336 new MockConfigurationPolicyProvider());
328 provider->AddPolicy(kPolicyProxyBypassList, 337 provider->AddPolicy(kPolicyProxyBypassList,
329 Value::CreateStringValue("http://chromium.org/override")); 338 Value::CreateStringValue("http://chromium.org/override"));
330 provider->AddPolicy(kPolicyProxyServerMode, 339 provider->AddPolicy(kPolicyProxyServerMode,
331 Value::CreateIntegerValue( 340 Value::CreateIntegerValue(
332 kPolicyUseSystemProxyMode)); 341 kPolicyUseSystemProxyMode));
333 342
334 ConfigurationPolicyPrefStore store(provider.get()); 343 scoped_refptr<ConfigurationPolicyPrefStore> store(
344 new ConfigurationPolicyPrefStore(provider.get()));
335 345
336 std::string string_result; 346 std::string string_result;
337 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, 347 EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyBypassList,
338 &string_result)); 348 &string_result));
339 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 349 EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyPacUrl, &string_result));
340 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 350 EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyServer, &string_result));
341 bool bool_result; 351 bool bool_result;
342 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 352 EXPECT_FALSE(store->prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
343 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, 353 EXPECT_FALSE(store->prefs()->GetBoolean(prefs::kProxyAutoDetect,
344 &bool_result)); 354 &bool_result));
345 } 355 }
346 356
347 TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystemReversedApplyOrder) { 357 TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystemReversedApplyOrder) {
348 scoped_ptr<MockConfigurationPolicyProvider> provider( 358 scoped_ptr<MockConfigurationPolicyProvider> provider(
349 new MockConfigurationPolicyProvider()); 359 new MockConfigurationPolicyProvider());
350 provider->AddPolicy(kPolicyProxyServerMode, 360 provider->AddPolicy(kPolicyProxyServerMode,
351 Value::CreateIntegerValue( 361 Value::CreateIntegerValue(
352 kPolicyUseSystemProxyMode)); 362 kPolicyUseSystemProxyMode));
353 provider->AddPolicy(kPolicyProxyBypassList, 363 provider->AddPolicy(kPolicyProxyBypassList,
354 Value::CreateStringValue("http://chromium.org/override")); 364 Value::CreateStringValue("http://chromium.org/override"));
355 365
356 ConfigurationPolicyPrefStore store(provider.get()); 366 scoped_refptr<ConfigurationPolicyPrefStore> store(
367 new ConfigurationPolicyPrefStore(provider.get()));
357 368
358 std::string string_result; 369 std::string string_result;
359 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, 370 EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyBypassList,
360 &string_result)); 371 &string_result));
361 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 372 EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyPacUrl, &string_result));
362 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 373 EXPECT_FALSE(store->prefs()->GetString(prefs::kProxyServer, &string_result));
363 bool bool_result; 374 bool bool_result;
364 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 375 EXPECT_FALSE(store->prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
365 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, 376 EXPECT_FALSE(store->prefs()->GetBoolean(prefs::kProxyAutoDetect,
366 &bool_result)); 377 &bool_result));
367 } 378 }
368 379
369 class ConfigurationPolicyPrefStoreDefaultSearchTest : public testing::Test { 380 class ConfigurationPolicyPrefStoreDefaultSearchTest : public testing::Test {
370 }; 381 };
371 382
372 // Checks that if the policy for default search is valid, i.e. there's a 383 // Checks that if the policy for default search is valid, i.e. there's a
373 // search URL, that all the elements have been given proper defaults. 384 // search URL, that all the elements have been given proper defaults.
374 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MinimallyDefined) { 385 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MinimallyDefined) {
375 const char* const search_url = "http://test.com/search?t={searchTerms}"; 386 const char* const search_url = "http://test.com/search?t={searchTerms}";
376 scoped_ptr<MockConfigurationPolicyProvider> provider( 387 scoped_ptr<MockConfigurationPolicyProvider> provider(
377 new MockConfigurationPolicyProvider()); 388 new MockConfigurationPolicyProvider());
378 provider->AddPolicy( 389 provider->AddPolicy(
379 kPolicyDefaultSearchProviderEnabled, 390 kPolicyDefaultSearchProviderEnabled,
380 Value::CreateBooleanValue(true)); 391 Value::CreateBooleanValue(true));
381 provider->AddPolicy( 392 provider->AddPolicy(
382 kPolicyDefaultSearchProviderSearchURL, 393 kPolicyDefaultSearchProviderSearchURL,
383 Value::CreateStringValue(search_url)); 394 Value::CreateStringValue(search_url));
384 395
385 ConfigurationPolicyPrefStore store(provider.get()); 396 scoped_refptr<ConfigurationPolicyPrefStore> store(
386 const DictionaryValue* prefs = store.prefs(); 397 new ConfigurationPolicyPrefStore(provider.get()));
398 const DictionaryValue* prefs = store->prefs();
387 399
388 std::string string_result; 400 std::string string_result;
389 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL, 401 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL,
390 &string_result)); 402 &string_result));
391 EXPECT_EQ(string_result, search_url); 403 EXPECT_EQ(string_result, search_url);
392 404
393 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderName, 405 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderName,
394 &string_result)); 406 &string_result));
395 EXPECT_EQ(string_result, "test.com"); 407 EXPECT_EQ(string_result, "test.com");
396 408
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 provider->AddPolicy( 449 provider->AddPolicy(
438 kPolicyDefaultSearchProviderSuggestURL, 450 kPolicyDefaultSearchProviderSuggestURL,
439 Value::CreateStringValue(suggest_url)); 451 Value::CreateStringValue(suggest_url));
440 provider->AddPolicy( 452 provider->AddPolicy(
441 kPolicyDefaultSearchProviderIconURL, 453 kPolicyDefaultSearchProviderIconURL,
442 Value::CreateStringValue(icon_url)); 454 Value::CreateStringValue(icon_url));
443 provider->AddPolicy( 455 provider->AddPolicy(
444 kPolicyDefaultSearchProviderEncodings, 456 kPolicyDefaultSearchProviderEncodings,
445 Value::CreateStringValue(encodings)); 457 Value::CreateStringValue(encodings));
446 458
447 ConfigurationPolicyPrefStore store(provider.get()); 459 scoped_refptr<ConfigurationPolicyPrefStore> store(
448 const DictionaryValue* prefs = store.prefs(); 460 new ConfigurationPolicyPrefStore(provider.get()));
461 const DictionaryValue* prefs = store->prefs();
449 462
450 std::string result_search_url; 463 std::string result_search_url;
451 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL, 464 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL,
452 &result_search_url)); 465 &result_search_url));
453 EXPECT_EQ(result_search_url, search_url); 466 EXPECT_EQ(result_search_url, search_url);
454 467
455 std::string result_name; 468 std::string result_name;
456 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderName, 469 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderName,
457 &result_name)); 470 &result_name));
458 EXPECT_EQ(result_name, name); 471 EXPECT_EQ(result_name, name);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 provider->AddPolicy( 513 provider->AddPolicy(
501 kPolicyDefaultSearchProviderSuggestURL, 514 kPolicyDefaultSearchProviderSuggestURL,
502 Value::CreateStringValue(suggest_url)); 515 Value::CreateStringValue(suggest_url));
503 provider->AddPolicy( 516 provider->AddPolicy(
504 kPolicyDefaultSearchProviderIconURL, 517 kPolicyDefaultSearchProviderIconURL,
505 Value::CreateStringValue(icon_url)); 518 Value::CreateStringValue(icon_url));
506 provider->AddPolicy( 519 provider->AddPolicy(
507 kPolicyDefaultSearchProviderEncodings, 520 kPolicyDefaultSearchProviderEncodings,
508 Value::CreateStringValue(encodings)); 521 Value::CreateStringValue(encodings));
509 522
510 ConfigurationPolicyPrefStore store(provider.get()); 523 scoped_refptr<ConfigurationPolicyPrefStore> store(
511 const DictionaryValue* prefs = store.prefs(); 524 new ConfigurationPolicyPrefStore(provider.get()));
525 const DictionaryValue* prefs = store->prefs();
512 526
513 std::string string_result; 527 std::string string_result;
514 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL, 528 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL,
515 &string_result)); 529 &string_result));
516 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderName, 530 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderName,
517 &string_result)); 531 &string_result));
518 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderKeyword, 532 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderKeyword,
519 &string_result)); 533 &string_result));
520 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSuggestURL, 534 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSuggestURL,
521 &string_result)); 535 &string_result));
(...skipping 29 matching lines...) Expand all
551 provider->AddPolicy( 565 provider->AddPolicy(
552 kPolicyDefaultSearchProviderSuggestURL, 566 kPolicyDefaultSearchProviderSuggestURL,
553 Value::CreateStringValue(suggest_url)); 567 Value::CreateStringValue(suggest_url));
554 provider->AddPolicy( 568 provider->AddPolicy(
555 kPolicyDefaultSearchProviderIconURL, 569 kPolicyDefaultSearchProviderIconURL,
556 Value::CreateStringValue(icon_url)); 570 Value::CreateStringValue(icon_url));
557 provider->AddPolicy( 571 provider->AddPolicy(
558 kPolicyDefaultSearchProviderEncodings, 572 kPolicyDefaultSearchProviderEncodings,
559 Value::CreateStringValue(encodings)); 573 Value::CreateStringValue(encodings));
560 574
561 ConfigurationPolicyPrefStore store(provider.get()); 575 scoped_refptr<ConfigurationPolicyPrefStore> store(
562 const DictionaryValue* const prefs = store.prefs(); 576 new ConfigurationPolicyPrefStore(provider.get()));
577 const DictionaryValue* const prefs = store->prefs();
563 578
564 std::string string_result; 579 std::string string_result;
565 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderEnabled, 580 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderEnabled,
566 &string_result)); 581 &string_result));
567 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL, 582 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL,
568 &string_result)); 583 &string_result));
569 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderName, 584 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderName,
570 &string_result)); 585 &string_result));
571 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderKeyword, 586 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderKeyword,
572 &string_result)); 587 &string_result));
573 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSuggestURL, 588 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSuggestURL,
574 &string_result)); 589 &string_result));
575 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderIconURL, 590 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderIconURL,
576 &string_result)); 591 &string_result));
577 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderEncodings, 592 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderEncodings,
578 &string_result)); 593 &string_result));
579 } 594 }
580 595
581 // Test cases for the Sync policy setting. 596 // Test cases for the Sync policy setting.
582 class ConfigurationPolicyPrefStoreSyncTest 597 class ConfigurationPolicyPrefStoreSyncTest
583 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> { 598 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> {
584 }; 599 };
585 600
586 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) { 601 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) {
587 bool result = false; 602 bool result = false;
588 EXPECT_FALSE(store_.prefs()->GetBoolean(prefs::kSyncManaged, &result)); 603 EXPECT_FALSE(store_->prefs()->GetBoolean(prefs::kSyncManaged, &result));
589 } 604 }
590 605
591 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Enabled) { 606 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Enabled) {
592 store_.Apply(kPolicySyncDisabled, Value::CreateBooleanValue(false)); 607 store_->Apply(kPolicySyncDisabled, Value::CreateBooleanValue(false));
593 // Enabling Sync should not set the pref. 608 // Enabling Sync should not set the pref.
594 bool result = false; 609 bool result = false;
595 EXPECT_FALSE(store_.prefs()->GetBoolean(prefs::kSyncManaged, &result)); 610 EXPECT_FALSE(store_->prefs()->GetBoolean(prefs::kSyncManaged, &result));
596 } 611 }
597 612
598 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Disabled) { 613 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Disabled) {
599 store_.Apply(kPolicySyncDisabled, Value::CreateBooleanValue(true)); 614 store_->Apply(kPolicySyncDisabled, Value::CreateBooleanValue(true));
600 // Sync should be flagged as managed. 615 // Sync should be flagged as managed.
601 bool result = false; 616 bool result = false;
602 EXPECT_TRUE(store_.prefs()->GetBoolean(prefs::kSyncManaged, &result)); 617 EXPECT_TRUE(store_->prefs()->GetBoolean(prefs::kSyncManaged, &result));
603 EXPECT_TRUE(result); 618 EXPECT_TRUE(result);
604 } 619 }
605 620
606 // Test cases for the AutoFill policy setting. 621 // Test cases for the AutoFill policy setting.
607 class ConfigurationPolicyPrefStoreAutoFillTest 622 class ConfigurationPolicyPrefStoreAutoFillTest
608 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> { 623 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> {
609 }; 624 };
610 625
611 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Default) { 626 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Default) {
612 bool result = false; 627 bool result = false;
613 EXPECT_FALSE(store_.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result)); 628 EXPECT_FALSE(store_->prefs()->GetBoolean(prefs::kAutoFillEnabled, &result));
614 } 629 }
615 630
616 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Enabled) { 631 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Enabled) {
617 store_.Apply(kPolicyAutoFillEnabled, Value::CreateBooleanValue(true)); 632 store_->Apply(kPolicyAutoFillEnabled, Value::CreateBooleanValue(true));
618 // Enabling AutoFill should not set the pref. 633 // Enabling AutoFill should not set the pref.
619 bool result = false; 634 bool result = false;
620 EXPECT_FALSE(store_.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result)); 635 EXPECT_FALSE(store_->prefs()->GetBoolean(prefs::kAutoFillEnabled, &result));
621 } 636 }
622 637
623 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Disabled) { 638 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Disabled) {
624 store_.Apply(kPolicyAutoFillEnabled, Value::CreateBooleanValue(false)); 639 store_->Apply(kPolicyAutoFillEnabled, Value::CreateBooleanValue(false));
625 // Disabling AutoFill should switch the pref to managed. 640 // Disabling AutoFill should switch the pref to managed.
626 bool result = true; 641 bool result = true;
627 EXPECT_TRUE(store_.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result)); 642 EXPECT_TRUE(store_->prefs()->GetBoolean(prefs::kAutoFillEnabled, &result));
628 EXPECT_FALSE(result); 643 EXPECT_FALSE(result);
629 } 644 }
630 645
631 } // namespace policy 646 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698