Chromium Code Reviews| 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 3054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3065 // Verbatim match duplicates are added such that each one has a higher | 3065 // Verbatim match duplicates are added such that each one has a higher |
| 3066 // relevance than the previous one. | 3066 // relevance than the previous one. |
| 3067 EXPECT_EQ(2U, verbatim.duplicate_matches.size()); | 3067 EXPECT_EQ(2U, verbatim.duplicate_matches.size()); |
| 3068 | 3068 |
| 3069 // Other match duplicates are added in descending relevance order. | 3069 // Other match duplicates are added in descending relevance order. |
| 3070 EXPECT_EQ(1U, match_alpha.duplicate_matches.size()); | 3070 EXPECT_EQ(1U, match_alpha.duplicate_matches.size()); |
| 3071 EXPECT_EQ(1U, match_avid.duplicate_matches.size()); | 3071 EXPECT_EQ(1U, match_avid.duplicate_matches.size()); |
| 3072 | 3072 |
| 3073 EXPECT_EQ(0U, match_apricot.duplicate_matches.size()); | 3073 EXPECT_EQ(0U, match_apricot.duplicate_matches.size()); |
| 3074 } | 3074 } |
| 3075 | |
| 3076 #if defined(OS_ANDROID) | |
| 3077 TEST_F(SearchProviderTest, SuggestQueryUsesToken) { | |
| 3078 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 3079 switches::kEnableAnswersInSuggest); | |
| 3080 | |
| 3081 TemplateURLService* turl_model = | |
| 3082 TemplateURLServiceFactory::GetForProfile(&profile_); | |
| 3083 | |
| 3084 TemplateURLData data; | |
| 3085 data.short_name = ASCIIToUTF16("default"); | |
| 3086 data.SetKeyword(data.short_name); | |
| 3087 data.SetURL("http://example/{searchTerms}{google:sessionToken}"); | |
| 3088 data.suggestions_url = | |
| 3089 "http://suggest/?q={searchTerms}&{google:sessionToken}"; | |
| 3090 default_t_url_ = new TemplateURL(&profile_, data); | |
| 3091 turl_model->Add(default_t_url_); | |
| 3092 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url_); | |
| 3093 | |
| 3094 base::string16 term = term1_.substr(0, term1_.length() - 1); | |
| 3095 QueryForInput(term, false, false); | |
| 3096 | |
| 3097 // Make sure the default providers suggest service was queried. | |
|
Peter Kasting
2014/05/09 21:35:07
Nit: provider's
groby-ooo-7-16
2014/05/09 22:18:09
Done.
| |
| 3098 net::TestURLFetcher* fetcher = test_factory_.GetFetcherByID( | |
| 3099 SearchProvider::kDefaultProviderURLFetcherID); | |
| 3100 ASSERT_TRUE(fetcher); | |
| 3101 | |
| 3102 // And the URL matches what we expected. | |
| 3103 TemplateURLRef::SearchTermsArgs search_terms_args(term); | |
| 3104 search_terms_args.session_token = provider_->current_token_; | |
|
Peter Kasting
2014/05/09 21:35:07
Can this use GetSessionToken()? If so, perhaps th
groby-ooo-7-16
2014/05/09 21:50:25
Second test needs access to expiration time, so we
| |
| 3105 GURL expected_url(default_t_url_->suggestions_url_ref().ReplaceSearchTerms( | |
| 3106 search_terms_args)); | |
| 3107 EXPECT_EQ(fetcher->GetOriginalURL().spec(), expected_url.spec()); | |
| 3108 | |
| 3109 // complete running the fetcher to clean up. | |
|
Peter Kasting
2014/05/09 21:35:07
Nit: Capitalize
groby-ooo-7-16
2014/05/09 22:18:09
Done.
| |
| 3110 fetcher->set_response_code(200); | |
| 3111 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
| 3112 RunTillProviderDone(); | |
| 3113 } | |
| 3114 #endif | |
| 3115 | |
| 3116 TEST_F(SearchProviderTest, SessionToken) { | |
| 3117 const base::TimeDelta small_delta = base::TimeDelta::FromMilliseconds(1); | |
|
Peter Kasting
2014/05/09 21:35:07
Nit: Declare this just above first use
groby-ooo-7-16
2014/05/09 22:18:09
Done.
| |
| 3118 // Subsequent calls always get the same token. | |
| 3119 std::string token = provider_->GetSessionToken(); | |
| 3120 std::string token2 = provider_->GetSessionToken(); | |
| 3121 EXPECT_EQ(token, token2); | |
| 3122 EXPECT_FALSE(token.empty()); | |
| 3123 | |
| 3124 // Calls do not regenerate a token. | |
| 3125 provider_->current_token_ = "PRE-EXISTING TOKEN"; | |
| 3126 token = provider_->GetSessionToken(); | |
| 3127 EXPECT_EQ(token, "PRE-EXISTING TOKEN"); | |
| 3128 | |
| 3129 // ... unless the token has expired. | |
| 3130 provider_->current_token_ = ""; | |
|
Peter Kasting
2014/05/09 21:35:07
Nit: .clear()
groby-ooo-7-16
2014/05/09 22:18:09
Done.
| |
| 3131 provider_->token_expiration_time_ = base::Time::Now() - small_delta; | |
| 3132 token = provider_->GetSessionToken(); | |
| 3133 EXPECT_FALSE(token.empty()); | |
| 3134 EXPECT_EQ(token, provider_->current_token_); | |
| 3135 | |
| 3136 // The expiration time is always updated. | |
| 3137 provider_->GetSessionToken(); | |
| 3138 base::Time expiration_time_1 = provider_->token_expiration_time_; | |
| 3139 base::PlatformThread::Sleep(small_delta); | |
| 3140 provider_->GetSessionToken(); | |
| 3141 base::Time expiration_time_2 = provider_->token_expiration_time_; | |
| 3142 EXPECT_GT(expiration_time_2, expiration_time_1); | |
| 3143 EXPECT_GE(expiration_time_2, expiration_time_1 + small_delta); | |
| 3144 } | |
| OLD | NEW |