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 // Instantiate the test case for all policies. |
200 INSTANTIATE_TEST_CASE_P( | 200 INSTANTIATE_TEST_CASE_P( |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 key::kExtensionInstallBlacklist), | 299 key::kExtensionInstallBlacklist), |
300 PolicyTestParams::ForBooleanPolicy( | 300 PolicyTestParams::ForBooleanPolicy( |
301 kPolicyShowHomeButton, | 301 kPolicyShowHomeButton, |
302 key::kShowHomeButton), | 302 key::kShowHomeButton), |
303 PolicyTestParams::ForBooleanPolicy( | 303 PolicyTestParams::ForBooleanPolicy( |
304 kPolicyPrintingEnabled, | 304 kPolicyPrintingEnabled, |
305 key::kPrintingEnabled), | 305 key::kPrintingEnabled), |
306 PolicyTestParams::ForBooleanPolicy( | 306 PolicyTestParams::ForBooleanPolicy( |
307 kPolicyInstantEnabled, | 307 kPolicyInstantEnabled, |
308 key::kInstantEnabled), | 308 key::kInstantEnabled), |
309 PolicyTestParams::ForIntegerPolicy( | |
310 kPolicyPolicyRefreshRate, | |
311 key::kPolicyRefreshRate), | |
312 PolicyTestParams::ForBooleanPolicy( | 309 PolicyTestParams::ForBooleanPolicy( |
313 kPolicyDisablePluginFinder, | 310 kPolicyDisablePluginFinder, |
314 key::kDisablePluginFinder), | 311 key::kDisablePluginFinder), |
315 PolicyTestParams::ForBooleanPolicy( | 312 PolicyTestParams::ForBooleanPolicy( |
316 kPolicyClearSiteDataOnExit, | 313 kPolicyClearSiteDataOnExit, |
317 key::kClearSiteDataOnExit), | 314 key::kClearSiteDataOnExit), |
318 PolicyTestParams::ForStringPolicy( | 315 PolicyTestParams::ForStringPolicy( |
319 kPolicyDownloadDirectory, | 316 kPolicyDownloadDirectory, |
320 key::kDownloadDirectory), | 317 key::kDownloadDirectory), |
321 PolicyTestParams::ForBooleanPolicy( | 318 PolicyTestParams::ForBooleanPolicy( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 ConfigurationPolicyProviderMacTest, | 356 ConfigurationPolicyProviderMacTest, |
360 testing::Values( | 357 testing::Values( |
361 PolicyTestParams::ForListPolicy( | 358 PolicyTestParams::ForListPolicy( |
362 kPolicyURLBlacklist, | 359 kPolicyURLBlacklist, |
363 key::kURLBlacklist), | 360 key::kURLBlacklist), |
364 PolicyTestParams::ForListPolicy( | 361 PolicyTestParams::ForListPolicy( |
365 kPolicyURLWhitelist, | 362 kPolicyURLWhitelist, |
366 key::kURLWhitelist))); | 363 key::kURLWhitelist))); |
367 | 364 |
368 } // namespace policy | 365 } // namespace policy |
OLD | NEW |