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

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

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

Powered by Google App Engine
This is Rietveld 408576698