OLD | NEW |
1 // Copyright (c) 2011 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/autocomplete/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "chrome/browser/autocomplete/autocomplete.h" | 11 #include "chrome/browser/autocomplete/autocomplete.h" |
12 #include "chrome/browser/autocomplete/autocomplete_match.h" | 12 #include "chrome/browser/autocomplete/autocomplete_match.h" |
13 #include "chrome/browser/history/history.h" | 13 #include "chrome/browser/history/history.h" |
14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
15 #include "chrome/browser/search_engines/template_url.h" | 15 #include "chrome/browser/search_engines/template_url.h" |
16 #include "chrome/browser/search_engines/template_url_service.h" | 16 #include "chrome/browser/search_engines/template_url_service.h" |
17 #include "chrome/browser/search_engines/template_url_service_factory.h" | 17 #include "chrome/browser/search_engines/template_url_service_factory.h" |
18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
19 #include "chrome/test/testing_browser_process.h" | 19 #include "chrome/test/testing_browser_process.h" |
20 #include "chrome/test/testing_browser_process_test.h" | 20 #include "chrome/test/testing_browser_process_test.h" |
21 #include "chrome/test/testing_profile.h" | 21 #include "chrome/test/testing_profile.h" |
22 #include "content/browser/browser_thread.h" | 22 #include "content/browser/browser_thread.h" |
23 #include "content/common/test_url_fetcher_factory.h" | 23 #include "content/test/test_url_fetcher_factory.h" |
24 #include "net/url_request/url_request_status.h" | 24 #include "net/url_request/url_request_status.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 | 26 |
27 // The following environment is configured for these tests: | 27 // The following environment is configured for these tests: |
28 // . The TemplateURL default_t_url_ is set as the default provider. | 28 // . The TemplateURL default_t_url_ is set as the default provider. |
29 // . The TemplateURL keyword_t_url_ is added to the TemplateURLService. This | 29 // . The TemplateURL keyword_t_url_ is added to the TemplateURLService. This |
30 // TemplateURL has a valid suggest and search URL. | 30 // TemplateURL has a valid suggest and search URL. |
31 // . The URL created by using the search term term1_ with default_t_url_ is | 31 // . The URL created by using the search term term1_ with default_t_url_ is |
32 // added to history. | 32 // added to history. |
33 // . The URL created by using the search term keyword_term_ with keyword_t_url_ | 33 // . The URL created by using the search term keyword_term_ with keyword_t_url_ |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // Add a page and search term for keyword_t_url_. | 145 // Add a page and search term for keyword_t_url_. |
146 keyword_url_ = AddSearchToHistory(keyword_t_url_, keyword_term_, 1); | 146 keyword_url_ = AddSearchToHistory(keyword_t_url_, keyword_term_, 1); |
147 | 147 |
148 // Keywords are updated by the InMemoryHistoryBackend only after the message | 148 // Keywords are updated by the InMemoryHistoryBackend only after the message |
149 // has been processed on the history thread. Block until history processes all | 149 // has been processed on the history thread. Block until history processes all |
150 // requests to ensure the InMemoryDatabase is the state we expect it. | 150 // requests to ensure the InMemoryDatabase is the state we expect it. |
151 profile_.BlockUntilHistoryProcessesPendingRequests(); | 151 profile_.BlockUntilHistoryProcessesPendingRequests(); |
152 | 152 |
153 provider_ = new SearchProvider(this, &profile_); | 153 provider_ = new SearchProvider(this, &profile_); |
154 | 154 |
155 URLFetcher::set_factory(&test_factory_); | |
156 | |
157 // Prevent the Instant field trial from kicking in. | 155 // Prevent the Instant field trial from kicking in. |
158 PrefService* service = profile_.GetPrefs(); | 156 PrefService* service = profile_.GetPrefs(); |
159 service->SetBoolean(prefs::kInstantEnabledOnce, true); | 157 service->SetBoolean(prefs::kInstantEnabledOnce, true); |
160 } | 158 } |
161 | 159 |
162 void SearchProviderTest::OnProviderUpdate(bool updated_matches) { | 160 void SearchProviderTest::OnProviderUpdate(bool updated_matches) { |
163 if (quit_when_done_ && provider_->done()) { | 161 if (quit_when_done_ && provider_->done()) { |
164 quit_when_done_ = false; | 162 quit_when_done_ = false; |
165 message_loop_.Quit(); | 163 message_loop_.Quit(); |
166 } | 164 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 return; | 200 return; |
203 ASSERT_GE(provider_->matches().size(), 1u); | 201 ASSERT_GE(provider_->matches().size(), 1u); |
204 EXPECT_TRUE(FindMatchWithDestination(GURL( | 202 EXPECT_TRUE(FindMatchWithDestination(GURL( |
205 default_t_url_->url()->ReplaceSearchTerms(*default_t_url_, text, 0, | 203 default_t_url_->url()->ReplaceSearchTerms(*default_t_url_, text, 0, |
206 string16())), wyt_match)); | 204 string16())), wyt_match)); |
207 } | 205 } |
208 | 206 |
209 void SearchProviderTest::TearDown() { | 207 void SearchProviderTest::TearDown() { |
210 message_loop_.RunAllPending(); | 208 message_loop_.RunAllPending(); |
211 | 209 |
212 URLFetcher::set_factory(NULL); | |
213 | |
214 // Shutdown the provider before the profile. | 210 // Shutdown the provider before the profile. |
215 provider_ = NULL; | 211 provider_ = NULL; |
216 } | 212 } |
217 | 213 |
218 GURL SearchProviderTest::AddSearchToHistory(TemplateURL* t_url, | 214 GURL SearchProviderTest::AddSearchToHistory(TemplateURL* t_url, |
219 string16 term, | 215 string16 term, |
220 int visit_count) { | 216 int visit_count) { |
221 HistoryService* history = | 217 HistoryService* history = |
222 profile_.GetHistoryService(Profile::EXPLICIT_ACCESS); | 218 profile_.GetHistoryService(Profile::EXPLICIT_ACCESS); |
223 GURL search(t_url->url()->ReplaceSearchTerms(*t_url, term, 0, string16())); | 219 GURL search(t_url->url()->ReplaceSearchTerms(*t_url, term, 0, string16())); |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 fetcher = NULL; | 662 fetcher = NULL; |
667 | 663 |
668 // Run till the history results complete. | 664 // Run till the history results complete. |
669 RunTillProviderDone(); | 665 RunTillProviderDone(); |
670 | 666 |
671 // Make sure there is a match for 'a.com' and it doesn't have a template_url. | 667 // Make sure there is a match for 'a.com' and it doesn't have a template_url. |
672 AutocompleteMatch nav_match; | 668 AutocompleteMatch nav_match; |
673 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match)); | 669 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match)); |
674 EXPECT_FALSE(nav_match.template_url); | 670 EXPECT_FALSE(nav_match.template_url); |
675 } | 671 } |
OLD | NEW |