Update V8 to version 4.6.62.
[chromium-blink-merge.git] / components / policy / core / common / proxy_policy_provider_unittest.cc
blob09c5da9f6b9ba19f368a79ddc03d22d368e4f197
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
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "base/callback.h"
7 #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/proxy_policy_provider.h"
10 #include "components/policy/core/common/schema_registry.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 using testing::Mock;
16 namespace policy {
18 class ProxyPolicyProviderTest : public testing::Test {
19 protected:
20 ProxyPolicyProviderTest() {
21 mock_provider_.Init();
22 proxy_provider_.Init(&schema_registry_);
23 proxy_provider_.AddObserver(&observer_);
26 ~ProxyPolicyProviderTest() override {
27 proxy_provider_.RemoveObserver(&observer_);
28 proxy_provider_.Shutdown();
29 mock_provider_.Shutdown();
32 SchemaRegistry schema_registry_;
33 MockConfigurationPolicyObserver observer_;
34 MockConfigurationPolicyProvider mock_provider_;
35 ProxyPolicyProvider proxy_provider_;
37 static scoped_ptr<PolicyBundle> CopyBundle(const PolicyBundle& bundle) {
38 scoped_ptr<PolicyBundle> copy(new PolicyBundle());
39 copy->CopyFrom(bundle);
40 return copy.Pass();
43 private:
44 DISALLOW_COPY_AND_ASSIGN(ProxyPolicyProviderTest);
47 TEST_F(ProxyPolicyProviderTest, Init) {
48 EXPECT_TRUE(proxy_provider_.IsInitializationComplete(POLICY_DOMAIN_CHROME));
49 EXPECT_TRUE(PolicyBundle().Equals(proxy_provider_.policies()));
52 TEST_F(ProxyPolicyProviderTest, Delegate) {
53 PolicyBundle bundle;
54 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
55 .Set("policy",
56 POLICY_LEVEL_MANDATORY,
57 POLICY_SCOPE_USER,
58 new base::StringValue("value"),
59 NULL);
60 mock_provider_.UpdatePolicy(CopyBundle(bundle));
62 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_));
63 proxy_provider_.SetDelegate(&mock_provider_);
64 Mock::VerifyAndClearExpectations(&observer_);
65 EXPECT_TRUE(bundle.Equals(proxy_provider_.policies()));
67 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_));
68 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
69 .Set("policy",
70 POLICY_LEVEL_MANDATORY,
71 POLICY_SCOPE_USER,
72 new base::StringValue("new value"),
73 NULL);
74 mock_provider_.UpdatePolicy(CopyBundle(bundle));
75 Mock::VerifyAndClearExpectations(&observer_);
76 EXPECT_TRUE(bundle.Equals(proxy_provider_.policies()));
78 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_));
79 proxy_provider_.SetDelegate(NULL);
80 EXPECT_TRUE(PolicyBundle().Equals(proxy_provider_.policies()));
83 TEST_F(ProxyPolicyProviderTest, RefreshPolicies) {
84 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_));
85 proxy_provider_.RefreshPolicies();
86 Mock::VerifyAndClearExpectations(&observer_);
88 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_));
89 proxy_provider_.SetDelegate(&mock_provider_);
90 Mock::VerifyAndClearExpectations(&observer_);
92 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_)).Times(0);
93 EXPECT_CALL(mock_provider_, RefreshPolicies());
94 proxy_provider_.RefreshPolicies();
95 Mock::VerifyAndClearExpectations(&observer_);
96 Mock::VerifyAndClearExpectations(&mock_provider_);
98 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_));
99 mock_provider_.UpdatePolicy(scoped_ptr<PolicyBundle>(new PolicyBundle()));
100 Mock::VerifyAndClearExpectations(&observer_);
103 } // namespace policy