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

Side by Side Diff: components/search_engines/default_search_policy_handler_unittest.cc

Issue 2598033004: Remove old default search preferences. (Closed)
Patch Set: Fixed after review, added value type checks for policies, added unittest Created 3 years, 11 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 "components/search_engines/default_search_policy_handler.h" 5 #include "components/search_engines/default_search_policy_handler.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "components/policy/core/browser/configuration_policy_pref_store.h" 10 #include "components/policy/core/browser/configuration_policy_pref_store.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, 139 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
140 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 140 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
141 base::WrapUnique(new base::StringValue(bad_search_url)), nullptr); 141 base::WrapUnique(new base::StringValue(bad_search_url)), nullptr);
142 UpdateProviderPolicy(policy); 142 UpdateProviderPolicy(policy);
143 143
144 const base::Value* temp = nullptr; 144 const base::Value* temp = nullptr;
145 EXPECT_FALSE(store_->GetValue( 145 EXPECT_FALSE(store_->GetValue(
146 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp)); 146 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp));
147 } 147 }
148 148
149 // Checks that if the default search policy has invalid type for elements,
150 // that no elements of the default search policy will be present in prefs.
151 TEST_F(DefaultSearchPolicyHandlerTest, InvalidType) {
152 // List of policies defined in test policy.
153 const char* kPolicyNamesToCheck[] = {
154 key::kDefaultSearchProviderEnabled,
155 key::kDefaultSearchProviderName,
156 key::kDefaultSearchProviderKeyword,
157 key::kDefaultSearchProviderSearchURL,
158 key::kDefaultSearchProviderSuggestURL,
159 key::kDefaultSearchProviderIconURL,
160 key::kDefaultSearchProviderEncodings,
161 key::kDefaultSearchProviderAlternateURLs,
162 key::kDefaultSearchProviderSearchTermsReplacementKey,
163 key::kDefaultSearchProviderImageURL,
164 key::kDefaultSearchProviderNewTabURL,
165 key::kDefaultSearchProviderImageURLPostParams
166 };
167
168 PolicyMap policy;
169 BuildDefaultSearchPolicy(&policy);
170
171 for (auto policy_name : kPolicyNamesToCheck) {
172 // Check that policy can be successfully applied first.
173 UpdateProviderPolicy(policy);
174 const base::Value* temp = nullptr;
175 EXPECT_TRUE(store_->GetValue(
176 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp));
177
178 auto old_value = base::WrapUnique(policy.GetValue(policy_name)->DeepCopy());
179 // BinaryValue is not supported in any current default search policy params.
180 // Try changing policy param to BinaryValue and check that policy becomes
181 // invalid.
182 policy.Set(policy_name, POLICY_LEVEL_MANDATORY,
183 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
Peter Kasting 2017/01/09 22:00:06 Nit: Indentation
Alexander Yashkin 2017/01/10 05:01:44 Done.
184 base::WrapUnique(new base::BinaryValue()), nullptr);
185 UpdateProviderPolicy(policy);
186
187 EXPECT_FALSE(store_->GetValue(
188 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp)) <<
189 "Policy type check failed " << policy_name;
190 // Return old value to policy map.
191 policy.Set(policy_name, POLICY_LEVEL_MANDATORY,
192 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
Peter Kasting 2017/01/09 22:00:06 Nit: Indentation
Alexander Yashkin 2017/01/10 05:01:44 Done.
193 std::move(old_value), nullptr);
194 }
195 }
196
149 // Checks that for a fully defined search policy, all elements have been 197 // Checks that for a fully defined search policy, all elements have been
150 // read properly into the dictionary pref. 198 // read properly into the dictionary pref.
151 TEST_F(DefaultSearchPolicyHandlerTest, FullyDefined) { 199 TEST_F(DefaultSearchPolicyHandlerTest, FullyDefined) {
152 PolicyMap policy; 200 PolicyMap policy;
153 BuildDefaultSearchPolicy(&policy); 201 BuildDefaultSearchPolicy(&policy);
154 UpdateProviderPolicy(policy); 202 UpdateProviderPolicy(policy);
155 203
156 const base::Value* temp = NULL; 204 const base::Value* temp = NULL;
157 const base::DictionaryValue* dictionary; 205 const base::DictionaryValue* dictionary;
158 std::string value; 206 std::string value;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp)); 356 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp));
309 temp->GetAsDictionary(&dictionary); 357 temp->GetAsDictionary(&dictionary);
310 358
311 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value)); 359 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value));
312 EXPECT_EQ(kFileSearchURL, value); 360 EXPECT_EQ(kFileSearchURL, value);
313 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value)); 361 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value));
314 EXPECT_EQ("_", value); 362 EXPECT_EQ("_", value);
315 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value)); 363 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value));
316 EXPECT_EQ("_", value); 364 EXPECT_EQ("_", value);
317 } 365 }
366
318 } // namespace policy 367 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698