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

Side by Side Diff: chrome/browser/policy/configuration_policy_provider_test.cc

Issue 10384145: Removed ConfigurationPolicyProvider::Provide(). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebased Created 8 years, 7 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/policy/configuration_policy_provider_test.h" 5 #include "chrome/browser/policy/configuration_policy_provider_test.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h" 9 #include "base/values.h"
9 #include "chrome/browser/policy/asynchronous_policy_loader.h" 10 #include "chrome/browser/policy/asynchronous_policy_loader.h"
10 #include "chrome/browser/policy/asynchronous_policy_provider.h" 11 #include "chrome/browser/policy/asynchronous_policy_provider.h"
11 #include "chrome/browser/policy/configuration_policy_provider.h" 12 #include "chrome/browser/policy/configuration_policy_provider.h"
12 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 13 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
14 #include "chrome/browser/policy/policy_bundle.h"
13 #include "chrome/browser/policy/policy_map.h" 15 #include "chrome/browser/policy/policy_map.h"
14 #include "policy/policy_constants.h" 16 #include "policy/policy_constants.h"
15 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
16 18
17 using ::testing::Mock; 19 using ::testing::Mock;
18 using ::testing::_; 20 using ::testing::_;
19 21
20 namespace policy { 22 namespace policy {
21 23
22 namespace test_policy_definitions { 24 namespace test_policy_definitions {
(...skipping 11 matching lines...) Expand all
34 { kKeyStringList, base::Value::TYPE_LIST }, 36 { kKeyStringList, base::Value::TYPE_LIST },
35 { kKeyDictionary, base::Value::TYPE_DICTIONARY }, 37 { kKeyDictionary, base::Value::TYPE_DICTIONARY },
36 }; 38 };
37 39
38 const PolicyDefinitionList kList = { 40 const PolicyDefinitionList kList = {
39 kEntries, kEntries + arraysize(kEntries) 41 kEntries, kEntries + arraysize(kEntries)
40 }; 42 };
41 43
42 } // namespace test_policy_definitions 44 } // namespace test_policy_definitions
43 45
44 PolicyProviderTestHarness::PolicyProviderTestHarness() {} 46 PolicyProviderTestHarness::PolicyProviderTestHarness(PolicyLevel level,
47 PolicyScope scope)
48 : level_(level), scope_(scope) {}
45 49
46 PolicyProviderTestHarness::~PolicyProviderTestHarness() {} 50 PolicyProviderTestHarness::~PolicyProviderTestHarness() {}
47 51
52 PolicyLevel PolicyProviderTestHarness::policy_level() const {
53 return level_;
54 }
55
56 PolicyScope PolicyProviderTestHarness::policy_scope() const {
57 return scope_;
58 }
59
48 ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest() {} 60 ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest() {}
49 61
50 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {} 62 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {}
51 63
52 void ConfigurationPolicyProviderTest::SetUp() { 64 void ConfigurationPolicyProviderTest::SetUp() {
53 AsynchronousPolicyTestBase::SetUp(); 65 AsynchronousPolicyTestBase::SetUp();
54 66
55 test_harness_.reset((*GetParam())()); 67 test_harness_.reset((*GetParam())());
56 test_harness_->SetUp(); 68 test_harness_->SetUp();
57 69
58 provider_.reset( 70 provider_.reset(
59 test_harness_->CreateProvider(&test_policy_definitions::kList)); 71 test_harness_->CreateProvider(&test_policy_definitions::kList));
60 // Some providers do a reload on init. Make sure any notifications generated 72 // Some providers do a reload on init. Make sure any notifications generated
61 // are fired now. 73 // are fired now.
62 loop_.RunAllPending(); 74 loop_.RunAllPending();
63 75
64 PolicyMap policy_map; 76 const PolicyBundle kEmptyBundle;
65 EXPECT_TRUE(provider_->Provide(&policy_map)); 77 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle));
66 EXPECT_TRUE(policy_map.empty());
67 } 78 }
68 79
69 void ConfigurationPolicyProviderTest::TearDown() { 80 void ConfigurationPolicyProviderTest::TearDown() {
70 // Give providers the chance to clean up after themselves on the file thread. 81 // Give providers the chance to clean up after themselves on the file thread.
71 provider_.reset(); 82 provider_.reset();
72 83
73 AsynchronousPolicyTestBase::TearDown(); 84 AsynchronousPolicyTestBase::TearDown();
74 } 85 }
75 86
76 void ConfigurationPolicyProviderTest::CheckValue( 87 void ConfigurationPolicyProviderTest::CheckValue(
77 const char* policy_name, 88 const char* policy_name,
78 const base::Value& expected_value, 89 const base::Value& expected_value,
79 base::Closure install_value) { 90 base::Closure install_value) {
80 // Install the value, reload policy and check the provider for the value. 91 // Install the value, reload policy and check the provider for the value.
81 install_value.Run(); 92 install_value.Run();
82 provider_->RefreshPolicies(); 93 provider_->RefreshPolicies();
83 loop_.RunAllPending(); 94 loop_.RunAllPending();
84 PolicyMap policy_map; 95 PolicyBundle expected_bundle;
85 EXPECT_TRUE(provider_->Provide(&policy_map)); 96 expected_bundle.Get(POLICY_DOMAIN_CHROME, "")
86 EXPECT_EQ(1U, policy_map.size()); 97 .Set(policy_name,
87 EXPECT_TRUE(base::Value::Equals(&expected_value, 98 test_harness_->policy_level(),
88 policy_map.GetValue(policy_name))); 99 test_harness_->policy_scope(),
100 expected_value.DeepCopy());
101 EXPECT_TRUE(provider_->policies().Equals(expected_bundle));
102 // TODO(joaodasilva): set the policy in the POLICY_DOMAIN_EXTENSIONS too,
103 // and extend the |expected_bundle|, once all providers are ready.
89 } 104 }
90 105
91 TEST_P(ConfigurationPolicyProviderTest, Empty) { 106 TEST_P(ConfigurationPolicyProviderTest, Empty) {
92 provider_->RefreshPolicies(); 107 provider_->RefreshPolicies();
93 loop_.RunAllPending(); 108 loop_.RunAllPending();
94 PolicyMap policy_map; 109 const PolicyBundle kEmptyBundle;
95 EXPECT_TRUE(provider_->Provide(&policy_map)); 110 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle));
96 EXPECT_TRUE(policy_map.empty());
97 } 111 }
98 112
99 TEST_P(ConfigurationPolicyProviderTest, StringValue) { 113 TEST_P(ConfigurationPolicyProviderTest, StringValue) {
100 const char kTestString[] = "string_value"; 114 const char kTestString[] = "string_value";
101 base::StringValue expected_value(kTestString); 115 base::StringValue expected_value(kTestString);
102 CheckValue(test_policy_definitions::kKeyString, 116 CheckValue(test_policy_definitions::kKeyString,
103 expected_value, 117 expected_value,
104 base::Bind(&PolicyProviderTestHarness::InstallStringPolicy, 118 base::Bind(&PolicyProviderTestHarness::InstallStringPolicy,
105 base::Unretained(test_harness_.get()), 119 base::Unretained(test_harness_.get()),
106 test_policy_definitions::kKeyString, 120 test_policy_definitions::kKeyString,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 180
167 CheckValue(test_policy_definitions::kKeyDictionary, 181 CheckValue(test_policy_definitions::kKeyDictionary,
168 expected_value, 182 expected_value,
169 base::Bind(&PolicyProviderTestHarness::InstallDictionaryPolicy, 183 base::Bind(&PolicyProviderTestHarness::InstallDictionaryPolicy,
170 base::Unretained(test_harness_.get()), 184 base::Unretained(test_harness_.get()),
171 test_policy_definitions::kKeyDictionary, 185 test_policy_definitions::kKeyDictionary,
172 &expected_value)); 186 &expected_value));
173 } 187 }
174 188
175 TEST_P(ConfigurationPolicyProviderTest, RefreshPolicies) { 189 TEST_P(ConfigurationPolicyProviderTest, RefreshPolicies) {
176 PolicyMap policy_map; 190 PolicyBundle bundle;
177 EXPECT_TRUE(provider_->Provide(&policy_map)); 191 EXPECT_TRUE(provider_->policies().Equals(bundle));
178 EXPECT_EQ(0U, policy_map.size());
179 192
180 // OnUpdatePolicy is called even when there are no changes. 193 // OnUpdatePolicy is called even when there are no changes.
181 MockConfigurationPolicyObserver observer; 194 MockConfigurationPolicyObserver observer;
182 ConfigurationPolicyObserverRegistrar registrar; 195 ConfigurationPolicyObserverRegistrar registrar;
183 registrar.Init(provider_.get(), &observer); 196 registrar.Init(provider_.get(), &observer);
184 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); 197 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1);
185 provider_->RefreshPolicies(); 198 provider_->RefreshPolicies();
186 loop_.RunAllPending(); 199 loop_.RunAllPending();
187 Mock::VerifyAndClearExpectations(&observer); 200 Mock::VerifyAndClearExpectations(&observer);
188 201
189 EXPECT_TRUE(provider_->Provide(&policy_map)); 202 EXPECT_TRUE(provider_->policies().Equals(bundle));
190 EXPECT_EQ(0U, policy_map.size());
191 203
192 // OnUpdatePolicy is called when there are changes. 204 // OnUpdatePolicy is called when there are changes.
193 test_harness_->InstallStringPolicy(test_policy_definitions::kKeyString, 205 test_harness_->InstallStringPolicy(test_policy_definitions::kKeyString,
194 "value"); 206 "value");
195 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); 207 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1);
196 provider_->RefreshPolicies(); 208 provider_->RefreshPolicies();
197 loop_.RunAllPending(); 209 loop_.RunAllPending();
198 Mock::VerifyAndClearExpectations(&observer); 210 Mock::VerifyAndClearExpectations(&observer);
199 211
200 policy_map.Clear(); 212 bundle.Get(POLICY_DOMAIN_CHROME, "")
201 EXPECT_TRUE(provider_->Provide(&policy_map)); 213 .Set(test_policy_definitions::kKeyString,
202 EXPECT_EQ(1U, policy_map.size()); 214 test_harness_->policy_level(),
215 test_harness_->policy_scope(),
216 base::Value::CreateStringValue("value"));
217 EXPECT_TRUE(provider_->policies().Equals(bundle));
203 } 218 }
204 219
205 TEST(ConfigurationPolicyProviderTest, FixDeprecatedPolicies) { 220 TEST(ConfigurationPolicyProviderTest, FixDeprecatedPolicies) {
206 PolicyMap policy_map; 221 PolicyMap policy_map;
207 policy_map.Set(key::kProxyServerMode, 222 policy_map.Set(key::kProxyServerMode,
208 POLICY_LEVEL_MANDATORY, 223 POLICY_LEVEL_MANDATORY,
209 POLICY_SCOPE_USER, 224 POLICY_SCOPE_USER,
210 base::Value::CreateIntegerValue(3)); 225 base::Value::CreateIntegerValue(3));
211 226
212 // Both these policies should be ignored, since there's a higher priority 227 // Both these policies should be ignored, since there's a higher priority
213 // policy available. 228 // policy available.
214 policy_map.Set(key::kProxyMode, 229 policy_map.Set(key::kProxyMode,
215 POLICY_LEVEL_RECOMMENDED, 230 POLICY_LEVEL_RECOMMENDED,
216 POLICY_SCOPE_USER, 231 POLICY_SCOPE_USER,
217 base::Value::CreateStringValue("pac_script")); 232 base::Value::CreateStringValue("pac_script"));
218 policy_map.Set(key::kProxyPacUrl, 233 policy_map.Set(key::kProxyPacUrl,
219 POLICY_LEVEL_RECOMMENDED, 234 POLICY_LEVEL_RECOMMENDED,
220 POLICY_SCOPE_USER, 235 POLICY_SCOPE_USER,
221 base::Value::CreateStringValue("http://example.com/wpad.dat")); 236 base::Value::CreateStringValue("http://example.com/wpad.dat"));
222 237
223 ConfigurationPolicyProvider::FixDeprecatedPolicies(&policy_map); 238 MockConfigurationPolicyProvider provider;
224 base::DictionaryValue expected; 239 provider.UpdateChromePolicy(policy_map);
225 expected.SetInteger(key::kProxyServerMode, 3); 240
226 EXPECT_EQ(1U, policy_map.size()); 241 PolicyBundle expected_bundle;
227 EXPECT_TRUE(base::Value::Equals(&expected, 242 base::DictionaryValue* expected_value = new base::DictionaryValue();
228 policy_map.GetValue(key::kProxySettings))); 243 expected_value->SetInteger(key::kProxyServerMode, 3);
244 expected_bundle.Get(POLICY_DOMAIN_CHROME, "")
245 .Set(key::kProxySettings, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
246 expected_value);
247 EXPECT_TRUE(provider.policies().Equals(expected_bundle));
229 } 248 }
230 249
231 } // namespace policy 250 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698