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

Side by Side Diff: components/policy/core/browser/configuration_policy_pref_store_unittest.cc

Issue 1304843004: Add source column to chrome://policy showing the origins of policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed another test. Created 5 years, 3 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 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 <string> 5 #include <string>
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/prefs/pref_store_observer_mock.h" 9 #include "base/prefs/pref_store_observer_mock.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "components/policy/core/browser/configuration_policy_handler.h" 11 #include "components/policy/core/browser/configuration_policy_handler.h"
12 #include "components/policy/core/browser/configuration_policy_pref_store.h" 12 #include "components/policy/core/browser/configuration_policy_pref_store.h"
13 #include "components/policy/core/browser/configuration_policy_pref_store_test.h" 13 #include "components/policy/core/browser/configuration_policy_pref_store_test.h"
14 #include "components/policy/core/common/external_data_fetcher.h" 14 #include "components/policy/core/common/external_data_fetcher.h"
15 #include "components/policy/core/common/policy_details.h" 15 #include "components/policy/core/common/policy_details.h"
16 #include "components/policy/core/common/policy_map.h" 16 #include "components/policy/core/common/policy_map.h"
17 #include "components/policy/core/common/policy_pref_names.h" 17 #include "components/policy/core/common/policy_pref_names.h"
18 #include "components/policy/core/common/policy_service_impl.h" 18 #include "components/policy/core/common/policy_service_impl.h"
19 #include "components/policy/core/common/policy_types.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 21
21 // Note: this file should move to components/policy/core/browser, but the 22 // Note: this file should move to components/policy/core/browser, but the
22 // components_unittests runner does not load the ResourceBundle as 23 // components_unittests runner does not load the ResourceBundle as
23 // ChromeTestSuite::Initialize does, which leads to failures using 24 // ChromeTestSuite::Initialize does, which leads to failures using
24 // PolicyErrorMap. 25 // PolicyErrorMap.
25 26
26 using testing::Mock; 27 using testing::Mock;
27 using testing::Return; 28 using testing::Return;
28 using testing::_; 29 using testing::_;
(...skipping 19 matching lines...) Expand all
48 49
49 TEST_F(ConfigurationPolicyPrefStoreListTest, GetDefault) { 50 TEST_F(ConfigurationPolicyPrefStoreListTest, GetDefault) {
50 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); 51 EXPECT_FALSE(store_->GetValue(kTestPref, NULL));
51 } 52 }
52 53
53 TEST_F(ConfigurationPolicyPrefStoreListTest, SetValue) { 54 TEST_F(ConfigurationPolicyPrefStoreListTest, SetValue) {
54 base::ListValue* in_value = new base::ListValue(); 55 base::ListValue* in_value = new base::ListValue();
55 in_value->Append(new base::StringValue("test1")); 56 in_value->Append(new base::StringValue("test1"));
56 in_value->Append(new base::StringValue("test2,")); 57 in_value->Append(new base::StringValue("test2,"));
57 PolicyMap policy; 58 PolicyMap policy;
58 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, 59 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
59 POLICY_SCOPE_USER, in_value, NULL); 60 POLICY_SOURCE_CLOUD, in_value, nullptr);
60 UpdateProviderPolicy(policy); 61 UpdateProviderPolicy(policy);
61 const base::Value* value = NULL; 62 const base::Value* value = NULL;
62 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); 63 EXPECT_TRUE(store_->GetValue(kTestPref, &value));
63 ASSERT_TRUE(value); 64 ASSERT_TRUE(value);
64 EXPECT_TRUE(in_value->Equals(value)); 65 EXPECT_TRUE(in_value->Equals(value));
65 } 66 }
66 67
67 // Test cases for string-valued policy settings. 68 // Test cases for string-valued policy settings.
68 class ConfigurationPolicyPrefStoreStringTest 69 class ConfigurationPolicyPrefStoreStringTest
69 : public ConfigurationPolicyPrefStoreTest { 70 : public ConfigurationPolicyPrefStoreTest {
70 void SetUp() override { 71 void SetUp() override {
71 handler_list_.AddHandler( 72 handler_list_.AddHandler(
72 make_scoped_ptr<ConfigurationPolicyHandler>(new SimplePolicyHandler( 73 make_scoped_ptr<ConfigurationPolicyHandler>(new SimplePolicyHandler(
73 kTestPolicy, kTestPref, base::Value::TYPE_STRING))); 74 kTestPolicy, kTestPref, base::Value::TYPE_STRING)));
74 } 75 }
75 }; 76 };
76 77
77 TEST_F(ConfigurationPolicyPrefStoreStringTest, GetDefault) { 78 TEST_F(ConfigurationPolicyPrefStoreStringTest, GetDefault) {
78 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); 79 EXPECT_FALSE(store_->GetValue(kTestPref, NULL));
79 } 80 }
80 81
81 TEST_F(ConfigurationPolicyPrefStoreStringTest, SetValue) { 82 TEST_F(ConfigurationPolicyPrefStoreStringTest, SetValue) {
82 PolicyMap policy; 83 PolicyMap policy;
83 policy.Set(kTestPolicy, 84 policy.Set(kTestPolicy,
84 POLICY_LEVEL_MANDATORY, 85 POLICY_LEVEL_MANDATORY,
85 POLICY_SCOPE_USER, 86 POLICY_SCOPE_USER,
87 POLICY_SOURCE_CLOUD,
86 new base::StringValue("http://chromium.org"), 88 new base::StringValue("http://chromium.org"),
87 NULL); 89 NULL);
88 UpdateProviderPolicy(policy); 90 UpdateProviderPolicy(policy);
89 const base::Value* value = NULL; 91 const base::Value* value = NULL;
90 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); 92 EXPECT_TRUE(store_->GetValue(kTestPref, &value));
91 ASSERT_TRUE(value); 93 ASSERT_TRUE(value);
92 EXPECT_TRUE(base::StringValue("http://chromium.org").Equals(value)); 94 EXPECT_TRUE(base::StringValue("http://chromium.org").Equals(value));
93 } 95 }
94 96
95 // Test cases for boolean-valued policy settings. 97 // Test cases for boolean-valued policy settings.
96 class ConfigurationPolicyPrefStoreBooleanTest 98 class ConfigurationPolicyPrefStoreBooleanTest
97 : public ConfigurationPolicyPrefStoreTest { 99 : public ConfigurationPolicyPrefStoreTest {
98 void SetUp() override { 100 void SetUp() override {
99 handler_list_.AddHandler( 101 handler_list_.AddHandler(
100 make_scoped_ptr<ConfigurationPolicyHandler>(new SimplePolicyHandler( 102 make_scoped_ptr<ConfigurationPolicyHandler>(new SimplePolicyHandler(
101 kTestPolicy, kTestPref, base::Value::TYPE_BOOLEAN))); 103 kTestPolicy, kTestPref, base::Value::TYPE_BOOLEAN)));
102 } 104 }
103 }; 105 };
104 106
105 TEST_F(ConfigurationPolicyPrefStoreBooleanTest, GetDefault) { 107 TEST_F(ConfigurationPolicyPrefStoreBooleanTest, GetDefault) {
106 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); 108 EXPECT_FALSE(store_->GetValue(kTestPref, NULL));
107 } 109 }
108 110
109 TEST_F(ConfigurationPolicyPrefStoreBooleanTest, SetValue) { 111 TEST_F(ConfigurationPolicyPrefStoreBooleanTest, SetValue) {
110 PolicyMap policy; 112 PolicyMap policy;
111 policy.Set(kTestPolicy, 113 policy.Set(kTestPolicy,
112 POLICY_LEVEL_MANDATORY, 114 POLICY_LEVEL_MANDATORY,
113 POLICY_SCOPE_USER, 115 POLICY_SCOPE_USER,
116 POLICY_SOURCE_CLOUD,
114 new base::FundamentalValue(false), 117 new base::FundamentalValue(false),
115 NULL); 118 NULL);
116 UpdateProviderPolicy(policy); 119 UpdateProviderPolicy(policy);
117 const base::Value* value = NULL; 120 const base::Value* value = NULL;
118 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); 121 EXPECT_TRUE(store_->GetValue(kTestPref, &value));
119 ASSERT_TRUE(value); 122 ASSERT_TRUE(value);
120 bool boolean_value = true; 123 bool boolean_value = true;
121 bool result = value->GetAsBoolean(&boolean_value); 124 bool result = value->GetAsBoolean(&boolean_value);
122 ASSERT_TRUE(result); 125 ASSERT_TRUE(result);
123 EXPECT_FALSE(boolean_value); 126 EXPECT_FALSE(boolean_value);
124 127
125 policy.Set(kTestPolicy, 128 policy.Set(kTestPolicy,
126 POLICY_LEVEL_MANDATORY, 129 POLICY_LEVEL_MANDATORY,
127 POLICY_SCOPE_USER, 130 POLICY_SCOPE_USER,
131 POLICY_SOURCE_CLOUD,
128 new base::FundamentalValue(true), 132 new base::FundamentalValue(true),
129 NULL); 133 NULL);
130 UpdateProviderPolicy(policy); 134 UpdateProviderPolicy(policy);
131 value = NULL; 135 value = NULL;
132 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); 136 EXPECT_TRUE(store_->GetValue(kTestPref, &value));
133 boolean_value = false; 137 boolean_value = false;
134 result = value->GetAsBoolean(&boolean_value); 138 result = value->GetAsBoolean(&boolean_value);
135 ASSERT_TRUE(result); 139 ASSERT_TRUE(result);
136 EXPECT_TRUE(boolean_value); 140 EXPECT_TRUE(boolean_value);
137 } 141 }
(...skipping 10 matching lines...) Expand all
148 152
149 TEST_F(ConfigurationPolicyPrefStoreIntegerTest, GetDefault) { 153 TEST_F(ConfigurationPolicyPrefStoreIntegerTest, GetDefault) {
150 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); 154 EXPECT_FALSE(store_->GetValue(kTestPref, NULL));
151 } 155 }
152 156
153 TEST_F(ConfigurationPolicyPrefStoreIntegerTest, SetValue) { 157 TEST_F(ConfigurationPolicyPrefStoreIntegerTest, SetValue) {
154 PolicyMap policy; 158 PolicyMap policy;
155 policy.Set(kTestPolicy, 159 policy.Set(kTestPolicy,
156 POLICY_LEVEL_MANDATORY, 160 POLICY_LEVEL_MANDATORY,
157 POLICY_SCOPE_USER, 161 POLICY_SCOPE_USER,
162 POLICY_SOURCE_CLOUD,
158 new base::FundamentalValue(2), 163 new base::FundamentalValue(2),
159 NULL); 164 NULL);
160 UpdateProviderPolicy(policy); 165 UpdateProviderPolicy(policy);
161 const base::Value* value = NULL; 166 const base::Value* value = NULL;
162 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); 167 EXPECT_TRUE(store_->GetValue(kTestPref, &value));
163 EXPECT_TRUE(base::FundamentalValue(2).Equals(value)); 168 EXPECT_TRUE(base::FundamentalValue(2).Equals(value));
164 } 169 }
165 170
166 // Exercises the policy refresh mechanism. 171 // Exercises the policy refresh mechanism.
167 class ConfigurationPolicyPrefStoreRefreshTest 172 class ConfigurationPolicyPrefStoreRefreshTest
(...skipping 16 matching lines...) Expand all
184 }; 189 };
185 190
186 TEST_F(ConfigurationPolicyPrefStoreRefreshTest, Refresh) { 191 TEST_F(ConfigurationPolicyPrefStoreRefreshTest, Refresh) {
187 const base::Value* value = NULL; 192 const base::Value* value = NULL;
188 EXPECT_FALSE(store_->GetValue(kTestPolicy, NULL)); 193 EXPECT_FALSE(store_->GetValue(kTestPolicy, NULL));
189 194
190 PolicyMap policy; 195 PolicyMap policy;
191 policy.Set(kTestPolicy, 196 policy.Set(kTestPolicy,
192 POLICY_LEVEL_MANDATORY, 197 POLICY_LEVEL_MANDATORY,
193 POLICY_SCOPE_USER, 198 POLICY_SCOPE_USER,
199 POLICY_SOURCE_CLOUD,
194 new base::StringValue("http://www.chromium.org"), 200 new base::StringValue("http://www.chromium.org"),
195 NULL); 201 NULL);
196 UpdateProviderPolicy(policy); 202 UpdateProviderPolicy(policy);
197 observer_.VerifyAndResetChangedKey(kTestPref); 203 observer_.VerifyAndResetChangedKey(kTestPref);
198 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); 204 EXPECT_TRUE(store_->GetValue(kTestPref, &value));
199 EXPECT_TRUE(base::StringValue("http://www.chromium.org").Equals(value)); 205 EXPECT_TRUE(base::StringValue("http://www.chromium.org").Equals(value));
200 206
201 UpdateProviderPolicy(policy); 207 UpdateProviderPolicy(policy);
202 EXPECT_TRUE(observer_.changed_keys.empty()); 208 EXPECT_TRUE(observer_.changed_keys.empty());
203 209
204 policy.Erase(kTestPolicy); 210 policy.Erase(kTestPolicy);
205 UpdateProviderPolicy(policy); 211 UpdateProviderPolicy(policy);
206 observer_.VerifyAndResetChangedKey(kTestPref); 212 observer_.VerifyAndResetChangedKey(kTestPref);
207 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); 213 EXPECT_FALSE(store_->GetValue(kTestPref, NULL));
208 } 214 }
209 215
210 TEST_F(ConfigurationPolicyPrefStoreRefreshTest, Initialization) { 216 TEST_F(ConfigurationPolicyPrefStoreRefreshTest, Initialization) {
211 EXPECT_FALSE(store_->IsInitializationComplete()); 217 EXPECT_FALSE(store_->IsInitializationComplete());
212 EXPECT_CALL(provider_, IsInitializationComplete(POLICY_DOMAIN_CHROME)) 218 EXPECT_CALL(provider_, IsInitializationComplete(POLICY_DOMAIN_CHROME))
213 .WillRepeatedly(Return(true)); 219 .WillRepeatedly(Return(true));
214 PolicyMap policy; 220 PolicyMap policy;
215 UpdateProviderPolicy(policy); 221 UpdateProviderPolicy(policy);
216 EXPECT_TRUE(observer_.initialized); 222 EXPECT_TRUE(observer_.initialized);
217 EXPECT_TRUE(observer_.initialization_success); 223 EXPECT_TRUE(observer_.initialization_success);
218 Mock::VerifyAndClearExpectations(&observer_); 224 Mock::VerifyAndClearExpectations(&observer_);
219 EXPECT_TRUE(store_->IsInitializationComplete()); 225 EXPECT_TRUE(store_->IsInitializationComplete());
220 } 226 }
221 227
222 } // namespace policy 228 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698