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

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

Issue 10236003: Added RefreshPolicies to PolicyService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
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 | Annotate | Revision Log
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 <string> 5 #include <string>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/policy/configuration_policy_pref_store.h" 10 #include "chrome/browser/policy/configuration_policy_pref_store.h"
11 #include "chrome/browser/policy/configuration_policy_reader.h" 11 #include "chrome/browser/policy/configuration_policy_reader.h"
12 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 12 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
13 #include "chrome/browser/policy/mock_configuration_policy_reader.h" 13 #include "chrome/browser/policy/mock_configuration_policy_reader.h"
14 #include "chrome/browser/policy/policy_map.h"
14 #include "policy/policy_constants.h" 15 #include "policy/policy_constants.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 using ::testing::Return; 18 using ::testing::Return;
18 using ::testing::ReturnNull; 19 using ::testing::ReturnNull;
19 using ::testing::_; 20 using ::testing::_;
20 21
21 namespace policy { 22 namespace policy {
22 23
23 class ConfigurationPolicyReaderTest : public testing::Test { 24 class ConfigurationPolicyReaderTest : public testing::Test {
24 protected: 25 protected:
25 ConfigurationPolicyReaderTest() : provider_() { 26 ConfigurationPolicyReaderTest() {
27 EXPECT_CALL(provider_, ProvideInternal(_))
28 .WillRepeatedly(CopyPolicyMap(&policy_));
29 EXPECT_CALL(provider_, IsInitializationComplete())
30 .WillRepeatedly(Return(true));
31
26 reader_.reset(new ConfigurationPolicyReader(&provider_)); 32 reader_.reset(new ConfigurationPolicyReader(&provider_));
27 status_ok_ = ASCIIToUTF16("OK"); 33 status_ok_ = ASCIIToUTF16("OK");
28 } 34 }
29 35
30 DictionaryValue* CreateDictionary(const char* policy_name, 36 DictionaryValue* CreateDictionary(const char* policy_name,
31 Value* policy_value) { 37 Value* policy_value) {
32 DictionaryValue* dict = new DictionaryValue(); 38 DictionaryValue* dict = new DictionaryValue();
33 dict->SetString(PolicyStatusInfo::kNameDictPath, ASCIIToUTF16(policy_name)); 39 dict->SetString(PolicyStatusInfo::kNameDictPath, ASCIIToUTF16(policy_name));
34 dict->SetString(PolicyStatusInfo::kLevelDictPath, 40 dict->SetString(PolicyStatusInfo::kLevelDictPath,
35 PolicyStatusInfo::GetPolicyLevelString( 41 PolicyStatusInfo::GetPolicyLevelString(
36 POLICY_LEVEL_MANDATORY)); 42 POLICY_LEVEL_MANDATORY));
37 dict->SetString(PolicyStatusInfo::kScopeDictPath, 43 dict->SetString(PolicyStatusInfo::kScopeDictPath,
38 PolicyStatusInfo::GetPolicyScopeString( 44 PolicyStatusInfo::GetPolicyScopeString(
39 POLICY_SCOPE_USER)); 45 POLICY_SCOPE_USER));
40 dict->Set(PolicyStatusInfo::kValueDictPath, policy_value); 46 dict->Set(PolicyStatusInfo::kValueDictPath, policy_value);
41 dict->SetBoolean(PolicyStatusInfo::kSetDictPath, true); 47 dict->SetBoolean(PolicyStatusInfo::kSetDictPath, true);
42 dict->SetString(PolicyStatusInfo::kStatusDictPath, status_ok_); 48 dict->SetString(PolicyStatusInfo::kStatusDictPath, status_ok_);
43 49
44 return dict; 50 return dict;
45 } 51 }
46 52
53 PolicyMap policy_;
47 MockConfigurationPolicyProvider provider_; 54 MockConfigurationPolicyProvider provider_;
48 scoped_ptr<ConfigurationPolicyReader> reader_; 55 scoped_ptr<ConfigurationPolicyReader> reader_;
49 string16 status_ok_; 56 string16 status_ok_;
50 }; 57 };
51 58
52 TEST_F(ConfigurationPolicyReaderTest, GetDefault) { 59 TEST_F(ConfigurationPolicyReaderTest, GetDefault) {
53 EXPECT_EQ(NULL, reader_->GetPolicyStatus(key::kHomepageLocation)); 60 EXPECT_EQ(NULL, reader_->GetPolicyStatus(key::kHomepageLocation));
54 } 61 }
55 62
56 // Test for list-valued policy settings. 63 // Test for list-valued policy settings.
57 TEST_F(ConfigurationPolicyReaderTest, SetListValue) { 64 TEST_F(ConfigurationPolicyReaderTest, SetListValue) {
58 ListValue mandatory_value; 65 ListValue mandatory_value;
59 mandatory_value.Append(Value::CreateStringValue("test1")); 66 mandatory_value.Append(Value::CreateStringValue("test1"));
60 mandatory_value.Append(Value::CreateStringValue("test2")); 67 mandatory_value.Append(Value::CreateStringValue("test2"));
61 ListValue recommended_value; 68 ListValue recommended_value;
62 recommended_value.Append(Value::CreateStringValue("test3")); 69 recommended_value.Append(Value::CreateStringValue("test3"));
63 recommended_value.Append(Value::CreateStringValue("test4")); 70 recommended_value.Append(Value::CreateStringValue("test4"));
64 provider_.AddMandatoryPolicy(key::kRestoreOnStartupURLs, 71 policy_.Set(key::kRestoreOnStartupURLs, POLICY_LEVEL_MANDATORY,
65 mandatory_value.DeepCopy()); 72 POLICY_SCOPE_USER, mandatory_value.DeepCopy());
66 provider_.AddRecommendedPolicy(key::kDisabledSchemes, 73 policy_.Set(key::kDisabledSchemes, POLICY_LEVEL_RECOMMENDED,
67 recommended_value.DeepCopy()); 74 POLICY_SCOPE_USER, recommended_value.DeepCopy());
68 reader_->OnUpdatePolicy(&provider_); 75 reader_->OnUpdatePolicy(&provider_);
69 76
70 scoped_ptr<DictionaryValue> dict( 77 scoped_ptr<DictionaryValue> dict(
71 CreateDictionary(key::kRestoreOnStartupURLs, 78 CreateDictionary(key::kRestoreOnStartupURLs,
72 mandatory_value.DeepCopy())); 79 mandatory_value.DeepCopy()));
73 scoped_ptr<DictionaryValue> result( 80 scoped_ptr<DictionaryValue> result(
74 reader_->GetPolicyStatus(key::kRestoreOnStartupURLs)); 81 reader_->GetPolicyStatus(key::kRestoreOnStartupURLs));
75 EXPECT_TRUE(dict->Equals(result.get())); 82 EXPECT_TRUE(dict->Equals(result.get()));
76 83
77 dict.reset(CreateDictionary(key::kDisabledSchemes, 84 dict.reset(CreateDictionary(key::kDisabledSchemes,
78 recommended_value.DeepCopy())); 85 recommended_value.DeepCopy()));
79 dict->SetString( 86 dict->SetString(
80 "level", 87 "level",
81 PolicyStatusInfo::GetPolicyLevelString(POLICY_LEVEL_RECOMMENDED)); 88 PolicyStatusInfo::GetPolicyLevelString(POLICY_LEVEL_RECOMMENDED));
82 result.reset(reader_->GetPolicyStatus(key::kDisabledSchemes)); 89 result.reset(reader_->GetPolicyStatus(key::kDisabledSchemes));
83 EXPECT_TRUE(dict->Equals(result.get())); 90 EXPECT_TRUE(dict->Equals(result.get()));
84 } 91 }
85 92
86 // Test for string-valued policy settings. 93 // Test for string-valued policy settings.
87 TEST_F(ConfigurationPolicyReaderTest, SetStringValue) { 94 TEST_F(ConfigurationPolicyReaderTest, SetStringValue) {
88 StringValue mandatory_value("http://chromium.org"); 95 StringValue mandatory_value("http://chromium.org");
89 StringValue recommended_value("http://www.google.com/q={searchTerms}"); 96 StringValue recommended_value("http://www.google.com/q={searchTerms}");
90 provider_.AddMandatoryPolicy(key::kHomepageLocation, 97 policy_.Set(key::kHomepageLocation, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
91 mandatory_value.DeepCopy()); 98 mandatory_value.DeepCopy());
92 provider_.AddRecommendedPolicy(key::kDefaultSearchProviderSearchURL, 99 policy_.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_RECOMMENDED,
93 recommended_value.DeepCopy()); 100 POLICY_SCOPE_USER, recommended_value.DeepCopy());
94 reader_->OnUpdatePolicy(&provider_); 101 reader_->OnUpdatePolicy(&provider_);
95 scoped_ptr<DictionaryValue> dict( 102 scoped_ptr<DictionaryValue> dict(
96 CreateDictionary(key::kHomepageLocation, 103 CreateDictionary(key::kHomepageLocation,
97 mandatory_value.DeepCopy())); 104 mandatory_value.DeepCopy()));
98 scoped_ptr<DictionaryValue> result( 105 scoped_ptr<DictionaryValue> result(
99 reader_->GetPolicyStatus(key::kHomepageLocation)); 106 reader_->GetPolicyStatus(key::kHomepageLocation));
100 EXPECT_TRUE(dict->Equals(result.get())); 107 EXPECT_TRUE(dict->Equals(result.get()));
101 108
102 dict.reset(CreateDictionary(key::kDefaultSearchProviderSearchURL, 109 dict.reset(CreateDictionary(key::kDefaultSearchProviderSearchURL,
103 recommended_value.DeepCopy())); 110 recommended_value.DeepCopy()));
104 dict->SetString( 111 dict->SetString(
105 "level", 112 "level",
106 PolicyStatusInfo::GetPolicyLevelString(POLICY_LEVEL_RECOMMENDED)); 113 PolicyStatusInfo::GetPolicyLevelString(POLICY_LEVEL_RECOMMENDED));
107 result.reset(reader_->GetPolicyStatus(key::kDefaultSearchProviderSearchURL)); 114 result.reset(reader_->GetPolicyStatus(key::kDefaultSearchProviderSearchURL));
108 EXPECT_TRUE(dict->Equals(result.get())); 115 EXPECT_TRUE(dict->Equals(result.get()));
109 } 116 }
110 117
111 // Test for boolean-valued policy settings. 118 // Test for boolean-valued policy settings.
112 TEST_F(ConfigurationPolicyReaderTest, SetBooleanValue) { 119 TEST_F(ConfigurationPolicyReaderTest, SetBooleanValue) {
113 provider_.AddMandatoryPolicy(key::kShowHomeButton, 120 policy_.Set(key::kShowHomeButton, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
114 Value::CreateBooleanValue(true)); 121 Value::CreateBooleanValue(true));
115 provider_.AddRecommendedPolicy(key::kHomepageIsNewTabPage, 122 policy_.Set(key::kHomepageIsNewTabPage, POLICY_LEVEL_RECOMMENDED,
116 Value::CreateBooleanValue(false)); 123 POLICY_SCOPE_USER, Value::CreateBooleanValue(false));
117 reader_->OnUpdatePolicy(&provider_); 124 reader_->OnUpdatePolicy(&provider_);
118 scoped_ptr<DictionaryValue> dict( 125 scoped_ptr<DictionaryValue> dict(
119 CreateDictionary(key::kShowHomeButton, Value::CreateBooleanValue(true))); 126 CreateDictionary(key::kShowHomeButton, Value::CreateBooleanValue(true)));
120 scoped_ptr<DictionaryValue> result( 127 scoped_ptr<DictionaryValue> result(
121 reader_->GetPolicyStatus(key::kShowHomeButton)); 128 reader_->GetPolicyStatus(key::kShowHomeButton));
122 EXPECT_TRUE(dict->Equals(result.get())); 129 EXPECT_TRUE(dict->Equals(result.get()));
123 130
124 dict.reset(CreateDictionary(key::kHomepageIsNewTabPage, 131 dict.reset(CreateDictionary(key::kHomepageIsNewTabPage,
125 Value::CreateBooleanValue(false))); 132 Value::CreateBooleanValue(false)));
126 dict->SetString( 133 dict->SetString(
127 "level", 134 "level",
128 PolicyStatusInfo::GetPolicyLevelString(POLICY_LEVEL_RECOMMENDED)); 135 PolicyStatusInfo::GetPolicyLevelString(POLICY_LEVEL_RECOMMENDED));
129 result.reset(reader_->GetPolicyStatus(key::kHomepageIsNewTabPage)); 136 result.reset(reader_->GetPolicyStatus(key::kHomepageIsNewTabPage));
130 EXPECT_TRUE(dict->Equals(result.get())); 137 EXPECT_TRUE(dict->Equals(result.get()));
131 } 138 }
132 139
133 // Test for integer-valued policy settings. 140 // Test for integer-valued policy settings.
134 TEST_F(ConfigurationPolicyReaderTest, SetIntegerValue) { 141 TEST_F(ConfigurationPolicyReaderTest, SetIntegerValue) {
135 provider_.AddMandatoryPolicy(key::kRestoreOnStartup, 142 policy_.Set(key::kRestoreOnStartup, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
136 Value::CreateIntegerValue(4)); 143 Value::CreateIntegerValue(4));
137 provider_.AddRecommendedPolicy(key::kIncognitoModeAvailability, 144 policy_.Set(key::kIncognitoModeAvailability, POLICY_LEVEL_RECOMMENDED,
138 Value::CreateIntegerValue(2)); 145 POLICY_SCOPE_USER, Value::CreateIntegerValue(2));
139 reader_->OnUpdatePolicy(&provider_); 146 reader_->OnUpdatePolicy(&provider_);
140 scoped_ptr<DictionaryValue> dict( 147 scoped_ptr<DictionaryValue> dict(
141 CreateDictionary(key::kRestoreOnStartup, Value::CreateIntegerValue(4))); 148 CreateDictionary(key::kRestoreOnStartup, Value::CreateIntegerValue(4)));
142 scoped_ptr<DictionaryValue> result( 149 scoped_ptr<DictionaryValue> result(
143 reader_->GetPolicyStatus(key::kRestoreOnStartup)); 150 reader_->GetPolicyStatus(key::kRestoreOnStartup));
144 EXPECT_TRUE(dict->Equals(result.get())); 151 EXPECT_TRUE(dict->Equals(result.get()));
145 152
146 dict.reset(CreateDictionary(key::kIncognitoModeAvailability, 153 dict.reset(CreateDictionary(key::kIncognitoModeAvailability,
147 Value::CreateIntegerValue(2))); 154 Value::CreateIntegerValue(2)));
148 dict->SetString( 155 dict->SetString(
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 cases[i].name != NULL, 324 cases[i].name != NULL,
318 cases[i].level); 325 cases[i].level);
319 EXPECT_TRUE(dict->Equals(status_dict)); 326 EXPECT_TRUE(dict->Equals(status_dict));
320 break; 327 break;
321 } 328 }
322 } 329 }
323 } 330 }
324 } 331 }
325 332
326 } // namespace policy 333 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698