OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_model_test_util.h" | 5 #include "chrome/browser/search_engines/template_url_model_test_util.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
11 #include "chrome/browser/search_engines/template_url.h" | 11 #include "chrome/browser/search_engines/template_url.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 }; | 78 }; |
79 | 79 |
80 // Trivial subclass of TemplateURLModel that records the last invocation of | 80 // Trivial subclass of TemplateURLModel that records the last invocation of |
81 // SetKeywordSearchTermsForURL. | 81 // SetKeywordSearchTermsForURL. |
82 class TestingTemplateURLModel : public TemplateURLModel { | 82 class TestingTemplateURLModel : public TemplateURLModel { |
83 public: | 83 public: |
84 explicit TestingTemplateURLModel(Profile* profile) | 84 explicit TestingTemplateURLModel(Profile* profile) |
85 : TemplateURLModel(profile) { | 85 : TemplateURLModel(profile) { |
86 } | 86 } |
87 | 87 |
88 std::wstring GetAndClearSearchTerm() { | 88 string16 GetAndClearSearchTerm() { |
89 std::wstring search_term; | 89 string16 search_term; |
90 search_term.swap(search_term_); | 90 search_term.swap(search_term_); |
91 return search_term; | 91 return search_term; |
92 } | 92 } |
93 | 93 |
94 protected: | 94 protected: |
95 virtual void SetKeywordSearchTermsForURL(const TemplateURL* t_url, | 95 virtual void SetKeywordSearchTermsForURL(const TemplateURL* t_url, |
96 const GURL& url, | 96 const GURL& url, |
97 const std::wstring& term) { | 97 const string16& term) { |
98 search_term_ = term; | 98 search_term_ = term; |
99 } | 99 } |
100 | 100 |
101 private: | 101 private: |
102 std::wstring search_term_; | 102 string16 search_term_; |
103 | 103 |
104 DISALLOW_COPY_AND_ASSIGN(TestingTemplateURLModel); | 104 DISALLOW_COPY_AND_ASSIGN(TestingTemplateURLModel); |
105 }; | 105 }; |
106 | 106 |
107 void TemplateURLModelTestingProfile::SetUp() { | 107 void TemplateURLModelTestingProfile::SetUp() { |
108 db_thread_.Start(); | 108 db_thread_.Start(); |
109 | 109 |
110 // Make unique temp directory. | 110 // Make unique temp directory. |
111 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 111 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
112 | 112 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 } | 203 } |
204 | 204 |
205 void TemplateURLModelTestUtil::ResetModel(bool verify_load) { | 205 void TemplateURLModelTestUtil::ResetModel(bool verify_load) { |
206 profile_->SetTemplateURLModel(new TestingTemplateURLModel(profile_.get())); | 206 profile_->SetTemplateURLModel(new TestingTemplateURLModel(profile_.get())); |
207 model()->AddObserver(this); | 207 model()->AddObserver(this); |
208 changed_count_ = 0; | 208 changed_count_ = 0; |
209 if (verify_load) | 209 if (verify_load) |
210 VerifyLoad(); | 210 VerifyLoad(); |
211 } | 211 } |
212 | 212 |
213 std::wstring TemplateURLModelTestUtil::GetAndClearSearchTerm() { | 213 string16 TemplateURLModelTestUtil::GetAndClearSearchTerm() { |
214 return | 214 return |
215 static_cast<TestingTemplateURLModel*>(model())->GetAndClearSearchTerm(); | 215 static_cast<TestingTemplateURLModel*>(model())->GetAndClearSearchTerm(); |
216 } | 216 } |
217 | 217 |
218 void TemplateURLModelTestUtil::SetGoogleBaseURL( | 218 void TemplateURLModelTestUtil::SetGoogleBaseURL( |
219 const std::string& base_url) const { | 219 const std::string& base_url) const { |
220 TemplateURLRef::SetGoogleBaseURL(new std::string(base_url)); | 220 TemplateURLRef::SetGoogleBaseURL(new std::string(base_url)); |
221 NotificationService::current()->Notify(NotificationType::GOOGLE_URL_UPDATED, | 221 NotificationService::current()->Notify(NotificationType::GOOGLE_URL_UPDATED, |
222 NotificationService::AllSources(), | 222 NotificationService::AllSources(), |
223 NotificationService::NoDetails()); | 223 NotificationService::NoDetails()); |
224 } | 224 } |
225 | 225 |
226 WebDataService* TemplateURLModelTestUtil::GetWebDataService() { | 226 WebDataService* TemplateURLModelTestUtil::GetWebDataService() { |
227 return profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 227 return profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); |
228 } | 228 } |
229 | 229 |
230 TemplateURLModel* TemplateURLModelTestUtil::model() const { | 230 TemplateURLModel* TemplateURLModelTestUtil::model() const { |
231 return profile_->GetTemplateURLModel(); | 231 return profile_->GetTemplateURLModel(); |
232 } | 232 } |
233 | 233 |
234 TestingProfile* TemplateURLModelTestUtil::profile() const { | 234 TestingProfile* TemplateURLModelTestUtil::profile() const { |
235 return profile_.get(); | 235 return profile_.get(); |
236 } | 236 } |
237 | 237 |
238 void TemplateURLModelTestUtil::StartIOThread() { | 238 void TemplateURLModelTestUtil::StartIOThread() { |
239 profile_->StartIOThread(); | 239 profile_->StartIOThread(); |
240 } | 240 } |
OLD | NEW |