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 3085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3096 // Verbatim match duplicates are added such that each one has a higher | 3096 // Verbatim match duplicates are added such that each one has a higher |
3097 // relevance than the previous one. | 3097 // relevance than the previous one. |
3098 EXPECT_EQ(2U, verbatim.duplicate_matches.size()); | 3098 EXPECT_EQ(2U, verbatim.duplicate_matches.size()); |
3099 | 3099 |
3100 // Other match duplicates are added in descending relevance order. | 3100 // Other match duplicates are added in descending relevance order. |
3101 EXPECT_EQ(1U, match_alpha.duplicate_matches.size()); | 3101 EXPECT_EQ(1U, match_alpha.duplicate_matches.size()); |
3102 EXPECT_EQ(1U, match_avid.duplicate_matches.size()); | 3102 EXPECT_EQ(1U, match_avid.duplicate_matches.size()); |
3103 | 3103 |
3104 EXPECT_EQ(0U, match_apricot.duplicate_matches.size()); | 3104 EXPECT_EQ(0U, match_apricot.duplicate_matches.size()); |
3105 } | 3105 } |
| 3106 |
| 3107 #if defined(OS_ANDROID) |
| 3108 TEST_F(SearchProviderTest, SuggestQueryUsesToken) { |
| 3109 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3110 switches::kEnableAnswersInSuggest); |
| 3111 |
| 3112 TemplateURLService* turl_model = |
| 3113 TemplateURLServiceFactory::GetForProfile(&profile_); |
| 3114 |
| 3115 TemplateURLData data; |
| 3116 data.short_name = ASCIIToUTF16("default"); |
| 3117 data.SetKeyword(data.short_name); |
| 3118 data.SetURL("http://example/{searchTerms}{google:sessionToken}"); |
| 3119 data.suggestions_url = |
| 3120 "http://suggest/?q={searchTerms}&{google:sessionToken}"; |
| 3121 default_t_url_ = new TemplateURL(&profile_, data); |
| 3122 turl_model->Add(default_t_url_); |
| 3123 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); |
| 3124 |
| 3125 base::string16 term = term1_.substr(0, term1_.length() - 1); |
| 3126 QueryForInput(term, false, false); |
| 3127 |
| 3128 // Make sure the default provider's suggest service was queried. |
| 3129 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( |
| 3130 SearchProvider::kDefaultProviderURLFetcherID); |
| 3131 ASSERT_TRUE(fetcher); |
| 3132 |
| 3133 // And the URL matches what we expected. |
| 3134 TemplateURLRef::SearchTermsArgs search_terms_args(term); |
| 3135 search_terms_args.session_token = provider_->current_token_; |
| 3136 GURL expected_url(default_t_url_->suggestions_url_ref().ReplaceSearchTerms( |
| 3137 search_terms_args)); |
| 3138 EXPECT_EQ(fetcher->GetOriginalURL().spec(), expected_url.spec()); |
| 3139 |
| 3140 // Complete running the fetcher to clean up. |
| 3141 fetcher->set_response_code(200); |
| 3142 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 3143 RunTillProviderDone(); |
| 3144 } |
| 3145 #endif |
| 3146 |
| 3147 TEST_F(SearchProviderTest, SessionToken) { |
| 3148 // Subsequent calls always get the same token. |
| 3149 std::string token = provider_->GetSessionToken(); |
| 3150 std::string token2 = provider_->GetSessionToken(); |
| 3151 EXPECT_EQ(token, token2); |
| 3152 EXPECT_FALSE(token.empty()); |
| 3153 |
| 3154 // Calls do not regenerate a token. |
| 3155 provider_->current_token_ = "PRE-EXISTING TOKEN"; |
| 3156 token = provider_->GetSessionToken(); |
| 3157 EXPECT_EQ(token, "PRE-EXISTING TOKEN"); |
| 3158 |
| 3159 // ... unless the token has expired. |
| 3160 provider_->current_token_.clear(); |
| 3161 const base::TimeDelta kSmallDelta = base::TimeDelta::FromMilliseconds(1); |
| 3162 provider_->token_expiration_time_ = base::TimeTicks::Now() - kSmallDelta; |
| 3163 token = provider_->GetSessionToken(); |
| 3164 EXPECT_FALSE(token.empty()); |
| 3165 EXPECT_EQ(token, provider_->current_token_); |
| 3166 |
| 3167 // The expiration time is always updated. |
| 3168 provider_->GetSessionToken(); |
| 3169 base::TimeTicks expiration_time_1 = provider_->token_expiration_time_; |
| 3170 base::PlatformThread::Sleep(kSmallDelta); |
| 3171 provider_->GetSessionToken(); |
| 3172 base::TimeTicks expiration_time_2 = provider_->token_expiration_time_; |
| 3173 EXPECT_GT(expiration_time_2, expiration_time_1); |
| 3174 EXPECT_GE(expiration_time_2, expiration_time_1 + kSmallDelta); |
| 3175 } |
OLD | NEW |