| 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 <UIKit/UIKit.h> | 5 #include <UIKit/UIKit.h> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #include "base/test/test_simple_task_runner.h" | 11 #include "base/test/test_simple_task_runner.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "components/policy/core/common/async_policy_provider.h" | 13 #include "components/policy/core/common/async_policy_provider.h" |
| 14 #include "components/policy/core/common/configuration_policy_provider_test.h" | 14 #include "components/policy/core/common/configuration_policy_provider_test.h" |
| 15 #include "components/policy/core/common/policy_bundle.h" | 15 #include "components/policy/core/common/policy_bundle.h" |
| 16 #include "components/policy/core/common/policy_loader_ios.h" | 16 #include "components/policy/core/common/policy_loader_ios.h" |
| 17 #include "components/policy/core/common/policy_map.h" | 17 #include "components/policy/core/common/policy_map.h" |
| 18 #include "components/policy/core/common/policy_test_utils.h" | 18 #include "components/policy/core/common/policy_test_utils.h" |
| 19 #include "components/policy/core/common/policy_types.h" | |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 20 |
| 22 namespace policy { | 21 namespace policy { |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| 26 // Key in the NSUserDefaults that contains the managed app configuration. | 25 // Key in the NSUserDefaults that contains the managed app configuration. |
| 27 NSString* const kConfigurationKey = @"com.apple.configuration.managed"; | 26 NSString* const kConfigurationKey = @"com.apple.configuration.managed"; |
| 28 | 27 |
| 29 class TestHarness : public PolicyProviderTestHarness { | 28 class TestHarness : public PolicyProviderTestHarness { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 void AddPolicies(NSDictionary* policy); | 61 void AddPolicies(NSDictionary* policy); |
| 63 void AddChromePolicy(NSDictionary* policy); | 62 void AddChromePolicy(NSDictionary* policy); |
| 64 void AddEncodedChromePolicy(NSDictionary* policy); | 63 void AddEncodedChromePolicy(NSDictionary* policy); |
| 65 | 64 |
| 66 bool use_encoded_key_; | 65 bool use_encoded_key_; |
| 67 | 66 |
| 68 DISALLOW_COPY_AND_ASSIGN(TestHarness); | 67 DISALLOW_COPY_AND_ASSIGN(TestHarness); |
| 69 }; | 68 }; |
| 70 | 69 |
| 71 TestHarness::TestHarness(bool use_encoded_key) | 70 TestHarness::TestHarness(bool use_encoded_key) |
| 72 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, | 71 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE), |
| 73 POLICY_SOURCE_PLATFORM), | |
| 74 use_encoded_key_(use_encoded_key) {} | 72 use_encoded_key_(use_encoded_key) {} |
| 75 | 73 |
| 76 TestHarness::~TestHarness() { | 74 TestHarness::~TestHarness() { |
| 77 // Cleanup any policies left from the test. | 75 // Cleanup any policies left from the test. |
| 78 [[NSUserDefaults standardUserDefaults] removeObjectForKey:kConfigurationKey]; | 76 [[NSUserDefaults standardUserDefaults] removeObjectForKey:kConfigurationKey]; |
| 79 } | 77 } |
| 80 | 78 |
| 81 void TestHarness::SetUp() { | 79 void TestHarness::SetUp() { |
| 82 // Make sure there is no pre-existing policy present. | 80 // Make sure there is no pre-existing policy present. |
| 83 [[NSUserDefaults standardUserDefaults] removeObjectForKey:kConfigurationKey]; | 81 [[NSUserDefaults standardUserDefaults] removeObjectForKey:kConfigurationKey]; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 @"EncodedChromePolicy": encodedChromePolicy, | 244 @"EncodedChromePolicy": encodedChromePolicy, |
| 247 }; | 245 }; |
| 248 | 246 |
| 249 [[NSUserDefaults standardUserDefaults] setObject:wrapper | 247 [[NSUserDefaults standardUserDefaults] setObject:wrapper |
| 250 forKey:kConfigurationKey]; | 248 forKey:kConfigurationKey]; |
| 251 | 249 |
| 252 PolicyBundle expected; | 250 PolicyBundle expected; |
| 253 PolicyMap& expectedMap = | 251 PolicyMap& expectedMap = |
| 254 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, "")); | 252 expected.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, "")); |
| 255 expectedMap.Set("shared", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, | 253 expectedMap.Set("shared", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
| 256 POLICY_SOURCE_PLATFORM, new base::StringValue("right"), | 254 new base::StringValue("right"), NULL); |
| 257 nullptr); | |
| 258 expectedMap.Set("key2", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, | 255 expectedMap.Set("key2", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, |
| 259 POLICY_SOURCE_PLATFORM, new base::StringValue("value2"), | 256 new base::StringValue("value2"), NULL); |
| 260 nullptr); | |
| 261 | 257 |
| 262 scoped_refptr<base::TestSimpleTaskRunner> taskRunner = | 258 scoped_refptr<base::TestSimpleTaskRunner> taskRunner = |
| 263 new base::TestSimpleTaskRunner(); | 259 new base::TestSimpleTaskRunner(); |
| 264 PolicyLoaderIOS loader(taskRunner); | 260 PolicyLoaderIOS loader(taskRunner); |
| 265 scoped_ptr<PolicyBundle> bundle = loader.Load(); | 261 scoped_ptr<PolicyBundle> bundle = loader.Load(); |
| 266 ASSERT_TRUE(bundle); | 262 ASSERT_TRUE(bundle); |
| 267 EXPECT_TRUE(bundle->Equals(expected)); | 263 EXPECT_TRUE(bundle->Equals(expected)); |
| 268 } | 264 } |
| 269 | 265 |
| 270 } // namespace policy | 266 } // namespace policy |
| OLD | NEW |