| 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 3086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 3106 |
| 3107 #if defined(OS_ANDROID) | |
| 3108 TEST_F(SearchProviderTest, SuggestQueryUsesToken) { | 3107 TEST_F(SearchProviderTest, SuggestQueryUsesToken) { |
| 3109 CommandLine::ForCurrentProcess()->AppendSwitch( | 3108 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3110 switches::kEnableAnswersInSuggest); | 3109 switches::kEnableAnswersInSuggest); |
| 3111 | 3110 |
| 3112 TemplateURLService* turl_model = | 3111 TemplateURLService* turl_model = |
| 3113 TemplateURLServiceFactory::GetForProfile(&profile_); | 3112 TemplateURLServiceFactory::GetForProfile(&profile_); |
| 3114 | 3113 |
| 3115 TemplateURLData data; | 3114 TemplateURLData data; |
| 3116 data.short_name = ASCIIToUTF16("default"); | 3115 data.short_name = ASCIIToUTF16("default"); |
| 3117 data.SetKeyword(data.short_name); | 3116 data.SetKeyword(data.short_name); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3135 search_terms_args.session_token = provider_->current_token_; | 3134 search_terms_args.session_token = provider_->current_token_; |
| 3136 GURL expected_url(default_t_url_->suggestions_url_ref().ReplaceSearchTerms( | 3135 GURL expected_url(default_t_url_->suggestions_url_ref().ReplaceSearchTerms( |
| 3137 search_terms_args)); | 3136 search_terms_args)); |
| 3138 EXPECT_EQ(fetcher->GetOriginalURL().spec(), expected_url.spec()); | 3137 EXPECT_EQ(fetcher->GetOriginalURL().spec(), expected_url.spec()); |
| 3139 | 3138 |
| 3140 // Complete running the fetcher to clean up. | 3139 // Complete running the fetcher to clean up. |
| 3141 fetcher->set_response_code(200); | 3140 fetcher->set_response_code(200); |
| 3142 fetcher->delegate()->OnURLFetchComplete(fetcher); | 3141 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 3143 RunTillProviderDone(); | 3142 RunTillProviderDone(); |
| 3144 } | 3143 } |
| 3145 #endif | |
| 3146 | 3144 |
| 3147 TEST_F(SearchProviderTest, SessionToken) { | 3145 TEST_F(SearchProviderTest, SessionToken) { |
| 3148 // Subsequent calls always get the same token. | 3146 // Subsequent calls always get the same token. |
| 3149 std::string token = provider_->GetSessionToken(); | 3147 std::string token = provider_->GetSessionToken(); |
| 3150 std::string token2 = provider_->GetSessionToken(); | 3148 std::string token2 = provider_->GetSessionToken(); |
| 3151 EXPECT_EQ(token, token2); | 3149 EXPECT_EQ(token, token2); |
| 3152 EXPECT_FALSE(token.empty()); | 3150 EXPECT_FALSE(token.empty()); |
| 3153 | 3151 |
| 3154 // Calls do not regenerate a token. | 3152 // Calls do not regenerate a token. |
| 3155 provider_->current_token_ = "PRE-EXISTING TOKEN"; | 3153 provider_->current_token_ = "PRE-EXISTING TOKEN"; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3166 | 3164 |
| 3167 // The expiration time is always updated. | 3165 // The expiration time is always updated. |
| 3168 provider_->GetSessionToken(); | 3166 provider_->GetSessionToken(); |
| 3169 base::TimeTicks expiration_time_1 = provider_->token_expiration_time_; | 3167 base::TimeTicks expiration_time_1 = provider_->token_expiration_time_; |
| 3170 base::PlatformThread::Sleep(kSmallDelta); | 3168 base::PlatformThread::Sleep(kSmallDelta); |
| 3171 provider_->GetSessionToken(); | 3169 provider_->GetSessionToken(); |
| 3172 base::TimeTicks expiration_time_2 = provider_->token_expiration_time_; | 3170 base::TimeTicks expiration_time_2 = provider_->token_expiration_time_; |
| 3173 EXPECT_GT(expiration_time_2, expiration_time_1); | 3171 EXPECT_GT(expiration_time_2, expiration_time_1); |
| 3174 EXPECT_GE(expiration_time_2, expiration_time_1 + kSmallDelta); | 3172 EXPECT_GE(expiration_time_2, expiration_time_1 + kSmallDelta); |
| 3175 } | 3173 } |
| OLD | NEW |