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 3213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3224 provider_->GetSessionToken(); | 3224 provider_->GetSessionToken(); |
3225 base::TimeTicks expiration_time_1 = provider_->token_expiration_time_; | 3225 base::TimeTicks expiration_time_1 = provider_->token_expiration_time_; |
3226 base::PlatformThread::Sleep(kSmallDelta); | 3226 base::PlatformThread::Sleep(kSmallDelta); |
3227 provider_->GetSessionToken(); | 3227 provider_->GetSessionToken(); |
3228 base::TimeTicks expiration_time_2 = provider_->token_expiration_time_; | 3228 base::TimeTicks expiration_time_2 = provider_->token_expiration_time_; |
3229 EXPECT_GT(expiration_time_2, expiration_time_1); | 3229 EXPECT_GT(expiration_time_2, expiration_time_1); |
3230 EXPECT_GE(expiration_time_2, expiration_time_1 + kSmallDelta); | 3230 EXPECT_GE(expiration_time_2, expiration_time_1 + kSmallDelta); |
3231 } | 3231 } |
3232 | 3232 |
3233 TEST_F(SearchProviderTest, AnswersCache) { | 3233 TEST_F(SearchProviderTest, AnswersCache) { |
3234 // Initial condition: empty cache. | |
3235 ASSERT_TRUE(provider_->last_answer_seen_.full_query_text.empty()); | |
3236 | |
3237 AutocompleteResult result; | 3234 AutocompleteResult result; |
3238 ACMatches matches; | 3235 ACMatches matches; |
3239 AutocompleteMatch match1; | 3236 AutocompleteMatch match1; |
3240 match1.answer_contents = base::ASCIIToUTF16("m1"); | 3237 match1.answer_contents = base::ASCIIToUTF16("m1"); |
3241 match1.answer_type = base::ASCIIToUTF16("2334"); | 3238 match1.answer_type = base::ASCIIToUTF16("2334"); |
3242 match1.fill_into_edit = base::ASCIIToUTF16("weather los angeles"); | 3239 match1.fill_into_edit = base::ASCIIToUTF16("weather los angeles"); |
3243 | 3240 |
3244 AutocompleteMatch non_answer_match1; | 3241 AutocompleteMatch non_answer_match1; |
3245 non_answer_match1.fill_into_edit = base::ASCIIToUTF16("weather laguna beach"); | 3242 non_answer_match1.fill_into_edit = base::ASCIIToUTF16("weather laguna beach"); |
3246 | 3243 |
3247 // Test that an answer in the first slot populates the cache. | 3244 // Test that an answer in the first slot populates the cache. |
3248 matches.push_back(match1); | 3245 matches.push_back(match1); |
3249 matches.push_back(non_answer_match1); | 3246 matches.push_back(non_answer_match1); |
3250 result.AppendMatches(matches); | 3247 result.AppendMatches(matches); |
3251 provider_->RegisterDisplayedAnswers(result); | 3248 provider_->RegisterDisplayedAnswers(result); |
3252 EXPECT_EQ(base::ASCIIToUTF16("weather los angeles"), | 3249 ASSERT_FALSE(provider_->answers_cache_.empty()); |
3253 provider_->last_answer_seen_.full_query_text); | |
3254 EXPECT_EQ(base::ASCIIToUTF16("2334"), | |
3255 provider_->last_answer_seen_.query_type); | |
3256 | 3250 |
3257 // Test that DoAnswersQuery retrieves data from cache. | 3251 // Test that DoAnswersQuery retrieves data from cache. |
3258 AutocompleteInput input(base::ASCIIToUTF16("weather l"), | 3252 AutocompleteInput input(base::ASCIIToUTF16("weather l"), |
3259 base::string16::npos, base::string16(), GURL(), | 3253 base::string16::npos, base::string16(), GURL(), |
3260 metrics::OmniboxEventProto::INVALID_SPEC, false, | 3254 metrics::OmniboxEventProto::INVALID_SPEC, false, |
3261 false, true, true, | 3255 false, true, true, |
3262 ChromeAutocompleteSchemeClassifier(&profile_)); | 3256 ChromeAutocompleteSchemeClassifier(&profile_)); |
3263 provider_->DoAnswersQuery(input); | 3257 provider_->DoAnswersQuery(input); |
3264 EXPECT_EQ(base::ASCIIToUTF16("weather los angeles"), | 3258 EXPECT_EQ(base::ASCIIToUTF16("weather los angeles"), |
3265 provider_->prefetch_data_.full_query_text); | 3259 provider_->prefetch_data_.full_query_text); |
3266 EXPECT_EQ(base::ASCIIToUTF16("2334"), provider_->prefetch_data_.query_type); | 3260 EXPECT_EQ(base::ASCIIToUTF16("2334"), provider_->prefetch_data_.query_type); |
3267 | |
3268 // Mismatching input will return empty prefetch data. | |
3269 AutocompleteInput input2(base::ASCIIToUTF16("weather n"), | |
3270 base::string16::npos, base::string16(), GURL(), | |
3271 metrics::OmniboxEventProto::INVALID_SPEC, false, | |
3272 false, true, true, | |
3273 ChromeAutocompleteSchemeClassifier(&profile_)); | |
3274 provider_->DoAnswersQuery(input2); | |
3275 EXPECT_TRUE(provider_->prefetch_data_.full_query_text.empty()); | |
3276 EXPECT_TRUE(provider_->prefetch_data_.query_type.empty()); | |
3277 } | 3261 } |
OLD | NEW |