| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_ios.h" |
| 6 |
| 5 #include <UIKit/UIKit.h> | 7 #include <UIKit/UIKit.h> |
| 6 | 8 |
| 7 #include "base/callback.h" | 9 #include "base/callback.h" |
| 8 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 11 #include "base/test/test_simple_task_runner.h" | 14 #include "base/test/test_simple_task_runner.h" |
| 12 #include "base/values.h" | 15 #include "base/values.h" |
| 13 #include "components/policy/core/common/async_policy_provider.h" | 16 #include "components/policy/core/common/async_policy_provider.h" |
| 14 #include "components/policy/core/common/configuration_policy_provider_test.h" | 17 #include "components/policy/core/common/configuration_policy_provider_test.h" |
| 15 #include "components/policy/core/common/policy_bundle.h" | 18 #include "components/policy/core/common/policy_bundle.h" |
| 16 #include "components/policy/core/common/policy_loader_ios.h" | |
| 17 #include "components/policy/core/common/policy_map.h" | 19 #include "components/policy/core/common/policy_map.h" |
| 18 #include "components/policy/core/common/policy_test_utils.h" | 20 #include "components/policy/core/common/policy_test_utils.h" |
| 19 #include "components/policy/core/common/policy_types.h" | 21 #include "components/policy/core/common/policy_types.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 23 |
| 22 namespace policy { | 24 namespace policy { |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 // Key in the NSUserDefaults that contains the managed app configuration. | 28 // Key in the NSUserDefaults that contains the managed app configuration. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 81 } |
| 80 | 82 |
| 81 void TestHarness::SetUp() { | 83 void TestHarness::SetUp() { |
| 82 // Make sure there is no pre-existing policy present. | 84 // Make sure there is no pre-existing policy present. |
| 83 [[NSUserDefaults standardUserDefaults] removeObjectForKey:kConfigurationKey]; | 85 [[NSUserDefaults standardUserDefaults] removeObjectForKey:kConfigurationKey]; |
| 84 } | 86 } |
| 85 | 87 |
| 86 ConfigurationPolicyProvider* TestHarness::CreateProvider( | 88 ConfigurationPolicyProvider* TestHarness::CreateProvider( |
| 87 SchemaRegistry* registry, | 89 SchemaRegistry* registry, |
| 88 scoped_refptr<base::SequencedTaskRunner> task_runner) { | 90 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
| 89 scoped_ptr<AsyncPolicyLoader> loader(); | 91 std::unique_ptr<AsyncPolicyLoader> loader(); |
| 90 return new AsyncPolicyProvider( | 92 return new AsyncPolicyProvider( |
| 91 registry, make_scoped_ptr(new PolicyLoaderIOS(task_runner))); | 93 registry, base::WrapUnique(new PolicyLoaderIOS(task_runner))); |
| 92 } | 94 } |
| 93 | 95 |
| 94 void TestHarness::InstallEmptyPolicy() { | 96 void TestHarness::InstallEmptyPolicy() { |
| 95 AddPolicies(@{}); | 97 AddPolicies(@{}); |
| 96 } | 98 } |
| 97 | 99 |
| 98 void TestHarness::InstallStringPolicy(const std::string& policy_name, | 100 void TestHarness::InstallStringPolicy(const std::string& policy_name, |
| 99 const std::string& policy_value) { | 101 const std::string& policy_value) { |
| 100 NSString* key = base::SysUTF8ToNSString(policy_name); | 102 NSString* key = base::SysUTF8ToNSString(policy_name); |
| 101 NSString* value = base::SysUTF8ToNSString(policy_value); | 103 NSString* value = base::SysUTF8ToNSString(policy_value); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 expectedMap.Set("shared", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, | 258 expectedMap.Set("shared", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
| 257 POLICY_SOURCE_PLATFORM, new base::StringValue("right"), | 259 POLICY_SOURCE_PLATFORM, new base::StringValue("right"), |
| 258 nullptr); | 260 nullptr); |
| 259 expectedMap.Set("key2", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, | 261 expectedMap.Set("key2", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
| 260 POLICY_SOURCE_PLATFORM, new base::StringValue("value2"), | 262 POLICY_SOURCE_PLATFORM, new base::StringValue("value2"), |
| 261 nullptr); | 263 nullptr); |
| 262 | 264 |
| 263 scoped_refptr<base::TestSimpleTaskRunner> taskRunner = | 265 scoped_refptr<base::TestSimpleTaskRunner> taskRunner = |
| 264 new base::TestSimpleTaskRunner(); | 266 new base::TestSimpleTaskRunner(); |
| 265 PolicyLoaderIOS loader(taskRunner); | 267 PolicyLoaderIOS loader(taskRunner); |
| 266 scoped_ptr<PolicyBundle> bundle = loader.Load(); | 268 std::unique_ptr<PolicyBundle> bundle = loader.Load(); |
| 267 ASSERT_TRUE(bundle); | 269 ASSERT_TRUE(bundle); |
| 268 EXPECT_TRUE(bundle->Equals(expected)); | 270 EXPECT_TRUE(bundle->Equals(expected)); |
| 269 } | 271 } |
| 270 | 272 |
| 271 } // namespace policy | 273 } // namespace policy |
| OLD | NEW |