| 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/browser/search_provider.h" | 5 #include "components/omnibox/browser/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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 void SearchProviderTest::CheckMatches(const std::string& description, | 520 void SearchProviderTest::CheckMatches(const std::string& description, |
| 521 const size_t num_expected_matches, | 521 const size_t num_expected_matches, |
| 522 const ExpectedMatch expected_matches[], | 522 const ExpectedMatch expected_matches[], |
| 523 const ACMatches& matches) { | 523 const ACMatches& matches) { |
| 524 ASSERT_FALSE(matches.empty()); | 524 ASSERT_FALSE(matches.empty()); |
| 525 ASSERT_LE(matches.size(), num_expected_matches); | 525 ASSERT_LE(matches.size(), num_expected_matches); |
| 526 size_t i = 0; | 526 size_t i = 0; |
| 527 SCOPED_TRACE(description); | 527 SCOPED_TRACE(description); |
| 528 // Ensure that the returned matches equal the expectations. | 528 // Ensure that the returned matches equal the expectations. |
| 529 for (; i < matches.size(); ++i) { | 529 for (; i < matches.size(); ++i) { |
| 530 SCOPED_TRACE(" Case # " + base::IntToString(i)); | 530 SCOPED_TRACE(" Case # " + base::SizeTToString(i)); |
| 531 EXPECT_EQ(ASCIIToUTF16(expected_matches[i].contents), matches[i].contents); | 531 EXPECT_EQ(ASCIIToUTF16(expected_matches[i].contents), matches[i].contents); |
| 532 EXPECT_EQ(expected_matches[i].allowed_to_be_default_match, | 532 EXPECT_EQ(expected_matches[i].allowed_to_be_default_match, |
| 533 matches[i].allowed_to_be_default_match); | 533 matches[i].allowed_to_be_default_match); |
| 534 } | 534 } |
| 535 // Ensure that no expected matches are missing. | 535 // Ensure that no expected matches are missing. |
| 536 for (; i < num_expected_matches; ++i) { | 536 for (; i < num_expected_matches; ++i) { |
| 537 SCOPED_TRACE(" Case # " + base::IntToString(i)); | 537 SCOPED_TRACE(" Case # " + base::SizeTToString(i)); |
| 538 EXPECT_EQ(kNotApplicable, expected_matches[i].contents); | 538 EXPECT_EQ(kNotApplicable, expected_matches[i].contents); |
| 539 } | 539 } |
| 540 } | 540 } |
| 541 | 541 |
| 542 void SearchProviderTest::ResetFieldTrialList() { | 542 void SearchProviderTest::ResetFieldTrialList() { |
| 543 // Destroy the existing FieldTrialList before creating a new one to avoid | 543 // Destroy the existing FieldTrialList before creating a new one to avoid |
| 544 // a DCHECK. | 544 // a DCHECK. |
| 545 field_trial_list_.reset(); | 545 field_trial_list_.reset(); |
| 546 field_trial_list_.reset(new base::FieldTrialList( | 546 field_trial_list_.reset(new base::FieldTrialList( |
| 547 new metrics::SHA1EntropyProvider("foo"))); | 547 new metrics::SHA1EntropyProvider("foo"))); |
| (...skipping 1511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2059 for (; j < matches.size(); ++j) { | 2059 for (; j < matches.size(); ++j) { |
| 2060 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents), | 2060 EXPECT_EQ(ASCIIToUTF16(cases[i].matches[j].contents), |
| 2061 matches[j].contents); | 2061 matches[j].contents); |
| 2062 EXPECT_EQ(cases[i].matches[j].from_keyword, | 2062 EXPECT_EQ(cases[i].matches[j].from_keyword, |
| 2063 matches[j].keyword == ASCIIToUTF16("k")); | 2063 matches[j].keyword == ASCIIToUTF16("k")); |
| 2064 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match, | 2064 EXPECT_EQ(cases[i].matches[j].allowed_to_be_default_match, |
| 2065 matches[j].allowed_to_be_default_match); | 2065 matches[j].allowed_to_be_default_match); |
| 2066 } | 2066 } |
| 2067 // Ensure that no expected matches are missing. | 2067 // Ensure that no expected matches are missing. |
| 2068 for (; j < arraysize(cases[i].matches); ++j) { | 2068 for (; j < arraysize(cases[i].matches); ++j) { |
| 2069 SCOPED_TRACE(" Case # " + base::IntToString(i)); | 2069 SCOPED_TRACE(" Case # " + base::SizeTToString(i)); |
| 2070 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents); | 2070 EXPECT_EQ(kNotApplicable, cases[i].matches[j].contents); |
| 2071 } | 2071 } |
| 2072 } | 2072 } |
| 2073 } | 2073 } |
| 2074 | 2074 |
| 2075 TEST_F(SearchProviderTest, DontInlineAutocompleteAsynchronously) { | 2075 TEST_F(SearchProviderTest, DontInlineAutocompleteAsynchronously) { |
| 2076 // This test sends two separate queries, each receiving different JSON | 2076 // This test sends two separate queries, each receiving different JSON |
| 2077 // replies, and checks that at each stage of processing (receiving first | 2077 // replies, and checks that at each stage of processing (receiving first |
| 2078 // asynchronous response, handling new keystroke synchronously / sending the | 2078 // asynchronous response, handling new keystroke synchronously / sending the |
| 2079 // second request, and receiving the second asynchronous response) we have the | 2079 // second request, and receiving the second asynchronous response) we have the |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2841 const ACMatches& matches = provider_->matches(); | 2841 const ACMatches& matches = provider_->matches(); |
| 2842 ASSERT_FALSE(matches.empty()); | 2842 ASSERT_FALSE(matches.empty()); |
| 2843 | 2843 |
| 2844 SCOPED_TRACE("for input with json = " + cases[i].response_json); | 2844 SCOPED_TRACE("for input with json = " + cases[i].response_json); |
| 2845 | 2845 |
| 2846 ASSERT_LE(matches.size(), arraysize(cases[i].matches)); | 2846 ASSERT_LE(matches.size(), arraysize(cases[i].matches)); |
| 2847 size_t j = 0; | 2847 size_t j = 0; |
| 2848 // Ensure that the returned matches equal the expectations. | 2848 // Ensure that the returned matches equal the expectations. |
| 2849 for (; j < matches.size(); ++j) { | 2849 for (; j < matches.size(); ++j) { |
| 2850 const Match& match = cases[i].matches[j]; | 2850 const Match& match = cases[i].matches[j]; |
| 2851 SCOPED_TRACE(" and match index: " + base::IntToString(j)); | 2851 SCOPED_TRACE(" and match index: " + base::SizeTToString(j)); |
| 2852 EXPECT_EQ(match.contents, | 2852 EXPECT_EQ(match.contents, |
| 2853 base::UTF16ToUTF8(matches[j].contents)); | 2853 base::UTF16ToUTF8(matches[j].contents)); |
| 2854 EXPECT_EQ(match.description, | 2854 EXPECT_EQ(match.description, |
| 2855 base::UTF16ToUTF8(matches[j].description)); | 2855 base::UTF16ToUTF8(matches[j].description)); |
| 2856 EXPECT_EQ(match.query_params, | 2856 EXPECT_EQ(match.query_params, |
| 2857 matches[j].search_terms_args->suggest_query_params); | 2857 matches[j].search_terms_args->suggest_query_params); |
| 2858 EXPECT_EQ(match.fill_into_edit, | 2858 EXPECT_EQ(match.fill_into_edit, |
| 2859 base::UTF16ToUTF8(matches[j].fill_into_edit)); | 2859 base::UTF16ToUTF8(matches[j].fill_into_edit)); |
| 2860 EXPECT_EQ(match.type, matches[j].type); | 2860 EXPECT_EQ(match.type, matches[j].type); |
| 2861 } | 2861 } |
| 2862 // Ensure that no expected matches are missing. | 2862 // Ensure that no expected matches are missing. |
| 2863 for (; j < arraysize(cases[i].matches); ++j) { | 2863 for (; j < arraysize(cases[i].matches); ++j) { |
| 2864 SCOPED_TRACE(" and match index: " + base::IntToString(j)); | 2864 SCOPED_TRACE(" and match index: " + base::SizeTToString(j)); |
| 2865 EXPECT_EQ(cases[i].matches[j].contents, kNotApplicable); | 2865 EXPECT_EQ(cases[i].matches[j].contents, kNotApplicable); |
| 2866 EXPECT_EQ(cases[i].matches[j].description, kNotApplicable); | 2866 EXPECT_EQ(cases[i].matches[j].description, kNotApplicable); |
| 2867 EXPECT_EQ(cases[i].matches[j].query_params, kNotApplicable); | 2867 EXPECT_EQ(cases[i].matches[j].query_params, kNotApplicable); |
| 2868 EXPECT_EQ(cases[i].matches[j].fill_into_edit, kNotApplicable); | 2868 EXPECT_EQ(cases[i].matches[j].fill_into_edit, kNotApplicable); |
| 2869 EXPECT_EQ(cases[i].matches[j].type, AutocompleteMatchType::NUM_TYPES); | 2869 EXPECT_EQ(cases[i].matches[j].type, AutocompleteMatchType::NUM_TYPES); |
| 2870 } | 2870 } |
| 2871 } | 2871 } |
| 2872 } | 2872 } |
| 2873 #endif // !defined(OS_WIN) | 2873 #endif // !defined(OS_WIN) |
| 2874 | 2874 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3061 ClearAllResults(); | 3061 ClearAllResults(); |
| 3062 QueryForInputAndWaitForFetcherResponses( | 3062 QueryForInputAndWaitForFetcherResponses( |
| 3063 ASCIIToUTF16(cases[i].input_text), false, | 3063 ASCIIToUTF16(cases[i].input_text), false, |
| 3064 cases[i].default_provider_response_json, std::string()); | 3064 cases[i].default_provider_response_json, std::string()); |
| 3065 | 3065 |
| 3066 const ACMatches& matches = provider_->matches(); | 3066 const ACMatches& matches = provider_->matches(); |
| 3067 // The top match must inline and score as highly as calculated verbatim. | 3067 // The top match must inline and score as highly as calculated verbatim. |
| 3068 ASSERT_FALSE(matches.empty()); | 3068 ASSERT_FALSE(matches.empty()); |
| 3069 EXPECT_GE(matches[0].relevance, 1300); | 3069 EXPECT_GE(matches[0].relevance, 1300); |
| 3070 | 3070 |
| 3071 SCOPED_TRACE("for case: " + base::IntToString(i)); | 3071 SCOPED_TRACE("for case: " + base::SizeTToString(i)); |
| 3072 ASSERT_LE(matches.size(), arraysize(cases[i].matches)); | 3072 ASSERT_LE(matches.size(), arraysize(cases[i].matches)); |
| 3073 size_t j = 0; | 3073 size_t j = 0; |
| 3074 // Ensure that the returned matches equal the expectations. | 3074 // Ensure that the returned matches equal the expectations. |
| 3075 for (; j < matches.size(); ++j) { | 3075 for (; j < matches.size(); ++j) { |
| 3076 SCOPED_TRACE("and match: " + base::IntToString(j)); | 3076 SCOPED_TRACE("and match: " + base::SizeTToString(j)); |
| 3077 EXPECT_EQ(cases[i].matches[j].contents, | 3077 EXPECT_EQ(cases[i].matches[j].contents, |
| 3078 base::UTF16ToUTF8(matches[j].contents)); | 3078 base::UTF16ToUTF8(matches[j].contents)); |
| 3079 EXPECT_EQ(cases[i].matches[j].type, matches[j].type); | 3079 EXPECT_EQ(cases[i].matches[j].type, matches[j].type); |
| 3080 } | 3080 } |
| 3081 for (; j < arraysize(cases[i].matches); ++j) { | 3081 for (; j < arraysize(cases[i].matches); ++j) { |
| 3082 SCOPED_TRACE("and match: " + base::IntToString(j)); | 3082 SCOPED_TRACE("and match: " + base::SizeTToString(j)); |
| 3083 EXPECT_EQ(cases[i].matches[j].contents, kNotApplicable); | 3083 EXPECT_EQ(cases[i].matches[j].contents, kNotApplicable); |
| 3084 EXPECT_EQ(cases[i].matches[j].type, AutocompleteMatchType::NUM_TYPES); | 3084 EXPECT_EQ(cases[i].matches[j].type, AutocompleteMatchType::NUM_TYPES); |
| 3085 } | 3085 } |
| 3086 } | 3086 } |
| 3087 } | 3087 } |
| 3088 | 3088 |
| 3089 // Test that deletion url gets set on an AutocompleteMatch when available for a | 3089 // Test that deletion url gets set on an AutocompleteMatch when available for a |
| 3090 // personalized query or a personalized URL. | 3090 // personalized query or a personalized URL. |
| 3091 TEST_F(SearchProviderTest, ParseDeletionUrl) { | 3091 TEST_F(SearchProviderTest, ParseDeletionUrl) { |
| 3092 struct Match { | 3092 struct Match { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3169 ASCIIToUTF16(cases[i].input_text), false, cases[i].response_json, | 3169 ASCIIToUTF16(cases[i].input_text), false, cases[i].response_json, |
| 3170 std::string()); | 3170 std::string()); |
| 3171 | 3171 |
| 3172 const ACMatches& matches = provider_->matches(); | 3172 const ACMatches& matches = provider_->matches(); |
| 3173 ASSERT_FALSE(matches.empty()); | 3173 ASSERT_FALSE(matches.empty()); |
| 3174 | 3174 |
| 3175 SCOPED_TRACE("for input with json = " + cases[i].response_json); | 3175 SCOPED_TRACE("for input with json = " + cases[i].response_json); |
| 3176 | 3176 |
| 3177 for (size_t j = 0; j < matches.size(); ++j) { | 3177 for (size_t j = 0; j < matches.size(); ++j) { |
| 3178 const Match& match = cases[i].matches[j]; | 3178 const Match& match = cases[i].matches[j]; |
| 3179 SCOPED_TRACE(" and match index: " + base::IntToString(j)); | 3179 SCOPED_TRACE(" and match index: " + base::SizeTToString(j)); |
| 3180 EXPECT_EQ(match.contents, base::UTF16ToUTF8(matches[j].contents)); | 3180 EXPECT_EQ(match.contents, base::UTF16ToUTF8(matches[j].contents)); |
| 3181 EXPECT_EQ(match.deletion_url, matches[j].GetAdditionalInfo( | 3181 EXPECT_EQ(match.deletion_url, matches[j].GetAdditionalInfo( |
| 3182 "deletion_url")); | 3182 "deletion_url")); |
| 3183 } | 3183 } |
| 3184 } | 3184 } |
| 3185 } | 3185 } |
| 3186 | 3186 |
| 3187 TEST_F(SearchProviderTest, ReflectsBookmarkBarState) { | 3187 TEST_F(SearchProviderTest, ReflectsBookmarkBarState) { |
| 3188 profile_.GetPrefs()->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false); | 3188 profile_.GetPrefs()->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false); |
| 3189 base::string16 term = term1_.substr(0, term1_.length() - 1); | 3189 base::string16 term = term1_.substr(0, term1_.length() - 1); |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3572 } | 3572 } |
| 3573 | 3573 |
| 3574 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { | 3574 TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { |
| 3575 AutocompleteInput input( | 3575 AutocompleteInput input( |
| 3576 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(), | 3576 base::ASCIIToUTF16("f"), base::string16::npos, std::string(), GURL(), |
| 3577 metrics::OmniboxEventProto::INVALID_SPEC, false, true, true, true, true, | 3577 metrics::OmniboxEventProto::INVALID_SPEC, false, true, true, true, true, |
| 3578 ChromeAutocompleteSchemeClassifier(&profile_)); | 3578 ChromeAutocompleteSchemeClassifier(&profile_)); |
| 3579 provider_->Start(input, false); | 3579 provider_->Start(input, false); |
| 3580 EXPECT_TRUE(provider_->matches().empty()); | 3580 EXPECT_TRUE(provider_->matches().empty()); |
| 3581 } | 3581 } |
| OLD | NEW |