| OLD | NEW |
| 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/mac/scoped_cftyperef.h" | 7 #include "base/mac/scoped_cftyperef.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.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" |
| 11 #include "chrome/browser/policy/configuration_policy_provider_mac.h" | 11 #include "chrome/browser/policy/configuration_policy_provider_mac.h" |
| 12 #include "chrome/browser/policy/mock_configuration_policy_store.h" | 12 #include "chrome/browser/policy/mock_configuration_policy_store.h" |
| 13 #include "chrome/browser/preferences_mock_mac.h" | 13 #include "chrome/browser/preferences_mock_mac.h" |
| 14 #include "chrome/common/policy_constants.h" | 14 #include "chrome/common/policy_constants.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace policy { | 17 namespace policy { |
| 18 | 18 |
| 19 // Holds parameters for the parametrized policy tests. | 19 // Holds parameters for the parametrized policy tests. |
| 20 class PolicyTestParams { | 20 class PolicyTestParams { |
| 21 public: | 21 public: |
| 22 // Takes ownership of |test_value|. | 22 // Takes ownership of |test_value|. |
| 23 PolicyTestParams(ConfigurationPolicyStore::PolicyType type, | 23 PolicyTestParams(ConfigurationPolicyType type, |
| 24 const char* policy_name, | 24 const char* policy_name, |
| 25 Value* test_value) | 25 Value* test_value) |
| 26 : type_(type), | 26 : type_(type), |
| 27 policy_name_(policy_name), | 27 policy_name_(policy_name), |
| 28 test_value_(test_value) {} | 28 test_value_(test_value) {} |
| 29 | 29 |
| 30 // testing::TestWithParam does copying, so provide copy constructor and | 30 // testing::TestWithParam does copying, so provide copy constructor and |
| 31 // assignment operator. | 31 // assignment operator. |
| 32 PolicyTestParams(const PolicyTestParams& other) | 32 PolicyTestParams(const PolicyTestParams& other) |
| 33 : type_(other.type_), | 33 : type_(other.type_), |
| 34 policy_name_(other.policy_name_), | 34 policy_name_(other.policy_name_), |
| 35 test_value_(other.test_value_->DeepCopy()) {} | 35 test_value_(other.test_value_->DeepCopy()) {} |
| 36 | 36 |
| 37 const PolicyTestParams& operator=(PolicyTestParams other) { | 37 const PolicyTestParams& operator=(PolicyTestParams other) { |
| 38 swap(other); | 38 swap(other); |
| 39 return *this; | 39 return *this; |
| 40 } | 40 } |
| 41 | 41 |
| 42 void swap(PolicyTestParams& other) { | 42 void swap(PolicyTestParams& other) { |
| 43 std::swap(type_, other.type_); | 43 std::swap(type_, other.type_); |
| 44 std::swap(policy_name_, other.policy_name_); | 44 std::swap(policy_name_, other.policy_name_); |
| 45 test_value_.swap(other.test_value_); | 45 test_value_.swap(other.test_value_); |
| 46 } | 46 } |
| 47 | 47 |
| 48 ConfigurationPolicyStore::PolicyType type() const { return type_; } | 48 ConfigurationPolicyType type() const { return type_; } |
| 49 const char* policy_name() const { return policy_name_; } | 49 const char* policy_name() const { return policy_name_; } |
| 50 const Value* test_value() const { return test_value_.get(); } | 50 const Value* test_value() const { return test_value_.get(); } |
| 51 | 51 |
| 52 // Get the test value in the appropriate CFPropertyListRef representation. | 52 // Get the test value in the appropriate CFPropertyListRef representation. |
| 53 CFPropertyListRef GetPropertyListValue() const { | 53 CFPropertyListRef GetPropertyListValue() const { |
| 54 switch (test_value_->GetType()) { | 54 switch (test_value_->GetType()) { |
| 55 case Value::TYPE_BOOLEAN: { | 55 case Value::TYPE_BOOLEAN: { |
| 56 bool v; | 56 bool v; |
| 57 if (!test_value_->GetAsBoolean(&v)) | 57 if (!test_value_->GetAsBoolean(&v)) |
| 58 return NULL; | 58 return NULL; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 89 } | 89 } |
| 90 return array.release(); | 90 return array.release(); |
| 91 } | 91 } |
| 92 default: | 92 default: |
| 93 return NULL; | 93 return NULL; |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Factory methods that create parameter objects for different value types. | 97 // Factory methods that create parameter objects for different value types. |
| 98 static PolicyTestParams ForStringPolicy( | 98 static PolicyTestParams ForStringPolicy( |
| 99 ConfigurationPolicyStore::PolicyType type, | 99 ConfigurationPolicyType type, |
| 100 const char* name) { | 100 const char* name) { |
| 101 return PolicyTestParams(type, name, Value::CreateStringValue("test")); | 101 return PolicyTestParams(type, name, Value::CreateStringValue("test")); |
| 102 } | 102 } |
| 103 static PolicyTestParams ForBooleanPolicy( | 103 static PolicyTestParams ForBooleanPolicy( |
| 104 ConfigurationPolicyStore::PolicyType type, | 104 ConfigurationPolicyType type, |
| 105 const char* name) { | 105 const char* name) { |
| 106 return PolicyTestParams(type, name, Value::CreateBooleanValue(true)); | 106 return PolicyTestParams(type, name, Value::CreateBooleanValue(true)); |
| 107 } | 107 } |
| 108 static PolicyTestParams ForIntegerPolicy( | 108 static PolicyTestParams ForIntegerPolicy( |
| 109 ConfigurationPolicyStore::PolicyType type, | 109 ConfigurationPolicyType type, |
| 110 const char* name) { | 110 const char* name) { |
| 111 return PolicyTestParams(type, name, Value::CreateIntegerValue(42)); | 111 return PolicyTestParams(type, name, Value::CreateIntegerValue(42)); |
| 112 } | 112 } |
| 113 static PolicyTestParams ForListPolicy( | 113 static PolicyTestParams ForListPolicy( |
| 114 ConfigurationPolicyStore::PolicyType type, | 114 ConfigurationPolicyType type, |
| 115 const char* name) { | 115 const char* name) { |
| 116 ListValue* value = new ListValue; | 116 ListValue* value = new ListValue; |
| 117 value->Set(0U, Value::CreateStringValue("first")); | 117 value->Set(0U, Value::CreateStringValue("first")); |
| 118 value->Set(1U, Value::CreateStringValue("second")); | 118 value->Set(1U, Value::CreateStringValue("second")); |
| 119 return PolicyTestParams(type, name, value); | 119 return PolicyTestParams(type, name, value); |
| 120 } | 120 } |
| 121 | 121 |
| 122 private: | 122 private: |
| 123 ConfigurationPolicyStore::PolicyType type_; | 123 ConfigurationPolicyType type_; |
| 124 const char* policy_name_; | 124 const char* policy_name_; |
| 125 scoped_ptr<Value> test_value_; | 125 scoped_ptr<Value> test_value_; |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 // Parametrized test class for testing whether ConfigurationPolicyProviderMac | 128 // Parametrized test class for testing whether ConfigurationPolicyProviderMac |
| 129 // can handle all policies correctly. | 129 // can handle all policies correctly. |
| 130 class ConfigurationPolicyProviderMacTest | 130 class ConfigurationPolicyProviderMacTest |
| 131 : public testing::TestWithParam<PolicyTestParams> { | 131 : public testing::TestWithParam<PolicyTestParams> { |
| 132 public: | 132 public: |
| 133 virtual void SetUp() { | 133 virtual void SetUp() { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 ASSERT_TRUE(value); | 193 ASSERT_TRUE(value); |
| 194 EXPECT_TRUE(GetParam().test_value()->Equals(value)); | 194 EXPECT_TRUE(GetParam().test_value()->Equals(value)); |
| 195 } | 195 } |
| 196 | 196 |
| 197 // Instantiate the test case for all policies. | 197 // Instantiate the test case for all policies. |
| 198 INSTANTIATE_TEST_CASE_P( | 198 INSTANTIATE_TEST_CASE_P( |
| 199 ConfigurationPolicyProviderMacTestInstance, | 199 ConfigurationPolicyProviderMacTestInstance, |
| 200 ConfigurationPolicyProviderMacTest, | 200 ConfigurationPolicyProviderMacTest, |
| 201 testing::Values( | 201 testing::Values( |
| 202 PolicyTestParams::ForStringPolicy( | 202 PolicyTestParams::ForStringPolicy( |
| 203 ConfigurationPolicyStore::kPolicyHomePage, | 203 kPolicyHomePage, |
| 204 key::kHomepageLocation), | 204 key::kHomepageLocation), |
| 205 PolicyTestParams::ForBooleanPolicy( | 205 PolicyTestParams::ForBooleanPolicy( |
| 206 ConfigurationPolicyStore::kPolicyHomepageIsNewTabPage, | 206 kPolicyHomepageIsNewTabPage, |
| 207 key::kHomepageIsNewTabPage), | 207 key::kHomepageIsNewTabPage), |
| 208 PolicyTestParams::ForIntegerPolicy( | 208 PolicyTestParams::ForIntegerPolicy( |
| 209 ConfigurationPolicyStore::kPolicyRestoreOnStartup, | 209 kPolicyRestoreOnStartup, |
| 210 key::kRestoreOnStartup), | 210 key::kRestoreOnStartup), |
| 211 PolicyTestParams::ForListPolicy( | 211 PolicyTestParams::ForListPolicy( |
| 212 ConfigurationPolicyStore::kPolicyURLsToRestoreOnStartup, | 212 kPolicyURLsToRestoreOnStartup, |
| 213 key::kURLsToRestoreOnStartup), | 213 key::kURLsToRestoreOnStartup), |
| 214 PolicyTestParams::ForBooleanPolicy( | 214 PolicyTestParams::ForBooleanPolicy( |
| 215 ConfigurationPolicyStore::kPolicyDefaultSearchProviderEnabled, | 215 kPolicyDefaultSearchProviderEnabled, |
| 216 key::kDefaultSearchProviderEnabled), | 216 key::kDefaultSearchProviderEnabled), |
| 217 PolicyTestParams::ForStringPolicy( | 217 PolicyTestParams::ForStringPolicy( |
| 218 ConfigurationPolicyStore::kPolicyDefaultSearchProviderName, | 218 kPolicyDefaultSearchProviderName, |
| 219 key::kDefaultSearchProviderName), | 219 key::kDefaultSearchProviderName), |
| 220 PolicyTestParams::ForStringPolicy( | 220 PolicyTestParams::ForStringPolicy( |
| 221 ConfigurationPolicyStore::kPolicyDefaultSearchProviderKeyword, | 221 kPolicyDefaultSearchProviderKeyword, |
| 222 key::kDefaultSearchProviderKeyword), | 222 key::kDefaultSearchProviderKeyword), |
| 223 PolicyTestParams::ForStringPolicy( | 223 PolicyTestParams::ForStringPolicy( |
| 224 ConfigurationPolicyStore::kPolicyDefaultSearchProviderSearchURL, | 224 kPolicyDefaultSearchProviderSearchURL, |
| 225 key::kDefaultSearchProviderSearchURL), | 225 key::kDefaultSearchProviderSearchURL), |
| 226 PolicyTestParams::ForStringPolicy( | 226 PolicyTestParams::ForStringPolicy( |
| 227 ConfigurationPolicyStore::kPolicyDefaultSearchProviderSuggestURL, | 227 kPolicyDefaultSearchProviderSuggestURL, |
| 228 key::kDefaultSearchProviderSuggestURL), | 228 key::kDefaultSearchProviderSuggestURL), |
| 229 PolicyTestParams::ForStringPolicy( | 229 PolicyTestParams::ForStringPolicy( |
| 230 ConfigurationPolicyStore::kPolicyDefaultSearchProviderIconURL, | 230 kPolicyDefaultSearchProviderIconURL, |
| 231 key::kDefaultSearchProviderIconURL), | 231 key::kDefaultSearchProviderIconURL), |
| 232 PolicyTestParams::ForStringPolicy( | 232 PolicyTestParams::ForStringPolicy( |
| 233 ConfigurationPolicyStore::kPolicyDefaultSearchProviderEncodings, | 233 kPolicyDefaultSearchProviderEncodings, |
| 234 key::kDefaultSearchProviderEncodings), | 234 key::kDefaultSearchProviderEncodings), |
| 235 PolicyTestParams::ForIntegerPolicy( | 235 PolicyTestParams::ForIntegerPolicy( |
| 236 ConfigurationPolicyStore::kPolicyProxyServerMode, | 236 kPolicyProxyServerMode, |
| 237 key::kProxyServerMode), | 237 key::kProxyServerMode), |
| 238 PolicyTestParams::ForStringPolicy( | 238 PolicyTestParams::ForStringPolicy( |
| 239 ConfigurationPolicyStore::kPolicyProxyServer, | 239 kPolicyProxyServer, |
| 240 key::kProxyServer), | 240 key::kProxyServer), |
| 241 PolicyTestParams::ForStringPolicy( | 241 PolicyTestParams::ForStringPolicy( |
| 242 ConfigurationPolicyStore::kPolicyProxyPacUrl, | 242 kPolicyProxyPacUrl, |
| 243 key::kProxyPacUrl), | 243 key::kProxyPacUrl), |
| 244 PolicyTestParams::ForStringPolicy( | 244 PolicyTestParams::ForStringPolicy( |
| 245 ConfigurationPolicyStore::kPolicyProxyBypassList, | 245 kPolicyProxyBypassList, |
| 246 key::kProxyBypassList), | 246 key::kProxyBypassList), |
| 247 PolicyTestParams::ForBooleanPolicy( | 247 PolicyTestParams::ForBooleanPolicy( |
| 248 ConfigurationPolicyStore::kPolicyAlternateErrorPagesEnabled, | 248 kPolicyAlternateErrorPagesEnabled, |
| 249 key::kAlternateErrorPagesEnabled), | 249 key::kAlternateErrorPagesEnabled), |
| 250 PolicyTestParams::ForBooleanPolicy( | 250 PolicyTestParams::ForBooleanPolicy( |
| 251 ConfigurationPolicyStore::kPolicySearchSuggestEnabled, | 251 kPolicySearchSuggestEnabled, |
| 252 key::kSearchSuggestEnabled), | 252 key::kSearchSuggestEnabled), |
| 253 PolicyTestParams::ForBooleanPolicy( | 253 PolicyTestParams::ForBooleanPolicy( |
| 254 ConfigurationPolicyStore::kPolicyDnsPrefetchingEnabled, | 254 kPolicyDnsPrefetchingEnabled, |
| 255 key::kDnsPrefetchingEnabled), | 255 key::kDnsPrefetchingEnabled), |
| 256 PolicyTestParams::ForBooleanPolicy( | 256 PolicyTestParams::ForBooleanPolicy( |
| 257 ConfigurationPolicyStore::kPolicySafeBrowsingEnabled, | 257 kPolicySafeBrowsingEnabled, |
| 258 key::kSafeBrowsingEnabled), | 258 key::kSafeBrowsingEnabled), |
| 259 PolicyTestParams::ForBooleanPolicy( | 259 PolicyTestParams::ForBooleanPolicy( |
| 260 ConfigurationPolicyStore::kPolicyMetricsReportingEnabled, | 260 kPolicyMetricsReportingEnabled, |
| 261 key::kMetricsReportingEnabled), | 261 key::kMetricsReportingEnabled), |
| 262 PolicyTestParams::ForBooleanPolicy( | 262 PolicyTestParams::ForBooleanPolicy( |
| 263 ConfigurationPolicyStore::kPolicyPasswordManagerEnabled, | 263 kPolicyPasswordManagerEnabled, |
| 264 key::kPasswordManagerEnabled), | 264 key::kPasswordManagerEnabled), |
| 265 PolicyTestParams::ForBooleanPolicy( | 265 PolicyTestParams::ForBooleanPolicy( |
| 266 ConfigurationPolicyStore::kPolicyPasswordManagerAllowShowPasswords, | 266 kPolicyPasswordManagerAllowShowPasswords, |
| 267 key::kPasswordManagerAllowShowPasswords), | 267 key::kPasswordManagerAllowShowPasswords), |
| 268 PolicyTestParams::ForListPolicy( | 268 PolicyTestParams::ForListPolicy( |
| 269 ConfigurationPolicyStore::kPolicyDisabledPlugins, | 269 kPolicyDisabledPlugins, |
| 270 key::kDisabledPlugins), | 270 key::kDisabledPlugins), |
| 271 PolicyTestParams::ForBooleanPolicy( | 271 PolicyTestParams::ForBooleanPolicy( |
| 272 ConfigurationPolicyStore::kPolicyAutoFillEnabled, | 272 kPolicyAutoFillEnabled, |
| 273 key::kAutoFillEnabled), | 273 key::kAutoFillEnabled), |
| 274 PolicyTestParams::ForStringPolicy( | 274 PolicyTestParams::ForStringPolicy( |
| 275 ConfigurationPolicyStore::kPolicyApplicationLocale, | 275 kPolicyApplicationLocale, |
| 276 key::kApplicationLocaleValue), | 276 key::kApplicationLocaleValue), |
| 277 PolicyTestParams::ForBooleanPolicy( | 277 PolicyTestParams::ForBooleanPolicy( |
| 278 ConfigurationPolicyStore::kPolicySyncDisabled, | 278 kPolicySyncDisabled, |
| 279 key::kSyncDisabled), | 279 key::kSyncDisabled), |
| 280 PolicyTestParams::ForListPolicy( | 280 PolicyTestParams::ForListPolicy( |
| 281 ConfigurationPolicyStore::kPolicyExtensionInstallAllowList, | 281 kPolicyExtensionInstallAllowList, |
| 282 key::kExtensionInstallAllowList), | 282 key::kExtensionInstallAllowList), |
| 283 PolicyTestParams::ForListPolicy( | 283 PolicyTestParams::ForListPolicy( |
| 284 ConfigurationPolicyStore::kPolicyExtensionInstallDenyList, | 284 kPolicyExtensionInstallDenyList, |
| 285 key::kExtensionInstallDenyList), | 285 key::kExtensionInstallDenyList), |
| 286 PolicyTestParams::ForBooleanPolicy( | 286 PolicyTestParams::ForBooleanPolicy( |
| 287 ConfigurationPolicyStore::kPolicyShowHomeButton, | 287 kPolicyShowHomeButton, |
| 288 key::kShowHomeButton), | 288 key::kShowHomeButton), |
| 289 PolicyTestParams::ForBooleanPolicy( | 289 PolicyTestParams::ForBooleanPolicy( |
| 290 ConfigurationPolicyStore::kPolicyPrintingEnabled, | 290 kPolicyPrintingEnabled, |
| 291 key::kPrintingEnabled))); | 291 key::kPrintingEnabled))); |
| 292 | 292 |
| 293 } // namespace policy | 293 } // namespace policy |
| OLD | NEW |