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" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 } | 232 } |
233 return false; | 233 return false; |
234 } | 234 } |
235 | 235 |
236 void SearchProviderTest::FinishDefaultSuggestQuery() { | 236 void SearchProviderTest::FinishDefaultSuggestQuery() { |
237 TestURLFetcher* default_fetcher = test_factory_.GetFetcherByID( | 237 TestURLFetcher* default_fetcher = test_factory_.GetFetcherByID( |
238 SearchProvider::kDefaultProviderURLFetcherID); | 238 SearchProvider::kDefaultProviderURLFetcherID); |
239 ASSERT_TRUE(default_fetcher); | 239 ASSERT_TRUE(default_fetcher); |
240 | 240 |
241 // Tell the SearchProvider the default suggest query is done. | 241 // Tell the SearchProvider the default suggest query is done. |
242 default_fetcher->delegate()->OnURLFetchComplete( | 242 default_fetcher->set_response_code(200); |
243 default_fetcher, GURL(), net::URLRequestStatus(), 200, | 243 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); |
244 net::ResponseCookies(), std::string()); | |
245 } | 244 } |
246 | 245 |
247 // Tests ----------------------------------------------------------------------- | 246 // Tests ----------------------------------------------------------------------- |
248 | 247 |
249 // Make sure we query history for the default provider and a URLFetcher is | 248 // Make sure we query history for the default provider and a URLFetcher is |
250 // created for the default provider suggest results. | 249 // created for the default provider suggest results. |
251 TEST_F(SearchProviderTest, QueryDefaultProvider) { | 250 TEST_F(SearchProviderTest, QueryDefaultProvider) { |
252 string16 term = term1_.substr(0, term1_.length() - 1); | 251 string16 term = term1_.substr(0, term1_.length() - 1); |
253 QueryForInput(term, false); | 252 QueryForInput(term, false); |
254 | 253 |
255 // Make sure the default providers suggest service was queried. | 254 // Make sure the default providers suggest service was queried. |
256 TestURLFetcher* fetcher = test_factory_.GetFetcherByID( | 255 TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
257 SearchProvider::kDefaultProviderURLFetcherID); | 256 SearchProvider::kDefaultProviderURLFetcherID); |
258 ASSERT_TRUE(fetcher); | 257 ASSERT_TRUE(fetcher); |
259 | 258 |
260 // And the URL matches what we expected. | 259 // And the URL matches what we expected. |
261 GURL expected_url = GURL(default_t_url_->suggestions_url()-> | 260 GURL expected_url = GURL(default_t_url_->suggestions_url()-> |
262 ReplaceSearchTerms(*default_t_url_, term, 0, string16())); | 261 ReplaceSearchTerms(*default_t_url_, term, 0, string16())); |
263 ASSERT_TRUE(fetcher->original_url() == expected_url); | 262 ASSERT_TRUE(fetcher->original_url() == expected_url); |
264 | 263 |
265 // Tell the SearchProvider the suggest query is done. | 264 // Tell the SearchProvider the suggest query is done. |
266 fetcher->delegate()->OnURLFetchComplete( | 265 fetcher->set_response_code(200); |
267 fetcher, GURL(), net::URLRequestStatus(), 200, net::ResponseCookies(), | 266 fetcher->delegate()->OnURLFetchComplete(fetcher); |
268 std::string()); | |
269 fetcher = NULL; | 267 fetcher = NULL; |
270 | 268 |
271 // Run till the history results complete. | 269 // Run till the history results complete. |
272 RunTillProviderDone(); | 270 RunTillProviderDone(); |
273 | 271 |
274 // The SearchProvider is done. Make sure it has a result for the history | 272 // The SearchProvider is done. Make sure it has a result for the history |
275 // term term1. | 273 // term term1. |
276 AutocompleteMatch term1_match; | 274 AutocompleteMatch term1_match; |
277 EXPECT_TRUE(FindMatchWithDestination(term1_url_, &term1_match)); | 275 EXPECT_TRUE(FindMatchWithDestination(term1_url_, &term1_match)); |
278 // Term1 should not have a description, it's set later. | 276 // Term1 should not have a description, it's set later. |
(...skipping 23 matching lines...) Expand all Loading... |
302 TEST_F(SearchProviderTest, QueryKeywordProvider) { | 300 TEST_F(SearchProviderTest, QueryKeywordProvider) { |
303 string16 term = keyword_term_.substr(0, keyword_term_.length() - 1); | 301 string16 term = keyword_term_.substr(0, keyword_term_.length() - 1); |
304 QueryForInput(keyword_t_url_->keyword() + UTF8ToUTF16(" ") + term, false); | 302 QueryForInput(keyword_t_url_->keyword() + UTF8ToUTF16(" ") + term, false); |
305 | 303 |
306 // Make sure the default providers suggest service was queried. | 304 // Make sure the default providers suggest service was queried. |
307 TestURLFetcher* default_fetcher = test_factory_.GetFetcherByID( | 305 TestURLFetcher* default_fetcher = test_factory_.GetFetcherByID( |
308 SearchProvider::kDefaultProviderURLFetcherID); | 306 SearchProvider::kDefaultProviderURLFetcherID); |
309 ASSERT_TRUE(default_fetcher); | 307 ASSERT_TRUE(default_fetcher); |
310 | 308 |
311 // Tell the SearchProvider the default suggest query is done. | 309 // Tell the SearchProvider the default suggest query is done. |
312 default_fetcher->delegate()->OnURLFetchComplete( | 310 default_fetcher->set_response_code(200); |
313 default_fetcher, GURL(), net::URLRequestStatus(), 200, | 311 default_fetcher->delegate()->OnURLFetchComplete(default_fetcher); |
314 net::ResponseCookies(), std::string()); | |
315 default_fetcher = NULL; | 312 default_fetcher = NULL; |
316 | 313 |
317 // Make sure the keyword providers suggest service was queried. | 314 // Make sure the keyword providers suggest service was queried. |
318 TestURLFetcher* keyword_fetcher = test_factory_.GetFetcherByID( | 315 TestURLFetcher* keyword_fetcher = test_factory_.GetFetcherByID( |
319 SearchProvider::kKeywordProviderURLFetcherID); | 316 SearchProvider::kKeywordProviderURLFetcherID); |
320 ASSERT_TRUE(keyword_fetcher); | 317 ASSERT_TRUE(keyword_fetcher); |
321 | 318 |
322 // And the URL matches what we expected. | 319 // And the URL matches what we expected. |
323 GURL expected_url = GURL(keyword_t_url_->suggestions_url()-> | 320 GURL expected_url = GURL(keyword_t_url_->suggestions_url()-> |
324 ReplaceSearchTerms(*keyword_t_url_, term, 0, string16())); | 321 ReplaceSearchTerms(*keyword_t_url_, term, 0, string16())); |
325 ASSERT_TRUE(keyword_fetcher->original_url() == expected_url); | 322 ASSERT_TRUE(keyword_fetcher->original_url() == expected_url); |
326 | 323 |
327 // Tell the SearchProvider the keyword suggest query is done. | 324 // Tell the SearchProvider the keyword suggest query is done. |
328 keyword_fetcher->delegate()->OnURLFetchComplete( | 325 keyword_fetcher->set_response_code(200); |
329 keyword_fetcher, GURL(), net::URLRequestStatus(), 200, | 326 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); |
330 net::ResponseCookies(), std::string()); | |
331 keyword_fetcher = NULL; | 327 keyword_fetcher = NULL; |
332 | 328 |
333 // Run till the history results complete. | 329 // Run till the history results complete. |
334 RunTillProviderDone(); | 330 RunTillProviderDone(); |
335 | 331 |
336 // The SearchProvider is done. Make sure it has a result for the history | 332 // The SearchProvider is done. Make sure it has a result for the history |
337 // term keyword. | 333 // term keyword. |
338 AutocompleteMatch match; | 334 AutocompleteMatch match; |
339 EXPECT_TRUE(FindMatchWithDestination(keyword_url_, &match)); | 335 EXPECT_TRUE(FindMatchWithDestination(keyword_url_, &match)); |
340 | 336 |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 // on). | 639 // on). |
644 TEST_F(SearchProviderTest, NoTemplateURLForNavsuggest) { | 640 TEST_F(SearchProviderTest, NoTemplateURLForNavsuggest) { |
645 QueryForInput(ASCIIToUTF16("a.c"), false); | 641 QueryForInput(ASCIIToUTF16("a.c"), false); |
646 | 642 |
647 // Make sure the default providers suggest service was queried. | 643 // Make sure the default providers suggest service was queried. |
648 TestURLFetcher* fetcher = test_factory_.GetFetcherByID( | 644 TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
649 SearchProvider::kDefaultProviderURLFetcherID); | 645 SearchProvider::kDefaultProviderURLFetcherID); |
650 ASSERT_TRUE(fetcher); | 646 ASSERT_TRUE(fetcher); |
651 | 647 |
652 // Tell the SearchProvider the suggest query is done. | 648 // Tell the SearchProvider the suggest query is done. |
653 fetcher->delegate()->OnURLFetchComplete( | 649 fetcher->set_response_code(200); |
654 fetcher, GURL(), net::URLRequestStatus(), 200, net::ResponseCookies(), | 650 fetcher->SetResponseString( |
655 "[\"a.c\",[\"a.com\"],[\"\"],[]," | 651 "[\"a.c\",[\"a.com\"],[\"\"],[]," |
656 "{\"google:suggesttype\":[\"NAVIGATION\"]}]"); | 652 "{\"google:suggesttype\":[\"NAVIGATION\"]}]"); |
| 653 fetcher->delegate()->OnURLFetchComplete(fetcher); |
657 fetcher = NULL; | 654 fetcher = NULL; |
658 | 655 |
659 // Run till the history results complete. | 656 // Run till the history results complete. |
660 RunTillProviderDone(); | 657 RunTillProviderDone(); |
661 | 658 |
662 // Make sure there is a match for 'a.com' and it doesn't have a template_url. | 659 // Make sure there is a match for 'a.com' and it doesn't have a template_url. |
663 AutocompleteMatch nav_match; | 660 AutocompleteMatch nav_match; |
664 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match)); | 661 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match)); |
665 EXPECT_FALSE(nav_match.template_url); | 662 EXPECT_FALSE(nav_match.template_url); |
666 } | 663 } |
OLD | NEW |