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 DCHECK(profile()->CreateHistoryService(false, false)); | |
droger
2014/10/14 15:15:24
Is it OK if this code is not called in release?
O
sdefresne
2014/10/14 16:02:05
Done.
| |
114 model_.reset(new TemplateURLService( | 116 model_.reset(new TemplateURLService( |
115 profile()->GetPrefs(), scoped_ptr<SearchTermsData>(search_terms_data_), | 117 profile()->GetPrefs(), scoped_ptr<SearchTermsData>(search_terms_data_), |
116 web_data_service_.get(), | 118 web_data_service_.get(), |
117 scoped_ptr<TemplateURLServiceClient>( | 119 scoped_ptr<TemplateURLServiceClient>( |
118 new TestingTemplateURLServiceClient(profile(), &search_term_)), | 120 new TestingTemplateURLServiceClient( |
121 HistoryServiceFactory::GetForProfile(profile(), | |
122 Profile::EXPLICIT_ACCESS), | |
123 &search_term_)), | |
119 NULL, NULL, base::Closure())); | 124 NULL, NULL, base::Closure())); |
120 model()->AddObserver(this); | 125 model()->AddObserver(this); |
121 changed_count_ = 0; | 126 changed_count_ = 0; |
122 if (verify_load) | 127 if (verify_load) |
123 VerifyLoad(); | 128 VerifyLoad(); |
124 } | 129 } |
125 | 130 |
126 base::string16 TemplateURLServiceTestUtil::GetAndClearSearchTerm() { | 131 base::string16 TemplateURLServiceTestUtil::GetAndClearSearchTerm() { |
127 base::string16 search_term; | 132 base::string16 search_term; |
128 search_term.swap(search_term_); | 133 search_term.swap(search_term_); |
(...skipping 19 matching lines...) Expand all Loading... | |
148 DefaultSearchPrefTestUtil::SetManagedPref( | 153 DefaultSearchPrefTestUtil::SetManagedPref( |
149 profile()->GetTestingPrefService(), | 154 profile()->GetTestingPrefService(), |
150 enabled, name, keyword, search_url, suggest_url, icon_url, encodings, | 155 enabled, name, keyword, search_url, suggest_url, icon_url, encodings, |
151 alternate_url, search_terms_replacement_key); | 156 alternate_url, search_terms_replacement_key); |
152 } | 157 } |
153 | 158 |
154 void TemplateURLServiceTestUtil::RemoveManagedDefaultSearchPreferences() { | 159 void TemplateURLServiceTestUtil::RemoveManagedDefaultSearchPreferences() { |
155 DefaultSearchPrefTestUtil::RemoveManagedPref( | 160 DefaultSearchPrefTestUtil::RemoveManagedPref( |
156 profile()->GetTestingPrefService()); | 161 profile()->GetTestingPrefService()); |
157 } | 162 } |
OLD | NEW |