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 "components/policy/core/common/policy_loader_mac.h" | 5 #include "components/policy/core/common/policy_loader_mac.h" |
6 | 6 |
7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/run_loop.h" |
16 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "components/policy/core/common/async_policy_provider.h" | 19 #include "components/policy/core/common/async_policy_provider.h" |
19 #include "components/policy/core/common/configuration_policy_provider_test.h" | 20 #include "components/policy/core/common/configuration_policy_provider_test.h" |
20 #include "components/policy/core/common/external_data_fetcher.h" | 21 #include "components/policy/core/common/external_data_fetcher.h" |
21 #include "components/policy/core/common/policy_bundle.h" | 22 #include "components/policy/core/common/policy_bundle.h" |
22 #include "components/policy/core/common/policy_map.h" | 23 #include "components/policy/core/common/policy_map.h" |
23 #include "components/policy/core/common/policy_test_utils.h" | 24 #include "components/policy/core/common/policy_test_utils.h" |
24 #include "components/policy/core/common/policy_types.h" | 25 #include "components/policy/core/common/policy_types.h" |
25 #include "components/policy/core/common/preferences_mock_mac.h" | 26 #include "components/policy/core/common/preferences_mock_mac.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 ScopedCFTypeRef<CFDataRef> invalid_data( | 170 ScopedCFTypeRef<CFDataRef> invalid_data( |
170 CFDataCreate(kCFAllocatorDefault, | 171 CFDataCreate(kCFAllocatorDefault, |
171 reinterpret_cast<const UInt8 *>(buffer), | 172 reinterpret_cast<const UInt8 *>(buffer), |
172 arraysize(buffer))); | 173 arraysize(buffer))); |
173 ASSERT_TRUE(invalid_data); | 174 ASSERT_TRUE(invalid_data); |
174 prefs_->AddTestItem(name, invalid_data.get(), true); | 175 prefs_->AddTestItem(name, invalid_data.get(), true); |
175 prefs_->AddTestItem(name, invalid_data.get(), false); | 176 prefs_->AddTestItem(name, invalid_data.get(), false); |
176 | 177 |
177 // Make the provider read the updated |prefs_|. | 178 // Make the provider read the updated |prefs_|. |
178 provider_->RefreshPolicies(); | 179 provider_->RefreshPolicies(); |
179 loop_.RunUntilIdle(); | 180 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent()); |
| 181 base::RunLoop().RunUntilIdle(); |
180 const PolicyBundle kEmptyBundle; | 182 const PolicyBundle kEmptyBundle; |
181 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); | 183 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); |
182 } | 184 } |
183 | 185 |
184 TEST_F(PolicyLoaderMacTest, TestNonForcedValue) { | 186 TEST_F(PolicyLoaderMacTest, TestNonForcedValue) { |
185 ScopedCFTypeRef<CFStringRef> name( | 187 ScopedCFTypeRef<CFStringRef> name( |
186 base::SysUTF8ToCFStringRef(test_keys::kKeyString)); | 188 base::SysUTF8ToCFStringRef(test_keys::kKeyString)); |
187 ScopedCFTypeRef<CFPropertyListRef> test_value( | 189 ScopedCFTypeRef<CFPropertyListRef> test_value( |
188 base::SysUTF8ToCFStringRef("string value")); | 190 base::SysUTF8ToCFStringRef("string value")); |
189 ASSERT_TRUE(test_value.get()); | 191 ASSERT_TRUE(test_value.get()); |
190 prefs_->AddTestItem(name, test_value.get(), false); | 192 prefs_->AddTestItem(name, test_value.get(), false); |
191 | 193 |
192 // Make the provider read the updated |prefs_|. | 194 // Make the provider read the updated |prefs_|. |
193 provider_->RefreshPolicies(); | 195 provider_->RefreshPolicies(); |
194 loop_.RunUntilIdle(); | 196 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent()); |
| 197 base::RunLoop().RunUntilIdle(); |
195 PolicyBundle expected_bundle; | 198 PolicyBundle expected_bundle; |
196 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 199 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
197 .Set(test_keys::kKeyString, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, | 200 .Set(test_keys::kKeyString, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, |
198 POLICY_SOURCE_PLATFORM, | 201 POLICY_SOURCE_PLATFORM, |
199 base::MakeUnique<base::StringValue>("string value"), nullptr); | 202 base::MakeUnique<base::StringValue>("string value"), nullptr); |
200 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); | 203 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); |
201 } | 204 } |
202 | 205 |
203 } // namespace policy | 206 } // namespace policy |
OLD | NEW |