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 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_TEST_UTIL_H_ 6 #define COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_TEST_UTIL_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "base/values.h" 13 #include "components/search_engines/default_search_manager.h" 14 15 class DefaultSearchPrefTestUtil { 16 public: 17 // Creates a DictionaryValue which can be used as a 18 // kDefaultSearchProviderDataPrefName preference value. 19 static scoped_ptr<base::DictionaryValue> CreateDefaultSearchPreferenceValue( 20 bool enabled, 21 const std::string& name, 22 const std::string& keyword, 23 const std::string& search_url, 24 const std::string& suggest_url, 25 const std::string& icon_url, 26 const std::string& encodings, 27 const std::string& alternate_url, 28 const std::string& search_terms_replacement_key); 29 30 // Set the managed preferences for the default search provider and trigger 31 // notification. If |alternate_url| is empty, uses an empty list of alternate 32 // URLs, otherwise use a list containing a single entry. 33 template<typename TestingPrefService> 34 static void SetManagedPref(TestingPrefService* pref_service, 35 bool enabled, 36 const std::string& name, 37 const std::string& keyword, 38 const std::string& search_url, 39 const std::string& suggest_url, 40 const std::string& icon_url, 41 const std::string& encodings, 42 const std::string& alternate_url, 43 const std::string& search_terms_replacement_key) { 44 pref_service->SetManagedPref( 45 DefaultSearchManager::kDefaultSearchProviderDataPrefName, 46 CreateDefaultSearchPreferenceValue( 47 enabled, name, keyword, search_url, suggest_url, icon_url, 48 encodings, alternate_url, search_terms_replacement_key).release()); 49 } 50 51 // Remove all the managed preferences for the default search provider and 52 // trigger notification. 53 template<typename TestingPrefService> 54 static void RemoveManagedPref(TestingPrefService* pref_service) { 55 pref_service->RemoveManagedPref( 56 DefaultSearchManager::kDefaultSearchProviderDataPrefName); 57 } 58 }; 59 60 #endif // COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_TEST_UTIL_H_ 61