| 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 13 matching lines...) Expand all Loading... |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 25 |
| 26 // The following environment is configured for these tests: | 26 // The following environment is configured for these tests: |
| 27 // . The TemplateURL default_t_url_ is set as the default provider. | 27 // . The TemplateURL default_t_url_ is set as the default provider. |
| 28 // . The TemplateURL keyword_t_url_ is added to the TemplateURLService. This | 28 // . The TemplateURL keyword_t_url_ is added to the TemplateURLService. This |
| 29 // TemplateURL has a valid suggest and search URL. | 29 // TemplateURL has a valid suggest and search URL. |
| 30 // . The URL created by using the search term term1_ with default_t_url_ is | 30 // . The URL created by using the search term term1_ with default_t_url_ is |
| 31 // added to history. | 31 // added to history. |
| 32 // . The URL created by using the search term keyword_term_ with keyword_t_url_ | 32 // . The URL created by using the search term keyword_term_ with keyword_t_url_ |
| 33 // is added to history. | 33 // is added to history. |
| 34 // . test_factory_ is set as the URLFetcher::Factory. | 34 // . test_factory_ is set as the URLFetcherFactory. |
| 35 class SearchProviderTest : public testing::Test, | 35 class SearchProviderTest : public testing::Test, |
| 36 public AutocompleteProvider::ACProviderListener { | 36 public AutocompleteProvider::ACProviderListener { |
| 37 public: | 37 public: |
| 38 SearchProviderTest() | 38 SearchProviderTest() |
| 39 : default_t_url_(NULL), | 39 : default_t_url_(NULL), |
| 40 term1_(UTF8ToUTF16("term1")), | 40 term1_(UTF8ToUTF16("term1")), |
| 41 keyword_t_url_(NULL), | 41 keyword_t_url_(NULL), |
| 42 keyword_term_(UTF8ToUTF16("keyword")), | 42 keyword_term_(UTF8ToUTF16("keyword")), |
| 43 io_thread_(BrowserThread::IO), | 43 io_thread_(BrowserThread::IO), |
| 44 quit_when_done_(false) { | 44 quit_when_done_(false) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 TemplateURL* default_t_url_; | 84 TemplateURL* default_t_url_; |
| 85 const string16 term1_; | 85 const string16 term1_; |
| 86 GURL term1_url_; | 86 GURL term1_url_; |
| 87 TemplateURL* keyword_t_url_; | 87 TemplateURL* keyword_t_url_; |
| 88 const string16 keyword_term_; | 88 const string16 keyword_term_; |
| 89 GURL keyword_url_; | 89 GURL keyword_url_; |
| 90 | 90 |
| 91 MessageLoopForUI message_loop_; | 91 MessageLoopForUI message_loop_; |
| 92 BrowserThread io_thread_; | 92 BrowserThread io_thread_; |
| 93 | 93 |
| 94 // URLFetcher::Factory implementation registered. | 94 // URLFetcherFactory implementation registered. |
| 95 TestURLFetcherFactory test_factory_; | 95 TestURLFetcherFactory test_factory_; |
| 96 | 96 |
| 97 // Profile we use. | 97 // Profile we use. |
| 98 TestingProfile profile_; | 98 TestingProfile profile_; |
| 99 | 99 |
| 100 // The provider. | 100 // The provider. |
| 101 scoped_refptr<SearchProvider> provider_; | 101 scoped_refptr<SearchProvider> provider_; |
| 102 | 102 |
| 103 // If true, OnProviderUpdate exits out of the current message loop. | 103 // If true, OnProviderUpdate exits out of the current message loop. |
| 104 bool quit_when_done_; | 104 bool quit_when_done_; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 QueryForInput(term, false); | 252 QueryForInput(term, false); |
| 253 | 253 |
| 254 // Make sure the default providers suggest service was queried. | 254 // Make sure the default providers suggest service was queried. |
| 255 TestURLFetcher* fetcher = test_factory_.GetFetcherByID( | 255 TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
| 256 SearchProvider::kDefaultProviderURLFetcherID); | 256 SearchProvider::kDefaultProviderURLFetcherID); |
| 257 ASSERT_TRUE(fetcher); | 257 ASSERT_TRUE(fetcher); |
| 258 | 258 |
| 259 // And the URL matches what we expected. | 259 // And the URL matches what we expected. |
| 260 GURL expected_url = GURL(default_t_url_->suggestions_url()-> | 260 GURL expected_url = GURL(default_t_url_->suggestions_url()-> |
| 261 ReplaceSearchTerms(*default_t_url_, term, 0, string16())); | 261 ReplaceSearchTerms(*default_t_url_, term, 0, string16())); |
| 262 ASSERT_TRUE(fetcher->GetOriginalUrl() == expected_url); | 262 ASSERT_TRUE(fetcher->GetOriginalURL() == expected_url); |
| 263 | 263 |
| 264 // Tell the SearchProvider the suggest query is done. | 264 // Tell the SearchProvider the suggest query is done. |
| 265 fetcher->set_response_code(200); | 265 fetcher->set_response_code(200); |
| 266 fetcher->delegate()->OnURLFetchComplete(fetcher); | 266 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 267 fetcher = NULL; | 267 fetcher = NULL; |
| 268 | 268 |
| 269 // Run till the history results complete. | 269 // Run till the history results complete. |
| 270 RunTillProviderDone(); | 270 RunTillProviderDone(); |
| 271 | 271 |
| 272 // 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 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 default_fetcher = NULL; | 312 default_fetcher = NULL; |
| 313 | 313 |
| 314 // Make sure the keyword providers suggest service was queried. | 314 // Make sure the keyword providers suggest service was queried. |
| 315 TestURLFetcher* keyword_fetcher = test_factory_.GetFetcherByID( | 315 TestURLFetcher* keyword_fetcher = test_factory_.GetFetcherByID( |
| 316 SearchProvider::kKeywordProviderURLFetcherID); | 316 SearchProvider::kKeywordProviderURLFetcherID); |
| 317 ASSERT_TRUE(keyword_fetcher); | 317 ASSERT_TRUE(keyword_fetcher); |
| 318 | 318 |
| 319 // And the URL matches what we expected. | 319 // And the URL matches what we expected. |
| 320 GURL expected_url = GURL(keyword_t_url_->suggestions_url()-> | 320 GURL expected_url = GURL(keyword_t_url_->suggestions_url()-> |
| 321 ReplaceSearchTerms(*keyword_t_url_, term, 0, string16())); | 321 ReplaceSearchTerms(*keyword_t_url_, term, 0, string16())); |
| 322 ASSERT_TRUE(keyword_fetcher->GetOriginalUrl() == expected_url); | 322 ASSERT_TRUE(keyword_fetcher->GetOriginalURL() == expected_url); |
| 323 | 323 |
| 324 // Tell the SearchProvider the keyword suggest query is done. | 324 // Tell the SearchProvider the keyword suggest query is done. |
| 325 keyword_fetcher->set_response_code(200); | 325 keyword_fetcher->set_response_code(200); |
| 326 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); | 326 keyword_fetcher->delegate()->OnURLFetchComplete(keyword_fetcher); |
| 327 keyword_fetcher = NULL; | 327 keyword_fetcher = NULL; |
| 328 | 328 |
| 329 // Run till the history results complete. | 329 // Run till the history results complete. |
| 330 RunTillProviderDone(); | 330 RunTillProviderDone(); |
| 331 | 331 |
| 332 // 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 |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 fetcher = NULL; | 654 fetcher = NULL; |
| 655 | 655 |
| 656 // Run till the history results complete. | 656 // Run till the history results complete. |
| 657 RunTillProviderDone(); | 657 RunTillProviderDone(); |
| 658 | 658 |
| 659 // 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. |
| 660 AutocompleteMatch nav_match; | 660 AutocompleteMatch nav_match; |
| 661 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match)); | 661 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match)); |
| 662 EXPECT_FALSE(nav_match.template_url); | 662 EXPECT_FALSE(nav_match.template_url); |
| 663 } | 663 } |
| OLD | NEW |