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/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
8 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
9 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 10 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
10 #include "chrome/browser/policy/configuration_policy_provider_mac.h" | 11 #include "chrome/browser/policy/configuration_policy_provider_mac.h" |
11 #include "chrome/browser/policy/mock_configuration_policy_store.h" | 12 #include "chrome/browser/policy/mock_configuration_policy_store.h" |
12 #include "chrome/browser/preferences_mock_mac.h" | 13 #include "chrome/browser/preferences_mock_mac.h" |
13 #include "chrome/common/policy_constants.h" | 14 #include "chrome/common/policy_constants.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace policy { | 17 namespace policy { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 66 } |
66 case Value::TYPE_STRING: { | 67 case Value::TYPE_STRING: { |
67 std::string v; | 68 std::string v; |
68 if (!test_value_->GetAsString(&v)) | 69 if (!test_value_->GetAsString(&v)) |
69 return NULL; | 70 return NULL; |
70 return base::SysUTF8ToCFStringRef(v); | 71 return base::SysUTF8ToCFStringRef(v); |
71 } | 72 } |
72 case Value::TYPE_LIST: { | 73 case Value::TYPE_LIST: { |
73 const ListValue* list = | 74 const ListValue* list = |
74 static_cast<const ListValue*>(test_value_.get()); | 75 static_cast<const ListValue*>(test_value_.get()); |
75 scoped_cftyperef<CFMutableArrayRef> array( | 76 base::mac::ScopedCFTypeRef<CFMutableArrayRef> array( |
76 CFArrayCreateMutable(NULL, list->GetSize(), | 77 CFArrayCreateMutable(NULL, list->GetSize(), |
77 &kCFTypeArrayCallBacks)); | 78 &kCFTypeArrayCallBacks)); |
78 for (ListValue::const_iterator element(list->begin()); | 79 for (ListValue::const_iterator element(list->begin()); |
79 element != list->end(); ++element) { | 80 element != list->end(); ++element) { |
80 if (!(*element)->IsType(Value::TYPE_STRING)) | 81 if (!(*element)->IsType(Value::TYPE_STRING)) |
81 return NULL; | 82 return NULL; |
82 std::string element_value; | 83 std::string element_value; |
83 if (!(*element)->GetAsString(&element_value)) | 84 if (!(*element)->GetAsString(&element_value)) |
84 return NULL; | 85 return NULL; |
85 scoped_cftyperef<CFStringRef> cf_element_value( | 86 base::mac::ScopedCFTypeRef<CFStringRef> cf_element_value( |
86 base::SysUTF8ToCFStringRef(element_value)); | 87 base::SysUTF8ToCFStringRef(element_value)); |
87 CFArrayAppendValue(array, cf_element_value.get()); | 88 CFArrayAppendValue(array, cf_element_value.get()); |
88 } | 89 } |
89 return array.release(); | 90 return array.release(); |
90 } | 91 } |
91 default: | 92 default: |
92 return NULL; | 93 return NULL; |
93 } | 94 } |
94 } | 95 } |
95 | 96 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 scoped_ptr<MockConfigurationPolicyStore> store_; | 144 scoped_ptr<MockConfigurationPolicyStore> store_; |
144 scoped_ptr<ConfigurationPolicyProviderMac> provider_; | 145 scoped_ptr<ConfigurationPolicyProviderMac> provider_; |
145 }; | 146 }; |
146 | 147 |
147 TEST_P(ConfigurationPolicyProviderMacTest, Default) { | 148 TEST_P(ConfigurationPolicyProviderMacTest, Default) { |
148 EXPECT_TRUE(provider_->Provide(store_.get())); | 149 EXPECT_TRUE(provider_->Provide(store_.get())); |
149 EXPECT_TRUE(store_->policy_map().empty()); | 150 EXPECT_TRUE(store_->policy_map().empty()); |
150 } | 151 } |
151 | 152 |
152 TEST_P(ConfigurationPolicyProviderMacTest, Invalid) { | 153 TEST_P(ConfigurationPolicyProviderMacTest, Invalid) { |
153 scoped_cftyperef<CFStringRef> name( | 154 base::mac::ScopedCFTypeRef<CFStringRef> name( |
154 base::SysUTF8ToCFStringRef(GetParam().policy_name())); | 155 base::SysUTF8ToCFStringRef(GetParam().policy_name())); |
155 scoped_cftyperef<CFDataRef> invalid_data(CFDataCreate(NULL, NULL, 0)); | 156 base::mac::ScopedCFTypeRef<CFDataRef> invalid_data( |
| 157 CFDataCreate(NULL, NULL, 0)); |
156 prefs_->AddTestItem(name, invalid_data.get(), true); | 158 prefs_->AddTestItem(name, invalid_data.get(), true); |
157 EXPECT_TRUE(provider_->Provide(store_.get())); | 159 EXPECT_TRUE(provider_->Provide(store_.get())); |
158 EXPECT_TRUE(store_->policy_map().empty()); | 160 EXPECT_TRUE(store_->policy_map().empty()); |
159 } | 161 } |
160 | 162 |
161 TEST_P(ConfigurationPolicyProviderMacTest, TestNonForcedValue) { | 163 TEST_P(ConfigurationPolicyProviderMacTest, TestNonForcedValue) { |
162 scoped_cftyperef<CFStringRef> name( | 164 base::mac::ScopedCFTypeRef<CFStringRef> name( |
163 base::SysUTF8ToCFStringRef(GetParam().policy_name())); | 165 base::SysUTF8ToCFStringRef(GetParam().policy_name())); |
164 scoped_cftyperef<CFPropertyListRef> test_value( | 166 base::mac::ScopedCFTypeRef<CFPropertyListRef> test_value( |
165 GetParam().GetPropertyListValue()); | 167 GetParam().GetPropertyListValue()); |
166 ASSERT_TRUE(test_value.get()); | 168 ASSERT_TRUE(test_value.get()); |
167 prefs_->AddTestItem(name, test_value.get(), false); | 169 prefs_->AddTestItem(name, test_value.get(), false); |
168 EXPECT_TRUE(provider_->Provide(store_.get())); | 170 EXPECT_TRUE(provider_->Provide(store_.get())); |
169 EXPECT_TRUE(store_->policy_map().empty()); | 171 EXPECT_TRUE(store_->policy_map().empty()); |
170 } | 172 } |
171 | 173 |
172 TEST_P(ConfigurationPolicyProviderMacTest, TestValue) { | 174 TEST_P(ConfigurationPolicyProviderMacTest, TestValue) { |
173 scoped_cftyperef<CFStringRef> name( | 175 base::mac::ScopedCFTypeRef<CFStringRef> name( |
174 base::SysUTF8ToCFStringRef(GetParam().policy_name())); | 176 base::SysUTF8ToCFStringRef(GetParam().policy_name())); |
175 scoped_cftyperef<CFPropertyListRef> test_value( | 177 base::mac::ScopedCFTypeRef<CFPropertyListRef> test_value( |
176 GetParam().GetPropertyListValue()); | 178 GetParam().GetPropertyListValue()); |
177 ASSERT_TRUE(test_value.get()); | 179 ASSERT_TRUE(test_value.get()); |
178 prefs_->AddTestItem(name, test_value, true); | 180 prefs_->AddTestItem(name, test_value, true); |
179 EXPECT_TRUE(provider_->Provide(store_.get())); | 181 EXPECT_TRUE(provider_->Provide(store_.get())); |
180 ASSERT_EQ(1U, store_->policy_map().size()); | 182 ASSERT_EQ(1U, store_->policy_map().size()); |
181 const Value* value = store_->Get(GetParam().type()); | 183 const Value* value = store_->Get(GetParam().type()); |
182 ASSERT_TRUE(value); | 184 ASSERT_TRUE(value); |
183 EXPECT_TRUE(GetParam().test_value()->Equals(value)); | 185 EXPECT_TRUE(GetParam().test_value()->Equals(value)); |
184 } | 186 } |
185 | 187 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 ConfigurationPolicyStore::kPolicyExtensionInstallDenyList, | 275 ConfigurationPolicyStore::kPolicyExtensionInstallDenyList, |
274 key::kExtensionInstallDenyList), | 276 key::kExtensionInstallDenyList), |
275 PolicyTestParams::ForBooleanPolicy( | 277 PolicyTestParams::ForBooleanPolicy( |
276 ConfigurationPolicyStore::kPolicyShowHomeButton, | 278 ConfigurationPolicyStore::kPolicyShowHomeButton, |
277 key::kShowHomeButton), | 279 key::kShowHomeButton), |
278 PolicyTestParams::ForBooleanPolicy( | 280 PolicyTestParams::ForBooleanPolicy( |
279 ConfigurationPolicyStore::kPolicyPrintingEnabled, | 281 ConfigurationPolicyStore::kPolicyPrintingEnabled, |
280 key::kPrintingEnabled))); | 282 key::kPrintingEnabled))); |
281 | 283 |
282 } // namespace policy | 284 } // namespace policy |
OLD | NEW |