| 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 "components/omnibox/search_provider.h" | 5 #include "components/omnibox/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 21 matching lines...) Expand all Loading... |
| 32 #include "chrome/test/base/testing_browser_process.h" | 32 #include "chrome/test/base/testing_browser_process.h" |
| 33 #include "chrome/test/base/testing_profile.h" | 33 #include "chrome/test/base/testing_profile.h" |
| 34 #include "components/google/core/browser/google_switches.h" | 34 #include "components/google/core/browser/google_switches.h" |
| 35 #include "components/metrics/proto/omnibox_event.pb.h" | 35 #include "components/metrics/proto/omnibox_event.pb.h" |
| 36 #include "components/omnibox/autocomplete_input.h" | 36 #include "components/omnibox/autocomplete_input.h" |
| 37 #include "components/omnibox/autocomplete_match.h" | 37 #include "components/omnibox/autocomplete_match.h" |
| 38 #include "components/omnibox/autocomplete_provider.h" | 38 #include "components/omnibox/autocomplete_provider.h" |
| 39 #include "components/omnibox/autocomplete_provider_listener.h" | 39 #include "components/omnibox/autocomplete_provider_listener.h" |
| 40 #include "components/omnibox/omnibox_field_trial.h" | 40 #include "components/omnibox/omnibox_field_trial.h" |
| 41 #include "components/omnibox/omnibox_switches.h" | 41 #include "components/omnibox/omnibox_switches.h" |
| 42 #include "components/omnibox/suggestion_answer.h" |
| 42 #include "components/search_engines/search_engine_type.h" | 43 #include "components/search_engines/search_engine_type.h" |
| 43 #include "components/search_engines/search_engines_switches.h" | 44 #include "components/search_engines/search_engines_switches.h" |
| 44 #include "components/search_engines/search_terms_data.h" | 45 #include "components/search_engines/search_terms_data.h" |
| 45 #include "components/search_engines/template_url.h" | 46 #include "components/search_engines/template_url.h" |
| 46 #include "components/search_engines/template_url_service.h" | 47 #include "components/search_engines/template_url_service.h" |
| 47 #include "components/signin/core/browser/signin_manager.h" | 48 #include "components/signin/core/browser/signin_manager.h" |
| 48 #include "components/sync_driver/pref_names.h" | 49 #include "components/sync_driver/pref_names.h" |
| 49 #include "components/variations/entropy_provider.h" | 50 #include "components/variations/entropy_provider.h" |
| 50 #include "components/variations/variations_associated_data.h" | 51 #include "components/variations/variations_associated_data.h" |
| 51 #include "content/public/test/test_browser_thread_bundle.h" | 52 #include "content/public/test/test_browser_thread_bundle.h" |
| (...skipping 3359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3411 | 3412 |
| 3412 // Without scored results, no answers will be retrieved. | 3413 // Without scored results, no answers will be retrieved. |
| 3413 AnswersQueryData answer = provider_->FindAnswersPrefetchData(); | 3414 AnswersQueryData answer = provider_->FindAnswersPrefetchData(); |
| 3414 EXPECT_TRUE(answer.full_query_text.empty()); | 3415 EXPECT_TRUE(answer.full_query_text.empty()); |
| 3415 EXPECT_TRUE(answer.query_type.empty()); | 3416 EXPECT_TRUE(answer.query_type.empty()); |
| 3416 | 3417 |
| 3417 // Inject a scored result, which will trigger answer retrieval. | 3418 // Inject a scored result, which will trigger answer retrieval. |
| 3418 base::string16 query = base::ASCIIToUTF16("weather los angeles"); | 3419 base::string16 query = base::ASCIIToUTF16("weather los angeles"); |
| 3419 SearchSuggestionParser::SuggestResult suggest_result( | 3420 SearchSuggestionParser::SuggestResult suggest_result( |
| 3420 query, AutocompleteMatchType::SEARCH_HISTORY, query, base::string16(), | 3421 query, AutocompleteMatchType::SEARCH_HISTORY, query, base::string16(), |
| 3421 base::string16(), base::string16(), base::string16(), std::string(), | 3422 base::string16(), base::string16(), base::string16(), nullptr, |
| 3422 std::string(), false, 1200, false, false, query); | 3423 std::string(), std::string(), false, 1200, false, false, query); |
| 3423 QueryForInput(ASCIIToUTF16("weather l"), false, false); | 3424 QueryForInput(ASCIIToUTF16("weather l"), false, false); |
| 3424 provider_->transformed_default_history_results_.push_back(suggest_result); | 3425 provider_->transformed_default_history_results_.push_back(suggest_result); |
| 3425 answer = provider_->FindAnswersPrefetchData(); | 3426 answer = provider_->FindAnswersPrefetchData(); |
| 3426 EXPECT_EQ(base::ASCIIToUTF16("weather los angeles"), answer.full_query_text); | 3427 EXPECT_EQ(base::ASCIIToUTF16("weather los angeles"), answer.full_query_text); |
| 3427 EXPECT_EQ(base::ASCIIToUTF16("2334"), answer.query_type); | 3428 EXPECT_EQ(base::ASCIIToUTF16("2334"), answer.query_type); |
| 3428 } | 3429 } |
| 3429 | 3430 |
| 3430 TEST_F(SearchProviderTest, RemoveExtraAnswers) { | 3431 TEST_F(SearchProviderTest, RemoveExtraAnswers) { |
| 3432 SuggestionAnswer answer1; |
| 3433 answer1.set_type(42); |
| 3434 SuggestionAnswer answer2; |
| 3435 answer2.set_type(1983); |
| 3436 SuggestionAnswer answer3; |
| 3437 answer3.set_type(423); |
| 3438 |
| 3431 ACMatches matches; | 3439 ACMatches matches; |
| 3432 AutocompleteMatch match1, match2, match3, match4, match5; | 3440 AutocompleteMatch match1, match2, match3, match4, match5; |
| 3441 match1.answer = SuggestionAnswer::copy(&answer1); |
| 3433 match1.answer_contents = base::ASCIIToUTF16("the answer"); | 3442 match1.answer_contents = base::ASCIIToUTF16("the answer"); |
| 3434 match1.answer_type = base::ASCIIToUTF16("42"); | 3443 match1.answer_type = base::ASCIIToUTF16("42"); |
| 3444 match3.answer = SuggestionAnswer::copy(&answer2); |
| 3435 match3.answer_contents = base::ASCIIToUTF16("not to play"); | 3445 match3.answer_contents = base::ASCIIToUTF16("not to play"); |
| 3436 match3.answer_type = base::ASCIIToUTF16("1983"); | 3446 match3.answer_type = base::ASCIIToUTF16("1983"); |
| 3447 match5.answer = SuggestionAnswer::copy(&answer3); |
| 3437 match5.answer_contents = base::ASCIIToUTF16("a man"); | 3448 match5.answer_contents = base::ASCIIToUTF16("a man"); |
| 3438 match5.answer_type = base::ASCIIToUTF16("423"); | 3449 match5.answer_type = base::ASCIIToUTF16("423"); |
| 3439 | 3450 |
| 3440 matches.push_back(match1); | 3451 matches.push_back(match1); |
| 3441 matches.push_back(match2); | 3452 matches.push_back(match2); |
| 3442 matches.push_back(match3); | 3453 matches.push_back(match3); |
| 3443 matches.push_back(match4); | 3454 matches.push_back(match4); |
| 3444 matches.push_back(match5); | 3455 matches.push_back(match5); |
| 3445 | 3456 |
| 3446 SearchProvider::RemoveExtraAnswers(&matches); | 3457 SearchProvider::RemoveExtraAnswers(&matches); |
| 3447 EXPECT_EQ(base::ASCIIToUTF16("the answer"), matches[0].answer_contents); | 3458 EXPECT_EQ(base::ASCIIToUTF16("the answer"), matches[0].answer_contents); |
| 3448 EXPECT_EQ(base::ASCIIToUTF16("42"), matches[0].answer_type); | 3459 EXPECT_EQ(base::ASCIIToUTF16("42"), matches[0].answer_type); |
| 3460 EXPECT_TRUE(answer1.Equals(*matches[0].answer)); |
| 3449 EXPECT_TRUE(matches[1].answer_contents.empty()); | 3461 EXPECT_TRUE(matches[1].answer_contents.empty()); |
| 3450 EXPECT_TRUE(matches[1].answer_type.empty()); | 3462 EXPECT_TRUE(matches[1].answer_type.empty()); |
| 3463 EXPECT_FALSE(matches[1].answer); |
| 3451 EXPECT_TRUE(matches[2].answer_contents.empty()); | 3464 EXPECT_TRUE(matches[2].answer_contents.empty()); |
| 3452 EXPECT_TRUE(matches[2].answer_type.empty()); | 3465 EXPECT_TRUE(matches[2].answer_type.empty()); |
| 3466 EXPECT_FALSE(matches[2].answer); |
| 3453 EXPECT_TRUE(matches[3].answer_contents.empty()); | 3467 EXPECT_TRUE(matches[3].answer_contents.empty()); |
| 3454 EXPECT_TRUE(matches[3].answer_type.empty()); | 3468 EXPECT_TRUE(matches[3].answer_type.empty()); |
| 3469 EXPECT_FALSE(matches[3].answer); |
| 3455 EXPECT_TRUE(matches[4].answer_contents.empty()); | 3470 EXPECT_TRUE(matches[4].answer_contents.empty()); |
| 3456 EXPECT_TRUE(matches[4].answer_type.empty()); | 3471 EXPECT_TRUE(matches[4].answer_type.empty()); |
| 3472 EXPECT_FALSE(matches[4].answer); |
| 3457 } | 3473 } |
| OLD | NEW |