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

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

Issue 23621037: Send URLs on non-zero prefix suggest requests also. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Try to fix more tests Created 7 years, 1 month 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
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"
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
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 // Create field trial.
3000 scoped_ptr<base::FieldTrialList> field_trial_list_;
3001 base::FieldTrial* field_trial = base::FieldTrialList::CreateFieldTrial(
3002 "AutocompleteDynamicTrial_2", "EnableZeroSuggest");
3003 field_trial->group();
3004
3005 // Not signed in.
3006 EXPECT_FALSE(SearchProvider::CanSendURL(
3007 GURL("http://www.google.com/search"),
3008 GURL("https://www.google.com/complete/search"), &google_template_url,
3009 AutocompleteInput::OTHER, &profile_));
3010 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(&profile_);
3011 signin->SetAuthenticatedUsername("test");
3012
3013 // All conditions should be met.
3014 EXPECT_TRUE(SearchProvider::CanSendURL(
3015 GURL("http://www.google.com/search"),
3016 GURL("https://www.google.com/complete/search"), &google_template_url,
3017 AutocompleteInput::OTHER, &profile_));
3018
3019 // Not in field trial.
3020 field_trial_list_.reset();
3021 field_trial_list_.reset(new base::FieldTrialList(
3022 new metrics::SHA1EntropyProvider("foo")));
3023 EXPECT_FALSE(SearchProvider::CanSendURL(
3024 GURL("http://www.google.com/search"),
3025 GURL("https://www.google.com/complete/search"), &google_template_url,
3026 AutocompleteInput::OTHER, &profile_));
3027 field_trial = base::FieldTrialList::CreateFieldTrial(
3028 "AutocompleteDynamicTrial_2", "EnableZeroSuggest");
3029 field_trial->group();
3030
3031 // Invalid page URL.
3032 EXPECT_FALSE(SearchProvider::CanSendURL(
3033 GURL("badpageurl"),
3034 GURL("https://www.google.com/complete/search"), &google_template_url,
3035 AutocompleteInput::OTHER, &profile_));
3036
3037 // Invalid page classification.
3038 EXPECT_FALSE(SearchProvider::CanSendURL(
3039 GURL("http://www.google.com/search"),
3040 GURL("https://www.google.com/complete/search"), &google_template_url,
3041 AutocompleteInput::INSTANT_NEW_TAB_PAGE_WITH_FAKEBOX_AS_STARTING_FOCUS,
3042 &profile_));
3043
3044 // Invalid page classification.
3045 EXPECT_FALSE(SearchProvider::CanSendURL(
3046 GURL("http://www.google.com/search"),
3047 GURL("https://www.google.com/complete/search"), &google_template_url,
3048 AutocompleteInput::INSTANT_NEW_TAB_PAGE_WITH_OMNIBOX_AS_STARTING_FOCUS,
3049 &profile_));
3050
3051 // HTTPS page URL on same domain as provider.
3052 EXPECT_TRUE(SearchProvider::CanSendURL(
3053 GURL("https://www.google.com/search"),
3054 GURL("https://www.google.com/complete/search"),
3055 &google_template_url, AutocompleteInput::OTHER, &profile_));
3056
3057 // Non-HTTP[S] page URL on same domain as provider.
3058 EXPECT_FALSE(SearchProvider::CanSendURL(
3059 GURL("ftp://www.google.com/search"),
3060 GURL("https://www.google.com/complete/search"), &google_template_url,
3061 AutocompleteInput::OTHER, &profile_));
3062
3063 // Non-HTTP page URL on different domain.
3064 EXPECT_FALSE(SearchProvider::CanSendURL(
3065 GURL("https://www.notgoogle.com/search"),
3066 GURL("https://www.google.com/complete/search"), &google_template_url,
3067 AutocompleteInput::OTHER, &profile_));
3068
3069 // Non-HTTPS provider.
3070 EXPECT_FALSE(SearchProvider::CanSendURL(
3071 GURL("http://www.google.com/search"),
3072 GURL("http://www.google.com/complete/search"), &google_template_url,
3073 AutocompleteInput::OTHER, &profile_));
3074
3075 // Suggest disabled.
3076 profile_.GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false);
3077 EXPECT_FALSE(SearchProvider::CanSendURL(
3078 GURL("http://www.google.com/search"),
3079 GURL("https://www.google.com/complete/search"), &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"), &google_template_url,
3087 AutocompleteInput::OTHER, profile_.GetOffTheRecordProfile()));
3088
3089 // Tab sync not enabled.
3090 profile_.GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false);
3091 profile_.GetPrefs()->SetBoolean(prefs::kSyncTabs, false);
3092 EXPECT_FALSE(SearchProvider::CanSendURL(
3093 GURL("http://www.google.com/search"),
3094 GURL("https://www.google.com/complete/search"), &google_template_url,
3095 AutocompleteInput::OTHER, &profile_));
3096 profile_.GetPrefs()->SetBoolean(prefs::kSyncTabs, true);
3097
3098 // Tab sync is encrypted.
3099 ProfileSyncService* service =
3100 ProfileSyncServiceFactory::GetInstance()->GetForProfile(&profile_);
3101 syncer::ModelTypeSet encrypted_types = service->GetEncryptedDataTypes();
3102 encrypted_types.Put(syncer::SESSIONS);
3103 service->OnEncryptedTypesChanged(encrypted_types, false);
3104 EXPECT_FALSE(SearchProvider::CanSendURL(
3105 GURL("http://www.google.com/search"),
3106 GURL("https://www.google.com/complete/search"), &google_template_url,
3107 AutocompleteInput::OTHER, &profile_));
3108 encrypted_types.Remove(syncer::SESSIONS);
3109 service->OnEncryptedTypesChanged(encrypted_types, false);
3110
3111 // Check that there were no side effects from previous tests.
3112 EXPECT_TRUE(SearchProvider::CanSendURL(
3113 GURL("http://www.google.com/search"),
3114 GURL("https://www.google.com/complete/search"), &google_template_url,
3115 AutocompleteInput::OTHER, &profile_));
3116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698