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

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

Issue 2541493002: Refactor search_engines tests to better reuse code (Closed)
Patch Set: Fixed after review Created 4 years 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
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 <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "components/search_engines/template_url_data.h"
15 #include "components/search_engines/template_url_service_observer.h" 16 #include "components/search_engines/template_url_service_observer.h"
16 17
17 class GURL; 18 class GURL;
18 class KeywordWebDataService; 19 class KeywordWebDataService;
19 class TemplateURLService; 20 class TemplateURLService;
20 class TestingProfile; 21 class TestingProfile;
21 class TestingSearchTermsData; 22 class TestingSearchTermsData;
22 23
24 // Sets the managed preferences for the default search provider.
25 // enabled arg enables/disables use of managed engine by DefaultSearchManager.
26 void SetManagedDefaultSearchPreferences(const TemplateURLData& managed_data,
27 bool enabled,
28 TestingProfile* profile);
29
30 // Removes all the managed preferences for the default search provider.
31 void RemoveManagedDefaultSearchPreferences(TestingProfile* profile);
32
23 class TemplateURLServiceTestUtil : public TemplateURLServiceObserver { 33 class TemplateURLServiceTestUtil : public TemplateURLServiceObserver {
24 public: 34 public:
25 TemplateURLServiceTestUtil(); 35 TemplateURLServiceTestUtil();
26 ~TemplateURLServiceTestUtil() override; 36 ~TemplateURLServiceTestUtil() override;
27 37
28 // TemplateURLServiceObserver implemementation. 38 // TemplateURLServiceObserver implemementation.
29 void OnTemplateURLServiceChanged() override; 39 void OnTemplateURLServiceChanged() override;
30 40
31 // Gets the observer count. 41 // Gets the observer count.
32 int GetObserverCount(); 42 int GetObserverCount();
(...skipping 15 matching lines...) Expand all
48 // Creates a new TemplateURLService. 58 // Creates a new TemplateURLService.
49 void ResetModel(bool verify_load); 59 void ResetModel(bool verify_load);
50 60
51 // Returns the search term from the last invocation of 61 // Returns the search term from the last invocation of
52 // TemplateURLService::SetKeywordSearchTermsForURL and clears the search term. 62 // TemplateURLService::SetKeywordSearchTermsForURL and clears the search term.
53 base::string16 GetAndClearSearchTerm(); 63 base::string16 GetAndClearSearchTerm();
54 64
55 // Sets the google base url. |base_url| must be valid. 65 // Sets the google base url. |base_url| must be valid.
56 void SetGoogleBaseURL(const GURL& base_url); 66 void SetGoogleBaseURL(const GURL& base_url);
57 67
58 // Sets the managed preferences for the default search provider and trigger
59 // notification. If |alternate_url| is empty, uses an empty list of alternate
60 // URLs, otherwise uses a list containing a single entry.
61 void SetManagedDefaultSearchPreferences(
62 bool enabled,
63 const std::string& name,
64 const std::string& keyword,
65 const std::string& search_url,
66 const std::string& suggest_url,
67 const std::string& icon_url,
68 const std::string& encodings,
69 const std::string& alternate_url,
70 const std::string& search_terms_replacement_key);
71
72 // Removes all the managed preferences for the default search provider and
73 // triggers notification.
74 void RemoveManagedDefaultSearchPreferences();
75
76 KeywordWebDataService* web_data_service() { return web_data_service_.get(); } 68 KeywordWebDataService* web_data_service() { return web_data_service_.get(); }
77 TemplateURLService* model() { return model_.get(); } 69 TemplateURLService* model() { return model_.get(); }
78 TestingProfile* profile() { return profile_.get(); } 70 TestingProfile* profile() { return profile_.get(); }
79 71
80 private: 72 private:
81 std::unique_ptr<TestingProfile> profile_; 73 std::unique_ptr<TestingProfile> profile_;
82 base::ScopedTempDir temp_dir_; 74 base::ScopedTempDir temp_dir_;
83 int changed_count_; 75 int changed_count_;
84 base::string16 search_term_; 76 base::string16 search_term_;
85 scoped_refptr<KeywordWebDataService> web_data_service_; 77 scoped_refptr<KeywordWebDataService> web_data_service_;
86 TestingSearchTermsData* search_terms_data_; 78 TestingSearchTermsData* search_terms_data_;
87 std::unique_ptr<TemplateURLService> model_; 79 std::unique_ptr<TemplateURLService> model_;
88 80
89 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTestUtil); 81 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceTestUtil);
90 }; 82 };
91 83
92 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_ 84 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_SERVICE_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698