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