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 "base/string_util.h" | 5 #include "base/string_util.h" |
6 #include "base/time.h" | 6 #include "base/time.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "chrome/browser/autocomplete/autocomplete_match.h" | 9 #include "chrome/browser/autocomplete/autocomplete_match.h" |
10 #include "chrome/browser/autocomplete/search_provider.h" | 10 #include "chrome/browser/autocomplete/search_provider.h" |
11 #include "chrome/browser/browser_thread.h" | 11 #include "chrome/browser/browser_thread.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 return AutocompleteMatch(NULL, 1, false, AutocompleteMatch::HISTORY_URL); | 201 return AutocompleteMatch(NULL, 1, false, AutocompleteMatch::HISTORY_URL); |
202 } | 202 } |
203 | 203 |
204 void SearchProviderTest::FinishDefaultSuggestQuery() { | 204 void SearchProviderTest::FinishDefaultSuggestQuery() { |
205 TestURLFetcher* default_fetcher = test_factory_.GetFetcherByID( | 205 TestURLFetcher* default_fetcher = test_factory_.GetFetcherByID( |
206 SearchProvider::kDefaultProviderURLFetcherID); | 206 SearchProvider::kDefaultProviderURLFetcherID); |
207 ASSERT_TRUE(default_fetcher); | 207 ASSERT_TRUE(default_fetcher); |
208 | 208 |
209 // Tell the SearchProvider the default suggest query is done. | 209 // Tell the SearchProvider the default suggest query is done. |
210 default_fetcher->delegate()->OnURLFetchComplete( | 210 default_fetcher->delegate()->OnURLFetchComplete( |
211 default_fetcher, GURL(), URLRequestStatus(), 200, ResponseCookies(), | 211 default_fetcher, GURL(), net::URLRequestStatus(), 200, ResponseCookies(), |
212 std::string()); | 212 std::string()); |
213 } | 213 } |
214 | 214 |
215 // Tests ----------------------------------------------------------------------- | 215 // Tests ----------------------------------------------------------------------- |
216 | 216 |
217 // Make sure we query history for the default provider and a URLFetcher is | 217 // Make sure we query history for the default provider and a URLFetcher is |
218 // created for the default provider suggest results. | 218 // created for the default provider suggest results. |
219 TEST_F(SearchProviderTest, QueryDefaultProvider) { | 219 TEST_F(SearchProviderTest, QueryDefaultProvider) { |
220 string16 term = term1_.substr(0, term1_.size() - 1); | 220 string16 term = term1_.substr(0, term1_.size() - 1); |
221 QueryForInput(term, false); | 221 QueryForInput(term, false); |
222 | 222 |
223 // Make sure the default providers suggest service was queried. | 223 // Make sure the default providers suggest service was queried. |
224 TestURLFetcher* fetcher = test_factory_.GetFetcherByID( | 224 TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
225 SearchProvider::kDefaultProviderURLFetcherID); | 225 SearchProvider::kDefaultProviderURLFetcherID); |
226 ASSERT_TRUE(fetcher); | 226 ASSERT_TRUE(fetcher); |
227 | 227 |
228 // And the URL matches what we expected. | 228 // And the URL matches what we expected. |
229 GURL expected_url = GURL(default_t_url_->suggestions_url()-> | 229 GURL expected_url = GURL(default_t_url_->suggestions_url()-> |
230 ReplaceSearchTerms(*default_t_url_, UTF16ToWide(term), | 230 ReplaceSearchTerms(*default_t_url_, UTF16ToWide(term), |
231 0, std::wstring())); | 231 0, std::wstring())); |
232 ASSERT_TRUE(fetcher->original_url() == expected_url); | 232 ASSERT_TRUE(fetcher->original_url() == expected_url); |
233 | 233 |
234 // Tell the SearchProvider the suggest query is done. | 234 // Tell the SearchProvider the suggest query is done. |
235 fetcher->delegate()->OnURLFetchComplete( | 235 fetcher->delegate()->OnURLFetchComplete( |
236 fetcher, GURL(), URLRequestStatus(), 200, ResponseCookies(), | 236 fetcher, GURL(), net::URLRequestStatus(), 200, ResponseCookies(), |
237 std::string()); | 237 std::string()); |
238 fetcher = NULL; | 238 fetcher = NULL; |
239 | 239 |
240 // Run till the history results complete. | 240 // Run till the history results complete. |
241 RunTillProviderDone(); | 241 RunTillProviderDone(); |
242 | 242 |
243 // The SearchProvider is done. Make sure it has a result for the history | 243 // The SearchProvider is done. Make sure it has a result for the history |
244 // term term1. | 244 // term term1. |
245 AutocompleteMatch term1_match = FindMatchWithDestination(term1_url_); | 245 AutocompleteMatch term1_match = FindMatchWithDestination(term1_url_); |
246 EXPECT_TRUE(!term1_match.destination_url.is_empty()); | 246 EXPECT_TRUE(!term1_match.destination_url.is_empty()); |
(...skipping 27 matching lines...) Expand all Loading... |
274 QueryForInput(WideToUTF16(keyword_t_url_->keyword()) + | 274 QueryForInput(WideToUTF16(keyword_t_url_->keyword()) + |
275 UTF8ToUTF16(" ") + term, false); | 275 UTF8ToUTF16(" ") + term, false); |
276 | 276 |
277 // Make sure the default providers suggest service was queried. | 277 // Make sure the default providers suggest service was queried. |
278 TestURLFetcher* default_fetcher = test_factory_.GetFetcherByID( | 278 TestURLFetcher* default_fetcher = test_factory_.GetFetcherByID( |
279 SearchProvider::kDefaultProviderURLFetcherID); | 279 SearchProvider::kDefaultProviderURLFetcherID); |
280 ASSERT_TRUE(default_fetcher); | 280 ASSERT_TRUE(default_fetcher); |
281 | 281 |
282 // Tell the SearchProvider the default suggest query is done. | 282 // Tell the SearchProvider the default suggest query is done. |
283 default_fetcher->delegate()->OnURLFetchComplete( | 283 default_fetcher->delegate()->OnURLFetchComplete( |
284 default_fetcher, GURL(), URLRequestStatus(), 200, ResponseCookies(), | 284 default_fetcher, GURL(), net::URLRequestStatus(), 200, ResponseCookies(), |
285 std::string()); | 285 std::string()); |
286 default_fetcher = NULL; | 286 default_fetcher = NULL; |
287 | 287 |
288 // Make sure the keyword providers suggest service was queried. | 288 // Make sure the keyword providers suggest service was queried. |
289 TestURLFetcher* keyword_fetcher = test_factory_.GetFetcherByID( | 289 TestURLFetcher* keyword_fetcher = test_factory_.GetFetcherByID( |
290 SearchProvider::kKeywordProviderURLFetcherID); | 290 SearchProvider::kKeywordProviderURLFetcherID); |
291 ASSERT_TRUE(keyword_fetcher); | 291 ASSERT_TRUE(keyword_fetcher); |
292 | 292 |
293 // And the URL matches what we expected. | 293 // And the URL matches what we expected. |
294 GURL expected_url = GURL(keyword_t_url_->suggestions_url()-> | 294 GURL expected_url = GURL(keyword_t_url_->suggestions_url()-> |
295 ReplaceSearchTerms(*keyword_t_url_, UTF16ToWide(term), 0, | 295 ReplaceSearchTerms(*keyword_t_url_, UTF16ToWide(term), 0, |
296 std::wstring())); | 296 std::wstring())); |
297 ASSERT_TRUE(keyword_fetcher->original_url() == expected_url); | 297 ASSERT_TRUE(keyword_fetcher->original_url() == expected_url); |
298 | 298 |
299 // Tell the SearchProvider the keyword suggest query is done. | 299 // Tell the SearchProvider the keyword suggest query is done. |
300 keyword_fetcher->delegate()->OnURLFetchComplete( | 300 keyword_fetcher->delegate()->OnURLFetchComplete( |
301 keyword_fetcher, GURL(), URLRequestStatus(), 200, ResponseCookies(), | 301 keyword_fetcher, GURL(), net::URLRequestStatus(), 200, ResponseCookies(), |
302 std::string()); | 302 std::string()); |
303 keyword_fetcher = NULL; | 303 keyword_fetcher = NULL; |
304 | 304 |
305 // Run till the history results complete. | 305 // Run till the history results complete. |
306 RunTillProviderDone(); | 306 RunTillProviderDone(); |
307 | 307 |
308 // The SearchProvider is done. Make sure it has a result for the history | 308 // The SearchProvider is done. Make sure it has a result for the history |
309 // term keyword. | 309 // term keyword. |
310 AutocompleteMatch match = FindMatchWithDestination(keyword_url_); | 310 AutocompleteMatch match = FindMatchWithDestination(keyword_url_); |
311 ASSERT_TRUE(!match.destination_url.is_empty()); | 311 ASSERT_TRUE(!match.destination_url.is_empty()); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 | 417 |
418 // There should be two matches, one for what you typed, the other for | 418 // There should be two matches, one for what you typed, the other for |
419 // 'foobar'. | 419 // 'foobar'. |
420 EXPECT_EQ(2u, provider_->matches().size()); | 420 EXPECT_EQ(2u, provider_->matches().size()); |
421 instant_match = FindMatchWithDestination(instant_url); | 421 instant_match = FindMatchWithDestination(instant_url); |
422 EXPECT_FALSE(instant_match.destination_url.is_empty()); | 422 EXPECT_FALSE(instant_match.destination_url.is_empty()); |
423 | 423 |
424 // And the 'foobar' match should have a description. | 424 // And the 'foobar' match should have a description. |
425 EXPECT_FALSE(instant_match.description.empty()); | 425 EXPECT_FALSE(instant_match.description.empty()); |
426 } | 426 } |
OLD | NEW |