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

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

Issue 8586030: Added ConfigurationPolicyProvider::RefreshPolicies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 TEST_F(ConfigurationPolicyReaderTest, GetDefault) { 55 TEST_F(ConfigurationPolicyReaderTest, GetDefault) {
56 EXPECT_EQ(NULL, managed_reader_->GetPolicyStatus(kPolicyHomepageLocation)); 56 EXPECT_EQ(NULL, managed_reader_->GetPolicyStatus(kPolicyHomepageLocation));
57 } 57 }
58 58
59 // Test for list-valued policy settings. 59 // Test for list-valued policy settings.
60 TEST_F(ConfigurationPolicyReaderTest, SetListValue) { 60 TEST_F(ConfigurationPolicyReaderTest, SetListValue) {
61 ListValue* in_value = new ListValue(); 61 ListValue* in_value = new ListValue();
62 in_value->Append(Value::CreateStringValue("test1")); 62 in_value->Append(Value::CreateStringValue("test1"));
63 in_value->Append(Value::CreateStringValue("test2")); 63 in_value->Append(Value::CreateStringValue("test2"));
64 provider_.AddPolicy(kPolicyRestoreOnStartupURLs, in_value); 64 provider_.AddPolicy(kPolicyRestoreOnStartupURLs, in_value);
65 managed_reader_->OnUpdatePolicy(); 65 managed_reader_->OnUpdatePolicy(&provider_);
66 66
67 scoped_ptr<DictionaryValue> 67 scoped_ptr<DictionaryValue>
68 dict(CreateDictionary(key::kRestoreOnStartupURLs, in_value->DeepCopy())); 68 dict(CreateDictionary(key::kRestoreOnStartupURLs, in_value->DeepCopy()));
69 scoped_ptr<DictionaryValue> result( 69 scoped_ptr<DictionaryValue> result(
70 managed_reader_->GetPolicyStatus(kPolicyRestoreOnStartupURLs)); 70 managed_reader_->GetPolicyStatus(kPolicyRestoreOnStartupURLs));
71 EXPECT_TRUE(dict->Equals(result.get())); 71 EXPECT_TRUE(dict->Equals(result.get()));
72 72
73 recommended_reader_->OnUpdatePolicy(); 73 recommended_reader_->OnUpdatePolicy(&provider_);
74 dict->SetString("level", 74 dict->SetString("level",
75 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); 75 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED));
76 result.reset( 76 result.reset(
77 recommended_reader_->GetPolicyStatus(kPolicyRestoreOnStartupURLs)); 77 recommended_reader_->GetPolicyStatus(kPolicyRestoreOnStartupURLs));
78 EXPECT_TRUE(dict->Equals(result.get())); 78 EXPECT_TRUE(dict->Equals(result.get()));
79 } 79 }
80 80
81 // Test for string-valued policy settings. 81 // Test for string-valued policy settings.
82 TEST_F(ConfigurationPolicyReaderTest, SetStringValue) { 82 TEST_F(ConfigurationPolicyReaderTest, SetStringValue) {
83 provider_.AddPolicy(kPolicyHomepageLocation, 83 provider_.AddPolicy(kPolicyHomepageLocation,
84 Value::CreateStringValue("http://chromium.org")); 84 Value::CreateStringValue("http://chromium.org"));
85 managed_reader_->OnUpdatePolicy(); 85 managed_reader_->OnUpdatePolicy(&provider_);
86 scoped_ptr<DictionaryValue> dict(CreateDictionary(key::kHomepageLocation, 86 scoped_ptr<DictionaryValue> dict(CreateDictionary(key::kHomepageLocation,
87 Value::CreateStringValue("http://chromium.org"))); 87 Value::CreateStringValue("http://chromium.org")));
88 scoped_ptr<DictionaryValue> result( 88 scoped_ptr<DictionaryValue> result(
89 managed_reader_->GetPolicyStatus(kPolicyHomepageLocation)); 89 managed_reader_->GetPolicyStatus(kPolicyHomepageLocation));
90 EXPECT_TRUE(dict->Equals(result.get())); 90 EXPECT_TRUE(dict->Equals(result.get()));
91 91
92 recommended_reader_->OnUpdatePolicy(); 92 recommended_reader_->OnUpdatePolicy(&provider_);
93 dict->SetString("level", 93 dict->SetString("level",
94 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); 94 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED));
95 result.reset( 95 result.reset(
96 recommended_reader_->GetPolicyStatus(kPolicyHomepageLocation)); 96 recommended_reader_->GetPolicyStatus(kPolicyHomepageLocation));
97 EXPECT_TRUE(dict->Equals(result.get())); 97 EXPECT_TRUE(dict->Equals(result.get()));
98 } 98 }
99 99
100 // Test for boolean-valued policy settings. 100 // Test for boolean-valued policy settings.
101 TEST_F(ConfigurationPolicyReaderTest, SetBooleanValue) { 101 TEST_F(ConfigurationPolicyReaderTest, SetBooleanValue) {
102 provider_.AddPolicy(kPolicyShowHomeButton, Value::CreateBooleanValue(true)); 102 provider_.AddPolicy(kPolicyShowHomeButton, Value::CreateBooleanValue(true));
103 managed_reader_->OnUpdatePolicy(); 103 managed_reader_->OnUpdatePolicy(&provider_);
104 scoped_ptr<DictionaryValue> dict(CreateDictionary(key::kShowHomeButton, 104 scoped_ptr<DictionaryValue> dict(CreateDictionary(key::kShowHomeButton,
105 Value::CreateBooleanValue(true))); 105 Value::CreateBooleanValue(true)));
106 scoped_ptr<DictionaryValue> result( 106 scoped_ptr<DictionaryValue> result(
107 managed_reader_->GetPolicyStatus(kPolicyShowHomeButton)); 107 managed_reader_->GetPolicyStatus(kPolicyShowHomeButton));
108 EXPECT_TRUE(dict->Equals(result.get())); 108 EXPECT_TRUE(dict->Equals(result.get()));
109 109
110 recommended_reader_->OnUpdatePolicy(); 110 recommended_reader_->OnUpdatePolicy(&provider_);
111 dict->SetString("level", 111 dict->SetString("level",
112 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); 112 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED));
113 result.reset(recommended_reader_->GetPolicyStatus(kPolicyShowHomeButton)); 113 result.reset(recommended_reader_->GetPolicyStatus(kPolicyShowHomeButton));
114 EXPECT_TRUE(dict->Equals(result.get())); 114 EXPECT_TRUE(dict->Equals(result.get()));
115 115
116 provider_.AddPolicy(kPolicyShowHomeButton, Value::CreateBooleanValue(false)); 116 provider_.AddPolicy(kPolicyShowHomeButton, Value::CreateBooleanValue(false));
117 managed_reader_->OnUpdatePolicy(); 117 managed_reader_->OnUpdatePolicy(&provider_);
118 dict->Set( 118 dict->Set(
119 PolicyStatusInfo::kValueDictPath, Value::CreateBooleanValue(false)); 119 PolicyStatusInfo::kValueDictPath, Value::CreateBooleanValue(false));
120 dict->SetString("level", 120 dict->SetString("level",
121 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::MANDATORY)); 121 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::MANDATORY));
122 result.reset(managed_reader_->GetPolicyStatus(kPolicyShowHomeButton)); 122 result.reset(managed_reader_->GetPolicyStatus(kPolicyShowHomeButton));
123 EXPECT_TRUE(dict->Equals(result.get())); 123 EXPECT_TRUE(dict->Equals(result.get()));
124 124
125 recommended_reader_->OnUpdatePolicy(); 125 recommended_reader_->OnUpdatePolicy(&provider_);
126 dict->SetString("level", 126 dict->SetString("level",
127 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); 127 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED));
128 result.reset(recommended_reader_->GetPolicyStatus(kPolicyShowHomeButton)); 128 result.reset(recommended_reader_->GetPolicyStatus(kPolicyShowHomeButton));
129 EXPECT_TRUE(dict->Equals(result.get())); 129 EXPECT_TRUE(dict->Equals(result.get()));
130 } 130 }
131 131
132 // Test for integer-valued policy settings. 132 // Test for integer-valued policy settings.
133 TEST_F(ConfigurationPolicyReaderTest, SetIntegerValue) { 133 TEST_F(ConfigurationPolicyReaderTest, SetIntegerValue) {
134 provider_.AddPolicy(kPolicyRestoreOnStartup, Value::CreateIntegerValue(3)); 134 provider_.AddPolicy(kPolicyRestoreOnStartup, Value::CreateIntegerValue(3));
135 managed_reader_->OnUpdatePolicy(); 135 managed_reader_->OnUpdatePolicy(&provider_);
136 scoped_ptr<DictionaryValue> dict(CreateDictionary(key::kRestoreOnStartup, 136 scoped_ptr<DictionaryValue> dict(CreateDictionary(key::kRestoreOnStartup,
137 Value::CreateIntegerValue(3))); 137 Value::CreateIntegerValue(3)));
138 scoped_ptr<DictionaryValue> result( 138 scoped_ptr<DictionaryValue> result(
139 managed_reader_->GetPolicyStatus(kPolicyRestoreOnStartup)); 139 managed_reader_->GetPolicyStatus(kPolicyRestoreOnStartup));
140 EXPECT_TRUE(dict->Equals(result.get())); 140 EXPECT_TRUE(dict->Equals(result.get()));
141 141
142 recommended_reader_->OnUpdatePolicy(); 142 recommended_reader_->OnUpdatePolicy(&provider_);
143 dict->SetString("level", 143 dict->SetString("level",
144 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); 144 PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED));
145 result.reset(recommended_reader_->GetPolicyStatus(kPolicyRestoreOnStartup)); 145 result.reset(recommended_reader_->GetPolicyStatus(kPolicyRestoreOnStartup));
146 EXPECT_TRUE(dict->Equals(result.get())); 146 EXPECT_TRUE(dict->Equals(result.get()));
147 } 147 }
148 148
149 class PolicyStatusTest : public testing::Test { 149 class PolicyStatusTest : public testing::Test {
150 protected: 150 protected:
151 PolicyStatusTest() { 151 PolicyStatusTest() {
152 managed_platform_ = new MockConfigurationPolicyReader(); 152 managed_platform_ = new MockConfigurationPolicyReader();
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 entry->name, 337 entry->name,
338 false, 338 false,
339 PolicyStatusInfo::LEVEL_UNDEFINED); 339 PolicyStatusInfo::LEVEL_UNDEFINED);
340 EXPECT_TRUE(undefined_dict->Equals(status_dict)); 340 EXPECT_TRUE(undefined_dict->Equals(status_dict));
341 break; 341 break;
342 } 342 }
343 } 343 }
344 } 344 }
345 345
346 } // namespace policy 346 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/configuration_policy_reader.cc ('k') | chrome/browser/policy/device_policy_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698