Chromium Code Reviews| Index: components/search_engines/default_search_policy_handler_unittest.cc |
| diff --git a/components/search_engines/default_search_policy_handler_unittest.cc b/components/search_engines/default_search_policy_handler_unittest.cc |
| index 3f9c6ac1c4066c95eddb453d17ef1a7c889b356b..b9565d410d0488e346c00c405e5e62e7b803b19a 100644 |
| --- a/components/search_engines/default_search_policy_handler_unittest.cc |
| +++ b/components/search_engines/default_search_policy_handler_unittest.cc |
| @@ -146,6 +146,54 @@ TEST_F(DefaultSearchPolicyHandlerTest, Invalid) { |
| DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp)); |
| } |
| +// Checks that if the default search policy has invalid type for elements, |
| +// that no elements of the default search policy will be present in prefs. |
| +TEST_F(DefaultSearchPolicyHandlerTest, InvalidType) { |
| + // List of policies defined in test policy. |
| + const char* kPolicyNamesToCheck[] = { |
| + key::kDefaultSearchProviderEnabled, |
| + key::kDefaultSearchProviderName, |
| + key::kDefaultSearchProviderKeyword, |
| + key::kDefaultSearchProviderSearchURL, |
| + key::kDefaultSearchProviderSuggestURL, |
| + key::kDefaultSearchProviderIconURL, |
| + key::kDefaultSearchProviderEncodings, |
| + key::kDefaultSearchProviderAlternateURLs, |
| + key::kDefaultSearchProviderSearchTermsReplacementKey, |
| + key::kDefaultSearchProviderImageURL, |
| + key::kDefaultSearchProviderNewTabURL, |
| + key::kDefaultSearchProviderImageURLPostParams |
| + }; |
| + |
| + PolicyMap policy; |
| + BuildDefaultSearchPolicy(&policy); |
| + |
| + for (auto policy_name : kPolicyNamesToCheck) { |
| + // Check that policy can be successfully applied first. |
| + UpdateProviderPolicy(policy); |
| + const base::Value* temp = nullptr; |
| + EXPECT_TRUE(store_->GetValue( |
| + DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp)); |
| + |
| + auto old_value = base::WrapUnique(policy.GetValue(policy_name)->DeepCopy()); |
| + // BinaryValue is not supported in any current default search policy params. |
| + // Try changing policy param to BinaryValue and check that policy becomes |
| + // invalid. |
| + policy.Set(policy_name, POLICY_LEVEL_MANDATORY, |
| + 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.
|
| + base::WrapUnique(new base::BinaryValue()), nullptr); |
| + UpdateProviderPolicy(policy); |
| + |
| + EXPECT_FALSE(store_->GetValue( |
| + DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp)) << |
| + "Policy type check failed " << policy_name; |
| + // Return old value to policy map. |
| + policy.Set(policy_name, POLICY_LEVEL_MANDATORY, |
| + 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.
|
| + std::move(old_value), nullptr); |
| + } |
| +} |
| + |
| // Checks that for a fully defined search policy, all elements have been |
| // read properly into the dictionary pref. |
| TEST_F(DefaultSearchPolicyHandlerTest, FullyDefined) { |
| @@ -315,4 +363,5 @@ TEST_F(DefaultSearchPolicyHandlerTest, FileURL) { |
| EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value)); |
| EXPECT_EQ("_", value); |
| } |
| + |
| } // namespace policy |