| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/omnibox/browser/search_provider.h" | 5 #include "components/omnibox/browser/search_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 24 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
| 25 #include "chrome/browser/history/history_service_factory.h" | 25 #include "chrome/browser/history/history_service_factory.h" |
| 26 #include "chrome/browser/search_engines/template_url_service_factory.h" | 26 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 27 #include "chrome/browser/signin/account_tracker_service_factory.h" | 27 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 28 #include "chrome/browser/signin/signin_manager_factory.h" | 28 #include "chrome/browser/signin/signin_manager_factory.h" |
| 29 #include "chrome/browser/sync/profile_sync_service_factory.h" | 29 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 30 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 32 #include "chrome/test/base/testing_browser_process.h" | 32 #include "chrome/test/base/testing_browser_process.h" |
| 33 #include "chrome/test/base/testing_profile.h" | 33 #include "chrome/test/base/testing_profile.h" |
| 34 #include "components/bookmarks/common/bookmark_pref_names.h" | |
| 35 #include "components/browser_sync/browser/profile_sync_service.h" | 34 #include "components/browser_sync/browser/profile_sync_service.h" |
| 36 #include "components/google/core/browser/google_switches.h" | 35 #include "components/google/core/browser/google_switches.h" |
| 37 #include "components/history/core/browser/history_service.h" | 36 #include "components/history/core/browser/history_service.h" |
| 38 #include "components/metrics/proto/omnibox_event.pb.h" | 37 #include "components/metrics/proto/omnibox_event.pb.h" |
| 39 #include "components/omnibox/browser/autocomplete_controller.h" | 38 #include "components/omnibox/browser/autocomplete_controller.h" |
| 40 #include "components/omnibox/browser/autocomplete_input.h" | 39 #include "components/omnibox/browser/autocomplete_input.h" |
| 41 #include "components/omnibox/browser/autocomplete_match.h" | 40 #include "components/omnibox/browser/autocomplete_match.h" |
| 42 #include "components/omnibox/browser/autocomplete_provider.h" | 41 #include "components/omnibox/browser/autocomplete_provider.h" |
| 43 #include "components/omnibox/browser/autocomplete_provider_listener.h" | 42 #include "components/omnibox/browser/autocomplete_provider_listener.h" |
| 44 #include "components/omnibox/browser/history_url_provider.h" | 43 #include "components/omnibox/browser/history_url_provider.h" |
| (...skipping 3177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3222 for (size_t j = 0; j < matches.size(); ++j) { | 3221 for (size_t j = 0; j < matches.size(); ++j) { |
| 3223 const Match& match = cases[i].matches[j]; | 3222 const Match& match = cases[i].matches[j]; |
| 3224 SCOPED_TRACE(" and match index: " + base::SizeTToString(j)); | 3223 SCOPED_TRACE(" and match index: " + base::SizeTToString(j)); |
| 3225 EXPECT_EQ(match.contents, base::UTF16ToUTF8(matches[j].contents)); | 3224 EXPECT_EQ(match.contents, base::UTF16ToUTF8(matches[j].contents)); |
| 3226 EXPECT_EQ(match.deletion_url, matches[j].GetAdditionalInfo( | 3225 EXPECT_EQ(match.deletion_url, matches[j].GetAdditionalInfo( |
| 3227 "deletion_url")); | 3226 "deletion_url")); |
| 3228 } | 3227 } |
| 3229 } | 3228 } |
| 3230 } | 3229 } |
| 3231 | 3230 |
| 3232 TEST_F(SearchProviderTest, ReflectsBookmarkBarState) { | |
| 3233 profile_.GetPrefs()->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false); | |
| 3234 base::string16 term = term1_.substr(0, term1_.length() - 1); | |
| 3235 QueryForInput(term, true, false); | |
| 3236 ASSERT_FALSE(provider_->matches().empty()); | |
| 3237 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | |
| 3238 provider_->matches()[0].type); | |
| 3239 ASSERT_TRUE(provider_->matches()[0].search_terms_args != NULL); | |
| 3240 EXPECT_FALSE(provider_->matches()[0].search_terms_args->bookmark_bar_pinned); | |
| 3241 | |
| 3242 profile_.GetPrefs()->SetBoolean(bookmarks::prefs::kShowBookmarkBar, true); | |
| 3243 term = term1_.substr(0, term1_.length() - 1); | |
| 3244 QueryForInput(term, true, false); | |
| 3245 ASSERT_FALSE(provider_->matches().empty()); | |
| 3246 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | |
| 3247 provider_->matches()[0].type); | |
| 3248 ASSERT_TRUE(provider_->matches()[0].search_terms_args != NULL); | |
| 3249 EXPECT_TRUE(provider_->matches()[0].search_terms_args->bookmark_bar_pinned); | |
| 3250 } | |
| 3251 | |
| 3252 TEST_F(SearchProviderTest, CanSendURL) { | 3231 TEST_F(SearchProviderTest, CanSendURL) { |
| 3253 TemplateURLData template_url_data; | 3232 TemplateURLData template_url_data; |
| 3254 template_url_data.SetShortName(ASCIIToUTF16("t")); | 3233 template_url_data.SetShortName(ASCIIToUTF16("t")); |
| 3255 template_url_data.SetURL("http://www.google.com/{searchTerms}"); | 3234 template_url_data.SetURL("http://www.google.com/{searchTerms}"); |
| 3256 template_url_data.suggestions_url = "http://www.google.com/{searchTerms}"; | 3235 template_url_data.suggestions_url = "http://www.google.com/{searchTerms}"; |
| 3257 template_url_data.instant_url = "http://does/not/exist?strk=1"; | 3236 template_url_data.instant_url = "http://does/not/exist?strk=1"; |
| 3258 template_url_data.search_terms_replacement_key = "strk"; | 3237 template_url_data.search_terms_replacement_key = "strk"; |
| 3259 template_url_data.id = SEARCH_ENGINE_GOOGLE; | 3238 template_url_data.id = SEARCH_ENGINE_GOOGLE; |
| 3260 TemplateURL google_template_url(template_url_data); | 3239 TemplateURL google_template_url(template_url_data); |
| 3261 | 3240 |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3617 } | 3596 } |
| 3618 | 3597 |
| 3619 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { | 3598 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { |
| 3620 AutocompleteInput input( | 3599 AutocompleteInput input( |
| 3621 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(), | 3600 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(), |
| 3622 metrics::OmniboxEventProto::INVALID_SPEC, false, true, true, true, true, | 3601 metrics::OmniboxEventProto::INVALID_SPEC, false, true, true, true, true, |
| 3623 ChromeAutocompleteSchemeClassifier(&profile_)); | 3602 ChromeAutocompleteSchemeClassifier(&profile_)); |
| 3624 provider_->Start(input, false); | 3603 provider_->Start(input, false); |
| 3625 EXPECT_TRUE(provider_->matches().empty()); | 3604 EXPECT_TRUE(provider_->matches().empty()); |
| 3626 } | 3605 } |
| OLD | NEW |