Chromium Code Reviews| 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 "chrome/browser/autocomplete/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 19 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 20 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 20 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
| 21 #include "chrome/browser/autocomplete/autocomplete_input.h" | 21 #include "chrome/browser/autocomplete/autocomplete_input.h" |
| 22 #include "chrome/browser/autocomplete/autocomplete_match.h" | 22 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 23 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 23 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
| 24 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" | 24 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" |
| 25 #include "chrome/browser/autocomplete/history_url_provider.h" | 25 #include "chrome/browser/autocomplete/history_url_provider.h" |
| 26 #include "chrome/browser/history/history_service.h" | 26 #include "chrome/browser/history/history_service.h" |
| 27 #include "chrome/browser/history/history_service_factory.h" | 27 #include "chrome/browser/history/history_service_factory.h" |
| 28 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 28 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
| 29 #include "chrome/browser/search/search.h" | 29 #include "chrome/browser/search/search.h" |
| 30 #include "chrome/browser/search_engines/search_engine_type.h" | |
| 30 #include "chrome/browser/search_engines/template_url.h" | 31 #include "chrome/browser/search_engines/template_url.h" |
| 31 #include "chrome/browser/search_engines/template_url_service.h" | 32 #include "chrome/browser/search_engines/template_url_service.h" |
| 32 #include "chrome/browser/search_engines/template_url_service_factory.h" | 33 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 34 #include "chrome/browser/signin/signin_manager.h" | |
| 35 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 36 #include "chrome/browser/sync/profile_sync_service.h" | |
| 37 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
| 33 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
| 34 #include "chrome/common/metrics/variations/variations_util.h" | 39 #include "chrome/common/metrics/variations/variations_util.h" |
| 35 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
| 36 #include "chrome/test/base/testing_browser_process.h" | 41 #include "chrome/test/base/testing_browser_process.h" |
| 37 #include "chrome/test/base/testing_profile.h" | 42 #include "chrome/test/base/testing_profile.h" |
| 38 #include "components/variations/entropy_provider.h" | 43 #include "components/variations/entropy_provider.h" |
| 39 #include "content/public/test/test_browser_thread_bundle.h" | 44 #include "content/public/test/test_browser_thread_bundle.h" |
| 40 #include "net/url_request/test_url_fetcher_factory.h" | 45 #include "net/url_request/test_url_fetcher_factory.h" |
| 41 #include "net/url_request/url_request_status.h" | 46 #include "net/url_request/url_request_status.h" |
| 42 #include "testing/gtest/include/gtest/gtest.h" | 47 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 2930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2973 | 2978 |
| 2974 profile_.GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, true); | 2979 profile_.GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, true); |
| 2975 term = term1_.substr(0, term1_.length() - 1); | 2980 term = term1_.substr(0, term1_.length() - 1); |
| 2976 QueryForInput(term, true, false); | 2981 QueryForInput(term, true, false); |
| 2977 ASSERT_FALSE(provider_->matches().empty()); | 2982 ASSERT_FALSE(provider_->matches().empty()); |
| 2978 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 2983 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
| 2979 provider_->matches()[0].type); | 2984 provider_->matches()[0].type); |
| 2980 ASSERT_TRUE(provider_->matches()[0].search_terms_args != NULL); | 2985 ASSERT_TRUE(provider_->matches()[0].search_terms_args != NULL); |
| 2981 EXPECT_TRUE(provider_->matches()[0].search_terms_args->bookmark_bar_pinned); | 2986 EXPECT_TRUE(provider_->matches()[0].search_terms_args->bookmark_bar_pinned); |
| 2982 } | 2987 } |
| 2988 | |
| 2989 TEST_F(SearchProviderTest, CanSendURL) { | |
| 2990 TemplateURLData template_url_data; | |
| 2991 template_url_data.short_name = ASCIIToUTF16("t"); | |
| 2992 template_url_data.SetURL("http://www.google.com/{searchTerms}"); | |
| 2993 template_url_data.suggestions_url = "http://www.google.com/{searchTerms}"; | |
| 2994 template_url_data.instant_url = "http://does/not/exist?strk=1"; | |
| 2995 template_url_data.search_terms_replacement_key = "strk"; | |
| 2996 template_url_data.id = SEARCH_ENGINE_GOOGLE; | |
| 2997 TemplateURL google_template_url(&profile_, template_url_data); | |
| 2998 | |
| 2999 SigninManager* signin = SigninManagerFactory::GetForProfile(&profile_); | |
| 3000 signin->SetAuthenticatedUsername("test"); | |
| 3001 // profile_.GetPrefs()->SetBoolean(prefs::kSyncTabs, true); | |
|
Peter Kasting
2013/11/05 04:17:51
Nit: Uncomment or remove
H Fung
2013/11/05 07:00:15
Done.
| |
| 3002 | |
| 3003 // Not in field trial. | |
| 3004 EXPECT_FALSE(SearchProvider::CanSendURL( | |
| 3005 GURL("http://www.google.com/search"), | |
| 3006 GURL("https://www.google.com/complete/search"), | |
| 3007 &google_template_url, | |
| 3008 AutocompleteInput::OTHER, &profile_)); | |
|
Peter Kasting
2013/11/05 04:17:51
Nit: The wrapping in all these EXPECTs is inconsis
H Fung
2013/11/05 07:00:15
Done. Sorry, probably too much cut/paste.
| |
| 3009 | |
| 3010 // All conditions should be met. | |
| 3011 base::FieldTrial* field_trial = base::FieldTrialList::CreateFieldTrial( | |
| 3012 "AutocompleteDynamicTrial_2", "EnableZeroSuggest"); | |
| 3013 field_trial->group(); | |
| 3014 EXPECT_TRUE(SearchProvider::CanSendURL( | |
| 3015 GURL("http://www.google.com/search"), | |
| 3016 GURL("https://www.google.com/complete/search"), | |
| 3017 &google_template_url, | |
| 3018 AutocompleteInput::OTHER, &profile_)); | |
| 3019 | |
| 3020 // Invalid page URL. | |
| 3021 EXPECT_FALSE(SearchProvider::CanSendURL( | |
| 3022 GURL("badpageurl"), | |
| 3023 GURL("https://www.google.com/complete/search"), | |
| 3024 &google_template_url, | |
| 3025 AutocompleteInput::OTHER, &profile_)); | |
| 3026 | |
| 3027 // Invalid page classification. | |
| 3028 EXPECT_FALSE(SearchProvider::CanSendURL( | |
| 3029 GURL("http://www.google.com/search"), | |
| 3030 GURL("https://www.google.com/complete/search"), | |
| 3031 &google_template_url, | |
| 3032 AutocompleteInput::INSTANT_NEW_TAB_PAGE_WITH_FAKEBOX_AS_STARTING_FOCUS, | |
| 3033 &profile_)); | |
| 3034 | |
| 3035 // Invalid page classification. | |
| 3036 EXPECT_FALSE(SearchProvider::CanSendURL( | |
| 3037 GURL("http://www.google.com/search"), | |
| 3038 GURL("https://www.google.com/complete/search"), | |
| 3039 &google_template_url, | |
| 3040 AutocompleteInput::INSTANT_NEW_TAB_PAGE_WITH_OMNIBOX_AS_STARTING_FOCUS, | |
| 3041 &profile_)); | |
| 3042 | |
| 3043 // HTTPS page URL on same domain as provider. | |
| 3044 EXPECT_TRUE(SearchProvider::CanSendURL( | |
| 3045 GURL("https://www.google.com/search"), | |
| 3046 GURL("https://www.google.com/complete/search"), | |
| 3047 &google_template_url, | |
| 3048 AutocompleteInput::OTHER, | |
| 3049 &profile_)); | |
| 3050 | |
| 3051 // Non-HTTP[S] page URL on same domain as provider. | |
| 3052 EXPECT_FALSE(SearchProvider::CanSendURL( | |
| 3053 GURL("ftp://www.google.com/search"), | |
| 3054 GURL("https://www.google.com/complete/search"), | |
| 3055 &google_template_url, | |
| 3056 AutocompleteInput::OTHER, | |
| 3057 &profile_)); | |
| 3058 | |
| 3059 // Non-HTTP page URL on different domain. | |
| 3060 EXPECT_FALSE(SearchProvider::CanSendURL( | |
| 3061 GURL("https://www.notgoogle.com/search"), | |
| 3062 GURL("https://www.google.com/complete/search"), | |
| 3063 &google_template_url, | |
| 3064 AutocompleteInput::OTHER, | |
| 3065 &profile_)); | |
| 3066 | |
| 3067 // Non-HTTPS provider. | |
| 3068 EXPECT_FALSE(SearchProvider::CanSendURL( | |
| 3069 GURL("http://www.google.com/search"), | |
| 3070 GURL("http://www.google.com/complete/search"), | |
| 3071 &google_template_url, | |
| 3072 AutocompleteInput::OTHER, &profile_)); | |
| 3073 | |
| 3074 // Suggest disabled. | |
| 3075 profile_.GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); | |
| 3076 EXPECT_FALSE(SearchProvider::CanSendURL( | |
| 3077 GURL("http://www.google.com/search"), | |
| 3078 GURL("https://www.google.com/complete/search"), | |
| 3079 &google_template_url, | |
| 3080 AutocompleteInput::OTHER, &profile_)); | |
| 3081 profile_.GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); | |
| 3082 | |
| 3083 // Incognito. | |
| 3084 EXPECT_FALSE(SearchProvider::CanSendURL( | |
| 3085 GURL("http://www.google.com/search"), | |
| 3086 GURL("https://www.google.com/complete/search"), | |
| 3087 &google_template_url, | |
| 3088 AutocompleteInput::OTHER, profile_.GetOffTheRecordProfile())); | |
| 3089 | |
| 3090 // Not signed in. | |
| 3091 signin->SignOut(); | |
| 3092 EXPECT_FALSE(SearchProvider::CanSendURL( | |
| 3093 GURL("http://www.google.com/search"), | |
| 3094 GURL("https://www.google.com/complete/search"), | |
| 3095 &google_template_url, | |
| 3096 AutocompleteInput::OTHER, &profile_)); | |
| 3097 signin->SetAuthenticatedUsername("test"); | |
| 3098 | |
| 3099 // Tab sync not enabled. | |
| 3100 profile_.GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); | |
| 3101 profile_.GetPrefs()->SetBoolean(prefs::kSyncTabs, false); | |
| 3102 EXPECT_FALSE(SearchProvider::CanSendURL( | |
| 3103 GURL("http://www.google.com/search"), | |
| 3104 GURL("https://www.google.com/complete/search"), | |
| 3105 &google_template_url, | |
| 3106 AutocompleteInput::OTHER, &profile_)); | |
| 3107 profile_.GetPrefs()->SetBoolean(prefs::kSyncTabs, true); | |
| 3108 | |
| 3109 // Tab sync is encrypted. | |
| 3110 ProfileSyncService* service = | |
| 3111 ProfileSyncServiceFactory::GetInstance()->GetForProfile(&profile_); | |
| 3112 syncer::ModelTypeSet encrypted_types = service->GetEncryptedDataTypes(); | |
| 3113 encrypted_types.Put(syncer::SESSIONS); | |
| 3114 service->OnEncryptedTypesChanged(encrypted_types, false); | |
| 3115 EXPECT_FALSE(SearchProvider::CanSendURL( | |
| 3116 GURL("http://www.google.com/search"), | |
| 3117 GURL("https://www.google.com/complete/search"), | |
| 3118 &google_template_url, | |
| 3119 AutocompleteInput::OTHER, &profile_)); | |
| 3120 encrypted_types.Remove(syncer::SESSIONS); | |
| 3121 service->OnEncryptedTypesChanged(encrypted_types, false); | |
| 3122 | |
| 3123 // Check that there were no side effect from previous tests. | |
|
Peter Kasting
2013/11/05 04:17:51
Nit: effect -> effects
H Fung
2013/11/05 07:00:15
Done.
| |
| 3124 EXPECT_TRUE(SearchProvider::CanSendURL( | |
| 3125 GURL("http://www.google.com/search"), | |
| 3126 GURL("https://www.google.com/complete/search"), | |
| 3127 &google_template_url, | |
| 3128 AutocompleteInput::OTHER, &profile_)); | |
| 3129 } | |
| OLD | NEW |