summaryrefslogtreecommitdiffstats
path: root/components/search_engines
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-17 07:39:05 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-17 07:39:05 +0000
commit7d0d3743d253348452d2c5b055d30d50b4f7c2b5 (patch)
tree8f4565cdfac85a4cd304720526e753abc71276a8 /components/search_engines
parent1ea46f6fe0aa266d4b1ff2a0c4f6039633fd36e6 (diff)
downloadchromium_src-7d0d3743d253348452d2c5b055d30d50b4f7c2b5.zip
chromium_src-7d0d3743d253348452d2c5b055d30d50b4f7c2b5.tar.gz
chromium_src-7d0d3743d253348452d2c5b055d30d50b4f7c2b5.tar.bz2
Stop using TemplateURLServiceTestUtil to initialize TemplateURLServiceFactory
To drop all dependencies on chrome, TemplateURLServiceTestUtil is going to stop interact with TemplateURLServiceFactory. All tests which have used the util to initialize the factory are rewritten to do it with TemplateURLServiceFactoryTestUtil. BUG=387985 TEST=unit_tests TBR=sky@chromium.org for an include removal in ui_test_utils.cc Review URL: https://codereview.chromium.org/376413002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283695 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/search_engines')
-rw-r--r--components/search_engines/default_search_pref_test_util.cc60
-rw-r--r--components/search_engines/default_search_pref_test_util.h60
-rw-r--r--components/search_engines/template_url_service.h2
3 files changed, 121 insertions, 1 deletions
diff --git a/components/search_engines/default_search_pref_test_util.cc b/components/search_engines/default_search_pref_test_util.cc
new file mode 100644
index 0000000..f3041b6
--- /dev/null
+++ b/components/search_engines/default_search_pref_test_util.cc
@@ -0,0 +1,60 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/search_engines/default_search_pref_test_util.h"
+
+#include "base/strings/string_split.h"
+#include "components/search_engines/default_search_manager.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+// static
+scoped_ptr<base::DictionaryValue>
+DefaultSearchPrefTestUtil::CreateDefaultSearchPreferenceValue(
+ bool enabled,
+ const std::string& name,
+ const std::string& keyword,
+ const std::string& search_url,
+ const std::string& suggest_url,
+ const std::string& icon_url,
+ const std::string& encodings,
+ const std::string& alternate_url,
+ const std::string& search_terms_replacement_key) {
+ scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue);
+ if (!enabled) {
+ value->SetBoolean(DefaultSearchManager::kDisabledByPolicy, true);
+ return value.Pass();
+ }
+
+ EXPECT_FALSE(keyword.empty());
+ EXPECT_FALSE(search_url.empty());
+ value->Set(DefaultSearchManager::kShortName,
+ base::Value::CreateStringValue(name));
+ value->Set(DefaultSearchManager::kKeyword,
+ base::Value::CreateStringValue(keyword));
+ value->Set(DefaultSearchManager::kURL,
+ base::Value::CreateStringValue(search_url));
+ value->Set(DefaultSearchManager::kSuggestionsURL,
+ base::Value::CreateStringValue(suggest_url));
+ value->Set(DefaultSearchManager::kFaviconURL,
+ base::Value::CreateStringValue(icon_url));
+ value->Set(DefaultSearchManager::kSearchTermsReplacementKey,
+ base::Value::CreateStringValue(search_terms_replacement_key));
+
+ std::vector<std::string> encodings_items;
+ base::SplitString(encodings, ';', &encodings_items);
+ scoped_ptr<base::ListValue> encodings_list(new base::ListValue);
+ for (std::vector<std::string>::const_iterator it = encodings_items.begin();
+ it != encodings_items.end();
+ ++it) {
+ encodings_list->AppendString(*it);
+ }
+ value->Set(DefaultSearchManager::kInputEncodings, encodings_list.release());
+
+ scoped_ptr<base::ListValue> alternate_url_list(new base::ListValue());
+ if (!alternate_url.empty())
+ alternate_url_list->Append(base::Value::CreateStringValue(alternate_url));
+ value->Set(DefaultSearchManager::kAlternateURLs,
+ alternate_url_list.release());
+ return value.Pass();
+}
diff --git a/components/search_engines/default_search_pref_test_util.h b/components/search_engines/default_search_pref_test_util.h
new file mode 100644
index 0000000..53484e6
--- /dev/null
+++ b/components/search_engines/default_search_pref_test_util.h
@@ -0,0 +1,60 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_TEST_UTIL_H_
+#define COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_TEST_UTIL_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+#include "components/search_engines/default_search_manager.h"
+
+class DefaultSearchPrefTestUtil {
+ public:
+ // Creates a DictionaryValue which can be used as a
+ // kDefaultSearchProviderDataPrefName preference value.
+ static scoped_ptr<base::DictionaryValue> CreateDefaultSearchPreferenceValue(
+ bool enabled,
+ const std::string& name,
+ const std::string& keyword,
+ const std::string& search_url,
+ const std::string& suggest_url,
+ const std::string& icon_url,
+ const std::string& encodings,
+ const std::string& alternate_url,
+ const std::string& search_terms_replacement_key);
+
+ // Set the managed preferences for the default search provider and trigger
+ // notification. If |alternate_url| is empty, uses an empty list of alternate
+ // URLs, otherwise use a list containing a single entry.
+ template<typename TestingPrefService>
+ static void SetManagedPref(TestingPrefService* pref_service,
+ bool enabled,
+ const std::string& name,
+ const std::string& keyword,
+ const std::string& search_url,
+ const std::string& suggest_url,
+ const std::string& icon_url,
+ const std::string& encodings,
+ const std::string& alternate_url,
+ const std::string& search_terms_replacement_key) {
+ pref_service->SetManagedPref(
+ DefaultSearchManager::kDefaultSearchProviderDataPrefName,
+ CreateDefaultSearchPreferenceValue(
+ enabled, name, keyword, search_url, suggest_url, icon_url,
+ encodings, alternate_url, search_terms_replacement_key).release());
+ }
+
+ // Remove all the managed preferences for the default search provider and
+ // trigger notification.
+ template<typename TestingPrefService>
+ static void RemoveManagedPref(TestingPrefService* pref_service) {
+ pref_service->RemoveManagedPref(
+ DefaultSearchManager::kDefaultSearchProviderDataPrefName);
+ }
+};
+
+#endif // COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_TEST_UTIL_H_
diff --git a/components/search_engines/template_url_service.h b/components/search_engines/template_url_service.h
index da49772..3e4f19a 100644
--- a/components/search_engines/template_url_service.h
+++ b/components/search_engines/template_url_service.h
@@ -399,7 +399,7 @@ class TemplateURLService : public WebDataServiceConsumer,
FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, MergeInSyncTemplateURL);
friend class InstantUnitTestBase;
- friend class TemplateURLServiceTestUtilBase;
+ friend class TemplateURLServiceTestUtil;
typedef std::map<base::string16, TemplateURL*> KeywordToTemplateMap;
typedef std::map<std::string, TemplateURL*> GUIDToTemplateMap;