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

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

Issue 388963002: Get rid of the rest of CreateStringValue (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix bad rebase Created 6 years, 5 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 | Annotate | Revision Log
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"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 kTestPolicy, kTestPref, base::Value::TYPE_LIST))); 45 kTestPolicy, kTestPref, base::Value::TYPE_LIST)));
46 } 46 }
47 }; 47 };
48 48
49 TEST_F(ConfigurationPolicyPrefStoreListTest, GetDefault) { 49 TEST_F(ConfigurationPolicyPrefStoreListTest, GetDefault) {
50 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); 50 EXPECT_FALSE(store_->GetValue(kTestPref, NULL));
51 } 51 }
52 52
53 TEST_F(ConfigurationPolicyPrefStoreListTest, SetValue) { 53 TEST_F(ConfigurationPolicyPrefStoreListTest, SetValue) {
54 base::ListValue* in_value = new base::ListValue(); 54 base::ListValue* in_value = new base::ListValue();
55 in_value->Append(base::Value::CreateStringValue("test1")); 55 in_value->Append(new base::StringValue("test1"));
56 in_value->Append(base::Value::CreateStringValue("test2,")); 56 in_value->Append(new base::StringValue("test2,"));
57 PolicyMap policy; 57 PolicyMap policy;
58 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, 58 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY,
59 POLICY_SCOPE_USER, in_value, NULL); 59 POLICY_SCOPE_USER, in_value, NULL);
60 UpdateProviderPolicy(policy); 60 UpdateProviderPolicy(policy);
61 const base::Value* value = NULL; 61 const base::Value* value = NULL;
62 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); 62 EXPECT_TRUE(store_->GetValue(kTestPref, &value));
63 ASSERT_TRUE(value); 63 ASSERT_TRUE(value);
64 EXPECT_TRUE(in_value->Equals(value)); 64 EXPECT_TRUE(in_value->Equals(value));
65 } 65 }
66 66
67 // Test cases for string-valued policy settings. 67 // Test cases for string-valued policy settings.
68 class ConfigurationPolicyPrefStoreStringTest 68 class ConfigurationPolicyPrefStoreStringTest
69 : public ConfigurationPolicyPrefStoreTest { 69 : public ConfigurationPolicyPrefStoreTest {
70 virtual void SetUp() OVERRIDE { 70 virtual void SetUp() OVERRIDE {
71 handler_list_.AddHandler( 71 handler_list_.AddHandler(
72 make_scoped_ptr<ConfigurationPolicyHandler>(new SimplePolicyHandler( 72 make_scoped_ptr<ConfigurationPolicyHandler>(new SimplePolicyHandler(
73 kTestPolicy, kTestPref, base::Value::TYPE_STRING))); 73 kTestPolicy, kTestPref, base::Value::TYPE_STRING)));
74 } 74 }
75 }; 75 };
76 76
77 TEST_F(ConfigurationPolicyPrefStoreStringTest, GetDefault) { 77 TEST_F(ConfigurationPolicyPrefStoreStringTest, GetDefault) {
78 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); 78 EXPECT_FALSE(store_->GetValue(kTestPref, NULL));
79 } 79 }
80 80
81 TEST_F(ConfigurationPolicyPrefStoreStringTest, SetValue) { 81 TEST_F(ConfigurationPolicyPrefStoreStringTest, SetValue) {
82 PolicyMap policy; 82 PolicyMap policy;
83 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, 83 policy.Set(kTestPolicy,
84 POLICY_LEVEL_MANDATORY,
84 POLICY_SCOPE_USER, 85 POLICY_SCOPE_USER,
85 base::Value::CreateStringValue("http://chromium.org"), NULL); 86 new base::StringValue("http://chromium.org"),
87 NULL);
86 UpdateProviderPolicy(policy); 88 UpdateProviderPolicy(policy);
87 const base::Value* value = NULL; 89 const base::Value* value = NULL;
88 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); 90 EXPECT_TRUE(store_->GetValue(kTestPref, &value));
89 ASSERT_TRUE(value); 91 ASSERT_TRUE(value);
90 EXPECT_TRUE(base::StringValue("http://chromium.org").Equals(value)); 92 EXPECT_TRUE(base::StringValue("http://chromium.org").Equals(value));
91 } 93 }
92 94
93 // Test cases for boolean-valued policy settings. 95 // Test cases for boolean-valued policy settings.
94 class ConfigurationPolicyPrefStoreBooleanTest 96 class ConfigurationPolicyPrefStoreBooleanTest
95 : public ConfigurationPolicyPrefStoreTest { 97 : public ConfigurationPolicyPrefStoreTest {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 }; 184 };
183 185
184 TEST_F(ConfigurationPolicyPrefStoreRefreshTest, Refresh) { 186 TEST_F(ConfigurationPolicyPrefStoreRefreshTest, Refresh) {
185 const base::Value* value = NULL; 187 const base::Value* value = NULL;
186 EXPECT_FALSE(store_->GetValue(kTestPolicy, NULL)); 188 EXPECT_FALSE(store_->GetValue(kTestPolicy, NULL));
187 189
188 PolicyMap policy; 190 PolicyMap policy;
189 policy.Set(kTestPolicy, 191 policy.Set(kTestPolicy,
190 POLICY_LEVEL_MANDATORY, 192 POLICY_LEVEL_MANDATORY,
191 POLICY_SCOPE_USER, 193 POLICY_SCOPE_USER,
192 base::Value::CreateStringValue("http://www.chromium.org"), 194 new base::StringValue("http://www.chromium.org"),
193 NULL); 195 NULL);
194 UpdateProviderPolicy(policy); 196 UpdateProviderPolicy(policy);
195 observer_.VerifyAndResetChangedKey(kTestPref); 197 observer_.VerifyAndResetChangedKey(kTestPref);
196 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); 198 EXPECT_TRUE(store_->GetValue(kTestPref, &value));
197 EXPECT_TRUE(base::StringValue("http://www.chromium.org").Equals(value)); 199 EXPECT_TRUE(base::StringValue("http://www.chromium.org").Equals(value));
198 200
199 UpdateProviderPolicy(policy); 201 UpdateProviderPolicy(policy);
200 EXPECT_TRUE(observer_.changed_keys.empty()); 202 EXPECT_TRUE(observer_.changed_keys.empty());
201 203
202 policy.Erase(kTestPolicy); 204 policy.Erase(kTestPolicy);
203 UpdateProviderPolicy(policy); 205 UpdateProviderPolicy(policy);
204 observer_.VerifyAndResetChangedKey(kTestPref); 206 observer_.VerifyAndResetChangedKey(kTestPref);
205 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); 207 EXPECT_FALSE(store_->GetValue(kTestPref, NULL));
206 } 208 }
207 209
208 TEST_F(ConfigurationPolicyPrefStoreRefreshTest, Initialization) { 210 TEST_F(ConfigurationPolicyPrefStoreRefreshTest, Initialization) {
209 EXPECT_FALSE(store_->IsInitializationComplete()); 211 EXPECT_FALSE(store_->IsInitializationComplete());
210 EXPECT_CALL(provider_, IsInitializationComplete(POLICY_DOMAIN_CHROME)) 212 EXPECT_CALL(provider_, IsInitializationComplete(POLICY_DOMAIN_CHROME))
211 .WillRepeatedly(Return(true)); 213 .WillRepeatedly(Return(true));
212 PolicyMap policy; 214 PolicyMap policy;
213 UpdateProviderPolicy(policy); 215 UpdateProviderPolicy(policy);
214 EXPECT_TRUE(observer_.initialized); 216 EXPECT_TRUE(observer_.initialized);
215 EXPECT_TRUE(observer_.initialization_success); 217 EXPECT_TRUE(observer_.initialization_success);
216 Mock::VerifyAndClearExpectations(&observer_); 218 Mock::VerifyAndClearExpectations(&observer_);
217 EXPECT_TRUE(store_->IsInitializationComplete()); 219 EXPECT_TRUE(store_->IsInitializationComplete());
218 } 220 }
219 221
220 } // namespace policy 222 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698