| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/schema_registry_tracking_policy_provider
.h" | 5 #include "components/policy/core/common/schema_registry_tracking_policy_provider
.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 12 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| 12 #include "components/policy/core/common/policy_bundle.h" | 13 #include "components/policy/core/common/policy_bundle.h" |
| 13 #include "components/policy/core/common/policy_map.h" | 14 #include "components/policy/core/common/policy_map.h" |
| 14 #include "components/policy/core/common/policy_types.h" | 15 #include "components/policy/core/common/policy_types.h" |
| 15 #include "components/policy/core/common/schema.h" | 16 #include "components/policy/core/common/schema.h" |
| 16 #include "components/policy/core/common/schema_registry.h" | 17 #include "components/policy/core/common/schema_registry.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 EXPECT_CALL(observer_, OnUpdatePolicy(&schema_registry_tracking_provider_)); | 94 EXPECT_CALL(observer_, OnUpdatePolicy(&schema_registry_tracking_provider_)); |
| 94 scoped_ptr<PolicyBundle> delegate_bundle(new PolicyBundle); | 95 scoped_ptr<PolicyBundle> delegate_bundle(new PolicyBundle); |
| 95 delegate_bundle->CopyFrom(bundle); | 96 delegate_bundle->CopyFrom(bundle); |
| 96 delegate_bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "xyz")) | 97 delegate_bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "xyz")) |
| 97 .Set("foo", | 98 .Set("foo", |
| 98 POLICY_LEVEL_MANDATORY, | 99 POLICY_LEVEL_MANDATORY, |
| 99 POLICY_SCOPE_USER, | 100 POLICY_SCOPE_USER, |
| 100 POLICY_SOURCE_CLOUD, | 101 POLICY_SOURCE_CLOUD, |
| 101 new base::StringValue("not visible"), | 102 new base::StringValue("not visible"), |
| 102 NULL); | 103 NULL); |
| 103 mock_provider_.UpdatePolicy(delegate_bundle.Pass()); | 104 mock_provider_.UpdatePolicy(std::move(delegate_bundle)); |
| 104 Mock::VerifyAndClearExpectations(&observer_); | 105 Mock::VerifyAndClearExpectations(&observer_); |
| 105 | 106 |
| 106 EXPECT_FALSE(schema_registry_tracking_provider_.IsInitializationComplete( | 107 EXPECT_FALSE(schema_registry_tracking_provider_.IsInitializationComplete( |
| 107 POLICY_DOMAIN_EXTENSIONS)); | 108 POLICY_DOMAIN_EXTENSIONS)); |
| 108 EXPECT_TRUE(schema_registry_tracking_provider_.policies().Equals(bundle)); | 109 EXPECT_TRUE(schema_registry_tracking_provider_.policies().Equals(bundle)); |
| 109 } | 110 } |
| 110 | 111 |
| 111 TEST_F(SchemaRegistryTrackingPolicyProviderTest, RefreshPolicies) { | 112 TEST_F(SchemaRegistryTrackingPolicyProviderTest, RefreshPolicies) { |
| 112 EXPECT_CALL(mock_provider_, RefreshPolicies()); | 113 EXPECT_CALL(mock_provider_, RefreshPolicies()); |
| 113 schema_registry_tracking_provider_.RefreshPolicies(); | 114 schema_registry_tracking_provider_.RefreshPolicies(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 130 POLICY_LEVEL_MANDATORY, | 131 POLICY_LEVEL_MANDATORY, |
| 131 POLICY_SCOPE_USER, | 132 POLICY_SCOPE_USER, |
| 132 POLICY_SOURCE_CLOUD, | 133 POLICY_SOURCE_CLOUD, |
| 133 new base::StringValue("omg"), | 134 new base::StringValue("omg"), |
| 134 NULL); | 135 NULL); |
| 135 scoped_ptr<PolicyBundle> bundle(new PolicyBundle); | 136 scoped_ptr<PolicyBundle> bundle(new PolicyBundle); |
| 136 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, "")).CopyFrom(policy_map); | 137 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, "")).CopyFrom(policy_map); |
| 137 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "xyz")) | 138 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "xyz")) |
| 138 .CopyFrom(policy_map); | 139 .CopyFrom(policy_map); |
| 139 EXPECT_CALL(observer_, OnUpdatePolicy(&schema_registry_tracking_provider_)); | 140 EXPECT_CALL(observer_, OnUpdatePolicy(&schema_registry_tracking_provider_)); |
| 140 mock_provider_.UpdatePolicy(bundle.Pass()); | 141 mock_provider_.UpdatePolicy(std::move(bundle)); |
| 141 Mock::VerifyAndClearExpectations(&observer_); | 142 Mock::VerifyAndClearExpectations(&observer_); |
| 142 | 143 |
| 143 EXPECT_CALL(mock_provider_, RefreshPolicies()).Times(0); | 144 EXPECT_CALL(mock_provider_, RefreshPolicies()).Times(0); |
| 144 schema_registry_.RegisterComponent( | 145 schema_registry_.RegisterComponent( |
| 145 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "xyz"), CreateTestSchema()); | 146 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "xyz"), CreateTestSchema()); |
| 146 schema_registry_.SetReady(POLICY_DOMAIN_EXTENSIONS); | 147 schema_registry_.SetReady(POLICY_DOMAIN_EXTENSIONS); |
| 147 Mock::VerifyAndClearExpectations(&mock_provider_); | 148 Mock::VerifyAndClearExpectations(&mock_provider_); |
| 148 | 149 |
| 149 EXPECT_CALL(mock_provider_, RefreshPolicies()); | 150 EXPECT_CALL(mock_provider_, RefreshPolicies()); |
| 150 schema_registry_.SetReady(POLICY_DOMAIN_CHROME); | 151 schema_registry_.SetReady(POLICY_DOMAIN_CHROME); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 PolicyBundle platform_policy; | 225 PolicyBundle platform_policy; |
| 225 platform_policy.Get(ns).Set("foo", | 226 platform_policy.Get(ns).Set("foo", |
| 226 POLICY_LEVEL_MANDATORY, | 227 POLICY_LEVEL_MANDATORY, |
| 227 POLICY_SCOPE_USER, | 228 POLICY_SCOPE_USER, |
| 228 POLICY_SOURCE_CLOUD, | 229 POLICY_SOURCE_CLOUD, |
| 229 new base::StringValue("omg"), | 230 new base::StringValue("omg"), |
| 230 NULL); | 231 NULL); |
| 231 scoped_ptr<PolicyBundle> copy(new PolicyBundle); | 232 scoped_ptr<PolicyBundle> copy(new PolicyBundle); |
| 232 copy->CopyFrom(platform_policy); | 233 copy->CopyFrom(platform_policy); |
| 233 EXPECT_CALL(observer_, OnUpdatePolicy(_)); | 234 EXPECT_CALL(observer_, OnUpdatePolicy(_)); |
| 234 mock_provider_.UpdatePolicy(copy.Pass()); | 235 mock_provider_.UpdatePolicy(std::move(copy)); |
| 235 Mock::VerifyAndClearExpectations(&observer_); | 236 Mock::VerifyAndClearExpectations(&observer_); |
| 236 EXPECT_TRUE( | 237 EXPECT_TRUE( |
| 237 schema_registry_tracking_provider_.policies().Equals(platform_policy)); | 238 schema_registry_tracking_provider_.policies().Equals(platform_policy)); |
| 238 | 239 |
| 239 // Now remove that component. | 240 // Now remove that component. |
| 240 EXPECT_CALL(observer_, OnUpdatePolicy(_)); | 241 EXPECT_CALL(observer_, OnUpdatePolicy(_)); |
| 241 schema_registry_.UnregisterComponent(ns); | 242 schema_registry_.UnregisterComponent(ns); |
| 242 Mock::VerifyAndClearExpectations(&observer_); | 243 Mock::VerifyAndClearExpectations(&observer_); |
| 243 const PolicyBundle empty; | 244 const PolicyBundle empty; |
| 244 EXPECT_TRUE(schema_registry_tracking_provider_.policies().Equals(empty)); | 245 EXPECT_TRUE(schema_registry_tracking_provider_.policies().Equals(empty)); |
| 245 | 246 |
| 246 // Adding it back should serve the current policies again, even though they | 247 // Adding it back should serve the current policies again, even though they |
| 247 // haven't changed on the platform provider. | 248 // haven't changed on the platform provider. |
| 248 EXPECT_CALL(mock_provider_, RefreshPolicies()); | 249 EXPECT_CALL(mock_provider_, RefreshPolicies()); |
| 249 schema_registry_.RegisterComponent(ns, CreateTestSchema()); | 250 schema_registry_.RegisterComponent(ns, CreateTestSchema()); |
| 250 Mock::VerifyAndClearExpectations(&mock_provider_); | 251 Mock::VerifyAndClearExpectations(&mock_provider_); |
| 251 | 252 |
| 252 EXPECT_CALL(observer_, OnUpdatePolicy(_)); | 253 EXPECT_CALL(observer_, OnUpdatePolicy(_)); |
| 253 copy.reset(new PolicyBundle); | 254 copy.reset(new PolicyBundle); |
| 254 copy->CopyFrom(platform_policy); | 255 copy->CopyFrom(platform_policy); |
| 255 mock_provider_.UpdatePolicy(copy.Pass()); | 256 mock_provider_.UpdatePolicy(std::move(copy)); |
| 256 Mock::VerifyAndClearExpectations(&observer_); | 257 Mock::VerifyAndClearExpectations(&observer_); |
| 257 EXPECT_TRUE( | 258 EXPECT_TRUE( |
| 258 schema_registry_tracking_provider_.policies().Equals(platform_policy)); | 259 schema_registry_tracking_provider_.policies().Equals(platform_policy)); |
| 259 } | 260 } |
| 260 | 261 |
| 261 } // namespace policy | 262 } // namespace policy |
| OLD | NEW |