Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: chrome/browser/chromeos/policy/proxy_policy_provider_unittest.cc

Issue 137203005: Moved the ProxyPolicyProvider to the policy component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@BPC-3-dm-url-at-base
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 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.
4
5 #include "base/basictypes.h"
6 #include "base/callback.h"
7 #include "chrome/browser/chromeos/policy/proxy_policy_provider.h"
8 #include "components/policy/core/common/external_data_fetcher.h"
9 #include "components/policy/core/common/mock_configuration_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"
13
14 using testing::Mock;
15
16 namespace policy {
17
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_);
24 }
25
26 virtual ~ProxyPolicyProviderTest() {
27 proxy_provider_.RemoveObserver(&observer_);
28 proxy_provider_.Shutdown();
29 mock_provider_.Shutdown();
30 }
31
32 SchemaRegistry schema_registry_;
33 MockConfigurationPolicyObserver observer_;
34 MockConfigurationPolicyProvider mock_provider_;
35 ProxyPolicyProvider proxy_provider_;
36
37 static scoped_ptr<PolicyBundle> CopyBundle(const PolicyBundle& bundle) {
38 scoped_ptr<PolicyBundle> copy(new PolicyBundle());
39 copy->CopyFrom(bundle);
40 return copy.Pass();
41 }
42
43 DISALLOW_COPY_AND_ASSIGN(ProxyPolicyProviderTest);
44 };
45
46 TEST_F(ProxyPolicyProviderTest, Init) {
47 EXPECT_TRUE(proxy_provider_.IsInitializationComplete(POLICY_DOMAIN_CHROME));
48 EXPECT_TRUE(PolicyBundle().Equals(proxy_provider_.policies()));
49 }
50
51 TEST_F(ProxyPolicyProviderTest, Delegate) {
52 PolicyBundle bundle;
53 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
54 .Set("policy",
55 POLICY_LEVEL_MANDATORY,
56 POLICY_SCOPE_USER,
57 base::Value::CreateStringValue("value"),
58 NULL);
59 mock_provider_.UpdatePolicy(CopyBundle(bundle));
60
61 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_));
62 proxy_provider_.SetDelegate(&mock_provider_);
63 Mock::VerifyAndClearExpectations(&observer_);
64 EXPECT_TRUE(bundle.Equals(proxy_provider_.policies()));
65
66 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_));
67 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
68 .Set("policy",
69 POLICY_LEVEL_MANDATORY,
70 POLICY_SCOPE_USER,
71 base::Value::CreateStringValue("new value"),
72 NULL);
73 mock_provider_.UpdatePolicy(CopyBundle(bundle));
74 Mock::VerifyAndClearExpectations(&observer_);
75 EXPECT_TRUE(bundle.Equals(proxy_provider_.policies()));
76
77 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_));
78 proxy_provider_.SetDelegate(NULL);
79 EXPECT_TRUE(PolicyBundle().Equals(proxy_provider_.policies()));
80 }
81
82 TEST_F(ProxyPolicyProviderTest, RefreshPolicies) {
83 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_));
84 proxy_provider_.RefreshPolicies();
85 Mock::VerifyAndClearExpectations(&observer_);
86
87 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_));
88 proxy_provider_.SetDelegate(&mock_provider_);
89 Mock::VerifyAndClearExpectations(&observer_);
90
91 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_)).Times(0);
92 EXPECT_CALL(mock_provider_, RefreshPolicies());
93 proxy_provider_.RefreshPolicies();
94 Mock::VerifyAndClearExpectations(&observer_);
95 Mock::VerifyAndClearExpectations(&mock_provider_);
96
97 EXPECT_CALL(observer_, OnUpdatePolicy(&proxy_provider_));
98 mock_provider_.UpdatePolicy(scoped_ptr<PolicyBundle>(new PolicyBundle()));
99 Mock::VerifyAndClearExpectations(&observer_);
100 }
101
102 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/proxy_policy_provider.cc ('k') | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698