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

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: Fixed after review, round 7 Created 3 years, 12 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
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/history/history_service_factory.h" 10 #include "chrome/browser/history/history_service_factory.h"
11 #include "chrome/browser/search_engines/chrome_template_url_service_client.h" 11 #include "chrome/browser/search_engines/chrome_template_url_service_client.h"
12 #include "chrome/test/base/testing_profile.h" 12 #include "chrome/test/base/testing_profile.h"
13 #include "components/search_engines/keyword_table.h" 13 #include "components/search_engines/keyword_table.h"
14 #include "components/search_engines/keyword_web_data_service.h" 14 #include "components/search_engines/keyword_web_data_service.h"
15 #include "components/search_engines/search_engines_test_util.h"
15 #include "components/search_engines/template_url_data_util.h" 16 #include "components/search_engines/template_url_data_util.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 {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 void TemplateURLServiceTestUtil::ClearModel() { 121 void TemplateURLServiceTestUtil::ClearModel() {
121 model_->Shutdown(); 122 model_->Shutdown();
122 model_.reset(); 123 model_.reset();
123 search_terms_data_ = NULL; 124 search_terms_data_ = NULL;
124 } 125 }
125 126
126 void TemplateURLServiceTestUtil::ResetModel(bool verify_load) { 127 void TemplateURLServiceTestUtil::ResetModel(bool verify_load) {
127 if (model_) 128 if (model_)
128 ClearModel(); 129 ClearModel();
129 search_terms_data_ = new TestingSearchTermsData("http://www.google.com/"); 130 search_terms_data_ = new TestingSearchTermsData("http://www.google.com/");
131
Peter Kasting 2017/01/06 01:44:57 Nit: Not sure why this blank line here
Alexander Yashkin 2017/01/07 12:55:59 Removed.
130 model_.reset(new TemplateURLService( 132 model_.reset(new TemplateURLService(
131 profile()->GetPrefs(), 133 profile()->GetPrefs(),
132 std::unique_ptr<SearchTermsData>(search_terms_data_), 134 std::unique_ptr<SearchTermsData>(search_terms_data_),
133 web_data_service_.get(), 135 web_data_service_.get(),
134 std::unique_ptr<TemplateURLServiceClient>( 136 std::unique_ptr<TemplateURLServiceClient>(
135 new TestingTemplateURLServiceClient( 137 new TestingTemplateURLServiceClient(
136 HistoryServiceFactory::GetForProfileIfExists( 138 HistoryServiceFactory::GetForProfileIfExists(
137 profile(), ServiceAccessType::EXPLICIT_ACCESS), 139 profile(), ServiceAccessType::EXPLICIT_ACCESS),
138 &search_term_)), 140 &search_term_)),
139 NULL, NULL, base::Closure())); 141 NULL, NULL, base::Closure()));
140 model()->AddObserver(this); 142 model()->AddObserver(this);
141 changed_count_ = 0; 143 changed_count_ = 0;
142 if (verify_load) 144 if (verify_load)
143 VerifyLoad(); 145 VerifyLoad();
144 } 146 }
145 147
146 base::string16 TemplateURLServiceTestUtil::GetAndClearSearchTerm() { 148 base::string16 TemplateURLServiceTestUtil::GetAndClearSearchTerm() {
147 base::string16 search_term; 149 base::string16 search_term;
148 search_term.swap(search_term_); 150 search_term.swap(search_term_);
149 return search_term; 151 return search_term;
150 } 152 }
151 153
152 void TemplateURLServiceTestUtil::SetGoogleBaseURL(const GURL& base_url) { 154 void TemplateURLServiceTestUtil::SetGoogleBaseURL(const GURL& base_url) {
153 DCHECK(base_url.is_valid()); 155 DCHECK(base_url.is_valid());
154 search_terms_data_->set_google_base_url(base_url.spec()); 156 search_terms_data_->set_google_base_url(base_url.spec());
155 model_->GoogleBaseURLChanged(); 157 model_->GoogleBaseURLChanged();
156 } 158 }
159
160 TemplateURL* TemplateURLServiceTestUtil::AddExtensionControlledTURL(
161 std::unique_ptr<TemplateURL> extension_turl,
162 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> info) {
163 bool wants_to_be_default = info->wants_to_be_default_engine;
164 TemplateURLData extension_data = extension_turl->data();
Peter Kasting 2017/01/06 01:44:57 Nit: Why copy this off instead of using result->da
Alexander Yashkin 2017/01/07 12:55:59 Thanks, fixed.
165 TemplateURL* result = model()->AddExtensionControlledTURL(
166 std::move(extension_turl), std::move(info));
167 if (wants_to_be_default) {
Peter Kasting 2017/01/06 01:44:57 Should this check |result| too? Seems like yes, u
Alexander Yashkin 2017/01/07 12:55:59 Added check.
168 SetExtensionDefaultSearchInPrefs(profile()->GetTestingPrefService(),
169 extension_data);
170 }
171 return result;
172 }
173
174 void TemplateURLServiceTestUtil::RemoveExtensionControlledTURL(
175 const std::string& extension_id) {
176 TemplateURL* turl = model()->FindTemplateURLForExtension(
177 extension_id, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
178 ASSERT_TRUE(turl);
179 ASSERT_TRUE(turl->GetExtensionInfoForTesting());
180 if (turl->GetExtensionInfoForTesting()->wants_to_be_default_engine)
181 RemoveExtensionDefaultSearchFromPrefs(profile()->GetTestingPrefService());
182 model()->RemoveExtensionControlledTURL(
183 extension_id, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698