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

Side by Side Diff: chrome/browser/search_engines/template_url_service_test_util.h

Issue 376413002: Stop using TemplateURLServiceTestUtil to initialize TemplateURLServiceFactory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add DefaultSearchPrefTestUtil 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 (c) 2012 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 CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_
6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_ 6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_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" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop.h"
15 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
16 #include "components/search_engines/template_url_service_observer.h" 14 #include "components/search_engines/template_url_service_observer.h"
17 #include "content/public/test/test_browser_thread_bundle.h" 15 #include "content/public/test/test_browser_thread_bundle.h"
18 16
19 class GURL; 17 class GURL;
20 class TemplateURLService; 18 class TemplateURLService;
21 class TestingProfile; 19 class TestingProfile;
22 class TestingTemplateURLService; 20 class TestingTemplateURLService;
23 class TestingProfile;
24 21
25 // TemplateURLServiceTestUtilBase contains basic API to ease testing of 22 class TemplateURLServiceTestUtil : public TemplateURLServiceObserver {
26 // TemplateURLService. User should take care of the infrastructure separately.
27 class TemplateURLServiceTestUtilBase : public TemplateURLServiceObserver {
28 public: 23 public:
29 TemplateURLServiceTestUtilBase(); 24 TemplateURLServiceTestUtil();
30 virtual ~TemplateURLServiceTestUtilBase(); 25 virtual ~TemplateURLServiceTestUtil();
31 26
32 void CreateTemplateUrlService(); 27 // Sets up the data structures for this class (mirroring gtest standard
28 // methods).
29 void SetUp();
Peter Kasting 2014/07/15 18:48:58 Can these also be moved into the constructor/destr
hashimoto 2014/07/16 03:20:59 ASSERT_TRUE cannot be moved into the ctor so at le
Peter Kasting 2014/07/16 05:38:12 Shrug, you could just nuke the ASSERT_TRUE.
30
31 // Cleans up data structures for this class (mirroring gtest standard
Peter Kasting 2014/07/15 18:48:58 Nit: Extra space
hashimoto 2014/07/16 03:20:59 Done.
32 // methods).
33 void TearDown();
33 34
34 // TemplateURLServiceObserver implemementation. 35 // TemplateURLServiceObserver implemementation.
35 virtual void OnTemplateURLServiceChanged() OVERRIDE; 36 virtual void OnTemplateURLServiceChanged() OVERRIDE;
36 37
37 // Gets the observer count. 38 // Gets the observer count.
38 int GetObserverCount(); 39 int GetObserverCount();
39 40
40 // Sets the observer count to 0. 41 // Sets the observer count to 0.
41 void ResetObserverCount(); 42 void ResetObserverCount();
42 43
43 // Makes sure the load was successful and sent the correct notification. 44 // Makes sure the load was successful and sent the correct notification.
44 void VerifyLoad(); 45 void VerifyLoad();
45 46
46 // Makes the model believe it has been loaded (without actually doing the 47 // 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). Since this avoids setting the built-in keyword version, the next
48 // load will do a merge from prepopulated data. 49 // load will do a merge from prepopulated data.
49 void ChangeModelToLoadState(); 50 void ChangeModelToLoadState();
50 51
51 // Deletes the current model (and doesn't create a new one). 52 // Deletes the current model (and doesn't create a new one).
52 void ClearModel(); 53 void ClearModel();
53 54
54 // Creates a new TemplateURLService. 55 // Creates a new TemplateURLService.
55 void ResetModel(bool verify_load); 56 void ResetModel(bool verify_load);
56 57
57 // Returns the search term from the last invocation of 58 // Returns the search term from the last invocation of
58 // TemplateURLService::SetKeywordSearchTermsForURL and clears the search term. 59 // TemplateURLService::SetKeywordSearchTermsForURL and clears the search term.
59 base::string16 GetAndClearSearchTerm(); 60 base::string16 GetAndClearSearchTerm();
60 61
61 // Set the google base url. |base_url| must be valid. 62 // Set the google base url. |base_url| must be valid.
62 void SetGoogleBaseURL(const GURL& base_url) const; 63 void SetGoogleBaseURL(const GURL& base_url);
63 64
64 // Set the managed preferences for the default search provider and trigger 65 // 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 // notification. If |alternate_url| is empty, uses an empty list of alternate
66 // URLs, otherwise use a list containing a single entry. 67 // URLs, otherwise use a list containing a single entry.
67 void SetManagedDefaultSearchPreferences( 68 void SetManagedDefaultSearchPreferences(
68 bool enabled, 69 bool enabled,
69 const std::string& name, 70 const std::string& name,
70 const std::string& keyword, 71 const std::string& keyword,
71 const std::string& search_url, 72 const std::string& search_url,
72 const std::string& suggest_url, 73 const std::string& suggest_url,
73 const std::string& icon_url, 74 const std::string& icon_url,
74 const std::string& encodings, 75 const std::string& encodings,
75 const std::string& alternate_url, 76 const std::string& alternate_url,
76 const std::string& search_terms_replacement_key); 77 const std::string& search_terms_replacement_key);
77 78
78 // Remove all the managed preferences for the default search provider and 79 // Remove all the managed preferences for the default search provider and
79 // trigger notification. 80 // trigger notification.
80 void RemoveManagedDefaultSearchPreferences(); 81 void RemoveManagedDefaultSearchPreferences();
81 82
82 // Returns the TemplateURLService. 83 // Returns the TemplateURLService.
83 TemplateURLService* model() const; 84 TemplateURLService* model();
84 85
85 // Returns the TestingProfile. 86 // Returns the TestingProfile.
86 virtual TestingProfile* profile() const = 0; 87 TestingProfile* profile() { return profile_.get(); }
87 88
88 private: 89 private:
89 int changed_count_;
90
91 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTestUtilBase);
92 };
93
94 // TemplateURLServiceTestUtil sets up TestingProfile, TemplateURLService and
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_; 90 content::TestBrowserThreadBundle thread_bundle_;
116 scoped_ptr<TestingProfile> profile_; 91 scoped_ptr<TestingProfile> profile_;
117 base::ScopedTempDir temp_dir_; 92 base::ScopedTempDir temp_dir_;
93 int changed_count_;
94 scoped_ptr<TestingTemplateURLService> model_;
118 95
119 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTestUtil); 96 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTestUtil);
120 }; 97 };
121 98
122 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_ 99 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698