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 "base/callback.h" | 5 #include "base/callback.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/memory/ptr_util.h" |
7 #include "components/policy/core/common/external_data_fetcher.h" | 8 #include "components/policy/core/common/external_data_fetcher.h" |
8 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 9 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
9 #include "components/policy/core/common/policy_types.h" | 10 #include "components/policy/core/common/policy_types.h" |
10 #include "components/policy/core/common/proxy_policy_provider.h" | 11 #include "components/policy/core/common/proxy_policy_provider.h" |
11 #include "components/policy/core/common/schema_registry.h" | 12 #include "components/policy/core/common/schema_registry.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 using testing::Mock; | 16 using testing::Mock; |
16 | 17 |
(...skipping 29 matching lines...) Expand all Loading... |
46 }; | 47 }; |
47 | 48 |
48 TEST_F(ProxyPolicyProviderTest, Init) { | 49 TEST_F(ProxyPolicyProviderTest, Init) { |
49 EXPECT_TRUE(proxy_provider_.IsInitializationComplete(POLICY_DOMAIN_CHROME)); | 50 EXPECT_TRUE(proxy_provider_.IsInitializationComplete(POLICY_DOMAIN_CHROME)); |
50 EXPECT_TRUE(PolicyBundle().Equals(proxy_provider_.policies())); | 51 EXPECT_TRUE(PolicyBundle().Equals(proxy_provider_.policies())); |
51 } | 52 } |
52 | 53 |
53 TEST_F(ProxyPolicyProviderTest, Delegate) { | 54 TEST_F(ProxyPolicyProviderTest, Delegate) { |
54 PolicyBundle bundle; | 55 PolicyBundle bundle; |
55 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 56 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
56 .Set("policy", | 57 .Set("policy", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
57 POLICY_LEVEL_MANDATORY, | |
58 POLICY_SCOPE_USER, | |
59 POLICY_SOURCE_CLOUD, | 58 POLICY_SOURCE_CLOUD, |
60 new base::StringValue("value"), | 59 base::WrapUnique(new base::StringValue("value")), nullptr); |
61 NULL); | |
62 mock_provider_.UpdatePolicy(CopyBundle(bundle)); | 60 mock_provider_.UpdatePolicy(CopyBundle(bundle)); |
63 | 61 |
64 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_)); | 62 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_)); |
65 proxy_provider_.SetDelegate(&mock_provider_); | 63 proxy_provider_.SetDelegate(&mock_provider_); |
66 Mock::VerifyAndClearExpectations(&observer_); | 64 Mock::VerifyAndClearExpectations(&observer_); |
67 EXPECT_TRUE(bundle.Equals(proxy_provider_.policies())); | 65 EXPECT_TRUE(bundle.Equals(proxy_provider_.policies())); |
68 | 66 |
69 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_)); | 67 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_)); |
70 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 68 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
71 .Set("policy", | 69 .Set("policy", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
72 POLICY_LEVEL_MANDATORY, | |
73 POLICY_SCOPE_USER, | |
74 POLICY_SOURCE_CLOUD, | 70 POLICY_SOURCE_CLOUD, |
75 new base::StringValue("new value"), | 71 base::WrapUnique(new base::StringValue("new value")), nullptr); |
76 NULL); | |
77 mock_provider_.UpdatePolicy(CopyBundle(bundle)); | 72 mock_provider_.UpdatePolicy(CopyBundle(bundle)); |
78 Mock::VerifyAndClearExpectations(&observer_); | 73 Mock::VerifyAndClearExpectations(&observer_); |
79 EXPECT_TRUE(bundle.Equals(proxy_provider_.policies())); | 74 EXPECT_TRUE(bundle.Equals(proxy_provider_.policies())); |
80 | 75 |
81 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_)); | 76 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_)); |
82 proxy_provider_.SetDelegate(NULL); | 77 proxy_provider_.SetDelegate(NULL); |
83 EXPECT_TRUE(PolicyBundle().Equals(proxy_provider_.policies())); | 78 EXPECT_TRUE(PolicyBundle().Equals(proxy_provider_.policies())); |
84 } | 79 } |
85 | 80 |
86 TEST_F(ProxyPolicyProviderTest, RefreshPolicies) { | 81 TEST_F(ProxyPolicyProviderTest, RefreshPolicies) { |
(...skipping 11 matching lines...) Expand all Loading... |
98 Mock::VerifyAndClearExpectations(&observer_); | 93 Mock::VerifyAndClearExpectations(&observer_); |
99 Mock::VerifyAndClearExpectations(&mock_provider_); | 94 Mock::VerifyAndClearExpectations(&mock_provider_); |
100 | 95 |
101 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_)); | 96 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_)); |
102 mock_provider_.UpdatePolicy( | 97 mock_provider_.UpdatePolicy( |
103 std::unique_ptr<PolicyBundle>(new PolicyBundle())); | 98 std::unique_ptr<PolicyBundle>(new PolicyBundle())); |
104 Mock::VerifyAndClearExpectations(&observer_); | 99 Mock::VerifyAndClearExpectations(&observer_); |
105 } | 100 } |
106 | 101 |
107 } // namespace policy | 102 } // namespace policy |
OLD | NEW |