Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: chrome/browser/autocomplete/search_provider_unittest.cc

Issue 343523003: Remove AutocompleteInput Type and PageClassification. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 19 matching lines...) Expand all
30 #include "chrome/browser/search_engines/template_url_service.h" 30 #include "chrome/browser/search_engines/template_url_service.h"
31 #include "chrome/browser/search_engines/template_url_service_factory.h" 31 #include "chrome/browser/search_engines/template_url_service_factory.h"
32 #include "chrome/browser/signin/signin_manager_factory.h" 32 #include "chrome/browser/signin/signin_manager_factory.h"
33 #include "chrome/browser/sync/profile_sync_service.h" 33 #include "chrome/browser/sync/profile_sync_service.h"
34 #include "chrome/browser/sync/profile_sync_service_factory.h" 34 #include "chrome/browser/sync/profile_sync_service_factory.h"
35 #include "chrome/common/chrome_switches.h" 35 #include "chrome/common/chrome_switches.h"
36 #include "chrome/common/pref_names.h" 36 #include "chrome/common/pref_names.h"
37 #include "chrome/test/base/testing_browser_process.h" 37 #include "chrome/test/base/testing_browser_process.h"
38 #include "chrome/test/base/testing_profile.h" 38 #include "chrome/test/base/testing_profile.h"
39 #include "components/google/core/browser/google_switches.h" 39 #include "components/google/core/browser/google_switches.h"
40 #include "components/metrics/proto/omnibox_event.pb.h"
40 #include "components/search_engines/search_engine_type.h" 41 #include "components/search_engines/search_engine_type.h"
41 #include "components/signin/core/browser/signin_manager.h" 42 #include "components/signin/core/browser/signin_manager.h"
42 #include "components/sync_driver/pref_names.h" 43 #include "components/sync_driver/pref_names.h"
43 #include "components/variations/entropy_provider.h" 44 #include "components/variations/entropy_provider.h"
44 #include "components/variations/variations_associated_data.h" 45 #include "components/variations/variations_associated_data.h"
45 #include "content/public/test/test_browser_thread_bundle.h" 46 #include "content/public/test/test_browser_thread_bundle.h"
46 #include "net/url_request/test_url_fetcher_factory.h" 47 #include "net/url_request/test_url_fetcher_factory.h"
47 #include "net/url_request/url_request_status.h" 48 #include "net/url_request/url_request_status.h"
48 #include "testing/gtest/include/gtest/gtest.h" 49 #include "testing/gtest/include/gtest/gtest.h"
49 50
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 provider_ = NULL; 291 provider_ = NULL;
291 } 292 }
292 293
293 void SearchProviderTest::RunTest(TestData* cases, 294 void SearchProviderTest::RunTest(TestData* cases,
294 int num_cases, 295 int num_cases,
295 bool prefer_keyword) { 296 bool prefer_keyword) {
296 ACMatches matches; 297 ACMatches matches;
297 for (int i = 0; i < num_cases; ++i) { 298 for (int i = 0; i < num_cases; ++i) {
298 AutocompleteInput input(cases[i].input, base::string16::npos, 299 AutocompleteInput input(cases[i].input, base::string16::npos,
299 base::string16(), GURL(), 300 base::string16(), GURL(),
300 AutocompleteInput::INVALID_SPEC, false, 301 metrics::OmniboxEventProto::INVALID_SPEC, false,
301 prefer_keyword, true, true); 302 prefer_keyword, true, true);
302 provider_->Start(input, false); 303 provider_->Start(input, false);
303 matches = provider_->matches(); 304 matches = provider_->matches();
304 base::string16 diagnostic_details = 305 base::string16 diagnostic_details =
305 ASCIIToUTF16("Input was: ") + 306 ASCIIToUTF16("Input was: ") +
306 cases[i].input + 307 cases[i].input +
307 ASCIIToUTF16("; prefer_keyword was: ") + 308 ASCIIToUTF16("; prefer_keyword was: ") +
308 (prefer_keyword ? ASCIIToUTF16("true") : ASCIIToUTF16("false")); 309 (prefer_keyword ? ASCIIToUTF16("true") : ASCIIToUTF16("false"));
309 EXPECT_EQ(cases[i].num_results, matches.size()) << diagnostic_details; 310 EXPECT_EQ(cases[i].num_results, matches.size()) << diagnostic_details;
310 if (matches.size() == cases[i].num_results) { 311 if (matches.size() == cases[i].num_results) {
(...skipping 25 matching lines...) Expand all
336 base::RunLoop run_loop; 337 base::RunLoop run_loop;
337 run_loop_ = &run_loop; 338 run_loop_ = &run_loop;
338 run_loop.Run(); 339 run_loop.Run();
339 } 340 }
340 341
341 void SearchProviderTest::QueryForInput(const base::string16& text, 342 void SearchProviderTest::QueryForInput(const base::string16& text,
342 bool prevent_inline_autocomplete, 343 bool prevent_inline_autocomplete,
343 bool prefer_keyword) { 344 bool prefer_keyword) {
344 // Start a query. 345 // Start a query.
345 AutocompleteInput input(text, base::string16::npos, base::string16(), GURL(), 346 AutocompleteInput input(text, base::string16::npos, base::string16(), GURL(),
346 AutocompleteInput::INVALID_SPEC, 347 metrics::OmniboxEventProto::INVALID_SPEC,
347 prevent_inline_autocomplete, prefer_keyword, true, 348 prevent_inline_autocomplete, prefer_keyword, true,
348 true); 349 true);
349 provider_->Start(input, false); 350 provider_->Start(input, false);
350 351
351 // RunUntilIdle so that the task scheduled by SearchProvider to create the 352 // RunUntilIdle so that the task scheduled by SearchProvider to create the
352 // URLFetchers runs. 353 // URLFetchers runs.
353 base::RunLoop().RunUntilIdle(); 354 base::RunLoop().RunUntilIdle();
354 } 355 }
355 356
356 void SearchProviderTest::QueryForInputAndSetWYTMatch( 357 void SearchProviderTest::QueryForInputAndSetWYTMatch(
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 // results) in the right order and set descriptions for them correctly. 876 // results) in the right order and set descriptions for them correctly.
876 TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) { 877 TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) {
877 // Add an entry that corresponds to a keyword search with 'term2'. 878 // Add an entry that corresponds to a keyword search with 'term2'.
878 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1); 879 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1);
879 profile_.BlockUntilHistoryProcessesPendingRequests(); 880 profile_.BlockUntilHistoryProcessesPendingRequests();
880 881
881 AutocompleteController controller(&profile_, NULL, 882 AutocompleteController controller(&profile_, NULL,
882 AutocompleteProvider::TYPE_SEARCH); 883 AutocompleteProvider::TYPE_SEARCH);
883 controller.Start(AutocompleteInput( 884 controller.Start(AutocompleteInput(
884 ASCIIToUTF16("k t"), base::string16::npos, base::string16(), GURL(), 885 ASCIIToUTF16("k t"), base::string16::npos, base::string16(), GURL(),
885 AutocompleteInput::INVALID_SPEC, false, false, true, true)); 886 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true));
886 const AutocompleteResult& result = controller.result(); 887 const AutocompleteResult& result = controller.result();
887 888
888 // There should be three matches, one for the keyword history, one for 889 // 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 890 // keyword provider's what-you-typed, and one for the default provider's
890 // what you typed, in that order. 891 // what you typed, in that order.
891 ASSERT_EQ(3u, result.size()); 892 ASSERT_EQ(3u, result.size());
892 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, result.match_at(0).type); 893 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, result.match_at(0).type);
893 EXPECT_EQ(AutocompleteMatchType::SEARCH_OTHER_ENGINE, 894 EXPECT_EQ(AutocompleteMatchType::SEARCH_OTHER_ENGINE,
894 result.match_at(1).type); 895 result.match_at(1).type);
895 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 896 EXPECT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
(...skipping 2004 matching lines...) Expand 10 before | Expand all | Expand 10 after
2900 2901
2901 // Create field trial. 2902 // Create field trial.
2902 base::FieldTrial* field_trial = base::FieldTrialList::CreateFieldTrial( 2903 base::FieldTrial* field_trial = base::FieldTrialList::CreateFieldTrial(
2903 "AutocompleteDynamicTrial_2", "EnableZeroSuggest"); 2904 "AutocompleteDynamicTrial_2", "EnableZeroSuggest");
2904 field_trial->group(); 2905 field_trial->group();
2905 2906
2906 // Not signed in. 2907 // Not signed in.
2907 EXPECT_FALSE(SearchProvider::CanSendURL( 2908 EXPECT_FALSE(SearchProvider::CanSendURL(
2908 GURL("http://www.google.com/search"), 2909 GURL("http://www.google.com/search"),
2909 GURL("https://www.google.com/complete/search"), &google_template_url, 2910 GURL("https://www.google.com/complete/search"), &google_template_url,
2910 AutocompleteInput::OTHER, &profile_)); 2911 metrics::OmniboxEventProto::OTHER, &profile_));
2911 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(&profile_); 2912 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(&profile_);
2912 signin->SetAuthenticatedUsername("test"); 2913 signin->SetAuthenticatedUsername("test");
2913 2914
2914 // All conditions should be met. 2915 // All conditions should be met.
2915 EXPECT_TRUE(SearchProvider::CanSendURL( 2916 EXPECT_TRUE(SearchProvider::CanSendURL(
2916 GURL("http://www.google.com/search"), 2917 GURL("http://www.google.com/search"),
2917 GURL("https://www.google.com/complete/search"), &google_template_url, 2918 GURL("https://www.google.com/complete/search"), &google_template_url,
2918 AutocompleteInput::OTHER, &profile_)); 2919 metrics::OmniboxEventProto::OTHER, &profile_));
2919 2920
2920 // Not in field trial. 2921 // Not in field trial.
2921 ResetFieldTrialList(); 2922 ResetFieldTrialList();
2922 EXPECT_FALSE(SearchProvider::CanSendURL( 2923 EXPECT_FALSE(SearchProvider::CanSendURL(
2923 GURL("http://www.google.com/search"), 2924 GURL("http://www.google.com/search"),
2924 GURL("https://www.google.com/complete/search"), &google_template_url, 2925 GURL("https://www.google.com/complete/search"), &google_template_url,
2925 AutocompleteInput::OTHER, &profile_)); 2926 metrics::OmniboxEventProto::OTHER, &profile_));
2926 field_trial = base::FieldTrialList::CreateFieldTrial( 2927 field_trial = base::FieldTrialList::CreateFieldTrial(
2927 "AutocompleteDynamicTrial_2", "EnableZeroSuggest"); 2928 "AutocompleteDynamicTrial_2", "EnableZeroSuggest");
2928 field_trial->group(); 2929 field_trial->group();
2929 2930
2930 // Invalid page URL. 2931 // Invalid page URL.
2931 EXPECT_FALSE(SearchProvider::CanSendURL( 2932 EXPECT_FALSE(SearchProvider::CanSendURL(
2932 GURL("badpageurl"), 2933 GURL("badpageurl"),
2933 GURL("https://www.google.com/complete/search"), &google_template_url, 2934 GURL("https://www.google.com/complete/search"), &google_template_url,
2934 AutocompleteInput::OTHER, &profile_)); 2935 metrics::OmniboxEventProto::OTHER, &profile_));
2935 2936
2936 // Invalid page classification. 2937 // Invalid page classification.
2937 EXPECT_FALSE(SearchProvider::CanSendURL( 2938 EXPECT_FALSE(SearchProvider::CanSendURL(
2938 GURL("http://www.google.com/search"), 2939 GURL("http://www.google.com/search"),
2939 GURL("https://www.google.com/complete/search"), &google_template_url, 2940 GURL("https://www.google.com/complete/search"), &google_template_url,
2940 AutocompleteInput::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS, 2941 metrics::OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS,
2941 &profile_)); 2942 &profile_));
2942 2943
2943 // Invalid page classification. 2944 // Invalid page classification.
2944 EXPECT_FALSE(SearchProvider::CanSendURL( 2945 EXPECT_FALSE(SearchProvider::CanSendURL(
2945 GURL("http://www.google.com/search"), 2946 GURL("http://www.google.com/search"),
2946 GURL("https://www.google.com/complete/search"), &google_template_url, 2947 GURL("https://www.google.com/complete/search"), &google_template_url,
2947 AutocompleteInput::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, 2948 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS,
2948 &profile_)); 2949 &profile_));
2949 2950
2950 // HTTPS page URL on same domain as provider. 2951 // HTTPS page URL on same domain as provider.
2951 EXPECT_TRUE(SearchProvider::CanSendURL( 2952 EXPECT_TRUE(SearchProvider::CanSendURL(
2952 GURL("https://www.google.com/search"), 2953 GURL("https://www.google.com/search"),
2953 GURL("https://www.google.com/complete/search"), 2954 GURL("https://www.google.com/complete/search"),
2954 &google_template_url, AutocompleteInput::OTHER, &profile_)); 2955 &google_template_url, metrics::OmniboxEventProto::OTHER, &profile_));
2955 2956
2956 // Non-HTTP[S] page URL on same domain as provider. 2957 // Non-HTTP[S] page URL on same domain as provider.
2957 EXPECT_FALSE(SearchProvider::CanSendURL( 2958 EXPECT_FALSE(SearchProvider::CanSendURL(
2958 GURL("ftp://www.google.com/search"), 2959 GURL("ftp://www.google.com/search"),
2959 GURL("https://www.google.com/complete/search"), &google_template_url, 2960 GURL("https://www.google.com/complete/search"), &google_template_url,
2960 AutocompleteInput::OTHER, &profile_)); 2961 metrics::OmniboxEventProto::OTHER, &profile_));
2961 2962
2962 // Non-HTTP page URL on different domain. 2963 // Non-HTTP page URL on different domain.
2963 EXPECT_FALSE(SearchProvider::CanSendURL( 2964 EXPECT_FALSE(SearchProvider::CanSendURL(
2964 GURL("https://www.notgoogle.com/search"), 2965 GURL("https://www.notgoogle.com/search"),
2965 GURL("https://www.google.com/complete/search"), &google_template_url, 2966 GURL("https://www.google.com/complete/search"), &google_template_url,
2966 AutocompleteInput::OTHER, &profile_)); 2967 metrics::OmniboxEventProto::OTHER, &profile_));
2967 2968
2968 // Non-HTTPS provider. 2969 // Non-HTTPS provider.
2969 EXPECT_FALSE(SearchProvider::CanSendURL( 2970 EXPECT_FALSE(SearchProvider::CanSendURL(
2970 GURL("http://www.google.com/search"), 2971 GURL("http://www.google.com/search"),
2971 GURL("http://www.google.com/complete/search"), &google_template_url, 2972 GURL("http://www.google.com/complete/search"), &google_template_url,
2972 AutocompleteInput::OTHER, &profile_)); 2973 metrics::OmniboxEventProto::OTHER, &profile_));
2973 2974
2974 // Suggest disabled. 2975 // Suggest disabled.
2975 profile_.GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); 2976 profile_.GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false);
2976 EXPECT_FALSE(SearchProvider::CanSendURL( 2977 EXPECT_FALSE(SearchProvider::CanSendURL(
2977 GURL("http://www.google.com/search"), 2978 GURL("http://www.google.com/search"),
2978 GURL("https://www.google.com/complete/search"), &google_template_url, 2979 GURL("https://www.google.com/complete/search"), &google_template_url,
2979 AutocompleteInput::OTHER, &profile_)); 2980 metrics::OmniboxEventProto::OTHER, &profile_));
2980 profile_.GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); 2981 profile_.GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true);
2981 2982
2982 // Incognito. 2983 // Incognito.
2983 EXPECT_FALSE(SearchProvider::CanSendURL( 2984 EXPECT_FALSE(SearchProvider::CanSendURL(
2984 GURL("http://www.google.com/search"), 2985 GURL("http://www.google.com/search"),
2985 GURL("https://www.google.com/complete/search"), &google_template_url, 2986 GURL("https://www.google.com/complete/search"), &google_template_url,
2986 AutocompleteInput::OTHER, profile_.GetOffTheRecordProfile())); 2987 metrics::OmniboxEventProto::OTHER, profile_.GetOffTheRecordProfile()));
2987 2988
2988 // Tab sync not enabled. 2989 // Tab sync not enabled.
2989 profile_.GetPrefs()->SetBoolean(sync_driver::prefs::kSyncKeepEverythingSynced, 2990 profile_.GetPrefs()->SetBoolean(sync_driver::prefs::kSyncKeepEverythingSynced,
2990 false); 2991 false);
2991 profile_.GetPrefs()->SetBoolean(sync_driver::prefs::kSyncTabs, false); 2992 profile_.GetPrefs()->SetBoolean(sync_driver::prefs::kSyncTabs, false);
2992 EXPECT_FALSE(SearchProvider::CanSendURL( 2993 EXPECT_FALSE(SearchProvider::CanSendURL(
2993 GURL("http://www.google.com/search"), 2994 GURL("http://www.google.com/search"),
2994 GURL("https://www.google.com/complete/search"), &google_template_url, 2995 GURL("https://www.google.com/complete/search"), &google_template_url,
2995 AutocompleteInput::OTHER, &profile_)); 2996 metrics::OmniboxEventProto::OTHER, &profile_));
2996 profile_.GetPrefs()->SetBoolean(sync_driver::prefs::kSyncTabs, true); 2997 profile_.GetPrefs()->SetBoolean(sync_driver::prefs::kSyncTabs, true);
2997 2998
2998 // Tab sync is encrypted. 2999 // Tab sync is encrypted.
2999 ProfileSyncService* service = 3000 ProfileSyncService* service =
3000 ProfileSyncServiceFactory::GetInstance()->GetForProfile(&profile_); 3001 ProfileSyncServiceFactory::GetInstance()->GetForProfile(&profile_);
3001 syncer::ModelTypeSet encrypted_types = service->GetEncryptedDataTypes(); 3002 syncer::ModelTypeSet encrypted_types = service->GetEncryptedDataTypes();
3002 encrypted_types.Put(syncer::SESSIONS); 3003 encrypted_types.Put(syncer::SESSIONS);
3003 service->OnEncryptedTypesChanged(encrypted_types, false); 3004 service->OnEncryptedTypesChanged(encrypted_types, false);
3004 EXPECT_FALSE(SearchProvider::CanSendURL( 3005 EXPECT_FALSE(SearchProvider::CanSendURL(
3005 GURL("http://www.google.com/search"), 3006 GURL("http://www.google.com/search"),
3006 GURL("https://www.google.com/complete/search"), &google_template_url, 3007 GURL("https://www.google.com/complete/search"), &google_template_url,
3007 AutocompleteInput::OTHER, &profile_)); 3008 metrics::OmniboxEventProto::OTHER, &profile_));
3008 encrypted_types.Remove(syncer::SESSIONS); 3009 encrypted_types.Remove(syncer::SESSIONS);
3009 service->OnEncryptedTypesChanged(encrypted_types, false); 3010 service->OnEncryptedTypesChanged(encrypted_types, false);
3010 3011
3011 // Check that there were no side effects from previous tests. 3012 // Check that there were no side effects from previous tests.
3012 EXPECT_TRUE(SearchProvider::CanSendURL( 3013 EXPECT_TRUE(SearchProvider::CanSendURL(
3013 GURL("http://www.google.com/search"), 3014 GURL("http://www.google.com/search"),
3014 GURL("https://www.google.com/complete/search"), &google_template_url, 3015 GURL("https://www.google.com/complete/search"), &google_template_url,
3015 AutocompleteInput::OTHER, &profile_)); 3016 metrics::OmniboxEventProto::OTHER, &profile_));
3016 } 3017 }
3017 3018
3018 TEST_F(SearchProviderTest, TestDeleteMatch) { 3019 TEST_F(SearchProviderTest, TestDeleteMatch) {
3019 AutocompleteMatch match(provider_, 0, true, 3020 AutocompleteMatch match(provider_, 0, true,
3020 AutocompleteMatchType::SEARCH_SUGGEST); 3021 AutocompleteMatchType::SEARCH_SUGGEST);
3021 match.RecordAdditionalInfo( 3022 match.RecordAdditionalInfo(
3022 SearchProvider::kDeletionUrlKey, 3023 SearchProvider::kDeletionUrlKey,
3023 "https://www.google.com/complete/deleteitem?q=foo"); 3024 "https://www.google.com/complete/deleteitem?q=foo");
3024 3025
3025 // Test a successful deletion request. 3026 // Test a successful deletion request.
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
3178 3179
3179 // The expiration time is always updated. 3180 // The expiration time is always updated.
3180 provider_->GetSessionToken(); 3181 provider_->GetSessionToken();
3181 base::TimeTicks expiration_time_1 = provider_->token_expiration_time_; 3182 base::TimeTicks expiration_time_1 = provider_->token_expiration_time_;
3182 base::PlatformThread::Sleep(kSmallDelta); 3183 base::PlatformThread::Sleep(kSmallDelta);
3183 provider_->GetSessionToken(); 3184 provider_->GetSessionToken();
3184 base::TimeTicks expiration_time_2 = provider_->token_expiration_time_; 3185 base::TimeTicks expiration_time_2 = provider_->token_expiration_time_;
3185 EXPECT_GT(expiration_time_2, expiration_time_1); 3186 EXPECT_GT(expiration_time_2, expiration_time_1);
3186 EXPECT_GE(expiration_time_2, expiration_time_1 + kSmallDelta); 3187 EXPECT_GE(expiration_time_2, expiration_time_1 + kSmallDelta);
3187 } 3188 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/search_provider.cc ('k') | chrome/browser/autocomplete/shortcuts_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698