OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/mac/scoped_cftyperef.h" | 7 #include "base/mac/scoped_cftyperef.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 10 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 virtual void SetUp() { | 133 virtual void SetUp() { |
134 prefs_ = new MockPreferences; | 134 prefs_ = new MockPreferences; |
135 } | 135 } |
136 | 136 |
137 protected: | 137 protected: |
138 MockPreferences* prefs_; | 138 MockPreferences* prefs_; |
139 }; | 139 }; |
140 | 140 |
141 TEST_P(ConfigurationPolicyProviderMacTest, Default) { | 141 TEST_P(ConfigurationPolicyProviderMacTest, Default) { |
142 ConfigurationPolicyProviderMac provider( | 142 ConfigurationPolicyProviderMac provider( |
143 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), prefs_); | 143 GetChromePolicyDefinitionList(), prefs_); |
144 PolicyMap policy_map; | 144 PolicyMap policy_map; |
145 EXPECT_TRUE(provider.Provide(&policy_map)); | 145 EXPECT_TRUE(provider.Provide(&policy_map)); |
146 EXPECT_TRUE(policy_map.empty()); | 146 EXPECT_TRUE(policy_map.empty()); |
147 } | 147 } |
148 | 148 |
149 TEST_P(ConfigurationPolicyProviderMacTest, Invalid) { | 149 TEST_P(ConfigurationPolicyProviderMacTest, Invalid) { |
150 base::mac::ScopedCFTypeRef<CFStringRef> name( | 150 base::mac::ScopedCFTypeRef<CFStringRef> name( |
151 base::SysUTF8ToCFStringRef(GetParam().policy_name())); | 151 base::SysUTF8ToCFStringRef(GetParam().policy_name())); |
152 base::mac::ScopedCFTypeRef<CFDataRef> invalid_data( | 152 base::mac::ScopedCFTypeRef<CFDataRef> invalid_data( |
153 CFDataCreate(NULL, NULL, 0)); | 153 CFDataCreate(NULL, NULL, 0)); |
154 prefs_->AddTestItem(name, invalid_data.get(), true); | 154 prefs_->AddTestItem(name, invalid_data.get(), true); |
155 | 155 |
156 // Create the provider and have it read |prefs_|. | 156 // Create the provider and have it read |prefs_|. |
157 ConfigurationPolicyProviderMac provider( | 157 ConfigurationPolicyProviderMac provider( |
158 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), prefs_); | 158 GetChromePolicyDefinitionList(), prefs_); |
159 PolicyMap policy_map; | 159 PolicyMap policy_map; |
160 EXPECT_TRUE(provider.Provide(&policy_map)); | 160 EXPECT_TRUE(provider.Provide(&policy_map)); |
161 EXPECT_TRUE(policy_map.empty()); | 161 EXPECT_TRUE(policy_map.empty()); |
162 } | 162 } |
163 | 163 |
164 TEST_P(ConfigurationPolicyProviderMacTest, TestNonForcedValue) { | 164 TEST_P(ConfigurationPolicyProviderMacTest, TestNonForcedValue) { |
165 base::mac::ScopedCFTypeRef<CFStringRef> name( | 165 base::mac::ScopedCFTypeRef<CFStringRef> name( |
166 base::SysUTF8ToCFStringRef(GetParam().policy_name())); | 166 base::SysUTF8ToCFStringRef(GetParam().policy_name())); |
167 base::mac::ScopedCFTypeRef<CFPropertyListRef> test_value( | 167 base::mac::ScopedCFTypeRef<CFPropertyListRef> test_value( |
168 GetParam().GetPropertyListValue()); | 168 GetParam().GetPropertyListValue()); |
169 ASSERT_TRUE(test_value.get()); | 169 ASSERT_TRUE(test_value.get()); |
170 prefs_->AddTestItem(name, test_value.get(), false); | 170 prefs_->AddTestItem(name, test_value.get(), false); |
171 | 171 |
172 // Create the provider and have it read |prefs_|. | 172 // Create the provider and have it read |prefs_|. |
173 ConfigurationPolicyProviderMac provider( | 173 ConfigurationPolicyProviderMac provider( |
174 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), prefs_); | 174 GetChromePolicyDefinitionList(), prefs_); |
175 PolicyMap policy_map; | 175 PolicyMap policy_map; |
176 EXPECT_TRUE(provider.Provide(&policy_map)); | 176 EXPECT_TRUE(provider.Provide(&policy_map)); |
177 EXPECT_TRUE(policy_map.empty()); | 177 EXPECT_TRUE(policy_map.empty()); |
178 } | 178 } |
179 | 179 |
180 TEST_P(ConfigurationPolicyProviderMacTest, TestValue) { | 180 TEST_P(ConfigurationPolicyProviderMacTest, TestValue) { |
181 base::mac::ScopedCFTypeRef<CFStringRef> name( | 181 base::mac::ScopedCFTypeRef<CFStringRef> name( |
182 base::SysUTF8ToCFStringRef(GetParam().policy_name())); | 182 base::SysUTF8ToCFStringRef(GetParam().policy_name())); |
183 base::mac::ScopedCFTypeRef<CFPropertyListRef> test_value( | 183 base::mac::ScopedCFTypeRef<CFPropertyListRef> test_value( |
184 GetParam().GetPropertyListValue()); | 184 GetParam().GetPropertyListValue()); |
185 ASSERT_TRUE(test_value.get()); | 185 ASSERT_TRUE(test_value.get()); |
186 prefs_->AddTestItem(name, test_value, true); | 186 prefs_->AddTestItem(name, test_value, true); |
187 | 187 |
188 // Create the provider and have it read |prefs_|. | 188 // Create the provider and have it read |prefs_|. |
189 ConfigurationPolicyProviderMac provider( | 189 ConfigurationPolicyProviderMac provider( |
190 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), prefs_); | 190 GetChromePolicyDefinitionList(), prefs_); |
191 PolicyMap policy_map; | 191 PolicyMap policy_map; |
192 EXPECT_TRUE(provider.Provide(&policy_map)); | 192 EXPECT_TRUE(provider.Provide(&policy_map)); |
193 ASSERT_EQ(1U, policy_map.size()); | 193 ASSERT_EQ(1U, policy_map.size()); |
194 const Value* value = policy_map.Get(GetParam().type()); | 194 const Value* value = policy_map.Get(GetParam().type()); |
195 ASSERT_TRUE(value); | 195 ASSERT_TRUE(value); |
196 EXPECT_TRUE(GetParam().test_value()->Equals(value)); | 196 EXPECT_TRUE(GetParam().test_value()->Equals(value)); |
197 } | 197 } |
198 | 198 |
199 // Instantiate the test case for all policies. | 199 // Test parameters for all supported policies. testing::Values() has a limit of |
| 200 // 50 parameters which is reached in this instantiation; new policies should go |
| 201 // in the next instantiation after this one. |
200 INSTANTIATE_TEST_CASE_P( | 202 INSTANTIATE_TEST_CASE_P( |
201 ConfigurationPolicyProviderMacTestInstance, | 203 ConfigurationPolicyProviderMacTestInstance, |
202 ConfigurationPolicyProviderMacTest, | 204 ConfigurationPolicyProviderMacTest, |
203 testing::Values( | 205 testing::Values( |
204 PolicyTestParams::ForStringPolicy( | 206 PolicyTestParams::ForStringPolicy( |
205 kPolicyHomepageLocation, | 207 kPolicyHomepageLocation, |
206 key::kHomepageLocation), | 208 key::kHomepageLocation), |
207 PolicyTestParams::ForBooleanPolicy( | 209 PolicyTestParams::ForBooleanPolicy( |
208 kPolicyHomepageIsNewTabPage, | 210 kPolicyHomepageIsNewTabPage, |
209 key::kHomepageIsNewTabPage), | 211 key::kHomepageIsNewTabPage), |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 key::kExtensionInstallBlacklist), | 301 key::kExtensionInstallBlacklist), |
300 PolicyTestParams::ForBooleanPolicy( | 302 PolicyTestParams::ForBooleanPolicy( |
301 kPolicyShowHomeButton, | 303 kPolicyShowHomeButton, |
302 key::kShowHomeButton), | 304 key::kShowHomeButton), |
303 PolicyTestParams::ForBooleanPolicy( | 305 PolicyTestParams::ForBooleanPolicy( |
304 kPolicyPrintingEnabled, | 306 kPolicyPrintingEnabled, |
305 key::kPrintingEnabled), | 307 key::kPrintingEnabled), |
306 PolicyTestParams::ForBooleanPolicy( | 308 PolicyTestParams::ForBooleanPolicy( |
307 kPolicyInstantEnabled, | 309 kPolicyInstantEnabled, |
308 key::kInstantEnabled), | 310 key::kInstantEnabled), |
309 PolicyTestParams::ForIntegerPolicy( | |
310 kPolicyPolicyRefreshRate, | |
311 key::kPolicyRefreshRate), | |
312 PolicyTestParams::ForBooleanPolicy( | 311 PolicyTestParams::ForBooleanPolicy( |
313 kPolicyDisablePluginFinder, | 312 kPolicyDisablePluginFinder, |
314 key::kDisablePluginFinder), | 313 key::kDisablePluginFinder), |
315 PolicyTestParams::ForBooleanPolicy( | 314 PolicyTestParams::ForBooleanPolicy( |
316 kPolicyClearSiteDataOnExit, | 315 kPolicyClearSiteDataOnExit, |
317 key::kClearSiteDataOnExit), | 316 key::kClearSiteDataOnExit), |
318 PolicyTestParams::ForStringPolicy( | 317 PolicyTestParams::ForStringPolicy( |
319 kPolicyDownloadDirectory, | 318 kPolicyDownloadDirectory, |
320 key::kDownloadDirectory), | 319 key::kDownloadDirectory), |
321 PolicyTestParams::ForBooleanPolicy( | 320 PolicyTestParams::ForBooleanPolicy( |
(...skipping 21 matching lines...) Expand all Loading... |
343 kPolicyAllowFileSelectionDialogs, | 342 kPolicyAllowFileSelectionDialogs, |
344 key::kAllowFileSelectionDialogs), | 343 key::kAllowFileSelectionDialogs), |
345 PolicyTestParams::ForListPolicy( | 344 PolicyTestParams::ForListPolicy( |
346 kPolicyDisabledSchemes, | 345 kPolicyDisabledSchemes, |
347 key::kDisabledSchemes), | 346 key::kDisabledSchemes), |
348 PolicyTestParams::ForStringPolicy( | 347 PolicyTestParams::ForStringPolicy( |
349 kPolicyDiskCacheDir, | 348 kPolicyDiskCacheDir, |
350 key::kDiskCacheDir), | 349 key::kDiskCacheDir), |
351 PolicyTestParams::ForIntegerPolicy( | 350 PolicyTestParams::ForIntegerPolicy( |
352 kPolicyMaxConnectionsPerProxy, | 351 kPolicyMaxConnectionsPerProxy, |
353 key::kMaxConnectionsPerProxy))); | 352 key::kMaxConnectionsPerProxy), |
| 353 PolicyTestParams::ForListPolicy( |
| 354 kPolicyURLBlacklist, |
| 355 key::kURLBlacklist))); |
354 | 356 |
355 // testing::Values has a limit of 50 test templates, which is reached by the | 357 // testing::Values has a limit of 50 test templates, which is reached by the |
356 // instantiations above. Add tests for new policies here: | 358 // instantiations above. Add tests for new policies here: |
357 INSTANTIATE_TEST_CASE_P( | 359 INSTANTIATE_TEST_CASE_P( |
358 ConfigurationPolicyProviderMacTestInstance2, | 360 ConfigurationPolicyProviderMacTestInstance2, |
359 ConfigurationPolicyProviderMacTest, | 361 ConfigurationPolicyProviderMacTest, |
360 testing::Values( | 362 testing::Values( |
361 PolicyTestParams::ForListPolicy( | 363 PolicyTestParams::ForListPolicy( |
362 kPolicyURLBlacklist, | |
363 key::kURLBlacklist), | |
364 PolicyTestParams::ForListPolicy( | |
365 kPolicyURLWhitelist, | 364 kPolicyURLWhitelist, |
366 key::kURLWhitelist))); | 365 key::kURLWhitelist))); |
367 | 366 |
368 } // namespace policy | 367 } // namespace policy |
OLD | NEW |