Chromium Code Reviews| 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" | |
| 12 #include "chrome/browser/policy/configuration_policy_provider_mac.h" | |
| 13 #include "chrome/browser/policy/configuration_policy_provider_test.h" | 11 #include "chrome/browser/policy/configuration_policy_provider_test.h" |
| 14 #include "chrome/browser/policy/policy_bundle.h" | 12 #include "chrome/browser/policy/policy_bundle.h" |
| 13 #include "chrome/browser/policy/policy_loader_mac.h" | |
| 15 #include "chrome/browser/policy/policy_map.h" | 14 #include "chrome/browser/policy/policy_map.h" |
| 16 #include "chrome/browser/preferences_mock_mac.h" | 15 #include "chrome/browser/preferences_mock_mac.h" |
| 17 #include "policy/policy_constants.h" | 16 #include "policy/policy_constants.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 18 |
| 20 using base::mac::ScopedCFTypeRef; | 19 using base::mac::ScopedCFTypeRef; |
| 21 | 20 |
| 22 namespace policy { | 21 namespace policy { |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 return NULL; | 115 return NULL; |
| 117 } | 116 } |
| 118 | 117 |
| 119 class TestHarness : public PolicyProviderTestHarness { | 118 class TestHarness : public PolicyProviderTestHarness { |
| 120 public: | 119 public: |
| 121 TestHarness(); | 120 TestHarness(); |
| 122 virtual ~TestHarness(); | 121 virtual ~TestHarness(); |
| 123 | 122 |
| 124 virtual void SetUp() OVERRIDE; | 123 virtual void SetUp() OVERRIDE; |
| 125 | 124 |
| 126 virtual AsynchronousPolicyProvider* CreateProvider( | 125 virtual ConfigurationPolicyProvider* CreateProvider( |
| 127 const PolicyDefinitionList* policy_definition_list) OVERRIDE; | 126 const PolicyDefinitionList* policy_definition_list) OVERRIDE; |
| 128 | 127 |
| 129 virtual void InstallEmptyPolicy() OVERRIDE; | 128 virtual void InstallEmptyPolicy() OVERRIDE; |
| 130 virtual void InstallStringPolicy(const std::string& policy_name, | 129 virtual void InstallStringPolicy(const std::string& policy_name, |
| 131 const std::string& policy_value) OVERRIDE; | 130 const std::string& policy_value) OVERRIDE; |
| 132 virtual void InstallIntegerPolicy(const std::string& policy_name, | 131 virtual void InstallIntegerPolicy(const std::string& policy_name, |
| 133 int policy_value) OVERRIDE; | 132 int policy_value) OVERRIDE; |
| 134 virtual void InstallBooleanPolicy(const std::string& policy_name, | 133 virtual void InstallBooleanPolicy(const std::string& policy_name, |
| 135 bool policy_value) OVERRIDE; | 134 bool policy_value) OVERRIDE; |
| 136 virtual void InstallStringListPolicy( | 135 virtual void InstallStringListPolicy( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 148 DISALLOW_COPY_AND_ASSIGN(TestHarness); | 147 DISALLOW_COPY_AND_ASSIGN(TestHarness); |
| 149 }; | 148 }; |
| 150 | 149 |
| 151 TestHarness::TestHarness() | 150 TestHarness::TestHarness() |
| 152 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER) {} | 151 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER) {} |
| 153 | 152 |
| 154 TestHarness::~TestHarness() {} | 153 TestHarness::~TestHarness() {} |
| 155 | 154 |
| 156 void TestHarness::SetUp() {} | 155 void TestHarness::SetUp() {} |
| 157 | 156 |
| 158 AsynchronousPolicyProvider* TestHarness::CreateProvider( | 157 ConfigurationPolicyProvider* TestHarness::CreateProvider( |
| 159 const PolicyDefinitionList* policy_definition_list) { | 158 const PolicyDefinitionList* policy_list) { |
| 160 prefs_ = new MockPreferences(); | 159 prefs_ = new MockPreferences(); |
| 161 return new ConfigurationPolicyProviderMac(policy_definition_list, prefs_); | 160 MacPolicyLoader* loader = new MacPolicyLoader(policy_list, prefs_); |
| 161 return new AsyncPolicyProvider(policy_list, loader); | |
| 162 } | 162 } |
| 163 | 163 |
| 164 void TestHarness::InstallEmptyPolicy() {} | 164 void TestHarness::InstallEmptyPolicy() {} |
| 165 | 165 |
| 166 void TestHarness::InstallStringPolicy(const std::string& policy_name, | 166 void TestHarness::InstallStringPolicy(const std::string& policy_name, |
| 167 const std::string& policy_value) { | 167 const std::string& policy_value) { |
| 168 ScopedCFTypeRef<CFStringRef> name(base::SysUTF8ToCFStringRef(policy_name)); | 168 ScopedCFTypeRef<CFStringRef> name(base::SysUTF8ToCFStringRef(policy_name)); |
| 169 ScopedCFTypeRef<CFStringRef> value(base::SysUTF8ToCFStringRef(policy_value)); | 169 ScopedCFTypeRef<CFStringRef> value(base::SysUTF8ToCFStringRef(policy_value)); |
| 170 prefs_->AddTestItem(name, value, true); | 170 prefs_->AddTestItem(name, value, true); |
| 171 } | 171 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 | 207 |
| 208 // static | 208 // static |
| 209 PolicyProviderTestHarness* TestHarness::Create() { | 209 PolicyProviderTestHarness* TestHarness::Create() { |
| 210 return new TestHarness(); | 210 return new TestHarness(); |
| 211 } | 211 } |
| 212 | 212 |
| 213 } // namespace | 213 } // namespace |
| 214 | 214 |
| 215 // Instantiate abstract test case for basic policy reading tests. | 215 // Instantiate abstract test case for basic policy reading tests. |
| 216 INSTANTIATE_TEST_CASE_P( | 216 INSTANTIATE_TEST_CASE_P( |
| 217 ConfigurationPolicyProviderMacTest, | 217 MacPolicyLoaderTest, |
| 218 ConfigurationPolicyProviderTest, | 218 ConfigurationPolicyProviderTest, |
| 219 testing::Values(TestHarness::Create)); | 219 testing::Values(TestHarness::Create)); |
| 220 | 220 |
| 221 // Special test cases for some mac preferences details. | 221 // Special test cases for some mac preferences details. |
| 222 class ConfigurationPolicyProviderMacTest : public AsynchronousPolicyTestBase { | 222 class MacPolicyLoaderTest : public PolicyTestBase { |
|
Mattias Nissler (ping if slow)
2012/06/04 09:19:02
Both the test case instance and this test fixture
Joao da Silva
2012/06/04 17:55:14
Done.
| |
| 223 protected: | 223 protected: |
| 224 ConfigurationPolicyProviderMacTest() | 224 MacPolicyLoaderTest() |
| 225 : prefs_(new MockPreferences()), | 225 : prefs_(new MockPreferences()), |
| 226 provider_(&test_policy_definitions::kList, prefs_) {} | 226 loader_(new MacPolicyLoader(&test_policy_definitions::kList, prefs_)), |
| 227 virtual ~ConfigurationPolicyProviderMacTest() {} | 227 provider_(&test_policy_definitions::kList, loader_) {} |
| 228 virtual ~MacPolicyLoaderTest() {} | |
| 228 | 229 |
| 229 MockPreferences* prefs_; | 230 MockPreferences* prefs_; |
| 230 ConfigurationPolicyProviderMac provider_; | 231 MacPolicyLoader* loader_; |
| 232 AsyncPolicyProvider provider_; | |
| 231 }; | 233 }; |
| 232 | 234 |
| 233 TEST_F(ConfigurationPolicyProviderMacTest, Invalid) { | 235 TEST_F(MacPolicyLoaderTest, Invalid) { |
| 234 ScopedCFTypeRef<CFStringRef> name( | 236 ScopedCFTypeRef<CFStringRef> name( |
| 235 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString)); | 237 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString)); |
| 236 const char buffer[] = "binary \xde\xad\xbe\xef data"; | 238 const char buffer[] = "binary \xde\xad\xbe\xef data"; |
| 237 ScopedCFTypeRef<CFDataRef> invalid_data( | 239 ScopedCFTypeRef<CFDataRef> invalid_data( |
| 238 CFDataCreate(kCFAllocatorDefault, | 240 CFDataCreate(kCFAllocatorDefault, |
| 239 reinterpret_cast<const UInt8 *>(buffer), | 241 reinterpret_cast<const UInt8 *>(buffer), |
| 240 arraysize(buffer))); | 242 arraysize(buffer))); |
| 241 ASSERT_TRUE(invalid_data); | 243 ASSERT_TRUE(invalid_data); |
| 242 prefs_->AddTestItem(name, invalid_data.get(), true); | 244 prefs_->AddTestItem(name, invalid_data.get(), true); |
| 243 prefs_->AddTestItem(name, invalid_data.get(), false); | 245 prefs_->AddTestItem(name, invalid_data.get(), false); |
| 244 | 246 |
| 245 // Make the provider read the updated |prefs_|. | 247 // Make the provider read the updated |prefs_|. |
| 246 provider_.RefreshPolicies(); | 248 provider_.RefreshPolicies(); |
| 247 loop_.RunAllPending(); | 249 loop_.RunAllPending(); |
| 248 const PolicyBundle kEmptyBundle; | 250 const PolicyBundle kEmptyBundle; |
| 249 EXPECT_TRUE(provider_.policies().Equals(kEmptyBundle)); | 251 EXPECT_TRUE(provider_.policies().Equals(kEmptyBundle)); |
| 250 } | 252 } |
| 251 | 253 |
| 252 TEST_F(ConfigurationPolicyProviderMacTest, TestNonForcedValue) { | 254 TEST_F(MacPolicyLoaderTest, TestNonForcedValue) { |
| 253 ScopedCFTypeRef<CFStringRef> name( | 255 ScopedCFTypeRef<CFStringRef> name( |
| 254 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString)); | 256 base::SysUTF8ToCFStringRef(test_policy_definitions::kKeyString)); |
| 255 ScopedCFTypeRef<CFPropertyListRef> test_value( | 257 ScopedCFTypeRef<CFPropertyListRef> test_value( |
| 256 base::SysUTF8ToCFStringRef("string value")); | 258 base::SysUTF8ToCFStringRef("string value")); |
| 257 ASSERT_TRUE(test_value.get()); | 259 ASSERT_TRUE(test_value.get()); |
| 258 prefs_->AddTestItem(name, test_value.get(), false); | 260 prefs_->AddTestItem(name, test_value.get(), false); |
| 259 | 261 |
| 260 // Make the provider read the updated |prefs_|. | 262 // Make the provider read the updated |prefs_|. |
| 261 provider_.RefreshPolicies(); | 263 provider_.RefreshPolicies(); |
| 262 loop_.RunAllPending(); | 264 loop_.RunAllPending(); |
| 263 PolicyBundle expected_bundle; | 265 PolicyBundle expected_bundle; |
| 264 expected_bundle.Get(POLICY_DOMAIN_CHROME, "") | 266 expected_bundle.Get(POLICY_DOMAIN_CHROME, "") |
| 265 .Set(test_policy_definitions::kKeyString, POLICY_LEVEL_RECOMMENDED, | 267 .Set(test_policy_definitions::kKeyString, POLICY_LEVEL_RECOMMENDED, |
| 266 POLICY_SCOPE_USER, base::Value::CreateStringValue("string value")); | 268 POLICY_SCOPE_USER, base::Value::CreateStringValue("string value")); |
| 267 EXPECT_TRUE(provider_.policies().Equals(expected_bundle)); | 269 EXPECT_TRUE(provider_.policies().Equals(expected_bundle)); |
| 268 } | 270 } |
| 269 | 271 |
| 270 TEST_F(ConfigurationPolicyProviderMacTest, TestConversions) { | 272 TEST_F(MacPolicyLoaderTest, TestConversions) { |
| 271 base::DictionaryValue root; | 273 base::DictionaryValue root; |
| 272 | 274 |
| 273 // base::Value::TYPE_NULL | 275 // base::Value::TYPE_NULL |
| 274 root.Set("null", base::Value::CreateNullValue()); | 276 root.Set("null", base::Value::CreateNullValue()); |
| 275 | 277 |
| 276 // base::Value::TYPE_BOOLEAN | 278 // base::Value::TYPE_BOOLEAN |
| 277 root.SetBoolean("false", false); | 279 root.SetBoolean("false", false); |
| 278 root.SetBoolean("true", true); | 280 root.SetBoolean("true", true); |
| 279 | 281 |
| 280 // base::Value::TYPE_INTEGER | 282 // base::Value::TYPE_INTEGER |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 300 | 302 |
| 301 // base::Value::TYPE_DICTIONARY | 303 // base::Value::TYPE_DICTIONARY |
| 302 base::DictionaryValue dict; | 304 base::DictionaryValue dict; |
| 303 root.Set("emptyd", dict.DeepCopy()); | 305 root.Set("emptyd", dict.DeepCopy()); |
| 304 // Very meta. | 306 // Very meta. |
| 305 root.Set("dict", root.DeepCopy()); | 307 root.Set("dict", root.DeepCopy()); |
| 306 | 308 |
| 307 ScopedCFTypeRef<CFPropertyListRef> property(CreatePropertyFromValue(&root)); | 309 ScopedCFTypeRef<CFPropertyListRef> property(CreatePropertyFromValue(&root)); |
| 308 ASSERT_TRUE(property); | 310 ASSERT_TRUE(property); |
| 309 scoped_ptr<base::Value> value( | 311 scoped_ptr<base::Value> value( |
| 310 MacPreferencesPolicyProviderDelegate::CreateValueFromProperty(property)); | 312 MacPolicyLoader::CreateValueFromProperty(property)); |
| 311 ASSERT_TRUE(value.get()); | 313 ASSERT_TRUE(value.get()); |
| 312 | 314 |
| 313 EXPECT_TRUE(root.Equals(value.get())); | 315 EXPECT_TRUE(root.Equals(value.get())); |
| 314 } | 316 } |
| 315 | 317 |
| 316 } // namespace policy | 318 } // namespace policy |
| OLD | NEW |