OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/webdata/web_data_service_factory.h" | |
18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
19 #include "chrome/test/base/testing_browser_process.h" | 20 #include "chrome/test/base/testing_browser_process.h" |
20 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
21 #include "content/test/test_browser_thread.h" | 22 #include "content/test/test_browser_thread.h" |
22 #include "content/test/test_url_fetcher_factory.h" | 23 #include "content/test/test_url_fetcher_factory.h" |
23 #include "net/url_request/url_request_status.h" | 24 #include "net/url_request/url_request_status.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 using content::BrowserThread; | 27 using content::BrowserThread; |
27 | 28 |
29 namespace { | |
30 | |
31 // Build no WebDataService. | |
32 static scoped_refptr<RefcountedProfileKeyedService> BuildNull( | |
Ilya Sherman
2012/03/27 01:01:17
nit: No need to declare this method static, since
GeorgeY
2012/03/30 19:20:12
Removed it.
| |
33 Profile* profile) { | |
34 return NULL; | |
35 } | |
36 | |
37 } // namespace | |
38 | |
28 // The following environment is configured for these tests: | 39 // The following environment is configured for these tests: |
29 // . The TemplateURL default_t_url_ is set as the default provider. | 40 // . The TemplateURL default_t_url_ is set as the default provider. |
30 // . The TemplateURL keyword_t_url_ is added to the TemplateURLService. This | 41 // . The TemplateURL keyword_t_url_ is added to the TemplateURLService. This |
31 // TemplateURL has a valid suggest and search URL. | 42 // TemplateURL has a valid suggest and search URL. |
32 // . The URL created by using the search term term1_ with default_t_url_ is | 43 // . The URL created by using the search term term1_ with default_t_url_ is |
33 // added to history. | 44 // added to history. |
34 // . The URL created by using the search term keyword_term_ with keyword_t_url_ | 45 // . The URL created by using the search term keyword_term_ with keyword_t_url_ |
35 // is added to history. | 46 // is added to history. |
36 // . test_factory_ is set as the URLFetcherFactory. | 47 // . test_factory_ is set as the URLFetcherFactory. |
37 class SearchProviderTest : public testing::Test, | 48 class SearchProviderTest : public testing::Test, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 // If true, OnProviderUpdate exits out of the current message loop. | 116 // If true, OnProviderUpdate exits out of the current message loop. |
106 bool quit_when_done_; | 117 bool quit_when_done_; |
107 | 118 |
108 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest); | 119 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest); |
109 }; | 120 }; |
110 | 121 |
111 void SearchProviderTest::SetUp() { | 122 void SearchProviderTest::SetUp() { |
112 SearchProvider::set_query_suggest_immediately(true); | 123 SearchProvider::set_query_suggest_immediately(true); |
113 | 124 |
114 // We need both the history service and template url model loaded. | 125 // We need both the history service and template url model loaded. |
126 // TemplateURLService relies on the absence of the WebDataService in tests. | |
127 WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile_, BuildNull); | |
115 profile_.CreateHistoryService(true, false); | 128 profile_.CreateHistoryService(true, false); |
116 profile_.CreateTemplateURLService(); | 129 profile_.CreateTemplateURLService(); |
117 | 130 |
118 TemplateURLService* turl_model = | 131 TemplateURLService* turl_model = |
119 TemplateURLServiceFactory::GetForProfile(&profile_); | 132 TemplateURLServiceFactory::GetForProfile(&profile_); |
120 | 133 |
121 turl_model->Load(); | 134 turl_model->Load(); |
122 | 135 |
123 // Reset the default TemplateURL. | 136 // Reset the default TemplateURL. |
124 default_t_url_ = new TemplateURL(); | 137 default_t_url_ = new TemplateURL(); |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
664 fetcher = NULL; | 677 fetcher = NULL; |
665 | 678 |
666 // Run till the history results complete. | 679 // Run till the history results complete. |
667 RunTillProviderDone(); | 680 RunTillProviderDone(); |
668 | 681 |
669 // Make sure there is a match for 'a.com' and it doesn't have a template_url. | 682 // Make sure there is a match for 'a.com' and it doesn't have a template_url. |
670 AutocompleteMatch nav_match; | 683 AutocompleteMatch nav_match; |
671 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match)); | 684 EXPECT_TRUE(FindMatchWithDestination(GURL("http://a.com"), &nav_match)); |
672 EXPECT_FALSE(nav_match.template_url); | 685 EXPECT_FALSE(nav_match.template_url); |
673 } | 686 } |
OLD | NEW |