Index: chrome/browser/search_engines/template_url_service_test_util.cc |
diff --git a/chrome/browser/search_engines/template_url_service_test_util.cc b/chrome/browser/search_engines/template_url_service_test_util.cc |
index adc01399a640a07dfd986d089920a92531a2ec60..dd328a0083d8b1c7a5e6786183fc354d7da0aa3a 100644 |
--- a/chrome/browser/search_engines/template_url_service_test_util.cc |
+++ b/chrome/browser/search_engines/template_url_service_test_util.cc |
@@ -4,72 +4,64 @@ |
#include "chrome/browser/search_engines/template_url_service_test_util.h" |
-#include "base/bind.h" |
+#include "base/message_loop/message_loop_proxy.h" |
#include "base/run_loop.h" |
-#include "base/strings/string_split.h" |
-#include "base/threading/thread.h" |
#include "chrome/browser/search_engines/chrome_template_url_service_client.h" |
-#include "chrome/browser/webdata/web_data_service_factory.h" |
#include "chrome/test/base/testing_pref_service_syncable.h" |
#include "chrome/test/base/testing_profile.h" |
-#include "components/google/core/browser/google_url_tracker.h" |
-#include "components/search_engines/default_search_manager.h" |
#include "components/search_engines/default_search_pref_test_util.h" |
+#include "components/search_engines/keyword_table.h" |
+#include "components/search_engines/keyword_web_data_service.h" |
#include "components/search_engines/template_url_service.h" |
#include "components/search_engines/testing_search_terms_data.h" |
+#include "components/webdata/common/web_database_service.h" |
#include "testing/gtest/include/gtest/gtest.h" |
-// Trivial subclass of TemplateURLService that records the last invocation of |
-// SetKeywordSearchTermsForURL. |
-class TestingTemplateURLService : public TemplateURLService { |
- public: |
- TestingTemplateURLService(Profile* profile, |
- scoped_ptr<SearchTermsData> search_terms_data) |
- : TemplateURLService( |
- profile->GetPrefs(), |
- search_terms_data.Pass(), |
- WebDataServiceFactory::GetKeywordWebDataForProfile( |
- profile, Profile::EXPLICIT_ACCESS), |
- scoped_ptr<TemplateURLServiceClient>( |
- new ChromeTemplateURLServiceClient(profile)), NULL, NULL, |
- base::Closure()) { |
- } |
+namespace { |
- base::string16 GetAndClearSearchTerm() { |
- base::string16 search_term; |
- search_term.swap(search_term_); |
- return search_term; |
- } |
+class TestingTemplateURLServiceClient : public ChromeTemplateURLServiceClient { |
+ public: |
+ TestingTemplateURLServiceClient(Profile* profile, |
+ base::string16* search_term) |
+ : ChromeTemplateURLServiceClient(profile), |
+ search_term_(search_term) {} |
- protected: |
virtual void SetKeywordSearchTermsForURL( |
- const TemplateURL* t_url, |
const GURL& url, |
+ TemplateURLID id, |
const base::string16& term) OVERRIDE { |
- search_term_ = term; |
+ *search_term_ = term; |
} |
private: |
- base::string16 search_term_; |
+ base::string16* search_term_; |
- DISALLOW_COPY_AND_ASSIGN(TestingTemplateURLService); |
+ DISALLOW_COPY_AND_ASSIGN(TestingTemplateURLServiceClient); |
}; |
+} // namespace |
TemplateURLServiceTestUtil::TemplateURLServiceTestUtil() |
- : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
- changed_count_(0), |
+ : changed_count_(0), |
search_terms_data_(NULL) { |
// Make unique temp directory. |
EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
profile_.reset(new TestingProfile(temp_dir_.path())); |
- profile()->CreateWebDataService(); |
+ scoped_refptr<WebDatabaseService> web_database_service = |
+ new WebDatabaseService(temp_dir_.path().AppendASCII("webdata"), |
+ base::MessageLoopProxy::current(), |
+ base::MessageLoopProxy::current()); |
+ web_database_service->AddTable( |
+ scoped_ptr<WebDatabaseTable>(new KeywordTable())); |
+ web_database_service->LoadDatabase(); |
- search_terms_data_ = new TestingSearchTermsData("http://www.google.com/"); |
- model_.reset(new TestingTemplateURLService( |
- profile(), scoped_ptr<SearchTermsData>(search_terms_data_))); |
- model_->AddObserver(this); |
+ web_data_service_ = new KeywordWebDataService( |
+ web_database_service.get(), base::MessageLoopProxy::current(), |
+ KeywordWebDataService::ProfileErrorCallback()); |
+ web_data_service_->Init(); |
+ |
+ ResetModel(false); |
} |
TemplateURLServiceTestUtil::~TemplateURLServiceTestUtil() { |
@@ -105,9 +97,7 @@ void TemplateURLServiceTestUtil::ChangeModelToLoadState() { |
// Initialize the web data service so that the database gets updated with |
// any changes made. |
- model()->web_data_service_ = |
- WebDataServiceFactory::GetKeywordWebDataForProfile( |
- profile(), Profile::EXPLICIT_ACCESS); |
+ model()->web_data_service_ = web_data_service_; |
base::RunLoop().RunUntilIdle(); |
} |
@@ -121,8 +111,12 @@ void TemplateURLServiceTestUtil::ResetModel(bool verify_load) { |
if (model_) |
ClearModel(); |
search_terms_data_ = new TestingSearchTermsData("http://www.google.com/"); |
- model_.reset(new TestingTemplateURLService( |
- profile(), scoped_ptr<SearchTermsData>(search_terms_data_))); |
+ model_.reset(new TemplateURLService( |
+ profile()->GetPrefs(), scoped_ptr<SearchTermsData>(search_terms_data_), |
+ web_data_service_.get(), |
+ scoped_ptr<TemplateURLServiceClient>( |
+ new TestingTemplateURLServiceClient(profile(), &search_term_)), |
+ NULL, NULL, base::Closure())); |
model()->AddObserver(this); |
changed_count_ = 0; |
if (verify_load) |
@@ -130,7 +124,9 @@ void TemplateURLServiceTestUtil::ResetModel(bool verify_load) { |
} |
base::string16 TemplateURLServiceTestUtil::GetAndClearSearchTerm() { |
- return model_->GetAndClearSearchTerm(); |
+ base::string16 search_term; |
+ search_term.swap(search_term_); |
+ return search_term; |
} |
void TemplateURLServiceTestUtil::SetGoogleBaseURL(const GURL& base_url) { |
@@ -159,7 +155,3 @@ void TemplateURLServiceTestUtil::RemoveManagedDefaultSearchPreferences() { |
DefaultSearchPrefTestUtil::RemoveManagedPref( |
profile()->GetTestingPrefService()); |
} |
- |
-TemplateURLService* TemplateURLServiceTestUtil::model() { |
- return model_.get(); |
-} |