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

Side by Side Diff: components/search_engines/default_search_policy_handler_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
« no previous file with comments | « components/policy_strings.grdp ('k') | components/sync_driver/sync_policy_handler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "components/policy/core/browser/configuration_policy_pref_store.h" 6 #include "components/policy/core/browser/configuration_policy_pref_store.h"
7 #include "components/policy/core/browser/configuration_policy_pref_store_test.h" 7 #include "components/policy/core/browser/configuration_policy_pref_store_test.h"
8 #include "components/policy/core/common/policy_types.h"
8 #include "components/search_engines/default_search_manager.h" 9 #include "components/search_engines/default_search_manager.h"
9 #include "components/search_engines/default_search_policy_handler.h" 10 #include "components/search_engines/default_search_policy_handler.h"
10 #include "components/search_engines/search_engines_pref_names.h" 11 #include "components/search_engines/search_engines_pref_names.h"
11 #include "policy/policy_constants.h" 12 #include "policy/policy_constants.h"
12 13
13 namespace { 14 namespace {
14 // TODO(caitkp): Should we find a way to route this through DefaultSearchManager 15 // TODO(caitkp): Should we find a way to route this through DefaultSearchManager
15 // to avoid hardcoding this here? 16 // to avoid hardcoding this here?
16 const char kDefaultSearchProviderData[] = 17 const char kDefaultSearchProviderData[] =
17 "default_search_provider_data.template_url_data"; 18 "default_search_provider_data.template_url_data";
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 const char DefaultSearchPolicyHandlerTest::kHostName[] = "test.com"; 79 const char DefaultSearchPolicyHandlerTest::kHostName[] = "test.com";
79 80
80 void DefaultSearchPolicyHandlerTest:: 81 void DefaultSearchPolicyHandlerTest::
81 BuildDefaultSearchPolicy(PolicyMap* policy) { 82 BuildDefaultSearchPolicy(PolicyMap* policy) {
82 base::ListValue* encodings = new base::ListValue(); 83 base::ListValue* encodings = new base::ListValue();
83 encodings->AppendString("UTF-16"); 84 encodings->AppendString("UTF-16");
84 encodings->AppendString("UTF-8"); 85 encodings->AppendString("UTF-8");
85 policy->Set(key::kDefaultSearchProviderEnabled, 86 policy->Set(key::kDefaultSearchProviderEnabled,
86 POLICY_LEVEL_MANDATORY, 87 POLICY_LEVEL_MANDATORY,
87 POLICY_SCOPE_USER, 88 POLICY_SCOPE_USER,
89 POLICY_SOURCE_CLOUD,
88 new base::FundamentalValue(true), 90 new base::FundamentalValue(true),
89 NULL); 91 NULL);
90 policy->Set(key::kDefaultSearchProviderSearchURL, 92 policy->Set(key::kDefaultSearchProviderSearchURL,
91 POLICY_LEVEL_MANDATORY, 93 POLICY_LEVEL_MANDATORY,
92 POLICY_SCOPE_USER, 94 POLICY_SCOPE_USER,
95 POLICY_SOURCE_CLOUD,
93 new base::StringValue(kSearchURL), 96 new base::StringValue(kSearchURL),
94 NULL); 97 NULL);
95 policy->Set(key::kDefaultSearchProviderName, 98 policy->Set(key::kDefaultSearchProviderName,
96 POLICY_LEVEL_MANDATORY, 99 POLICY_LEVEL_MANDATORY,
97 POLICY_SCOPE_USER, 100 POLICY_SCOPE_USER,
101 POLICY_SOURCE_CLOUD,
98 new base::StringValue(kName), 102 new base::StringValue(kName),
99 NULL); 103 NULL);
100 policy->Set(key::kDefaultSearchProviderKeyword, 104 policy->Set(key::kDefaultSearchProviderKeyword,
101 POLICY_LEVEL_MANDATORY, 105 POLICY_LEVEL_MANDATORY,
102 POLICY_SCOPE_USER, 106 POLICY_SCOPE_USER,
107 POLICY_SOURCE_CLOUD,
103 new base::StringValue(kKeyword), 108 new base::StringValue(kKeyword),
104 NULL); 109 NULL);
105 policy->Set(key::kDefaultSearchProviderSuggestURL, 110 policy->Set(key::kDefaultSearchProviderSuggestURL,
106 POLICY_LEVEL_MANDATORY, 111 POLICY_LEVEL_MANDATORY,
107 POLICY_SCOPE_USER, 112 POLICY_SCOPE_USER,
113 POLICY_SOURCE_CLOUD,
108 new base::StringValue(kSuggestURL), 114 new base::StringValue(kSuggestURL),
109 NULL); 115 NULL);
110 policy->Set(key::kDefaultSearchProviderIconURL, 116 policy->Set(key::kDefaultSearchProviderIconURL,
111 POLICY_LEVEL_MANDATORY, 117 POLICY_LEVEL_MANDATORY,
112 POLICY_SCOPE_USER, 118 POLICY_SCOPE_USER,
119 POLICY_SOURCE_CLOUD,
113 new base::StringValue(kIconURL), 120 new base::StringValue(kIconURL),
114 NULL); 121 NULL);
115 policy->Set(key::kDefaultSearchProviderEncodings, POLICY_LEVEL_MANDATORY, 122 policy->Set(key::kDefaultSearchProviderEncodings, POLICY_LEVEL_MANDATORY,
116 POLICY_SCOPE_USER, encodings, NULL); 123 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, encodings, nullptr);
117 policy->Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY, 124 policy->Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY,
118 POLICY_SCOPE_USER, default_alternate_urls_.DeepCopy(), NULL); 125 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
126 default_alternate_urls_.DeepCopy(), nullptr);
119 policy->Set(key::kDefaultSearchProviderSearchTermsReplacementKey, 127 policy->Set(key::kDefaultSearchProviderSearchTermsReplacementKey,
120 POLICY_LEVEL_MANDATORY, 128 POLICY_LEVEL_MANDATORY,
121 POLICY_SCOPE_USER, 129 POLICY_SCOPE_USER,
130 POLICY_SOURCE_CLOUD,
122 new base::StringValue(kReplacementKey), 131 new base::StringValue(kReplacementKey),
123 NULL); 132 NULL);
124 policy->Set(key::kDefaultSearchProviderImageURL, 133 policy->Set(key::kDefaultSearchProviderImageURL,
125 POLICY_LEVEL_MANDATORY, 134 POLICY_LEVEL_MANDATORY,
126 POLICY_SCOPE_USER, 135 POLICY_SCOPE_USER,
136 POLICY_SOURCE_CLOUD,
127 new base::StringValue(kImageURL), 137 new base::StringValue(kImageURL),
128 NULL); 138 NULL);
129 policy->Set(key::kDefaultSearchProviderImageURLPostParams, 139 policy->Set(key::kDefaultSearchProviderImageURLPostParams,
130 POLICY_LEVEL_MANDATORY, 140 POLICY_LEVEL_MANDATORY,
131 POLICY_SCOPE_USER, 141 POLICY_SCOPE_USER,
142 POLICY_SOURCE_CLOUD,
132 new base::StringValue(kImageParams), 143 new base::StringValue(kImageParams),
133 NULL); 144 NULL);
134 policy->Set(key::kDefaultSearchProviderNewTabURL, 145 policy->Set(key::kDefaultSearchProviderNewTabURL,
135 POLICY_LEVEL_MANDATORY, 146 POLICY_LEVEL_MANDATORY,
136 POLICY_SCOPE_USER, 147 POLICY_SCOPE_USER,
148 POLICY_SOURCE_CLOUD,
137 new base::StringValue(kNewTabURL), 149 new base::StringValue(kNewTabURL),
138 NULL); 150 NULL);
139 } 151 }
140 152
141 // Checks that if the default search policy is missing, that no elements of the 153 // Checks that if the default search policy is missing, that no elements of the
142 // default search policy will be present. 154 // default search policy will be present.
143 TEST_F(DefaultSearchPolicyHandlerTest, MissingUrl) { 155 TEST_F(DefaultSearchPolicyHandlerTest, MissingUrl) {
144 PolicyMap policy; 156 PolicyMap policy;
145 BuildDefaultSearchPolicy(&policy); 157 BuildDefaultSearchPolicy(&policy);
146 policy.Erase(key::kDefaultSearchProviderSearchURL); 158 policy.Erase(key::kDefaultSearchProviderSearchURL);
147 UpdateProviderPolicy(policy); 159 UpdateProviderPolicy(policy);
148 160
149 const base::Value* temp = nullptr; 161 const base::Value* temp = nullptr;
150 EXPECT_FALSE(store_->GetValue(kDefaultSearchProviderData, &temp)); 162 EXPECT_FALSE(store_->GetValue(kDefaultSearchProviderData, &temp));
151 } 163 }
152 164
153 // Checks that if the default search policy is invalid, that no elements of the 165 // Checks that if the default search policy is invalid, that no elements of the
154 // default search policy will be present. 166 // default search policy will be present.
155 TEST_F(DefaultSearchPolicyHandlerTest, Invalid) { 167 TEST_F(DefaultSearchPolicyHandlerTest, Invalid) {
156 PolicyMap policy; 168 PolicyMap policy;
157 BuildDefaultSearchPolicy(&policy); 169 BuildDefaultSearchPolicy(&policy);
158 const char bad_search_url[] = "http://test.com/noSearchTerms"; 170 const char bad_search_url[] = "http://test.com/noSearchTerms";
159 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, 171 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
160 POLICY_SCOPE_USER, new base::StringValue(bad_search_url), NULL); 172 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
173 new base::StringValue(bad_search_url), nullptr);
161 UpdateProviderPolicy(policy); 174 UpdateProviderPolicy(policy);
162 175
163 const base::Value* temp = nullptr; 176 const base::Value* temp = nullptr;
164 EXPECT_FALSE(store_->GetValue(kDefaultSearchProviderData, &temp)); 177 EXPECT_FALSE(store_->GetValue(kDefaultSearchProviderData, &temp));
165 } 178 }
166 179
167 // Checks that for a fully defined search policy, all elements have been 180 // Checks that for a fully defined search policy, all elements have been
168 // read properly into the dictionary pref. 181 // read properly into the dictionary pref.
169 TEST_F(DefaultSearchPolicyHandlerTest, FullyDefined) { 182 TEST_F(DefaultSearchPolicyHandlerTest, FullyDefined) {
170 PolicyMap policy; 183 PolicyMap policy;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 EXPECT_EQ(std::string(), value); 240 EXPECT_EQ(std::string(), value);
228 } 241 }
229 242
230 // Checks that disabling default search is properly reflected the dictionary 243 // Checks that disabling default search is properly reflected the dictionary
231 // pref. 244 // pref.
232 TEST_F(DefaultSearchPolicyHandlerTest, Disabled) { 245 TEST_F(DefaultSearchPolicyHandlerTest, Disabled) {
233 PolicyMap policy; 246 PolicyMap policy;
234 policy.Set(key::kDefaultSearchProviderEnabled, 247 policy.Set(key::kDefaultSearchProviderEnabled,
235 POLICY_LEVEL_MANDATORY, 248 POLICY_LEVEL_MANDATORY,
236 POLICY_SCOPE_USER, 249 POLICY_SCOPE_USER,
250 POLICY_SOURCE_CLOUD,
237 new base::FundamentalValue(false), 251 new base::FundamentalValue(false),
238 NULL); 252 NULL);
239 UpdateProviderPolicy(policy); 253 UpdateProviderPolicy(policy);
240 const base::Value* temp = NULL; 254 const base::Value* temp = NULL;
241 const base::DictionaryValue* dictionary; 255 const base::DictionaryValue* dictionary;
242 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp)); 256 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
243 temp->GetAsDictionary(&dictionary); 257 temp->GetAsDictionary(&dictionary);
244 bool disabled = false; 258 bool disabled = false;
245 EXPECT_TRUE(dictionary->GetBoolean(DefaultSearchManager::kDisabledByPolicy, 259 EXPECT_TRUE(dictionary->GetBoolean(DefaultSearchManager::kDisabledByPolicy,
246 &disabled)); 260 &disabled));
247 EXPECT_TRUE(disabled); 261 EXPECT_TRUE(disabled);
248 } 262 }
249 263
250 // Checks that if the policy for default search is valid, i.e. there's a 264 // Checks that if the policy for default search is valid, i.e. there's a
251 // search URL, that all the elements have been given proper defaults. 265 // search URL, that all the elements have been given proper defaults.
252 TEST_F(DefaultSearchPolicyHandlerTest, MinimallyDefined) { 266 TEST_F(DefaultSearchPolicyHandlerTest, MinimallyDefined) {
253 PolicyMap policy; 267 PolicyMap policy;
254 policy.Set(key::kDefaultSearchProviderEnabled, 268 policy.Set(key::kDefaultSearchProviderEnabled,
255 POLICY_LEVEL_MANDATORY, 269 POLICY_LEVEL_MANDATORY,
256 POLICY_SCOPE_USER, 270 POLICY_SCOPE_USER,
271 POLICY_SOURCE_CLOUD,
257 new base::FundamentalValue(true), 272 new base::FundamentalValue(true),
258 NULL); 273 NULL);
259 policy.Set(key::kDefaultSearchProviderSearchURL, 274 policy.Set(key::kDefaultSearchProviderSearchURL,
260 POLICY_LEVEL_MANDATORY, 275 POLICY_LEVEL_MANDATORY,
261 POLICY_SCOPE_USER, 276 POLICY_SCOPE_USER,
277 POLICY_SOURCE_CLOUD,
262 new base::StringValue(kSearchURL), 278 new base::StringValue(kSearchURL),
263 NULL); 279 NULL);
264 UpdateProviderPolicy(policy); 280 UpdateProviderPolicy(policy);
265 281
266 const base::Value* temp = NULL; 282 const base::Value* temp = NULL;
267 const base::DictionaryValue* dictionary; 283 const base::DictionaryValue* dictionary;
268 std::string value; 284 std::string value;
269 const base::ListValue* list_value; 285 const base::ListValue* list_value;
270 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp)); 286 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
271 temp->GetAsDictionary(&dictionary); 287 temp->GetAsDictionary(&dictionary);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 EXPECT_EQ(std::string(), value); 325 EXPECT_EQ(std::string(), value);
310 } 326 }
311 327
312 // Checks that setting a file URL as the default search is reflected properly in 328 // Checks that setting a file URL as the default search is reflected properly in
313 // the dictionary pref. 329 // the dictionary pref.
314 TEST_F(DefaultSearchPolicyHandlerTest, FileURL) { 330 TEST_F(DefaultSearchPolicyHandlerTest, FileURL) {
315 PolicyMap policy; 331 PolicyMap policy;
316 policy.Set(key::kDefaultSearchProviderEnabled, 332 policy.Set(key::kDefaultSearchProviderEnabled,
317 POLICY_LEVEL_MANDATORY, 333 POLICY_LEVEL_MANDATORY,
318 POLICY_SCOPE_USER, 334 POLICY_SCOPE_USER,
335 POLICY_SOURCE_CLOUD,
319 new base::FundamentalValue(true), 336 new base::FundamentalValue(true),
320 NULL); 337 NULL);
321 policy.Set(key::kDefaultSearchProviderSearchURL, 338 policy.Set(key::kDefaultSearchProviderSearchURL,
322 POLICY_LEVEL_MANDATORY, 339 POLICY_LEVEL_MANDATORY,
323 POLICY_SCOPE_USER, 340 POLICY_SCOPE_USER,
341 POLICY_SOURCE_CLOUD,
324 new base::StringValue(kFileSearchURL), 342 new base::StringValue(kFileSearchURL),
325 NULL); 343 NULL);
326 UpdateProviderPolicy(policy); 344 UpdateProviderPolicy(policy);
327 345
328 const base::Value* temp = NULL; 346 const base::Value* temp = NULL;
329 const base::DictionaryValue* dictionary; 347 const base::DictionaryValue* dictionary;
330 std::string value; 348 std::string value;
331 349
332 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp)); 350 EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
333 temp->GetAsDictionary(&dictionary); 351 temp->GetAsDictionary(&dictionary);
334 352
335 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value)); 353 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value));
336 EXPECT_EQ(kFileSearchURL, value); 354 EXPECT_EQ(kFileSearchURL, value);
337 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value)); 355 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value));
338 EXPECT_EQ("_", value); 356 EXPECT_EQ("_", value);
339 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value)); 357 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value));
340 EXPECT_EQ("_", value); 358 EXPECT_EQ("_", value);
341 } 359 }
342 } // namespace policy 360 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy_strings.grdp ('k') | components/sync_driver/sync_policy_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698