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

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

Issue 2479113002: Make extensions DSE persistent in browser prefs (Closed)
Patch Set: Created 4 years, 1 month 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 #include "chrome/browser/search_engines/template_url_service_test_util.h" 5 #include "chrome/browser/search_engines/template_url_service_test_util.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "chrome/browser/extensions/api/preference/preference_api.h"
10 #include "chrome/browser/history/history_service_factory.h" 11 #include "chrome/browser/history/history_service_factory.h"
11 #include "chrome/browser/search_engines/chrome_template_url_service_client.h" 12 #include "chrome/browser/search_engines/chrome_template_url_service_client.h"
12 #include "chrome/test/base/testing_profile.h" 13 #include "chrome/test/base/testing_profile.h"
13 #include "components/search_engines/default_search_pref_test_util.h" 14 #include "components/search_engines/default_search_pref_test_util.h"
14 #include "components/search_engines/keyword_table.h" 15 #include "components/search_engines/keyword_table.h"
15 #include "components/search_engines/keyword_web_data_service.h" 16 #include "components/search_engines/keyword_web_data_service.h"
16 #include "components/search_engines/template_url_service.h" 17 #include "components/search_engines/template_url_service.h"
17 #include "components/search_engines/testing_search_terms_data.h" 18 #include "components/search_engines/testing_search_terms_data.h"
18 #include "components/sync_preferences/testing_pref_service_syncable.h" 19 #include "components/sync_preferences/testing_pref_service_syncable.h"
19 #include "components/webdata/common/web_database_service.h" 20 #include "components/webdata/common/web_database_service.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 namespace { 23 namespace {
23 24
24 class TestingTemplateURLServiceClient : public ChromeTemplateURLServiceClient { 25 class TestingTemplateURLServiceClient : public ChromeTemplateURLServiceClient {
25 public: 26 public:
26 TestingTemplateURLServiceClient(history::HistoryService* history_service, 27 TestingTemplateURLServiceClient(history::HistoryService* history_service,
28 extensions::PreferenceAPI* pref_api,
27 base::string16* search_term) 29 base::string16* search_term)
28 : ChromeTemplateURLServiceClient(history_service), 30 : ChromeTemplateURLServiceClient(history_service, pref_api),
29 search_term_(search_term) {} 31 search_term_(search_term) {}
30 32
31 void SetKeywordSearchTermsForURL(const GURL& url, 33 void SetKeywordSearchTermsForURL(const GURL& url,
32 TemplateURLID id, 34 TemplateURLID id,
33 const base::string16& term) override { 35 const base::string16& term) override {
34 *search_term_ = term; 36 *search_term_ = term;
35 } 37 }
36 38
37 private: 39 private:
38 base::string16* search_term_; 40 base::string16* search_term_;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 void TemplateURLServiceTestUtil::ClearModel() { 107 void TemplateURLServiceTestUtil::ClearModel() {
106 model_->Shutdown(); 108 model_->Shutdown();
107 model_.reset(); 109 model_.reset();
108 search_terms_data_ = NULL; 110 search_terms_data_ = NULL;
109 } 111 }
110 112
111 void TemplateURLServiceTestUtil::ResetModel(bool verify_load) { 113 void TemplateURLServiceTestUtil::ResetModel(bool verify_load) {
112 if (model_) 114 if (model_)
113 ClearModel(); 115 ClearModel();
114 search_terms_data_ = new TestingSearchTermsData("http://www.google.com/"); 116 search_terms_data_ = new TestingSearchTermsData("http://www.google.com/");
117 extensions::PreferenceAPI* pref_api = profile() ?
118 extensions::PreferenceAPI::Get(profile()) : nullptr;
115 model_.reset(new TemplateURLService( 119 model_.reset(new TemplateURLService(
116 profile()->GetPrefs(), 120 profile()->GetPrefs(),
117 std::unique_ptr<SearchTermsData>(search_terms_data_), 121 std::unique_ptr<SearchTermsData>(search_terms_data_),
118 web_data_service_.get(), 122 web_data_service_.get(),
119 std::unique_ptr<TemplateURLServiceClient>( 123 std::unique_ptr<TemplateURLServiceClient>(
120 new TestingTemplateURLServiceClient( 124 new TestingTemplateURLServiceClient(
121 HistoryServiceFactory::GetForProfileIfExists( 125 HistoryServiceFactory::GetForProfileIfExists(
122 profile(), ServiceAccessType::EXPLICIT_ACCESS), 126 profile(), ServiceAccessType::EXPLICIT_ACCESS),
127 pref_api,
123 &search_term_)), 128 &search_term_)),
124 NULL, NULL, base::Closure())); 129 NULL, NULL, base::Closure()));
125 model()->AddObserver(this); 130 model()->AddObserver(this);
126 changed_count_ = 0; 131 changed_count_ = 0;
127 if (verify_load) 132 if (verify_load)
128 VerifyLoad(); 133 VerifyLoad();
129 } 134 }
130 135
131 base::string16 TemplateURLServiceTestUtil::GetAndClearSearchTerm() { 136 base::string16 TemplateURLServiceTestUtil::GetAndClearSearchTerm() {
132 base::string16 search_term; 137 base::string16 search_term;
(...skipping 20 matching lines...) Expand all
153 DefaultSearchPrefTestUtil::SetManagedPref( 158 DefaultSearchPrefTestUtil::SetManagedPref(
154 profile()->GetTestingPrefService(), 159 profile()->GetTestingPrefService(),
155 enabled, name, keyword, search_url, suggest_url, icon_url, encodings, 160 enabled, name, keyword, search_url, suggest_url, icon_url, encodings,
156 alternate_url, search_terms_replacement_key); 161 alternate_url, search_terms_replacement_key);
157 } 162 }
158 163
159 void TemplateURLServiceTestUtil::RemoveManagedDefaultSearchPreferences() { 164 void TemplateURLServiceTestUtil::RemoveManagedDefaultSearchPreferences() {
160 DefaultSearchPrefTestUtil::RemoveManagedPref( 165 DefaultSearchPrefTestUtil::RemoveManagedPref(
161 profile()->GetTestingPrefService()); 166 profile()->GetTestingPrefService());
162 } 167 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698