| OLD | NEW |
| 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 Loading... |
| 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 PolicyMap policy; |
| 168 BuildDefaultSearchPolicy(&policy); |
| 169 |
| 170 for (auto policy_name : kPolicyNamesToCheck) { |
| 171 // Check that policy can be successfully applied first. |
| 172 UpdateProviderPolicy(policy); |
| 173 const base::Value* temp = nullptr; |
| 174 EXPECT_TRUE(store_->GetValue( |
| 175 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp)); |
| 176 |
| 177 auto old_value = base::WrapUnique(policy.GetValue(policy_name)->DeepCopy()); |
| 178 // BinaryValue is not supported in any current default search policy params. |
| 179 // Try changing policy param to BinaryValue and check that policy becomes |
| 180 // invalid. |
| 181 policy.Set(policy_name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 182 POLICY_SOURCE_CLOUD, base::WrapUnique(new base::BinaryValue()), |
| 183 nullptr); |
| 184 UpdateProviderPolicy(policy); |
| 185 |
| 186 EXPECT_FALSE(store_->GetValue( |
| 187 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp)) |
| 188 << "Policy type check failed " << policy_name; |
| 189 // Return old value to policy map. |
| 190 policy.Set(policy_name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 191 POLICY_SOURCE_CLOUD, std::move(old_value), nullptr); |
| 192 } |
| 193 } |
| 194 |
| 149 // Checks that for a fully defined search policy, all elements have been | 195 // Checks that for a fully defined search policy, all elements have been |
| 150 // read properly into the dictionary pref. | 196 // read properly into the dictionary pref. |
| 151 TEST_F(DefaultSearchPolicyHandlerTest, FullyDefined) { | 197 TEST_F(DefaultSearchPolicyHandlerTest, FullyDefined) { |
| 152 PolicyMap policy; | 198 PolicyMap policy; |
| 153 BuildDefaultSearchPolicy(&policy); | 199 BuildDefaultSearchPolicy(&policy); |
| 154 UpdateProviderPolicy(policy); | 200 UpdateProviderPolicy(policy); |
| 155 | 201 |
| 156 const base::Value* temp = NULL; | 202 const base::Value* temp = NULL; |
| 157 const base::DictionaryValue* dictionary; | 203 const base::DictionaryValue* dictionary; |
| 158 std::string value; | 204 std::string value; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp)); | 354 DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp)); |
| 309 temp->GetAsDictionary(&dictionary); | 355 temp->GetAsDictionary(&dictionary); |
| 310 | 356 |
| 311 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value)); | 357 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value)); |
| 312 EXPECT_EQ(kFileSearchURL, value); | 358 EXPECT_EQ(kFileSearchURL, value); |
| 313 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value)); | 359 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kShortName, &value)); |
| 314 EXPECT_EQ("_", value); | 360 EXPECT_EQ("_", value); |
| 315 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value)); | 361 EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value)); |
| 316 EXPECT_EQ("_", value); | 362 EXPECT_EQ("_", value); |
| 317 } | 363 } |
| 364 |
| 318 } // namespace policy | 365 } // namespace policy |
| OLD | NEW |