| 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" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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() { |
| 134 prefs_ = new MockPreferences; | 134 prefs_ = new MockPreferences; |
| 135 store_.reset(new MockConfigurationPolicyStore); | 135 store_.reset(new MockConfigurationPolicyStore); |
| 136 provider_.reset( | |
| 137 new ConfigurationPolicyProviderMac( | |
| 138 ConfigurationPolicyPrefStore::GetChromePolicyValueMap(), | |
| 139 prefs_)); | |
| 140 } | 136 } |
| 141 | 137 |
| 142 protected: | 138 protected: |
| 143 MockPreferences* prefs_; | 139 MockPreferences* prefs_; |
| 144 scoped_ptr<MockConfigurationPolicyStore> store_; | 140 scoped_ptr<MockConfigurationPolicyStore> store_; |
| 145 scoped_ptr<ConfigurationPolicyProviderMac> provider_; | |
| 146 }; | 141 }; |
| 147 | 142 |
| 148 TEST_P(ConfigurationPolicyProviderMacTest, Default) { | 143 TEST_P(ConfigurationPolicyProviderMacTest, Default) { |
| 149 EXPECT_TRUE(provider_->Provide(store_.get())); | 144 ConfigurationPolicyProviderMac provider( |
| 145 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), prefs_); |
| 146 EXPECT_TRUE(provider.Provide(store_.get())); |
| 150 EXPECT_TRUE(store_->policy_map().empty()); | 147 EXPECT_TRUE(store_->policy_map().empty()); |
| 151 } | 148 } |
| 152 | 149 |
| 153 TEST_P(ConfigurationPolicyProviderMacTest, Invalid) { | 150 TEST_P(ConfigurationPolicyProviderMacTest, Invalid) { |
| 154 base::mac::ScopedCFTypeRef<CFStringRef> name( | 151 base::mac::ScopedCFTypeRef<CFStringRef> name( |
| 155 base::SysUTF8ToCFStringRef(GetParam().policy_name())); | 152 base::SysUTF8ToCFStringRef(GetParam().policy_name())); |
| 156 base::mac::ScopedCFTypeRef<CFDataRef> invalid_data( | 153 base::mac::ScopedCFTypeRef<CFDataRef> invalid_data( |
| 157 CFDataCreate(NULL, NULL, 0)); | 154 CFDataCreate(NULL, NULL, 0)); |
| 158 prefs_->AddTestItem(name, invalid_data.get(), true); | 155 prefs_->AddTestItem(name, invalid_data.get(), true); |
| 159 EXPECT_TRUE(provider_->Provide(store_.get())); | 156 |
| 157 // Create the provider and have it read |prefs_|. |
| 158 ConfigurationPolicyProviderMac provider( |
| 159 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), prefs_); |
| 160 EXPECT_TRUE(provider.Provide(store_.get())); |
| 160 EXPECT_TRUE(store_->policy_map().empty()); | 161 EXPECT_TRUE(store_->policy_map().empty()); |
| 161 } | 162 } |
| 162 | 163 |
| 163 TEST_P(ConfigurationPolicyProviderMacTest, TestNonForcedValue) { | 164 TEST_P(ConfigurationPolicyProviderMacTest, TestNonForcedValue) { |
| 164 base::mac::ScopedCFTypeRef<CFStringRef> name( | 165 base::mac::ScopedCFTypeRef<CFStringRef> name( |
| 165 base::SysUTF8ToCFStringRef(GetParam().policy_name())); | 166 base::SysUTF8ToCFStringRef(GetParam().policy_name())); |
| 166 base::mac::ScopedCFTypeRef<CFPropertyListRef> test_value( | 167 base::mac::ScopedCFTypeRef<CFPropertyListRef> test_value( |
| 167 GetParam().GetPropertyListValue()); | 168 GetParam().GetPropertyListValue()); |
| 168 ASSERT_TRUE(test_value.get()); | 169 ASSERT_TRUE(test_value.get()); |
| 169 prefs_->AddTestItem(name, test_value.get(), false); | 170 prefs_->AddTestItem(name, test_value.get(), false); |
| 170 EXPECT_TRUE(provider_->Provide(store_.get())); | 171 |
| 172 // Create the provider and have it read |prefs_|. |
| 173 ConfigurationPolicyProviderMac provider( |
| 174 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), prefs_); |
| 175 EXPECT_TRUE(provider.Provide(store_.get())); |
| 171 EXPECT_TRUE(store_->policy_map().empty()); | 176 EXPECT_TRUE(store_->policy_map().empty()); |
| 172 } | 177 } |
| 173 | 178 |
| 174 TEST_P(ConfigurationPolicyProviderMacTest, TestValue) { | 179 TEST_P(ConfigurationPolicyProviderMacTest, TestValue) { |
| 175 base::mac::ScopedCFTypeRef<CFStringRef> name( | 180 base::mac::ScopedCFTypeRef<CFStringRef> name( |
| 176 base::SysUTF8ToCFStringRef(GetParam().policy_name())); | 181 base::SysUTF8ToCFStringRef(GetParam().policy_name())); |
| 177 base::mac::ScopedCFTypeRef<CFPropertyListRef> test_value( | 182 base::mac::ScopedCFTypeRef<CFPropertyListRef> test_value( |
| 178 GetParam().GetPropertyListValue()); | 183 GetParam().GetPropertyListValue()); |
| 179 ASSERT_TRUE(test_value.get()); | 184 ASSERT_TRUE(test_value.get()); |
| 180 prefs_->AddTestItem(name, test_value, true); | 185 prefs_->AddTestItem(name, test_value, true); |
| 181 EXPECT_TRUE(provider_->Provide(store_.get())); | 186 |
| 187 // Create the provider and have it read |prefs_|. |
| 188 ConfigurationPolicyProviderMac provider( |
| 189 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), prefs_); |
| 190 EXPECT_TRUE(provider.Provide(store_.get())); |
| 182 ASSERT_EQ(1U, store_->policy_map().size()); | 191 ASSERT_EQ(1U, store_->policy_map().size()); |
| 183 const Value* value = store_->Get(GetParam().type()); | 192 const Value* value = store_->Get(GetParam().type()); |
| 184 ASSERT_TRUE(value); | 193 ASSERT_TRUE(value); |
| 185 EXPECT_TRUE(GetParam().test_value()->Equals(value)); | 194 EXPECT_TRUE(GetParam().test_value()->Equals(value)); |
| 186 } | 195 } |
| 187 | 196 |
| 188 // Instantiate the test case for all policies. | 197 // Instantiate the test case for all policies. |
| 189 INSTANTIATE_TEST_CASE_P( | 198 INSTANTIATE_TEST_CASE_P( |
| 190 ConfigurationPolicyProviderMacTestInstance, | 199 ConfigurationPolicyProviderMacTestInstance, |
| 191 ConfigurationPolicyProviderMacTest, | 200 ConfigurationPolicyProviderMacTest, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 ConfigurationPolicyStore::kPolicyExtensionInstallDenyList, | 284 ConfigurationPolicyStore::kPolicyExtensionInstallDenyList, |
| 276 key::kExtensionInstallDenyList), | 285 key::kExtensionInstallDenyList), |
| 277 PolicyTestParams::ForBooleanPolicy( | 286 PolicyTestParams::ForBooleanPolicy( |
| 278 ConfigurationPolicyStore::kPolicyShowHomeButton, | 287 ConfigurationPolicyStore::kPolicyShowHomeButton, |
| 279 key::kShowHomeButton), | 288 key::kShowHomeButton), |
| 280 PolicyTestParams::ForBooleanPolicy( | 289 PolicyTestParams::ForBooleanPolicy( |
| 281 ConfigurationPolicyStore::kPolicyPrintingEnabled, | 290 ConfigurationPolicyStore::kPolicyPrintingEnabled, |
| 282 key::kPrintingEnabled))); | 291 key::kPrintingEnabled))); |
| 283 | 292 |
| 284 } // namespace policy | 293 } // namespace policy |
| OLD | NEW |