| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <CoreFoundation/CoreFoundation.h> | 5 #include <CoreFoundation/CoreFoundation.h> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/mac/scoped_cftyperef.h" | 8 #include "base/mac/scoped_cftyperef.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/policy/asynchronous_policy_test_base.h" | 11 #include "chrome/browser/policy/asynchronous_policy_test_base.h" |
| 12 #include "chrome/browser/policy/configuration_policy_provider_mac.h" | 12 #include "chrome/browser/policy/configuration_policy_provider_mac.h" |
| 13 #include "chrome/browser/policy/configuration_policy_provider_test.h" | 13 #include "chrome/browser/policy/configuration_policy_provider_test.h" |
| 14 #include "chrome/browser/policy/policy_bundle.h" |
| 14 #include "chrome/browser/policy/policy_map.h" | 15 #include "chrome/browser/policy/policy_map.h" |
| 15 #include "chrome/browser/preferences_mock_mac.h" | 16 #include "chrome/browser/preferences_mock_mac.h" |
| 16 #include "policy/policy_constants.h" | 17 #include "policy/policy_constants.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 using base::mac::ScopedCFTypeRef; | 20 using base::mac::ScopedCFTypeRef; |
| 20 | 21 |
| 21 namespace policy { | 22 namespace policy { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 class TestHarness : public PolicyProviderTestHarness { | 119 class TestHarness : public PolicyProviderTestHarness { |
| 119 public: | 120 public: |
| 120 TestHarness(); | 121 TestHarness(); |
| 121 virtual ~TestHarness(); | 122 virtual ~TestHarness(); |
| 122 | 123 |
| 123 virtual void SetUp() OVERRIDE; | 124 virtual void SetUp() OVERRIDE; |
| 124 | 125 |
| 125 virtual AsynchronousPolicyProvider* CreateProvider( | 126 virtual AsynchronousPolicyProvider* CreateProvider( |
| 126 const PolicyDefinitionList* policy_definition_list) OVERRIDE; | 127 const PolicyDefinitionList* policy_definition_list) OVERRIDE; |
| 127 | 128 |
| 129 virtual PolicyLevel GetPolicyLevel() const OVERRIDE; |
| 130 virtual PolicyScope GetPolicyScope() const OVERRIDE; |
| 131 |
| 128 virtual void InstallEmptyPolicy() OVERRIDE; | 132 virtual void InstallEmptyPolicy() OVERRIDE; |
| 129 virtual void InstallStringPolicy(const std::string& policy_name, | 133 virtual void InstallStringPolicy(const std::string& policy_name, |
| 130 const std::string& policy_value) OVERRIDE; | 134 const std::string& policy_value) OVERRIDE; |
| 131 virtual void InstallIntegerPolicy(const std::string& policy_name, | 135 virtual void InstallIntegerPolicy(const std::string& policy_name, |
| 132 int policy_value) OVERRIDE; | 136 int policy_value) OVERRIDE; |
| 133 virtual void InstallBooleanPolicy(const std::string& policy_name, | 137 virtual void InstallBooleanPolicy(const std::string& policy_name, |
| 134 bool policy_value) OVERRIDE; | 138 bool policy_value) OVERRIDE; |
| 135 virtual void InstallStringListPolicy( | 139 virtual void InstallStringListPolicy( |
| 136 const std::string& policy_name, | 140 const std::string& policy_name, |
| 137 const base::ListValue* policy_value) OVERRIDE; | 141 const base::ListValue* policy_value) OVERRIDE; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 154 void TestHarness::SetUp() {} | 158 void TestHarness::SetUp() {} |
| 155 | 159 |
| 156 AsynchronousPolicyProvider* TestHarness::CreateProvider( | 160 AsynchronousPolicyProvider* TestHarness::CreateProvider( |
| 157 const PolicyDefinitionList* policy_definition_list) { | 161 const PolicyDefinitionList* policy_definition_list) { |
| 158 prefs_ = new MockPreferences(); | 162 prefs_ = new MockPreferences(); |
| 159 return new ConfigurationPolicyProviderMac(policy_definition_list, | 163 return new ConfigurationPolicyProviderMac(policy_definition_list, |
| 160 POLICY_LEVEL_MANDATORY, | 164 POLICY_LEVEL_MANDATORY, |
| 161 prefs_); | 165 prefs_); |
| 162 } | 166 } |
| 163 | 167 |
| 168 PolicyLevel TestHarness::GetPolicyLevel() const { |
| 169 return POLICY_LEVEL_MANDATORY; |
| 170 } |
| 171 |
| 172 PolicyScope TestHarness::GetPolicyScope() const { |
| 173 return POLICY_SCOPE_USER; |
| 174 } |
| 175 |
| 164 void TestHarness::InstallEmptyPolicy() {} | 176 void TestHarness::InstallEmptyPolicy() {} |
| 165 | 177 |
| 166 void TestHarness::InstallStringPolicy(const std::string& policy_name, | 178 void TestHarness::InstallStringPolicy(const std::string& policy_name, |
| 167 const std::string& policy_value) { | 179 const std::string& policy_value) { |
| 168 ScopedCFTypeRef<CFStringRef> name(base::SysUTF8ToCFStringRef(policy_name)); | 180 ScopedCFTypeRef<CFStringRef> name(base::SysUTF8ToCFStringRef(policy_name)); |
| 169 ScopedCFTypeRef<CFStringRef> value(base::SysUTF8ToCFStringRef(policy_value)); | 181 ScopedCFTypeRef<CFStringRef> value(base::SysUTF8ToCFStringRef(policy_value)); |
| 170 prefs_->AddTestItem(name, value, true); | 182 prefs_->AddTestItem(name, value, true); |
| 171 } | 183 } |
| 172 | 184 |
| 173 void TestHarness::InstallIntegerPolicy(const std::string& policy_name, | 185 void TestHarness::InstallIntegerPolicy(const std::string& policy_name, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 reinterpret_cast<const UInt8 *>(buffer), | 259 reinterpret_cast<const UInt8 *>(buffer), |
| 248 arraysize(buffer))); | 260 arraysize(buffer))); |
| 249 ASSERT_TRUE(invalid_data); | 261 ASSERT_TRUE(invalid_data); |
| 250 mandatory_prefs_->AddTestItem(name, invalid_data.get(), true); | 262 mandatory_prefs_->AddTestItem(name, invalid_data.get(), true); |
| 251 recommended_prefs_->AddTestItem(name, invalid_data.get(), false); | 263 recommended_prefs_->AddTestItem(name, invalid_data.get(), false); |
| 252 | 264 |
| 253 // Create the provider and have it read |mandatory_prefs_|. | 265 // Create the provider and have it read |mandatory_prefs_|. |
| 254 mandatory_provider_.RefreshPolicies(); | 266 mandatory_provider_.RefreshPolicies(); |
| 255 recommended_provider_.RefreshPolicies(); | 267 recommended_provider_.RefreshPolicies(); |
| 256 loop_.RunAllPending(); | 268 loop_.RunAllPending(); |
| 257 PolicyMap policy_map; | 269 const PolicyBundle kEmptyBundle; |
| 258 EXPECT_TRUE(mandatory_provider_.Provide(&policy_map)); | 270 EXPECT_TRUE(mandatory_provider_.policies().Equals(kEmptyBundle)); |
| 259 EXPECT_TRUE(policy_map.empty()); | 271 EXPECT_TRUE(recommended_provider_.policies().Equals(kEmptyBundle)); |
| 260 EXPECT_TRUE(recommended_provider_.Provide(&policy_map)); | |
| 261 EXPECT_TRUE(policy_map.empty()); | |
| 262 } | 272 } |
| 263 | 273 |
| 264 TEST_F(ConfigurationPolicyProviderMacTest, TestNonForcedValue) { | 274 TEST_F(ConfigurationPolicyProviderMacTest, TestNonForcedValue) { |
| 265 ScopedCFTypeRef<CFStringRef> name( | 275 ScopedCFTypeRef<CFStringRef> name( |
| 266 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString)); | 276 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString)); |
| 267 ScopedCFTypeRef<CFPropertyListRef> test_value( | 277 ScopedCFTypeRef<CFPropertyListRef> test_value( |
| 268 base::SysUTF8ToCFStringRef("string value")); | 278 base::SysUTF8ToCFStringRef("string value")); |
| 269 ASSERT_TRUE(test_value.get()); | 279 ASSERT_TRUE(test_value.get()); |
| 270 mandatory_prefs_->AddTestItem(name, test_value.get(), false); | 280 mandatory_prefs_->AddTestItem(name, test_value.get(), false); |
| 271 recommended_prefs_->AddTestItem(name, test_value.get(), false); | 281 recommended_prefs_->AddTestItem(name, test_value.get(), false); |
| 272 | 282 |
| 273 // Create the provider and have it read |mandatory_prefs_|. | 283 // Create the provider and have it read |mandatory_prefs_|. |
| 274 mandatory_provider_.RefreshPolicies(); | 284 mandatory_provider_.RefreshPolicies(); |
| 275 recommended_provider_.RefreshPolicies(); | 285 recommended_provider_.RefreshPolicies(); |
| 276 loop_.RunAllPending(); | 286 loop_.RunAllPending(); |
| 277 PolicyMap policy_map; | 287 PolicyBundle expected_bundle; |
| 278 EXPECT_TRUE(mandatory_provider_.Provide(&policy_map)); | 288 EXPECT_TRUE(mandatory_provider_.policies().Equals(expected_bundle)); |
| 279 EXPECT_TRUE(policy_map.empty()); | 289 expected_bundle.Get(POLICY_DOMAIN_CHROME, "") |
| 280 EXPECT_TRUE(recommended_provider_.Provide(&policy_map)); | 290 .Set(test_policy_definitions::kKeyString, POLICY_LEVEL_RECOMMENDED, |
| 281 EXPECT_EQ(1U, policy_map.size()); | 291 POLICY_SCOPE_USER, base::Value::CreateStringValue("string value")); |
| 292 EXPECT_TRUE(recommended_provider_.policies().Equals(expected_bundle)); |
| 282 } | 293 } |
| 283 | 294 |
| 284 TEST_F(ConfigurationPolicyProviderMacTest, TestConversions) { | 295 TEST_F(ConfigurationPolicyProviderMacTest, TestConversions) { |
| 285 base::DictionaryValue root; | 296 base::DictionaryValue root; |
| 286 | 297 |
| 287 // base::Value::TYPE_NULL | 298 // base::Value::TYPE_NULL |
| 288 root.Set("null", base::Value::CreateNullValue()); | 299 root.Set("null", base::Value::CreateNullValue()); |
| 289 | 300 |
| 290 // base::Value::TYPE_BOOLEAN | 301 // base::Value::TYPE_BOOLEAN |
| 291 root.SetBoolean("false", false); | 302 root.SetBoolean("false", false); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 321 ScopedCFTypeRef<CFPropertyListRef> property(CreatePropertyFromValue(&root)); | 332 ScopedCFTypeRef<CFPropertyListRef> property(CreatePropertyFromValue(&root)); |
| 322 ASSERT_TRUE(property); | 333 ASSERT_TRUE(property); |
| 323 scoped_ptr<base::Value> value( | 334 scoped_ptr<base::Value> value( |
| 324 MacPreferencesPolicyProviderDelegate::CreateValueFromProperty(property)); | 335 MacPreferencesPolicyProviderDelegate::CreateValueFromProperty(property)); |
| 325 ASSERT_TRUE(value.get()); | 336 ASSERT_TRUE(value.get()); |
| 326 | 337 |
| 327 EXPECT_TRUE(root.Equals(value.get())); | 338 EXPECT_TRUE(root.Equals(value.get())); |
| 328 } | 339 } |
| 329 | 340 |
| 330 } // namespace policy | 341 } // namespace policy |
| OLD | NEW |