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

Side by Side Diff: chrome/browser/search_engines/template_url_service_factory_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 CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_FACTORY_TEST_UTIL_H_
6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_ 6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_FACTORY_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"
14 #include "base/message_loop/message_loop.h"
15 #include "base/strings/string16.h"
16 #include "components/search_engines/template_url_service_observer.h"
17 #include "content/public/test/test_browser_thread_bundle.h"
18 11
19 class GURL;
20 class TemplateURLService; 12 class TemplateURLService;
21 class TestingProfile; 13 class TestingProfile;
22 class TestingTemplateURLService;
23 class TestingProfile;
24 14
25 // TemplateURLServiceTestUtilBase contains basic API to ease testing of 15 // TemplateURLServiceFactoryTestUtil initializes TemplateURLServiceFactory to
26 // TemplateURLService. User should take care of the infrastructure separately. 16 // return a valid TemplateURLService instance for the given profile.
27 class TemplateURLServiceTestUtilBase : public TemplateURLServiceObserver { 17 class TemplateURLServiceFactoryTestUtil {
28 public: 18 public:
29 TemplateURLServiceTestUtilBase(); 19 explicit TemplateURLServiceFactoryTestUtil(TestingProfile* profile);
30 virtual ~TemplateURLServiceTestUtilBase(); 20 virtual ~TemplateURLServiceFactoryTestUtil();
31 21
32 void CreateTemplateUrlService(); 22 // Makes sure the load was successful.
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(); 23 void VerifyLoad();
45 24
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 25 // Set the managed preferences for the default search provider and trigger
65 // notification. If |alternate_url| is empty, uses an empty list of alternate 26 // notification. If |alternate_url| is empty, uses an empty list of alternate
66 // URLs, otherwise use a list containing a single entry. 27 // URLs, otherwise use a list containing a single entry.
67 void SetManagedDefaultSearchPreferences( 28 void SetManagedDefaultSearchPreferences(
68 bool enabled, 29 bool enabled,
69 const std::string& name, 30 const std::string& name,
70 const std::string& keyword, 31 const std::string& keyword,
71 const std::string& search_url, 32 const std::string& search_url,
72 const std::string& suggest_url, 33 const std::string& suggest_url,
73 const std::string& icon_url, 34 const std::string& icon_url,
74 const std::string& encodings, 35 const std::string& encodings,
75 const std::string& alternate_url, 36 const std::string& alternate_url,
76 const std::string& search_terms_replacement_key); 37 const std::string& search_terms_replacement_key);
77 38
78 // Remove all the managed preferences for the default search provider and 39 // Remove all the managed preferences for the default search provider and
79 // trigger notification. 40 // trigger notification.
80 void RemoveManagedDefaultSearchPreferences(); 41 void RemoveManagedDefaultSearchPreferences();
81 42
82 // Returns the TemplateURLService. 43 // Returns the TemplateURLService.
83 TemplateURLService* model() const; 44 TemplateURLService* model() const;
84 45
85 // Returns the TestingProfile. 46 private:
86 virtual TestingProfile* profile() const = 0; 47 TestingProfile* profile_;
87 48
88 private: 49 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceFactoryTestUtil);
89 int changed_count_;
90
91 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTestUtilBase);
92 }; 50 };
93 51
94 // TemplateURLServiceTestUtil sets up TestingProfile, TemplateURLService and 52 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_FACTORY_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

Powered by Google App Engine
This is Rietveld 408576698