OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/time.h" | 5 #include "base/time.h" |
6 #include "build/build_config.h" | 6 #include "build/build_config.h" |
7 #include "chrome/browser/autocomplete/search_provider.h" | 7 #include "chrome/browser/autocomplete/search_provider.h" |
8 #include "chrome/browser/history/history.h" | 8 #include "chrome/browser/history/history.h" |
9 #include "chrome/browser/net/test_url_fetcher_factory.h" | 9 #include "chrome/browser/net/test_url_fetcher_factory.h" |
10 #include "chrome/browser/search_engines/template_url.h" | 10 #include "chrome/browser/search_engines/template_url.h" |
(...skipping 80 matching lines...) Loading... |
91 default_t_url_->SetURL(L"http://defaultturl/{searchTerms}", 0, 0); | 91 default_t_url_->SetURL(L"http://defaultturl/{searchTerms}", 0, 0); |
92 default_t_url_->SetSuggestionsURL(L"http://defaultturl2/{searchTerms}", 0, 0); | 92 default_t_url_->SetSuggestionsURL(L"http://defaultturl2/{searchTerms}", 0, 0); |
93 turl_model->Add(default_t_url_); | 93 turl_model->Add(default_t_url_); |
94 turl_model->SetDefaultSearchProvider(default_t_url_); | 94 turl_model->SetDefaultSearchProvider(default_t_url_); |
95 TemplateURL::IDType default_provider_id = default_t_url_->id(); | 95 TemplateURL::IDType default_provider_id = default_t_url_->id(); |
96 ASSERT_NE(0, default_provider_id); | 96 ASSERT_NE(0, default_provider_id); |
97 | 97 |
98 // Add url1, with search term term1_. | 98 // Add url1, with search term term1_. |
99 HistoryService* history = | 99 HistoryService* history = |
100 profile_.GetHistoryService(Profile::EXPLICIT_ACCESS); | 100 profile_.GetHistoryService(Profile::EXPLICIT_ACCESS); |
101 term1_url_ = default_t_url_->url()->ReplaceSearchTerms( | 101 term1_url_ = GURL(WideToUTF8(default_t_url_->url()->ReplaceSearchTerms( |
102 *default_t_url_, term1_, 0, std::wstring()); | 102 *default_t_url_, term1_, 0, std::wstring()))); |
103 history->AddPageWithDetails(term1_url_, std::wstring(), 1, 1, | 103 history->AddPageWithDetails(term1_url_, std::wstring(), 1, 1, |
104 base::Time::Now(), false); | 104 base::Time::Now(), false); |
105 history->SetKeywordSearchTermsForURL(term1_url_, default_t_url_->id(), | 105 history->SetKeywordSearchTermsForURL(term1_url_, default_t_url_->id(), |
106 term1_); | 106 term1_); |
107 | 107 |
108 // Create another TemplateURL. | 108 // Create another TemplateURL. |
109 keyword_t_url_ = new TemplateURL(); | 109 keyword_t_url_ = new TemplateURL(); |
110 keyword_t_url_->set_keyword(L"k"); | 110 keyword_t_url_->set_keyword(L"k"); |
111 keyword_t_url_->SetURL(L"http://keyword/{searchTerms}", 0, 0); | 111 keyword_t_url_->SetURL(L"http://keyword/{searchTerms}", 0, 0); |
112 keyword_t_url_->SetSuggestionsURL(L"http://suggest_keyword/{searchTerms}", 0, | 112 keyword_t_url_->SetSuggestionsURL(L"http://suggest_keyword/{searchTerms}", 0, |
113 0); | 113 0); |
114 profile_.GetTemplateURLModel()->Add(keyword_t_url_); | 114 profile_.GetTemplateURLModel()->Add(keyword_t_url_); |
115 ASSERT_NE(0, keyword_t_url_->id()); | 115 ASSERT_NE(0, keyword_t_url_->id()); |
116 | 116 |
117 // Add a page and search term for keyword_t_url_. | 117 // Add a page and search term for keyword_t_url_. |
118 keyword_url_ = keyword_t_url_->url()->ReplaceSearchTerms( | 118 keyword_url_ = GURL(WideToUTF8(keyword_t_url_->url()->ReplaceSearchTerms( |
119 *keyword_t_url_, keyword_term_, 0, std::wstring()); | 119 *keyword_t_url_, keyword_term_, 0, std::wstring()))); |
120 history->AddPageWithDetails(keyword_url_, std::wstring(), 1, 1, | 120 history->AddPageWithDetails(keyword_url_, std::wstring(), 1, 1, |
121 base::Time::Now(), false); | 121 base::Time::Now(), false); |
122 history->SetKeywordSearchTermsForURL(keyword_url_, keyword_t_url_->id(), | 122 history->SetKeywordSearchTermsForURL(keyword_url_, keyword_t_url_->id(), |
123 keyword_term_); | 123 keyword_term_); |
124 | 124 |
125 provider_ = new SearchProvider(this, &profile_); | 125 provider_ = new SearchProvider(this, &profile_); |
126 | 126 |
127 URLFetcher::set_factory(&test_factory_); | 127 URLFetcher::set_factory(&test_factory_); |
128 } | 128 } |
129 | 129 |
(...skipping 52 matching lines...) Loading... |
182 TEST_F(SearchProviderTest, QueryDefaultProvider) { | 182 TEST_F(SearchProviderTest, QueryDefaultProvider) { |
183 std::wstring term = term1_.substr(0, term1_.size() - 1); | 183 std::wstring term = term1_.substr(0, term1_.size() - 1); |
184 QueryForInput(term); | 184 QueryForInput(term); |
185 | 185 |
186 // Make sure the default providers suggest service was queried. | 186 // Make sure the default providers suggest service was queried. |
187 TestURLFetcher* fetcher = test_factory_.GetFetcherByID( | 187 TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
188 SearchProvider::kDefaultProviderURLFetcherID); | 188 SearchProvider::kDefaultProviderURLFetcherID); |
189 ASSERT_TRUE(fetcher); | 189 ASSERT_TRUE(fetcher); |
190 | 190 |
191 // And the URL matches what we expected. | 191 // And the URL matches what we expected. |
192 GURL expected_url = default_t_url_->suggestions_url()->ReplaceSearchTerms( | 192 GURL expected_url = GURL(WideToUTF8(default_t_url_->suggestions_url()-> |
193 *default_t_url_, term, 0, std::wstring()); | 193 ReplaceSearchTerms(*default_t_url_, term, 0, std::wstring()))); |
194 ASSERT_TRUE(fetcher->original_url() == expected_url); | 194 ASSERT_TRUE(fetcher->original_url() == expected_url); |
195 | 195 |
196 // Tell the SearchProvider the suggest query is done. | 196 // Tell the SearchProvider the suggest query is done. |
197 fetcher->delegate()->OnURLFetchComplete( | 197 fetcher->delegate()->OnURLFetchComplete( |
198 fetcher, GURL(), URLRequestStatus(), 200, ResponseCookies(), | 198 fetcher, GURL(), URLRequestStatus(), 200, ResponseCookies(), |
199 std::string()); | 199 std::string()); |
200 fetcher = NULL; | 200 fetcher = NULL; |
201 | 201 |
202 // Run till the history results complete. | 202 // Run till the history results complete. |
203 RunTillProviderDone(); | 203 RunTillProviderDone(); |
(...skipping 20 matching lines...) Loading... |
224 default_fetcher, GURL(), URLRequestStatus(), 200, ResponseCookies(), | 224 default_fetcher, GURL(), URLRequestStatus(), 200, ResponseCookies(), |
225 std::string()); | 225 std::string()); |
226 default_fetcher = NULL; | 226 default_fetcher = NULL; |
227 | 227 |
228 // Make sure the keyword providers suggest service was queried. | 228 // Make sure the keyword providers suggest service was queried. |
229 TestURLFetcher* keyword_fetcher = test_factory_.GetFetcherByID( | 229 TestURLFetcher* keyword_fetcher = test_factory_.GetFetcherByID( |
230 SearchProvider::kKeywordProviderURLFetcherID); | 230 SearchProvider::kKeywordProviderURLFetcherID); |
231 ASSERT_TRUE(keyword_fetcher); | 231 ASSERT_TRUE(keyword_fetcher); |
232 | 232 |
233 // And the URL matches what we expected. | 233 // And the URL matches what we expected. |
234 GURL expected_url = keyword_t_url_->suggestions_url()->ReplaceSearchTerms( | 234 GURL expected_url = GURL(WideToUTF8(keyword_t_url_->suggestions_url()-> |
235 *keyword_t_url_, term, 0, std::wstring()); | 235 ReplaceSearchTerms(*keyword_t_url_, term, 0, std::wstring()))); |
236 ASSERT_TRUE(keyword_fetcher->original_url() == expected_url); | 236 ASSERT_TRUE(keyword_fetcher->original_url() == expected_url); |
237 | 237 |
238 // Tell the SearchProvider the keyword suggest query is done. | 238 // Tell the SearchProvider the keyword suggest query is done. |
239 keyword_fetcher->delegate()->OnURLFetchComplete( | 239 keyword_fetcher->delegate()->OnURLFetchComplete( |
240 keyword_fetcher, GURL(), URLRequestStatus(), 200, ResponseCookies(), | 240 keyword_fetcher, GURL(), URLRequestStatus(), 200, ResponseCookies(), |
241 std::string()); | 241 std::string()); |
242 keyword_fetcher = NULL; | 242 keyword_fetcher = NULL; |
243 | 243 |
244 // Run till the history results complete. | 244 // Run till the history results complete. |
245 RunTillProviderDone(); | 245 RunTillProviderDone(); |
246 | 246 |
247 // The SearchProvider is done. Make sure it has a result for the history | 247 // The SearchProvider is done. Make sure it has a result for the history |
248 // term keyword. | 248 // term keyword. |
249 AutocompleteMatch match = FindMatchWithDestination(keyword_url_); | 249 AutocompleteMatch match = FindMatchWithDestination(keyword_url_); |
250 ASSERT_TRUE(!match.destination_url.is_empty()); | 250 ASSERT_TRUE(!match.destination_url.is_empty()); |
251 | 251 |
252 // The match should have a TemplateURL. | 252 // The match should have a TemplateURL. |
253 EXPECT_TRUE(match.template_url); | 253 EXPECT_TRUE(match.template_url); |
254 | 254 |
255 // The fill into edit should contain the keyword. | 255 // The fill into edit should contain the keyword. |
256 EXPECT_EQ(keyword_t_url_->keyword() + L" " + keyword_term_, | 256 EXPECT_EQ(keyword_t_url_->keyword() + L" " + keyword_term_, |
257 match.fill_into_edit); | 257 match.fill_into_edit); |
258 } | 258 } |
OLD | NEW |