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" |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 provider_ = NULL; | 290 provider_ = NULL; |
291 } | 291 } |
292 | 292 |
293 void SearchProviderTest::RunTest(TestData* cases, | 293 void SearchProviderTest::RunTest(TestData* cases, |
294 int num_cases, | 294 int num_cases, |
295 bool prefer_keyword) { | 295 bool prefer_keyword) { |
296 ACMatches matches; | 296 ACMatches matches; |
297 for (int i = 0; i < num_cases; ++i) { | 297 for (int i = 0; i < num_cases; ++i) { |
298 AutocompleteInput input(cases[i].input, base::string16::npos, | 298 AutocompleteInput input(cases[i].input, base::string16::npos, |
299 base::string16(), GURL(), | 299 base::string16(), GURL(), |
300 AutocompleteInput::INVALID_SPEC, false, | 300 metrics::OmniboxEventProto::INVALID_SPEC, false, |
301 prefer_keyword, true, true); | 301 prefer_keyword, true, true); |
302 provider_->Start(input, false); | 302 provider_->Start(input, false); |
303 matches = provider_->matches(); | 303 matches = provider_->matches(); |
304 base::string16 diagnostic_details = | 304 base::string16 diagnostic_details = |
305 ASCIIToUTF16("Input was: ") + | 305 ASCIIToUTF16("Input was: ") + |
306 cases[i].input + | 306 cases[i].input + |
307 ASCIIToUTF16("; prefer_keyword was: ") + | 307 ASCIIToUTF16("; prefer_keyword was: ") + |
308 (prefer_keyword ? ASCIIToUTF16("true") : ASCIIToUTF16("false")); | 308 (prefer_keyword ? ASCIIToUTF16("true") : ASCIIToUTF16("false")); |
309 EXPECT_EQ(cases[i].num_results, matches.size()) << diagnostic_details; | 309 EXPECT_EQ(cases[i].num_results, matches.size()) << diagnostic_details; |
310 if (matches.size() == cases[i].num_results) { | 310 if (matches.size() == cases[i].num_results) { |
(...skipping 25 matching lines...) Expand all Loading... |
336 base::RunLoop run_loop; | 336 base::RunLoop run_loop; |
337 run_loop_ = &run_loop; | 337 run_loop_ = &run_loop; |
338 run_loop.Run(); | 338 run_loop.Run(); |
339 } | 339 } |
340 | 340 |
341 void SearchProviderTest::QueryForInput(const base::string16& text, | 341 void SearchProviderTest::QueryForInput(const base::string16& text, |
342 bool prevent_inline_autocomplete, | 342 bool prevent_inline_autocomplete, |
343 bool prefer_keyword) { | 343 bool prefer_keyword) { |
344 // Start a query. | 344 // Start a query. |
345 AutocompleteInput input(text, base::string16::npos, base::string16(), GURL(), | 345 AutocompleteInput input(text, base::string16::npos, base::string16(), GURL(), |
346 AutocompleteInput::INVALID_SPEC, | 346 metrics::OmniboxEventProto::INVALID_SPEC, |
347 prevent_inline_autocomplete, prefer_keyword, true, | 347 prevent_inline_autocomplete, prefer_keyword, true, |
348 true); | 348 true); |
349 provider_->Start(input, false); | 349 provider_->Start(input, false); |
350 | 350 |
351 // RunUntilIdle so that the task scheduled by SearchProvider to create the | 351 // RunUntilIdle so that the task scheduled by SearchProvider to create the |
352 // URLFetchers runs. | 352 // URLFetchers runs. |
353 base::RunLoop().RunUntilIdle(); | 353 base::RunLoop().RunUntilIdle(); |
354 } | 354 } |
355 | 355 |
356 void SearchProviderTest::QueryForInputAndSetWYTMatch( | 356 void SearchProviderTest::QueryForInputAndSetWYTMatch( |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 // results) in the right order and set descriptions for them correctly. | 875 // results) in the right order and set descriptions for them correctly. |
876 TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) { | 876 TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) { |
877 // Add an entry that corresponds to a keyword search with 'term2'. | 877 // Add an entry that corresponds to a keyword search with 'term2'. |
878 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1); | 878 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1); |
879 profile_.BlockUntilHistoryProcessesPendingRequests(); | 879 profile_.BlockUntilHistoryProcessesPendingRequests(); |
880 | 880 |
881 AutocompleteController controller(&profile_, NULL, | 881 AutocompleteController controller(&profile_, NULL, |
882 AutocompleteProvider::TYPE_SEARCH); | 882 AutocompleteProvider::TYPE_SEARCH); |
883 controller.Start(AutocompleteInput( | 883 controller.Start(AutocompleteInput( |
884 ASCIIToUTF16("k t"), base::string16::npos, base::string16(), GURL(), | 884 ASCIIToUTF16("k t"), base::string16::npos, base::string16(), GURL(), |
885 AutocompleteInput::INVALID_SPEC, false, false, true, true)); | 885 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true)); |
886 const AutocompleteResult& result = controller.result(); | 886 const AutocompleteResult& result = controller.result(); |
887 | 887 |
888 // There should be three matches, one for the keyword history, one for | 888 // There should be three matches, one for the keyword history, one for |
889 // keyword provider's what-you-typed, and one for the default provider's | 889 // keyword provider's what-you-typed, and one for the default provider's |
890 // what you typed, in that order. | 890 // what you typed, in that order. |
891 ASSERT_EQ(3u, result.size()); | 891 ASSERT_EQ(3u, result.size()); |
892 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, result.match_at(0).type); | 892 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, result.match_at(0).type); |
893 EXPECT_EQ(AutocompleteMatchType::SEARCH_OTHER_ENGINE, | 893 EXPECT_EQ(AutocompleteMatchType::SEARCH_OTHER_ENGINE, |
894 result.match_at(1).type); | 894 result.match_at(1).type); |
895 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 895 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
(...skipping 2004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2900 | 2900 |
2901 // Create field trial. | 2901 // Create field trial. |
2902 base::FieldTrial* field_trial = base::FieldTrialList::CreateFieldTrial( | 2902 base::FieldTrial* field_trial = base::FieldTrialList::CreateFieldTrial( |
2903 "AutocompleteDynamicTrial_2", "EnableZeroSuggest"); | 2903 "AutocompleteDynamicTrial_2", "EnableZeroSuggest"); |
2904 field_trial->group(); | 2904 field_trial->group(); |
2905 | 2905 |
2906 // Not signed in. | 2906 // Not signed in. |
2907 EXPECT_FALSE(SearchProvider::CanSendURL( | 2907 EXPECT_FALSE(SearchProvider::CanSendURL( |
2908 GURL("http://www.google.com/search"), | 2908 GURL("http://www.google.com/search"), |
2909 GURL("https://www.google.com/complete/search"), &google_template_url, | 2909 GURL("https://www.google.com/complete/search"), &google_template_url, |
2910 AutocompleteInput::OTHER, &profile_)); | 2910 metrics::OmniboxEventProto::OTHER, &profile_)); |
2911 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(&profile_); | 2911 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(&profile_); |
2912 signin->SetAuthenticatedUsername("test"); | 2912 signin->SetAuthenticatedUsername("test"); |
2913 | 2913 |
2914 // All conditions should be met. | 2914 // All conditions should be met. |
2915 EXPECT_TRUE(SearchProvider::CanSendURL( | 2915 EXPECT_TRUE(SearchProvider::CanSendURL( |
2916 GURL("http://www.google.com/search"), | 2916 GURL("http://www.google.com/search"), |
2917 GURL("https://www.google.com/complete/search"), &google_template_url, | 2917 GURL("https://www.google.com/complete/search"), &google_template_url, |
2918 AutocompleteInput::OTHER, &profile_)); | 2918 metrics::OmniboxEventProto::OTHER, &profile_)); |
2919 | 2919 |
2920 // Not in field trial. | 2920 // Not in field trial. |
2921 ResetFieldTrialList(); | 2921 ResetFieldTrialList(); |
2922 EXPECT_FALSE(SearchProvider::CanSendURL( | 2922 EXPECT_FALSE(SearchProvider::CanSendURL( |
2923 GURL("http://www.google.com/search"), | 2923 GURL("http://www.google.com/search"), |
2924 GURL("https://www.google.com/complete/search"), &google_template_url, | 2924 GURL("https://www.google.com/complete/search"), &google_template_url, |
2925 AutocompleteInput::OTHER, &profile_)); | 2925 metrics::OmniboxEventProto::OTHER, &profile_)); |
2926 field_trial = base::FieldTrialList::CreateFieldTrial( | 2926 field_trial = base::FieldTrialList::CreateFieldTrial( |
2927 "AutocompleteDynamicTrial_2", "EnableZeroSuggest"); | 2927 "AutocompleteDynamicTrial_2", "EnableZeroSuggest"); |
2928 field_trial->group(); | 2928 field_trial->group(); |
2929 | 2929 |
2930 // Invalid page URL. | 2930 // Invalid page URL. |
2931 EXPECT_FALSE(SearchProvider::CanSendURL( | 2931 EXPECT_FALSE(SearchProvider::CanSendURL( |
2932 GURL("badpageurl"), | 2932 GURL("badpageurl"), |
2933 GURL("https://www.google.com/complete/search"), &google_template_url, | 2933 GURL("https://www.google.com/complete/search"), &google_template_url, |
2934 AutocompleteInput::OTHER, &profile_)); | 2934 metrics::OmniboxEventProto::OTHER, &profile_)); |
2935 | 2935 |
2936 // Invalid page classification. | 2936 // Invalid page classification. |
2937 EXPECT_FALSE(SearchProvider::CanSendURL( | 2937 EXPECT_FALSE(SearchProvider::CanSendURL( |
2938 GURL("http://www.google.com/search"), | 2938 GURL("http://www.google.com/search"), |
2939 GURL("https://www.google.com/complete/search"), &google_template_url, | 2939 GURL("https://www.google.com/complete/search"), &google_template_url, |
2940 AutocompleteInput::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, | 2940 metrics::OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, |
2941 &profile_)); | 2941 &profile_)); |
2942 | 2942 |
2943 // Invalid page classification. | 2943 // Invalid page classification. |
2944 EXPECT_FALSE(SearchProvider::CanSendURL( | 2944 EXPECT_FALSE(SearchProvider::CanSendURL( |
2945 GURL("http://www.google.com/search"), | 2945 GURL("http://www.google.com/search"), |
2946 GURL("https://www.google.com/complete/search"), &google_template_url, | 2946 GURL("https://www.google.com/complete/search"), &google_template_url, |
2947 AutocompleteInput::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, | 2947 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, |
2948 &profile_)); | 2948 &profile_)); |
2949 | 2949 |
2950 // HTTPS page URL on same domain as provider. | 2950 // HTTPS page URL on same domain as provider. |
2951 EXPECT_TRUE(SearchProvider::CanSendURL( | 2951 EXPECT_TRUE(SearchProvider::CanSendURL( |
2952 GURL("https://www.google.com/search"), | 2952 GURL("https://www.google.com/search"), |
2953 GURL("https://www.google.com/complete/search"), | 2953 GURL("https://www.google.com/complete/search"), |
2954 &google_template_url, AutocompleteInput::OTHER, &profile_)); | 2954 &google_template_url, metrics::OmniboxEventProto::OTHER, &profile_)); |
2955 | 2955 |
2956 // Non-HTTP[S] page URL on same domain as provider. | 2956 // Non-HTTP[S] page URL on same domain as provider. |
2957 EXPECT_FALSE(SearchProvider::CanSendURL( | 2957 EXPECT_FALSE(SearchProvider::CanSendURL( |
2958 GURL("ftp://www.google.com/search"), | 2958 GURL("ftp://www.google.com/search"), |
2959 GURL("https://www.google.com/complete/search"), &google_template_url, | 2959 GURL("https://www.google.com/complete/search"), &google_template_url, |
2960 AutocompleteInput::OTHER, &profile_)); | 2960 metrics::OmniboxEventProto::OTHER, &profile_)); |
2961 | 2961 |
2962 // Non-HTTP page URL on different domain. | 2962 // Non-HTTP page URL on different domain. |
2963 EXPECT_FALSE(SearchProvider::CanSendURL( | 2963 EXPECT_FALSE(SearchProvider::CanSendURL( |
2964 GURL("https://www.notgoogle.com/search"), | 2964 GURL("https://www.notgoogle.com/search"), |
2965 GURL("https://www.google.com/complete/search"), &google_template_url, | 2965 GURL("https://www.google.com/complete/search"), &google_template_url, |
2966 AutocompleteInput::OTHER, &profile_)); | 2966 metrics::OmniboxEventProto::OTHER, &profile_)); |
2967 | 2967 |
2968 // Non-HTTPS provider. | 2968 // Non-HTTPS provider. |
2969 EXPECT_FALSE(SearchProvider::CanSendURL( | 2969 EXPECT_FALSE(SearchProvider::CanSendURL( |
2970 GURL("http://www.google.com/search"), | 2970 GURL("http://www.google.com/search"), |
2971 GURL("http://www.google.com/complete/search"), &google_template_url, | 2971 GURL("http://www.google.com/complete/search"), &google_template_url, |
2972 AutocompleteInput::OTHER, &profile_)); | 2972 metrics::OmniboxEventProto::OTHER, &profile_)); |
2973 | 2973 |
2974 // Suggest disabled. | 2974 // Suggest disabled. |
2975 profile_.GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); | 2975 profile_.GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); |
2976 EXPECT_FALSE(SearchProvider::CanSendURL( | 2976 EXPECT_FALSE(SearchProvider::CanSendURL( |
2977 GURL("http://www.google.com/search"), | 2977 GURL("http://www.google.com/search"), |
2978 GURL("https://www.google.com/complete/search"), &google_template_url, | 2978 GURL("https://www.google.com/complete/search"), &google_template_url, |
2979 AutocompleteInput::OTHER, &profile_)); | 2979 metrics::OmniboxEventProto::OTHER, &profile_)); |
2980 profile_.GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); | 2980 profile_.GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); |
2981 | 2981 |
2982 // Incognito. | 2982 // Incognito. |
2983 EXPECT_FALSE(SearchProvider::CanSendURL( | 2983 EXPECT_FALSE(SearchProvider::CanSendURL( |
2984 GURL("http://www.google.com/search"), | 2984 GURL("http://www.google.com/search"), |
2985 GURL("https://www.google.com/complete/search"), &google_template_url, | 2985 GURL("https://www.google.com/complete/search"), &google_template_url, |
2986 AutocompleteInput::OTHER, profile_.GetOffTheRecordProfile())); | 2986 metrics::OmniboxEventProto::OTHER, profile_.GetOffTheRecordProfile())); |
2987 | 2987 |
2988 // Tab sync not enabled. | 2988 // Tab sync not enabled. |
2989 profile_.GetPrefs()->SetBoolean(sync_driver::prefs::kSyncKeepEverythingSynced, | 2989 profile_.GetPrefs()->SetBoolean(sync_driver::prefs::kSyncKeepEverythingSynced, |
2990 false); | 2990 false); |
2991 profile_.GetPrefs()->SetBoolean(sync_driver::prefs::kSyncTabs, false); | 2991 profile_.GetPrefs()->SetBoolean(sync_driver::prefs::kSyncTabs, false); |
2992 EXPECT_FALSE(SearchProvider::CanSendURL( | 2992 EXPECT_FALSE(SearchProvider::CanSendURL( |
2993 GURL("http://www.google.com/search"), | 2993 GURL("http://www.google.com/search"), |
2994 GURL("https://www.google.com/complete/search"), &google_template_url, | 2994 GURL("https://www.google.com/complete/search"), &google_template_url, |
2995 AutocompleteInput::OTHER, &profile_)); | 2995 metrics::OmniboxEventProto::OTHER, &profile_)); |
2996 profile_.GetPrefs()->SetBoolean(sync_driver::prefs::kSyncTabs, true); | 2996 profile_.GetPrefs()->SetBoolean(sync_driver::prefs::kSyncTabs, true); |
2997 | 2997 |
2998 // Tab sync is encrypted. | 2998 // Tab sync is encrypted. |
2999 ProfileSyncService* service = | 2999 ProfileSyncService* service = |
3000 ProfileSyncServiceFactory::GetInstance()->GetForProfile(&profile_); | 3000 ProfileSyncServiceFactory::GetInstance()->GetForProfile(&profile_); |
3001 syncer::ModelTypeSet encrypted_types = service->GetEncryptedDataTypes(); | 3001 syncer::ModelTypeSet encrypted_types = service->GetEncryptedDataTypes(); |
3002 encrypted_types.Put(syncer::SESSIONS); | 3002 encrypted_types.Put(syncer::SESSIONS); |
3003 service->OnEncryptedTypesChanged(encrypted_types, false); | 3003 service->OnEncryptedTypesChanged(encrypted_types, false); |
3004 EXPECT_FALSE(SearchProvider::CanSendURL( | 3004 EXPECT_FALSE(SearchProvider::CanSendURL( |
3005 GURL("http://www.google.com/search"), | 3005 GURL("http://www.google.com/search"), |
3006 GURL("https://www.google.com/complete/search"), &google_template_url, | 3006 GURL("https://www.google.com/complete/search"), &google_template_url, |
3007 AutocompleteInput::OTHER, &profile_)); | 3007 metrics::OmniboxEventProto::OTHER, &profile_)); |
3008 encrypted_types.Remove(syncer::SESSIONS); | 3008 encrypted_types.Remove(syncer::SESSIONS); |
3009 service->OnEncryptedTypesChanged(encrypted_types, false); | 3009 service->OnEncryptedTypesChanged(encrypted_types, false); |
3010 | 3010 |
3011 // Check that there were no side effects from previous tests. | 3011 // Check that there were no side effects from previous tests. |
3012 EXPECT_TRUE(SearchProvider::CanSendURL( | 3012 EXPECT_TRUE(SearchProvider::CanSendURL( |
3013 GURL("http://www.google.com/search"), | 3013 GURL("http://www.google.com/search"), |
3014 GURL("https://www.google.com/complete/search"), &google_template_url, | 3014 GURL("https://www.google.com/complete/search"), &google_template_url, |
3015 AutocompleteInput::OTHER, &profile_)); | 3015 metrics::OmniboxEventProto::OTHER, &profile_)); |
3016 } | 3016 } |
3017 | 3017 |
3018 TEST_F(SearchProviderTest, TestDeleteMatch) { | 3018 TEST_F(SearchProviderTest, TestDeleteMatch) { |
3019 AutocompleteMatch match(provider_, 0, true, | 3019 AutocompleteMatch match(provider_, 0, true, |
3020 AutocompleteMatchType::SEARCH_SUGGEST); | 3020 AutocompleteMatchType::SEARCH_SUGGEST); |
3021 match.RecordAdditionalInfo( | 3021 match.RecordAdditionalInfo( |
3022 SearchProvider::kDeletionUrlKey, | 3022 SearchProvider::kDeletionUrlKey, |
3023 "https://www.google.com/complete/deleteitem?q=foo"); | 3023 "https://www.google.com/complete/deleteitem?q=foo"); |
3024 | 3024 |
3025 // Test a successful deletion request. | 3025 // Test a successful deletion request. |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3178 | 3178 |
3179 // The expiration time is always updated. | 3179 // The expiration time is always updated. |
3180 provider_->GetSessionToken(); | 3180 provider_->GetSessionToken(); |
3181 base::TimeTicks expiration_time_1 = provider_->token_expiration_time_; | 3181 base::TimeTicks expiration_time_1 = provider_->token_expiration_time_; |
3182 base::PlatformThread::Sleep(kSmallDelta); | 3182 base::PlatformThread::Sleep(kSmallDelta); |
3183 provider_->GetSessionToken(); | 3183 provider_->GetSessionToken(); |
3184 base::TimeTicks expiration_time_2 = provider_->token_expiration_time_; | 3184 base::TimeTicks expiration_time_2 = provider_->token_expiration_time_; |
3185 EXPECT_GT(expiration_time_2, expiration_time_1); | 3185 EXPECT_GT(expiration_time_2, expiration_time_1); |
3186 EXPECT_GE(expiration_time_2, expiration_time_1 + kSmallDelta); | 3186 EXPECT_GE(expiration_time_2, expiration_time_1 + kSmallDelta); |
3187 } | 3187 } |
OLD | NEW |