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/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "chrome/browser/history/history_service_factory.h" |
9 #include "chrome/browser/search_engines/chrome_template_url_service_client.h" | 10 #include "chrome/browser/search_engines/chrome_template_url_service_client.h" |
10 #include "chrome/test/base/testing_pref_service_syncable.h" | 11 #include "chrome/test/base/testing_pref_service_syncable.h" |
11 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
12 #include "components/search_engines/default_search_pref_test_util.h" | 13 #include "components/search_engines/default_search_pref_test_util.h" |
13 #include "components/search_engines/keyword_table.h" | 14 #include "components/search_engines/keyword_table.h" |
14 #include "components/search_engines/keyword_web_data_service.h" | 15 #include "components/search_engines/keyword_web_data_service.h" |
15 #include "components/search_engines/template_url_service.h" | 16 #include "components/search_engines/template_url_service.h" |
16 #include "components/search_engines/testing_search_terms_data.h" | 17 #include "components/search_engines/testing_search_terms_data.h" |
17 #include "components/webdata/common/web_database_service.h" | 18 #include "components/webdata/common/web_database_service.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 class TestingTemplateURLServiceClient : public ChromeTemplateURLServiceClient { | 23 class TestingTemplateURLServiceClient : public ChromeTemplateURLServiceClient { |
23 public: | 24 public: |
24 TestingTemplateURLServiceClient(Profile* profile, | 25 TestingTemplateURLServiceClient(HistoryService* history_service, |
25 base::string16* search_term) | 26 base::string16* search_term) |
26 : ChromeTemplateURLServiceClient(profile), | 27 : ChromeTemplateURLServiceClient(history_service), |
27 search_term_(search_term) {} | 28 search_term_(search_term) {} |
28 | 29 |
29 virtual void SetKeywordSearchTermsForURL( | 30 virtual void SetKeywordSearchTermsForURL( |
30 const GURL& url, | 31 const GURL& url, |
31 TemplateURLID id, | 32 TemplateURLID id, |
32 const base::string16& term) override { | 33 const base::string16& term) override { |
33 *search_term_ = term; | 34 *search_term_ = term; |
34 } | 35 } |
35 | 36 |
36 private: | 37 private: |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 void TemplateURLServiceTestUtil::ClearModel() { | 105 void TemplateURLServiceTestUtil::ClearModel() { |
105 model_->Shutdown(); | 106 model_->Shutdown(); |
106 model_.reset(); | 107 model_.reset(); |
107 search_terms_data_ = NULL; | 108 search_terms_data_ = NULL; |
108 } | 109 } |
109 | 110 |
110 void TemplateURLServiceTestUtil::ResetModel(bool verify_load) { | 111 void TemplateURLServiceTestUtil::ResetModel(bool verify_load) { |
111 if (model_) | 112 if (model_) |
112 ClearModel(); | 113 ClearModel(); |
113 search_terms_data_ = new TestingSearchTermsData("http://www.google.com/"); | 114 search_terms_data_ = new TestingSearchTermsData("http://www.google.com/"); |
| 115 bool created = profile()->CreateHistoryService(false, false); |
| 116 DCHECK(created); |
114 model_.reset(new TemplateURLService( | 117 model_.reset(new TemplateURLService( |
115 profile()->GetPrefs(), scoped_ptr<SearchTermsData>(search_terms_data_), | 118 profile()->GetPrefs(), scoped_ptr<SearchTermsData>(search_terms_data_), |
116 web_data_service_.get(), | 119 web_data_service_.get(), |
117 scoped_ptr<TemplateURLServiceClient>( | 120 scoped_ptr<TemplateURLServiceClient>( |
118 new TestingTemplateURLServiceClient(profile(), &search_term_)), | 121 new TestingTemplateURLServiceClient( |
| 122 HistoryServiceFactory::GetForProfile(profile(), |
| 123 Profile::EXPLICIT_ACCESS), |
| 124 &search_term_)), |
119 NULL, NULL, base::Closure())); | 125 NULL, NULL, base::Closure())); |
120 model()->AddObserver(this); | 126 model()->AddObserver(this); |
121 changed_count_ = 0; | 127 changed_count_ = 0; |
122 if (verify_load) | 128 if (verify_load) |
123 VerifyLoad(); | 129 VerifyLoad(); |
124 } | 130 } |
125 | 131 |
126 base::string16 TemplateURLServiceTestUtil::GetAndClearSearchTerm() { | 132 base::string16 TemplateURLServiceTestUtil::GetAndClearSearchTerm() { |
127 base::string16 search_term; | 133 base::string16 search_term; |
128 search_term.swap(search_term_); | 134 search_term.swap(search_term_); |
(...skipping 19 matching lines...) Expand all Loading... |
148 DefaultSearchPrefTestUtil::SetManagedPref( | 154 DefaultSearchPrefTestUtil::SetManagedPref( |
149 profile()->GetTestingPrefService(), | 155 profile()->GetTestingPrefService(), |
150 enabled, name, keyword, search_url, suggest_url, icon_url, encodings, | 156 enabled, name, keyword, search_url, suggest_url, icon_url, encodings, |
151 alternate_url, search_terms_replacement_key); | 157 alternate_url, search_terms_replacement_key); |
152 } | 158 } |
153 | 159 |
154 void TemplateURLServiceTestUtil::RemoveManagedDefaultSearchPreferences() { | 160 void TemplateURLServiceTestUtil::RemoveManagedDefaultSearchPreferences() { |
155 DefaultSearchPrefTestUtil::RemoveManagedPref( | 161 DefaultSearchPrefTestUtil::RemoveManagedPref( |
156 profile()->GetTestingPrefService()); | 162 profile()->GetTestingPrefService()); |
157 } | 163 } |
OLD | NEW |