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

Side by Side Diff: components/search_engines/default_search_pref_test_util.h

Issue 376413002: Stop using TemplateURLServiceTestUtil to initialize TemplateURLServiceFactory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix TemplateURLServiceWithoutFallbackTest Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_ 5 #ifndef COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_TEST_UTIL_H_
6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_ 6 #define COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_TEST_UTIL_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop.h" 12 #include "base/values.h"
15 #include "base/strings/string16.h" 13 #include "components/search_engines/default_search_manager.h"
16 #include "components/search_engines/template_url_service_observer.h"
17 #include "content/public/test/test_browser_thread_bundle.h"
18 14
19 class GURL; 15 class DefaultSearchPrefTestUtil {
20 class TemplateURLService;
21 class TestingProfile;
22 class TestingTemplateURLService;
23 class TestingProfile;
24
25 // TemplateURLServiceTestUtilBase contains basic API to ease testing of
26 // TemplateURLService. User should take care of the infrastructure separately.
27 class TemplateURLServiceTestUtilBase : public TemplateURLServiceObserver {
28 public: 16 public:
29 TemplateURLServiceTestUtilBase(); 17 // Creates a DictionaryValue which can be used as a
30 virtual ~TemplateURLServiceTestUtilBase(); 18 // kDefaultSearchProviderDataPrefName preference value.
31 19 static scoped_ptr<base::DictionaryValue> CreateDefaultSearchPreferenceValue(
32 void CreateTemplateUrlService();
33
34 // TemplateURLServiceObserver implemementation.
35 virtual void OnTemplateURLServiceChanged() OVERRIDE;
36
37 // Gets the observer count.
38 int GetObserverCount();
39
40 // Sets the observer count to 0.
41 void ResetObserverCount();
42
43 // Makes sure the load was successful and sent the correct notification.
44 void VerifyLoad();
45
46 // Makes the model believe it has been loaded (without actually doing the
47 // load). Since this avoids setting the built-in keyword version, the next
48 // load will do a merge from prepopulated data.
49 void ChangeModelToLoadState();
50
51 // Deletes the current model (and doesn't create a new one).
52 void ClearModel();
53
54 // Creates a new TemplateURLService.
55 void ResetModel(bool verify_load);
56
57 // Returns the search term from the last invocation of
58 // TemplateURLService::SetKeywordSearchTermsForURL and clears the search term.
59 base::string16 GetAndClearSearchTerm();
60
61 // Set the google base url. |base_url| must be valid.
62 void SetGoogleBaseURL(const GURL& base_url) const;
63
64 // Set the managed preferences for the default search provider and trigger
65 // notification. If |alternate_url| is empty, uses an empty list of alternate
66 // URLs, otherwise use a list containing a single entry.
67 void SetManagedDefaultSearchPreferences(
68 bool enabled, 20 bool enabled,
69 const std::string& name, 21 const std::string& name,
70 const std::string& keyword, 22 const std::string& keyword,
71 const std::string& search_url, 23 const std::string& search_url,
72 const std::string& suggest_url, 24 const std::string& suggest_url,
73 const std::string& icon_url, 25 const std::string& icon_url,
74 const std::string& encodings, 26 const std::string& encodings,
75 const std::string& alternate_url, 27 const std::string& alternate_url,
76 const std::string& search_terms_replacement_key); 28 const std::string& search_terms_replacement_key);
77 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
78 // Remove all the managed preferences for the default search provider and 51 // Remove all the managed preferences for the default search provider and
79 // trigger notification. 52 // trigger notification.
80 void RemoveManagedDefaultSearchPreferences(); 53 template<typename TestingPrefService>
81 54 static void RemoveManagedPref(TestingPrefService* pref_service) {
82 // Returns the TemplateURLService. 55 pref_service->RemoveManagedPref(
83 TemplateURLService* model() const; 56 DefaultSearchManager::kDefaultSearchProviderDataPrefName);
84 57 }
85 // Returns the TestingProfile.
86 virtual TestingProfile* profile() const = 0;
87
88 private:
89 int changed_count_;
90
91 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTestUtilBase);
92 }; 58 };
93 59
94 // TemplateURLServiceTestUtil sets up TestingProfile, TemplateURLService and 60 #endif // COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_TEST_UTIL_H_
95 // required threads.
96 class TemplateURLServiceTestUtil : public TemplateURLServiceTestUtilBase {
97 public:
98 TemplateURLServiceTestUtil();
99 virtual ~TemplateURLServiceTestUtil();
100
101 // Sets up the data structures for this class (mirroring gtest standard
102 // methods).
103 void SetUp();
104
105 // Cleans up data structures for this class (mirroring gtest standard
106 // methods).
107 void TearDown();
108
109 // Returns the TestingProfile.
110 virtual TestingProfile* profile() const OVERRIDE;
111
112 private:
113 // Needed to make the DeleteOnUIThread trait of WebDataService work
114 // properly.
115 content::TestBrowserThreadBundle thread_bundle_;
116 scoped_ptr<TestingProfile> profile_;
117 base::ScopedTempDir temp_dir_;
118
119 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTestUtil);
120 };
121
122 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « components/search_engines.gypi ('k') | components/search_engines/default_search_pref_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698