| OLD | NEW |
| 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" | |
| 16 #include "components/search_engines/template_url_data_util.h" | 15 #include "components/search_engines/template_url_data_util.h" |
| 17 #include "components/search_engines/template_url_service.h" | 16 #include "components/search_engines/template_url_service.h" |
| 18 #include "components/search_engines/testing_search_terms_data.h" | 17 #include "components/search_engines/testing_search_terms_data.h" |
| 19 #include "components/sync_preferences/testing_pref_service_syncable.h" | 18 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 20 #include "components/webdata/common/web_database_service.h" | 19 #include "components/webdata/common/web_database_service.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 21 |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| 25 class TestingTemplateURLServiceClient : public ChromeTemplateURLServiceClient { | 24 class TestingTemplateURLServiceClient : public ChromeTemplateURLServiceClient { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 base::string16 search_term; | 147 base::string16 search_term; |
| 149 search_term.swap(search_term_); | 148 search_term.swap(search_term_); |
| 150 return search_term; | 149 return search_term; |
| 151 } | 150 } |
| 152 | 151 |
| 153 void TemplateURLServiceTestUtil::SetGoogleBaseURL(const GURL& base_url) { | 152 void TemplateURLServiceTestUtil::SetGoogleBaseURL(const GURL& base_url) { |
| 154 DCHECK(base_url.is_valid()); | 153 DCHECK(base_url.is_valid()); |
| 155 search_terms_data_->set_google_base_url(base_url.spec()); | 154 search_terms_data_->set_google_base_url(base_url.spec()); |
| 156 model_->GoogleBaseURLChanged(); | 155 model_->GoogleBaseURLChanged(); |
| 157 } | 156 } |
| 158 | |
| 159 TemplateURL* TemplateURLServiceTestUtil::AddExtensionControlledTURL( | |
| 160 std::unique_ptr<TemplateURL> extension_turl, | |
| 161 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> info) { | |
| 162 bool wants_to_be_default = info->wants_to_be_default_engine; | |
| 163 TemplateURL* result = model()->AddExtensionControlledTURL( | |
| 164 std::move(extension_turl), std::move(info)); | |
| 165 if (wants_to_be_default && result) { | |
| 166 SetExtensionDefaultSearchInPrefs(profile()->GetTestingPrefService(), | |
| 167 result->data()); | |
| 168 } | |
| 169 return result; | |
| 170 } | |
| 171 | |
| 172 void TemplateURLServiceTestUtil::RemoveExtensionControlledTURL( | |
| 173 const std::string& extension_id) { | |
| 174 TemplateURL* turl = model()->FindTemplateURLForExtension( | |
| 175 extension_id, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | |
| 176 ASSERT_TRUE(turl); | |
| 177 ASSERT_TRUE(turl->GetExtensionInfoForTesting()); | |
| 178 if (turl->GetExtensionInfoForTesting()->wants_to_be_default_engine) | |
| 179 RemoveExtensionDefaultSearchFromPrefs(profile()->GetTestingPrefService()); | |
| 180 model()->RemoveExtensionControlledTURL( | |
| 181 extension_id, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); | |
| 182 } | |
| OLD | NEW |