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

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

Issue 3774003: Cleanup and style guideline conformance for policy implementation (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: fix windows build and tests Created 10 years, 1 month 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
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 "chrome/browser/policy/configuration_policy_pref_store.h" 8 #include "chrome/browser/policy/configuration_policy_pref_store.h"
9 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 9 #include "chrome/browser/policy/mock_configuration_policy_provider.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/chrome_switches.h"
12 12
13 namespace policy { 13 namespace policy {
14 14
15 // Holds a set of test parameters, consisting of pref name and policy type. 15 // Holds a set of test parameters, consisting of pref name and policy type.
16 class TypeAndName { 16 class TypeAndName {
17 public: 17 public:
18 TypeAndName(ConfigurationPolicyStore::PolicyType type, const char* pref_name) 18 TypeAndName(ConfigurationPolicyType type, const char* pref_name)
19 : type_(type), 19 : type_(type),
20 pref_name_(pref_name) {} 20 pref_name_(pref_name) {}
21 21
22 ConfigurationPolicyStore::PolicyType type() const { return type_; } 22 ConfigurationPolicyType type() const { return type_; }
23 const char* pref_name() const { return pref_name_; } 23 const char* pref_name() const { return pref_name_; }
24 24
25 private: 25 private:
26 ConfigurationPolicyStore::PolicyType type_; 26 ConfigurationPolicyType type_;
27 const char* pref_name_; 27 const char* pref_name_;
28 }; 28 };
29 29
30 // Test cases for list-valued policy settings. 30 // Test cases for list-valued policy settings.
31 class ConfigurationPolicyPrefStoreListTest 31 class ConfigurationPolicyPrefStoreListTest
32 : public testing::TestWithParam<TypeAndName> { 32 : public testing::TestWithParam<TypeAndName> {
33 }; 33 };
34 34
35 TEST_P(ConfigurationPolicyPrefStoreListTest, GetDefault) { 35 TEST_P(ConfigurationPolicyPrefStoreListTest, GetDefault) {
36 ConfigurationPolicyPrefStore store(NULL); 36 ConfigurationPolicyPrefStore store(NULL);
37 ListValue* list = NULL; 37 ListValue* list = NULL;
38 EXPECT_FALSE(store.prefs()->GetList(GetParam().pref_name(), &list)); 38 EXPECT_FALSE(store.prefs()->GetList(GetParam().pref_name(), &list));
39 } 39 }
40 40
41 TEST_P(ConfigurationPolicyPrefStoreListTest, SetValue) { 41 TEST_P(ConfigurationPolicyPrefStoreListTest, SetValue) {
42 ConfigurationPolicyPrefStore store(NULL); 42 ConfigurationPolicyPrefStore store(NULL);
43 ListValue* in_value = new ListValue(); 43 ListValue* in_value = new ListValue();
44 in_value->Append(Value::CreateStringValue("test1")); 44 in_value->Append(Value::CreateStringValue("test1"));
45 in_value->Append(Value::CreateStringValue("test2,")); 45 in_value->Append(Value::CreateStringValue("test2,"));
46 store.Apply(GetParam().type(), in_value); 46 store.Apply(GetParam().type(), in_value);
47 ListValue* list = NULL; 47 ListValue* list = NULL;
48 EXPECT_TRUE(store.prefs()->GetList(GetParam().pref_name(), &list)); 48 EXPECT_TRUE(store.prefs()->GetList(GetParam().pref_name(), &list));
49 ListValue::const_iterator current(list->begin()); 49 ListValue::const_iterator current(list->begin());
50 ListValue::const_iterator end(list->end()); 50 const ListValue::const_iterator end(list->end());
51 ASSERT_TRUE(current != end); 51 ASSERT_TRUE(current != end);
52 std::string value; 52 std::string value;
53 (*current)->GetAsString(&value); 53 (*current)->GetAsString(&value);
54 EXPECT_EQ("test1", value); 54 EXPECT_EQ("test1", value);
55 ++current; 55 ++current;
56 ASSERT_TRUE(current != end); 56 ASSERT_TRUE(current != end);
57 (*current)->GetAsString(&value); 57 (*current)->GetAsString(&value);
58 EXPECT_EQ("test2,", value); 58 EXPECT_EQ("test2,", value);
59 ++current; 59 ++current;
60 EXPECT_TRUE(current == end); 60 EXPECT_TRUE(current == end);
61 } 61 }
62 62
63 INSTANTIATE_TEST_CASE_P( 63 INSTANTIATE_TEST_CASE_P(
64 ConfigurationPolicyPrefStoreListTestInstance, 64 ConfigurationPolicyPrefStoreListTestInstance,
65 ConfigurationPolicyPrefStoreListTest, 65 ConfigurationPolicyPrefStoreListTest,
66 testing::Values( 66 testing::Values(
67 TypeAndName(ConfigurationPolicyStore::kPolicyURLsToRestoreOnStartup, 67 TypeAndName(kPolicyURLsToRestoreOnStartup,
68 prefs::kURLsToRestoreOnStartup), 68 prefs::kURLsToRestoreOnStartup),
69 TypeAndName(ConfigurationPolicyStore::kPolicyExtensionInstallAllowList, 69 TypeAndName(kPolicyExtensionInstallAllowList,
70 prefs::kExtensionInstallAllowList), 70 prefs::kExtensionInstallAllowList),
71 TypeAndName(ConfigurationPolicyStore::kPolicyExtensionInstallDenyList, 71 TypeAndName(kPolicyExtensionInstallDenyList,
72 prefs::kExtensionInstallDenyList), 72 prefs::kExtensionInstallDenyList),
73 TypeAndName(ConfigurationPolicyStore::kPolicyDisabledPlugins, 73 TypeAndName(kPolicyDisabledPlugins,
74 prefs::kPluginsPluginsBlacklist))); 74 prefs::kPluginsPluginsBlacklist)));
75 75
76 // Test cases for string-valued policy settings. 76 // Test cases for string-valued policy settings.
77 class ConfigurationPolicyPrefStoreStringTest 77 class ConfigurationPolicyPrefStoreStringTest
78 : public testing::TestWithParam<TypeAndName> { 78 : public testing::TestWithParam<TypeAndName> {
79 }; 79 };
80 80
81 TEST_P(ConfigurationPolicyPrefStoreStringTest, GetDefault) { 81 TEST_P(ConfigurationPolicyPrefStoreStringTest, GetDefault) {
82 ConfigurationPolicyPrefStore store(NULL); 82 ConfigurationPolicyPrefStore store(NULL);
83 std::string result; 83 std::string result;
84 EXPECT_FALSE(store.prefs()->GetString(GetParam().pref_name(), &result)); 84 EXPECT_FALSE(store.prefs()->GetString(GetParam().pref_name(), &result));
85 } 85 }
86 86
87 TEST_P(ConfigurationPolicyPrefStoreStringTest, SetValue) { 87 TEST_P(ConfigurationPolicyPrefStoreStringTest, SetValue) {
88 ConfigurationPolicyPrefStore store(NULL); 88 ConfigurationPolicyPrefStore store(NULL);
89 store.Apply(GetParam().type(), 89 store.Apply(GetParam().type(),
90 Value::CreateStringValue("http://chromium.org")); 90 Value::CreateStringValue("http://chromium.org"));
91 std::string result; 91 std::string result;
92 EXPECT_TRUE(store.prefs()->GetString(GetParam().pref_name(), &result)); 92 EXPECT_TRUE(store.prefs()->GetString(GetParam().pref_name(), &result));
93 EXPECT_EQ(result, "http://chromium.org"); 93 EXPECT_EQ(result, "http://chromium.org");
94 } 94 }
95 95
96 INSTANTIATE_TEST_CASE_P( 96 INSTANTIATE_TEST_CASE_P(
97 ConfigurationPolicyPrefStoreStringTestInstance, 97 ConfigurationPolicyPrefStoreStringTestInstance,
98 ConfigurationPolicyPrefStoreStringTest, 98 ConfigurationPolicyPrefStoreStringTest,
99 testing::Values( 99 testing::Values(
100 TypeAndName(ConfigurationPolicyStore::kPolicyHomePage, 100 TypeAndName(kPolicyHomePage,
101 prefs::kHomePage), 101 prefs::kHomePage),
102 TypeAndName(ConfigurationPolicyStore::kPolicyProxyServer, 102 TypeAndName(kPolicyProxyServer,
103 prefs::kProxyServer), 103 prefs::kProxyServer),
104 TypeAndName(ConfigurationPolicyStore::kPolicyProxyPacUrl, 104 TypeAndName(kPolicyProxyPacUrl,
105 prefs::kProxyPacUrl), 105 prefs::kProxyPacUrl),
106 TypeAndName(ConfigurationPolicyStore::kPolicyProxyBypassList, 106 TypeAndName(kPolicyProxyBypassList,
107 prefs::kProxyBypassList), 107 prefs::kProxyBypassList),
108 TypeAndName(ConfigurationPolicyStore::kPolicyApplicationLocale, 108 TypeAndName(kPolicyApplicationLocale,
109 prefs::kApplicationLocale))); 109 prefs::kApplicationLocale)));
110 110
111 // Test cases for boolean-valued policy settings. 111 // Test cases for boolean-valued policy settings.
112 class ConfigurationPolicyPrefStoreBooleanTest 112 class ConfigurationPolicyPrefStoreBooleanTest
113 : public testing::TestWithParam<TypeAndName> { 113 : public testing::TestWithParam<TypeAndName> {
114 }; 114 };
115 115
116 TEST_P(ConfigurationPolicyPrefStoreBooleanTest, GetDefault) { 116 TEST_P(ConfigurationPolicyPrefStoreBooleanTest, GetDefault) {
117 ConfigurationPolicyPrefStore store(NULL); 117 ConfigurationPolicyPrefStore store(NULL);
118 bool result = false; 118 bool result = false;
(...skipping 10 matching lines...) Expand all
129 store.Apply(GetParam().type(), Value::CreateBooleanValue(true)); 129 store.Apply(GetParam().type(), Value::CreateBooleanValue(true));
130 result = false; 130 result = false;
131 EXPECT_TRUE(store.prefs()->GetBoolean(GetParam().pref_name(), &result)); 131 EXPECT_TRUE(store.prefs()->GetBoolean(GetParam().pref_name(), &result));
132 EXPECT_TRUE(result); 132 EXPECT_TRUE(result);
133 } 133 }
134 134
135 INSTANTIATE_TEST_CASE_P( 135 INSTANTIATE_TEST_CASE_P(
136 ConfigurationPolicyPrefStoreBooleanTestInstance, 136 ConfigurationPolicyPrefStoreBooleanTestInstance,
137 ConfigurationPolicyPrefStoreBooleanTest, 137 ConfigurationPolicyPrefStoreBooleanTest,
138 testing::Values( 138 testing::Values(
139 TypeAndName(ConfigurationPolicyStore::kPolicyHomepageIsNewTabPage, 139 TypeAndName(kPolicyHomepageIsNewTabPage,
140 prefs::kHomePageIsNewTabPage), 140 prefs::kHomePageIsNewTabPage),
141 TypeAndName(ConfigurationPolicyStore::kPolicyAlternateErrorPagesEnabled, 141 TypeAndName(kPolicyAlternateErrorPagesEnabled,
142 prefs::kAlternateErrorPagesEnabled), 142 prefs::kAlternateErrorPagesEnabled),
143 TypeAndName(ConfigurationPolicyStore::kPolicySearchSuggestEnabled, 143 TypeAndName(kPolicySearchSuggestEnabled,
144 prefs::kSearchSuggestEnabled), 144 prefs::kSearchSuggestEnabled),
145 TypeAndName(ConfigurationPolicyStore::kPolicyDnsPrefetchingEnabled, 145 TypeAndName(kPolicyDnsPrefetchingEnabled,
146 prefs::kDnsPrefetchingEnabled), 146 prefs::kDnsPrefetchingEnabled),
147 TypeAndName(ConfigurationPolicyStore::kPolicyDisableSpdy, 147 TypeAndName(kPolicyDisableSpdy,
148 prefs::kDisableSpdy), 148 prefs::kDisableSpdy),
149 TypeAndName(ConfigurationPolicyStore::kPolicySafeBrowsingEnabled, 149 TypeAndName(kPolicySafeBrowsingEnabled,
150 prefs::kSafeBrowsingEnabled), 150 prefs::kSafeBrowsingEnabled),
151 TypeAndName(ConfigurationPolicyStore::kPolicyMetricsReportingEnabled, 151 TypeAndName(kPolicyMetricsReportingEnabled,
152 prefs::kMetricsReportingEnabled), 152 prefs::kMetricsReportingEnabled),
153 TypeAndName(ConfigurationPolicyStore::kPolicyPasswordManagerEnabled, 153 TypeAndName(kPolicyPasswordManagerEnabled,
154 prefs::kPasswordManagerEnabled), 154 prefs::kPasswordManagerEnabled),
155 TypeAndName(ConfigurationPolicyStore:: 155 TypeAndName(kPolicyPasswordManagerAllowShowPasswords,
156 kPolicyPasswordManagerAllowShowPasswords,
157 prefs::kPasswordManagerAllowShowPasswords), 156 prefs::kPasswordManagerAllowShowPasswords),
158 TypeAndName(ConfigurationPolicyStore::kPolicyShowHomeButton, 157 TypeAndName(kPolicyShowHomeButton,
159 prefs::kShowHomeButton), 158 prefs::kShowHomeButton),
160 TypeAndName(ConfigurationPolicyStore::kPolicyPrintingEnabled, 159 TypeAndName(kPolicyPrintingEnabled,
161 prefs::kPrintingEnabled), 160 prefs::kPrintingEnabled),
162 TypeAndName(ConfigurationPolicyStore::kPolicyJavascriptEnabled, 161 TypeAndName(kPolicyJavascriptEnabled,
163 prefs::kWebKitJavascriptEnabled), 162 prefs::kWebKitJavascriptEnabled),
164 TypeAndName(ConfigurationPolicyStore:: 163 TypeAndName(kPolicySavingBrowserHistoryDisabled,
165 kPolicySavingBrowserHistoryDisabled,
166 prefs::kSavingBrowserHistoryDisabled))); 164 prefs::kSavingBrowserHistoryDisabled)));
167 165
168 #if defined(OS_CHROMEOS) 166 #if defined(OS_CHROMEOS)
169 INSTANTIATE_TEST_CASE_P( 167 INSTANTIATE_TEST_CASE_P(
170 CrosConfigurationPolicyPrefStoreBooleanTestInstance, 168 CrosConfigurationPolicyPrefStoreBooleanTestInstance,
171 ConfigurationPolicyPrefStoreBooleanTest, 169 ConfigurationPolicyPrefStoreBooleanTest,
172 testing::Values( 170 testing::Values(
173 TypeAndName(ConfigurationPolicyStore:: 171 TypeAndName(kPolicyChromeOsLockOnIdleSuspend,
174 kPolicyChromeOsLockOnIdleSuspend,
175 prefs::kEnableScreenLock))); 172 prefs::kEnableScreenLock)));
176 #endif // defined(OS_CHROMEOS) 173 #endif // defined(OS_CHROMEOS)
177 174
178 // Test cases for integer-valued policy settings. 175 // Test cases for integer-valued policy settings.
179 class ConfigurationPolicyPrefStoreIntegerTest 176 class ConfigurationPolicyPrefStoreIntegerTest
180 : public testing::TestWithParam<TypeAndName> { 177 : public testing::TestWithParam<TypeAndName> {
181 }; 178 };
182 179
183 TEST_P(ConfigurationPolicyPrefStoreIntegerTest, GetDefault) { 180 TEST_P(ConfigurationPolicyPrefStoreIntegerTest, GetDefault) {
184 ConfigurationPolicyPrefStore store(NULL); 181 ConfigurationPolicyPrefStore store(NULL);
185 int result = 0; 182 int result = 0;
186 EXPECT_FALSE(store.prefs()->GetInteger(GetParam().pref_name(), &result)); 183 EXPECT_FALSE(store.prefs()->GetInteger(GetParam().pref_name(), &result));
187 } 184 }
188 185
189 TEST_P(ConfigurationPolicyPrefStoreIntegerTest, SetValue) { 186 TEST_P(ConfigurationPolicyPrefStoreIntegerTest, SetValue) {
190 ConfigurationPolicyPrefStore store(NULL); 187 ConfigurationPolicyPrefStore store(NULL);
191 store.Apply(GetParam().type(), Value::CreateIntegerValue(2)); 188 store.Apply(GetParam().type(), Value::CreateIntegerValue(2));
192 int result = 0; 189 int result = 0;
193 EXPECT_TRUE(store.prefs()->GetInteger(GetParam().pref_name(), &result)); 190 EXPECT_TRUE(store.prefs()->GetInteger(GetParam().pref_name(), &result));
194 EXPECT_EQ(result, 2); 191 EXPECT_EQ(result, 2);
195 } 192 }
196 193
197 INSTANTIATE_TEST_CASE_P( 194 INSTANTIATE_TEST_CASE_P(
198 ConfigurationPolicyPrefStoreIntegerTestInstance, 195 ConfigurationPolicyPrefStoreIntegerTestInstance,
199 ConfigurationPolicyPrefStoreIntegerTest, 196 ConfigurationPolicyPrefStoreIntegerTest,
200 testing::Values( 197 testing::Values(
201 TypeAndName(ConfigurationPolicyStore::kPolicyRestoreOnStartup, 198 TypeAndName(kPolicyRestoreOnStartup,
202 prefs::kRestoreOnStartup))); 199 prefs::kRestoreOnStartup)));
203 200
204 // Test cases for the proxy policy settings. 201 // Test cases for the proxy policy settings.
205 class ConfigurationPolicyPrefStoreProxyTest : public testing::Test { 202 class ConfigurationPolicyPrefStoreProxyTest : public testing::Test {
206 }; 203 };
207 204
208 TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptions) { 205 TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptions) {
209 scoped_ptr<MockConfigurationPolicyProvider> provider( 206 scoped_ptr<MockConfigurationPolicyProvider> provider(
210 new MockConfigurationPolicyProvider()); 207 new MockConfigurationPolicyProvider());
211 provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList, 208 provider->AddPolicy(kPolicyProxyBypassList,
212 Value::CreateStringValue("http://chromium.org/override")); 209 Value::CreateStringValue("http://chromium.org/override"));
213 provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyPacUrl, 210 provider->AddPolicy(kPolicyProxyPacUrl,
214 Value::CreateStringValue("http://chromium.org/proxy.pac")); 211 Value::CreateStringValue("http://short.org/proxy.pac"));
215 provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServer, 212 provider->AddPolicy(kPolicyProxyServer,
216 Value::CreateStringValue("chromium.org")); 213 Value::CreateStringValue("chromium.org"));
217 provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServerMode, 214 provider->AddPolicy(kPolicyProxyServerMode,
218 Value::CreateIntegerValue( 215 Value::CreateIntegerValue(
219 ConfigurationPolicyStore::kPolicyManuallyConfiguredProxyMode)); 216 kPolicyManuallyConfiguredProxyMode));
220 217
221 ConfigurationPolicyPrefStore store(provider.get()); 218 ConfigurationPolicyPrefStore store(provider.get());
222 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); 219 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
223 220
224 std::string string_result; 221 std::string string_result;
225 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyBypassList, 222 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyBypassList,
226 &string_result)); 223 &string_result));
227 EXPECT_EQ("http://chromium.org/override", string_result); 224 EXPECT_EQ("http://chromium.org/override", string_result);
228 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 225 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
229 EXPECT_EQ("http://chromium.org/proxy.pac", string_result); 226 EXPECT_EQ("http://short.org/proxy.pac", string_result);
230 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 227 EXPECT_TRUE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
231 EXPECT_EQ("chromium.org", string_result); 228 EXPECT_EQ("chromium.org", string_result);
232 bool bool_result; 229 bool bool_result;
233 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 230 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
234 EXPECT_FALSE(bool_result); 231 EXPECT_FALSE(bool_result);
235 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result)); 232 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result));
236 EXPECT_FALSE(bool_result); 233 EXPECT_FALSE(bool_result);
237 } 234 }
238 235
239 TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxy) { 236 TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxy) {
240 scoped_ptr<MockConfigurationPolicyProvider> provider( 237 scoped_ptr<MockConfigurationPolicyProvider> provider(
241 new MockConfigurationPolicyProvider()); 238 new MockConfigurationPolicyProvider());
242 provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList, 239 provider->AddPolicy(kPolicyProxyBypassList,
243 Value::CreateStringValue("http://chromium.org/override")); 240 Value::CreateStringValue("http://chromium.org/override"));
244 provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServerMode, 241 provider->AddPolicy(kPolicyProxyServerMode,
245 Value::CreateIntegerValue( 242 Value::CreateIntegerValue(
246 ConfigurationPolicyStore::kPolicyNoProxyServerMode)); 243 kPolicyNoProxyServerMode));
247 244
248 ConfigurationPolicyPrefStore store(provider.get()); 245 ConfigurationPolicyPrefStore store(provider.get());
249 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); 246 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
250 247
251 std::string string_result; 248 std::string string_result;
252 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, 249 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList,
253 &string_result)); 250 &string_result));
254 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 251 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
255 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 252 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
256 bool bool_result; 253 bool bool_result;
257 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 254 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
258 EXPECT_TRUE(bool_result); 255 EXPECT_TRUE(bool_result);
259 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result)); 256 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result));
260 EXPECT_FALSE(bool_result); 257 EXPECT_FALSE(bool_result);
261 } 258 }
262 259
263 TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxyReversedApplyOrder) { 260 TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxyReversedApplyOrder) {
264 scoped_ptr<MockConfigurationPolicyProvider> provider( 261 scoped_ptr<MockConfigurationPolicyProvider> provider(
265 new MockConfigurationPolicyProvider()); 262 new MockConfigurationPolicyProvider());
266 provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServerMode, 263 provider->AddPolicy(kPolicyProxyServerMode,
267 Value::CreateIntegerValue( 264 Value::CreateIntegerValue(
268 ConfigurationPolicyStore::kPolicyNoProxyServerMode)); 265 kPolicyNoProxyServerMode));
269 provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList, 266 provider->AddPolicy(kPolicyProxyBypassList,
270 Value::CreateStringValue("http://chromium.org/override")); 267 Value::CreateStringValue("http://chromium.org/override"));
271 268
272 ConfigurationPolicyPrefStore store(provider.get()); 269 ConfigurationPolicyPrefStore store(provider.get());
273 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); 270 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
274 271
275 std::string string_result; 272 std::string string_result;
276 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, 273 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList,
277 &string_result)); 274 &string_result));
278 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 275 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
279 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 276 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
280 bool bool_result; 277 bool bool_result;
281 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 278 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
282 EXPECT_TRUE(bool_result); 279 EXPECT_TRUE(bool_result);
283 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result)); 280 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result));
284 EXPECT_FALSE(bool_result); 281 EXPECT_FALSE(bool_result);
285 } 282 }
286 283
287 TEST_F(ConfigurationPolicyPrefStoreProxyTest, AutoDetect) { 284 TEST_F(ConfigurationPolicyPrefStoreProxyTest, AutoDetect) {
288 scoped_ptr<MockConfigurationPolicyProvider> provider( 285 scoped_ptr<MockConfigurationPolicyProvider> provider(
289 new MockConfigurationPolicyProvider()); 286 new MockConfigurationPolicyProvider());
290 provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServerMode, 287 provider->AddPolicy(kPolicyProxyServerMode,
291 Value::CreateIntegerValue( 288 Value::CreateIntegerValue(
292 ConfigurationPolicyStore::kPolicyAutoDetectProxyMode)); 289 kPolicyAutoDetectProxyMode));
293 290
294 ConfigurationPolicyPrefStore store(provider.get()); 291 ConfigurationPolicyPrefStore store(provider.get());
295 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); 292 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
296 293
297 std::string string_result; 294 std::string string_result;
298 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, 295 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList,
299 &string_result)); 296 &string_result));
300 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 297 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
301 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 298 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
302 bool bool_result; 299 bool bool_result;
303 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 300 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
304 EXPECT_FALSE(bool_result); 301 EXPECT_FALSE(bool_result);
305 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result)); 302 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, &bool_result));
306 EXPECT_TRUE(bool_result); 303 EXPECT_TRUE(bool_result);
307 } 304 }
308 305
309 TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystem) { 306 TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystem) {
310 scoped_ptr<MockConfigurationPolicyProvider> provider( 307 scoped_ptr<MockConfigurationPolicyProvider> provider(
311 new MockConfigurationPolicyProvider()); 308 new MockConfigurationPolicyProvider());
312 provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList, 309 provider->AddPolicy(kPolicyProxyBypassList,
313 Value::CreateStringValue("http://chromium.org/override")); 310 Value::CreateStringValue("http://chromium.org/override"));
314 provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServerMode, 311 provider->AddPolicy(kPolicyProxyServerMode,
315 Value::CreateIntegerValue( 312 Value::CreateIntegerValue(
316 ConfigurationPolicyStore::kPolicyUseSystemProxyMode)); 313 kPolicyUseSystemProxyMode));
317 314
318 ConfigurationPolicyPrefStore store(provider.get()); 315 ConfigurationPolicyPrefStore store(provider.get());
319 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); 316 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
320 317
321 std::string string_result; 318 std::string string_result;
322 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, 319 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList,
323 &string_result)); 320 &string_result));
324 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 321 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
325 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 322 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
326 bool bool_result; 323 bool bool_result;
327 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 324 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
328 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, 325 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect,
329 &bool_result)); 326 &bool_result));
330 } 327 }
331 328
332 TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystemReversedApplyOrder) { 329 TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystemReversedApplyOrder) {
333 scoped_ptr<MockConfigurationPolicyProvider> provider( 330 scoped_ptr<MockConfigurationPolicyProvider> provider(
334 new MockConfigurationPolicyProvider()); 331 new MockConfigurationPolicyProvider());
335 provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyServerMode, 332 provider->AddPolicy(kPolicyProxyServerMode,
336 Value::CreateIntegerValue( 333 Value::CreateIntegerValue(
337 ConfigurationPolicyStore::kPolicyUseSystemProxyMode)); 334 kPolicyUseSystemProxyMode));
338 provider->AddPolicy(ConfigurationPolicyStore::kPolicyProxyBypassList, 335 provider->AddPolicy(kPolicyProxyBypassList,
339 Value::CreateStringValue("http://chromium.org/override")); 336 Value::CreateStringValue("http://chromium.org/override"));
340 337
341 ConfigurationPolicyPrefStore store(provider.get()); 338 ConfigurationPolicyPrefStore store(provider.get());
342 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); 339 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
343 340
344 std::string string_result; 341 std::string string_result;
345 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList, 342 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyBypassList,
346 &string_result)); 343 &string_result));
347 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result)); 344 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyPacUrl, &string_result));
348 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result)); 345 EXPECT_FALSE(store.prefs()->GetString(prefs::kProxyServer, &string_result));
349 bool bool_result; 346 bool bool_result;
350 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result)); 347 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kNoProxyServer, &bool_result));
351 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect, 348 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kProxyAutoDetect,
352 &bool_result)); 349 &bool_result));
353 } 350 }
354 351
355 class ConfigurationPolicyPrefStoreDefaultSearchTest : public testing::Test { 352 class ConfigurationPolicyPrefStoreDefaultSearchTest : public testing::Test {
356 }; 353 };
357 354
358 // Checks that if the policy for default search is valid, i.e. there's a 355 // Checks that if the policy for default search is valid, i.e. there's a
359 // search URL, that all the elements have been given proper defaults. 356 // search URL, that all the elements have been given proper defaults.
360 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MinimallyDefined) { 357 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MinimallyDefined) {
361 const char* search_url = "http://test.com/search?t={searchTerms}"; 358 const char* const search_url = "http://test.com/search?t={searchTerms}";
362 scoped_ptr<MockConfigurationPolicyProvider> provider( 359 scoped_ptr<MockConfigurationPolicyProvider> provider(
363 new MockConfigurationPolicyProvider()); 360 new MockConfigurationPolicyProvider());
364 provider->AddPolicy( 361 provider->AddPolicy(
365 ConfigurationPolicyStore::kPolicyDefaultSearchProviderEnabled, 362 kPolicyDefaultSearchProviderEnabled,
366 Value::CreateBooleanValue(true)); 363 Value::CreateBooleanValue(true));
367 provider->AddPolicy( 364 provider->AddPolicy(
368 ConfigurationPolicyStore::kPolicyDefaultSearchProviderSearchURL, 365 kPolicyDefaultSearchProviderSearchURL,
369 Value::CreateStringValue(search_url)); 366 Value::CreateStringValue(search_url));
370 367
371 ConfigurationPolicyPrefStore store(provider.get()); 368 ConfigurationPolicyPrefStore store(provider.get());
372 369
373 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); 370 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
374 DictionaryValue* prefs = store.prefs(); 371 const DictionaryValue* prefs = store.prefs();
375 372
376 std::string string_result; 373 std::string string_result;
377 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL, 374 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL,
378 &string_result)); 375 &string_result));
379 EXPECT_EQ(string_result, search_url); 376 EXPECT_EQ(string_result, search_url);
380 377
381 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderName, 378 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderName,
382 &string_result)); 379 &string_result));
383 EXPECT_EQ(string_result, "test.com"); 380 EXPECT_EQ(string_result, "test.com");
384 381
385 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderKeyword, 382 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderKeyword,
386 &string_result)); 383 &string_result));
387 EXPECT_EQ(string_result, ""); 384 EXPECT_EQ(string_result, std::string());
388 385
389 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderSuggestURL, 386 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderSuggestURL,
390 &string_result)); 387 &string_result));
391 EXPECT_EQ(string_result, ""); 388 EXPECT_EQ(string_result, std::string());
392 389
393 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderIconURL, 390 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderIconURL,
394 &string_result)); 391 &string_result));
395 EXPECT_EQ(string_result, ""); 392 EXPECT_EQ(string_result, std::string());
396 393
397 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderEncodings, 394 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderEncodings,
398 &string_result)); 395 &string_result));
399 EXPECT_EQ(string_result, ""); 396 EXPECT_EQ(string_result, std::string());
400 } 397 }
401 398
402 // Checks that for a fully defined search policy, all elements have been 399 // Checks that for a fully defined search policy, all elements have been
403 // read properly. 400 // read properly.
404 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, FullyDefined) { 401 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, FullyDefined) {
405 const char* search_url = "http://test.com/search?t={searchTerms}"; 402 const char* const search_url = "http://test.com/search?t={searchTerms}";
406 const char* suggest_url = "http://test.com/sugg?={searchTerms}"; 403 const char* const suggest_url = "http://test.com/sugg?={searchTerms}";
407 const char* icon_url = "http://test.com/icon.jpg"; 404 const char* const icon_url = "http://test.com/icon.jpg";
408 const char* name = "MyName"; 405 const char* const name = "MyName";
409 const char* keyword = "MyKeyword"; 406 const char* const keyword = "MyKeyword";
410 const char* encodings = "UTF-16;UTF-8"; 407 const char* const encodings = "UTF-16;UTF-8";
411 scoped_ptr<MockConfigurationPolicyProvider> provider( 408 scoped_ptr<MockConfigurationPolicyProvider> provider(
412 new MockConfigurationPolicyProvider()); 409 new MockConfigurationPolicyProvider());
413 provider->AddPolicy( 410 provider->AddPolicy(
414 ConfigurationPolicyStore::kPolicyDefaultSearchProviderEnabled, 411 kPolicyDefaultSearchProviderEnabled,
415 Value::CreateBooleanValue(true)); 412 Value::CreateBooleanValue(true));
416 provider->AddPolicy( 413 provider->AddPolicy(
417 ConfigurationPolicyStore::kPolicyDefaultSearchProviderSearchURL, 414 kPolicyDefaultSearchProviderSearchURL,
418 Value::CreateStringValue(search_url)); 415 Value::CreateStringValue(search_url));
419 provider->AddPolicy( 416 provider->AddPolicy(
420 ConfigurationPolicyStore::kPolicyDefaultSearchProviderName, 417 kPolicyDefaultSearchProviderName,
421 Value::CreateStringValue(name)); 418 Value::CreateStringValue(name));
422 provider->AddPolicy( 419 provider->AddPolicy(
423 ConfigurationPolicyStore::kPolicyDefaultSearchProviderKeyword, 420 kPolicyDefaultSearchProviderKeyword,
424 Value::CreateStringValue(keyword)); 421 Value::CreateStringValue(keyword));
425 provider->AddPolicy( 422 provider->AddPolicy(
426 ConfigurationPolicyStore::kPolicyDefaultSearchProviderSuggestURL, 423 kPolicyDefaultSearchProviderSuggestURL,
427 Value::CreateStringValue(suggest_url)); 424 Value::CreateStringValue(suggest_url));
428 provider->AddPolicy( 425 provider->AddPolicy(
429 ConfigurationPolicyStore::kPolicyDefaultSearchProviderIconURL, 426 kPolicyDefaultSearchProviderIconURL,
430 Value::CreateStringValue(icon_url)); 427 Value::CreateStringValue(icon_url));
431 provider->AddPolicy( 428 provider->AddPolicy(
432 ConfigurationPolicyStore::kPolicyDefaultSearchProviderEncodings, 429 kPolicyDefaultSearchProviderEncodings,
433 Value::CreateStringValue(encodings)); 430 Value::CreateStringValue(encodings));
434 431
435 ConfigurationPolicyPrefStore store(provider.get()); 432 ConfigurationPolicyPrefStore store(provider.get());
436 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); 433 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
437 DictionaryValue* prefs = store.prefs(); 434 const DictionaryValue* prefs = store.prefs();
438 435
439 std::string result_search_url; 436 std::string result_search_url;
440 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL, 437 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL,
441 &result_search_url)); 438 &result_search_url));
442 EXPECT_EQ(result_search_url, search_url); 439 EXPECT_EQ(result_search_url, search_url);
443 440
444 std::string result_name; 441 std::string result_name;
445 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderName, 442 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderName,
446 &result_name)); 443 &result_name));
447 EXPECT_EQ(result_name, name); 444 EXPECT_EQ(result_name, name);
(...skipping 15 matching lines...) Expand all
463 460
464 std::string result_encodings; 461 std::string result_encodings;
465 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderEncodings, 462 EXPECT_TRUE(prefs->GetString(prefs::kDefaultSearchProviderEncodings,
466 &result_encodings)); 463 &result_encodings));
467 EXPECT_EQ(result_encodings, encodings); 464 EXPECT_EQ(result_encodings, encodings);
468 } 465 }
469 466
470 // Checks that if the default search policy is missing, that no elements of the 467 // Checks that if the default search policy is missing, that no elements of the
471 // default search policy will be present. 468 // default search policy will be present.
472 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MissingUrl) { 469 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MissingUrl) {
473 const char* suggest_url = "http://test.com/sugg?t={searchTerms}"; 470 const char* const suggest_url = "http://test.com/sugg?t={searchTerms}";
474 const char* icon_url = "http://test.com/icon.jpg"; 471 const char* const icon_url = "http://test.com/icon.jpg";
475 const char* name = "MyName"; 472 const char* const name = "MyName";
476 const char* keyword = "MyKeyword"; 473 const char* const keyword = "MyKeyword";
477 const char* encodings = "UTF-16;UTF-8"; 474 const char* const encodings = "UTF-16;UTF-8";
478 scoped_ptr<MockConfigurationPolicyProvider> provider( 475 scoped_ptr<MockConfigurationPolicyProvider> provider(
479 new MockConfigurationPolicyProvider()); 476 new MockConfigurationPolicyProvider());
480 provider->AddPolicy( 477 provider->AddPolicy(
481 ConfigurationPolicyStore::kPolicyDefaultSearchProviderEnabled, 478 kPolicyDefaultSearchProviderEnabled,
482 Value::CreateBooleanValue(true)); 479 Value::CreateBooleanValue(true));
483 provider->AddPolicy( 480 provider->AddPolicy(
484 ConfigurationPolicyStore::kPolicyDefaultSearchProviderName, 481 kPolicyDefaultSearchProviderName,
485 Value::CreateStringValue(name)); 482 Value::CreateStringValue(name));
486 provider->AddPolicy( 483 provider->AddPolicy(
487 ConfigurationPolicyStore::kPolicyDefaultSearchProviderKeyword, 484 kPolicyDefaultSearchProviderKeyword,
488 Value::CreateStringValue(keyword)); 485 Value::CreateStringValue(keyword));
489 provider->AddPolicy( 486 provider->AddPolicy(
490 ConfigurationPolicyStore::kPolicyDefaultSearchProviderSuggestURL, 487 kPolicyDefaultSearchProviderSuggestURL,
491 Value::CreateStringValue(suggest_url)); 488 Value::CreateStringValue(suggest_url));
492 provider->AddPolicy( 489 provider->AddPolicy(
493 ConfigurationPolicyStore::kPolicyDefaultSearchProviderIconURL, 490 kPolicyDefaultSearchProviderIconURL,
494 Value::CreateStringValue(icon_url)); 491 Value::CreateStringValue(icon_url));
495 provider->AddPolicy( 492 provider->AddPolicy(
496 ConfigurationPolicyStore::kPolicyDefaultSearchProviderEncodings, 493 kPolicyDefaultSearchProviderEncodings,
497 Value::CreateStringValue(encodings)); 494 Value::CreateStringValue(encodings));
498 495
499 ConfigurationPolicyPrefStore store(provider.get()); 496 ConfigurationPolicyPrefStore store(provider.get());
500 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); 497 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
501 DictionaryValue* prefs = store.prefs(); 498 const DictionaryValue* prefs = store.prefs();
502 499
503 std::string string_result; 500 std::string string_result;
504 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL, 501 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL,
505 &string_result)); 502 &string_result));
506 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderName, 503 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderName,
507 &string_result)); 504 &string_result));
508 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderKeyword, 505 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderKeyword,
509 &string_result)); 506 &string_result));
510 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSuggestURL, 507 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSuggestURL,
511 &string_result)); 508 &string_result));
512 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderIconURL, 509 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderIconURL,
513 &string_result)); 510 &string_result));
514 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderEncodings, 511 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderEncodings,
515 &string_result)); 512 &string_result));
516 } 513 }
517 514
518 // Checks that if the default search policy is invalid, that no elements of the 515 // Checks that if the default search policy is invalid, that no elements of the
519 // default search policy will be present. 516 // default search policy will be present.
520 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, Invalid) { 517 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, Invalid) {
521 const char* bad_search_url = "http://test.com/noSearchTerms"; 518 const char* const bad_search_url = "http://test.com/noSearchTerms";
522 const char* suggest_url = "http://test.com/sugg?t={searchTerms}"; 519 const char* const suggest_url = "http://test.com/sugg?t={searchTerms}";
523 const char* icon_url = "http://test.com/icon.jpg"; 520 const char* const icon_url = "http://test.com/icon.jpg";
524 const char* name = "MyName"; 521 const char* const name = "MyName";
525 const char* keyword = "MyKeyword"; 522 const char* const keyword = "MyKeyword";
526 const char* encodings = "UTF-16;UTF-8"; 523 const char* const encodings = "UTF-16;UTF-8";
527 scoped_ptr<MockConfigurationPolicyProvider> provider( 524 scoped_ptr<MockConfigurationPolicyProvider> provider(
528 new MockConfigurationPolicyProvider()); 525 new MockConfigurationPolicyProvider());
529 provider->AddPolicy( 526 provider->AddPolicy(
530 ConfigurationPolicyStore::kPolicyDefaultSearchProviderEnabled, 527 kPolicyDefaultSearchProviderEnabled,
531 Value::CreateBooleanValue(true)); 528 Value::CreateBooleanValue(true));
532 provider->AddPolicy( 529 provider->AddPolicy(
533 ConfigurationPolicyStore::kPolicyDefaultSearchProviderSearchURL, 530 kPolicyDefaultSearchProviderSearchURL,
534 Value::CreateStringValue(bad_search_url)); 531 Value::CreateStringValue(bad_search_url));
535 provider->AddPolicy( 532 provider->AddPolicy(
536 ConfigurationPolicyStore::kPolicyDefaultSearchProviderName, 533 kPolicyDefaultSearchProviderName,
537 Value::CreateStringValue(name)); 534 Value::CreateStringValue(name));
538 provider->AddPolicy( 535 provider->AddPolicy(
539 ConfigurationPolicyStore::kPolicyDefaultSearchProviderKeyword, 536 kPolicyDefaultSearchProviderKeyword,
540 Value::CreateStringValue(keyword)); 537 Value::CreateStringValue(keyword));
541 provider->AddPolicy( 538 provider->AddPolicy(
542 ConfigurationPolicyStore::kPolicyDefaultSearchProviderSuggestURL, 539 kPolicyDefaultSearchProviderSuggestURL,
543 Value::CreateStringValue(suggest_url)); 540 Value::CreateStringValue(suggest_url));
544 provider->AddPolicy( 541 provider->AddPolicy(
545 ConfigurationPolicyStore::kPolicyDefaultSearchProviderIconURL, 542 kPolicyDefaultSearchProviderIconURL,
546 Value::CreateStringValue(icon_url)); 543 Value::CreateStringValue(icon_url));
547 provider->AddPolicy( 544 provider->AddPolicy(
548 ConfigurationPolicyStore::kPolicyDefaultSearchProviderEncodings, 545 kPolicyDefaultSearchProviderEncodings,
549 Value::CreateStringValue(encodings)); 546 Value::CreateStringValue(encodings));
550 547
551 ConfigurationPolicyPrefStore store(provider.get()); 548 ConfigurationPolicyPrefStore store(provider.get());
552 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE); 549 EXPECT_EQ(store.ReadPrefs(), PrefStore::PREF_READ_ERROR_NONE);
553 DictionaryValue* prefs = store.prefs(); 550 const DictionaryValue* const prefs = store.prefs();
554 551
555 std::string string_result; 552 std::string string_result;
556 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderEnabled, 553 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderEnabled,
557 &string_result)); 554 &string_result));
558 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL, 555 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSearchURL,
559 &string_result)); 556 &string_result));
560 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderName, 557 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderName,
561 &string_result)); 558 &string_result));
562 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderKeyword, 559 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderKeyword,
563 &string_result)); 560 &string_result));
564 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSuggestURL, 561 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderSuggestURL,
565 &string_result)); 562 &string_result));
566 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderIconURL, 563 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderIconURL,
567 &string_result)); 564 &string_result));
568 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderEncodings, 565 EXPECT_FALSE(prefs->GetString(prefs::kDefaultSearchProviderEncodings,
569 &string_result)); 566 &string_result));
570 } 567 }
571 568
572 // Test cases for the Sync policy setting. 569 // Test cases for the Sync policy setting.
573 class ConfigurationPolicyPrefStoreSyncTest : public testing::Test { 570 class ConfigurationPolicyPrefStoreSyncTest : public testing::Test {
574 }; 571 };
575 572
576 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) { 573 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Default) {
577 ConfigurationPolicyPrefStore store(NULL); 574 ConfigurationPolicyPrefStore store(NULL);
578 bool result = false; 575 bool result = false;
579 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kSyncManaged, &result)); 576 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kSyncManaged, &result));
580 } 577 }
581 578
582 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Enabled) { 579 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Enabled) {
583 ConfigurationPolicyPrefStore store(NULL); 580 ConfigurationPolicyPrefStore store(NULL);
584 store.Apply(ConfigurationPolicyPrefStore::kPolicySyncDisabled, 581 store.Apply(kPolicySyncDisabled, Value::CreateBooleanValue(false));
585 Value::CreateBooleanValue(false));
586 // Enabling Sync should not set the pref. 582 // Enabling Sync should not set the pref.
587 bool result = false; 583 bool result = false;
588 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kSyncManaged, &result)); 584 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kSyncManaged, &result));
589 } 585 }
590 586
591 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Disabled) { 587 TEST_F(ConfigurationPolicyPrefStoreSyncTest, Disabled) {
592 ConfigurationPolicyPrefStore store(NULL); 588 ConfigurationPolicyPrefStore store(NULL);
593 store.Apply(ConfigurationPolicyPrefStore::kPolicySyncDisabled, 589 store.Apply(kPolicySyncDisabled, Value::CreateBooleanValue(true));
594 Value::CreateBooleanValue(true));
595 // Sync should be flagged as managed. 590 // Sync should be flagged as managed.
596 bool result = false; 591 bool result = false;
597 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kSyncManaged, &result)); 592 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kSyncManaged, &result));
598 EXPECT_TRUE(result); 593 EXPECT_TRUE(result);
599 } 594 }
600 595
601 // Test cases for the AutoFill policy setting. 596 // Test cases for the AutoFill policy setting.
602 class ConfigurationPolicyPrefStoreAutoFillTest : public testing::Test { 597 class ConfigurationPolicyPrefStoreAutoFillTest : public testing::Test {
603 }; 598 };
604 599
605 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Default) { 600 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Default) {
606 ConfigurationPolicyPrefStore store(NULL); 601 ConfigurationPolicyPrefStore store(NULL);
607 bool result = false; 602 bool result = false;
608 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result)); 603 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result));
609 } 604 }
610 605
611 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Enabled) { 606 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Enabled) {
612 ConfigurationPolicyPrefStore store(NULL); 607 ConfigurationPolicyPrefStore store(NULL);
613 store.Apply(ConfigurationPolicyPrefStore::kPolicyAutoFillEnabled, 608 store.Apply(kPolicyAutoFillEnabled, Value::CreateBooleanValue(true));
614 Value::CreateBooleanValue(true));
615 // Enabling AutoFill should not set the pref. 609 // Enabling AutoFill should not set the pref.
616 bool result = false; 610 bool result = false;
617 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result)); 611 EXPECT_FALSE(store.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result));
618 } 612 }
619 613
620 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Disabled) { 614 TEST_F(ConfigurationPolicyPrefStoreAutoFillTest, Disabled) {
621 ConfigurationPolicyPrefStore store(NULL); 615 ConfigurationPolicyPrefStore store(NULL);
622 store.Apply(ConfigurationPolicyPrefStore::kPolicyAutoFillEnabled, 616 store.Apply(kPolicyAutoFillEnabled, Value::CreateBooleanValue(false));
623 Value::CreateBooleanValue(false));
624 // Disabling AutoFill should switch the pref to managed. 617 // Disabling AutoFill should switch the pref to managed.
625 bool result = true; 618 bool result = true;
626 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result)); 619 EXPECT_TRUE(store.prefs()->GetBoolean(prefs::kAutoFillEnabled, &result));
627 EXPECT_FALSE(result); 620 EXPECT_FALSE(result);
628 } 621 }
629 622
630 } // namespace policy 623 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/configuration_policy_pref_store.cc ('k') | chrome/browser/policy/configuration_policy_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698