Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/base_search_provider.h" | 5 #include "components/omnibox/browser/base_search_provider.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 #include "base/strings/string_number_conversions.h" | |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "components/omnibox/browser/autocomplete_match.h" | 13 #include "components/omnibox/browser/autocomplete_match.h" |
| 13 #include "components/omnibox/browser/autocomplete_match_type.h" | 14 #include "components/omnibox/browser/autocomplete_match_type.h" |
| 14 #include "components/omnibox/browser/autocomplete_scheme_classifier.h" | 15 #include "components/omnibox/browser/autocomplete_scheme_classifier.h" |
| 15 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" | 16 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" |
| 16 #include "components/omnibox/browser/search_suggestion_parser.h" | 17 #include "components/omnibox/browser/search_suggestion_parser.h" |
| 17 #include "components/omnibox/browser/suggestion_answer.h" | 18 #include "components/omnibox/browser/suggestion_answer.h" |
| 18 #include "components/search_engines/search_terms_data.h" | 19 #include "components/search_engines/search_terms_data.h" |
| 19 #include "components/search_engines/template_url_service.h" | 20 #include "components/search_engines/template_url_service.h" |
| 20 #include "components/search_engines/template_url_service_client.h" | 21 #include "components/search_engines/template_url_service_client.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 map); | 57 map); |
| 57 } | 58 } |
| 58 | 59 |
| 59 protected: | 60 protected: |
| 60 virtual ~TestBaseSearchProvider() {} | 61 virtual ~TestBaseSearchProvider() {} |
| 61 | 62 |
| 62 private: | 63 private: |
| 63 DISALLOW_COPY_AND_ASSIGN(TestBaseSearchProvider); | 64 DISALLOW_COPY_AND_ASSIGN(TestBaseSearchProvider); |
| 64 }; | 65 }; |
| 65 | 66 |
| 67 class TestSchemeClassifier : public AutocompleteSchemeClassifier { | |
| 68 public: | |
| 69 metrics::OmniboxInputType::Type GetInputTypeForScheme( | |
| 70 const std::string&) const override { | |
| 71 return metrics::OmniboxInputType::QUERY; | |
| 72 } | |
| 73 }; | |
| 74 | |
| 66 class BaseSearchProviderTest : public testing::Test { | 75 class BaseSearchProviderTest : public testing::Test { |
| 67 public: | 76 public: |
| 68 ~BaseSearchProviderTest() override {} | 77 ~BaseSearchProviderTest() override {} |
| 69 | 78 |
| 70 protected: | 79 protected: |
| 71 void SetUp() override { | 80 void SetUp() override { |
| 72 std::unique_ptr<TemplateURLService> template_url_service( | 81 std::unique_ptr<TemplateURLService> template_url_service( |
| 73 new TemplateURLService( | 82 new TemplateURLService( |
| 74 nullptr, std::unique_ptr<SearchTermsData>(new SearchTermsData), | 83 nullptr, std::unique_ptr<SearchTermsData>(new SearchTermsData), |
| 75 nullptr, std::unique_ptr<TemplateURLServiceClient>(), nullptr, | 84 nullptr, std::unique_ptr<TemplateURLServiceClient>(), nullptr, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 EXPECT_TRUE(answer2->Equals(*match.answer)); | 171 EXPECT_TRUE(answer2->Equals(*match.answer)); |
| 163 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, match.type); | 172 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, match.type); |
| 164 EXPECT_EQ(1300, match.relevance); | 173 EXPECT_EQ(1300, match.relevance); |
| 165 | 174 |
| 166 EXPECT_EQ(answer_contents, duplicate.answer_contents); | 175 EXPECT_EQ(answer_contents, duplicate.answer_contents); |
| 167 EXPECT_EQ(answer_type, duplicate.answer_type); | 176 EXPECT_EQ(answer_type, duplicate.answer_type); |
| 168 EXPECT_TRUE(answer->Equals(*duplicate.answer)); | 177 EXPECT_TRUE(answer->Equals(*duplicate.answer)); |
| 169 EXPECT_EQ(AutocompleteMatchType::SEARCH_SUGGEST, duplicate.type); | 178 EXPECT_EQ(AutocompleteMatchType::SEARCH_SUGGEST, duplicate.type); |
| 170 EXPECT_EQ(850, duplicate.relevance); | 179 EXPECT_EQ(850, duplicate.relevance); |
| 171 } | 180 } |
| 181 | |
| 182 TEST_F(BaseSearchProviderTest, MatchTailSuggestionProperly) { | |
| 183 TemplateURLData data; | |
| 184 data.SetURL("http://foo.com/url?bar={searchTerms}"); | |
| 185 std::unique_ptr<TemplateURL> template_url(new TemplateURL(data)); | |
|
Peter Kasting
2017/05/10 20:38:11
Nit: Prefer MakeUnique to bare new:
auto templa
Kevin Bailey
2017/05/11 13:27:37
Done. Fixed the other test too.
| |
| 186 | |
| 187 AutocompleteInput autocomplete_input( | |
| 188 base::ASCIIToUTF16("weather"), 7, "", GURL(), base::string16(), | |
|
Peter Kasting
2017/05/10 20:38:11
Nit: Prefer std::string() to ""
Kevin Bailey
2017/05/11 13:27:37
Done.
| |
| 189 metrics::OmniboxEventProto::BLANK, false, false, false, false, false, | |
| 190 TestSchemeClassifier()); | |
| 191 | |
| 192 EXPECT_CALL(*provider_, GetInput(_)) | |
| 193 .WillRepeatedly(Return(autocomplete_input)); | |
| 194 EXPECT_CALL(*provider_, GetTemplateURL(_)) | |
| 195 .WillRepeatedly(Return(template_url.get())); | |
| 196 | |
| 197 base::string16 query = base::ASCIIToUTF16("angeles now"); | |
| 198 base::string16 suggestion = base::ASCIIToUTF16("weather los ") + query; | |
| 199 SearchSuggestionParser::SuggestResult suggest_result( | |
| 200 suggestion, AutocompleteMatchType::SEARCH_SUGGEST_TAIL, 0, query, | |
| 201 base::ASCIIToUTF16("..."), base::string16(), base::string16(), | |
| 202 base::string16(), nullptr, std::string(), std::string(), false, 1300, | |
| 203 true, false, query); | |
| 204 | |
| 205 TestBaseSearchProvider::MatchMap map; | |
| 206 provider_->AddMatchToMap(suggest_result, std::string(), | |
| 207 TemplateURLRef::NO_SUGGESTION_CHOSEN, false, false, | |
| 208 &map); | |
| 209 | |
| 210 EXPECT_EQ(1UL, map.size()); | |
|
Peter Kasting
2017/05/10 20:38:12
Nit: Maybe this should be ASSERT, so we can blindl
Kevin Bailey
2017/05/11 13:27:37
Done.
| |
| 211 for (const auto& entry : map) { | |
| 212 std::string text = | |
| 213 entry.second.GetAdditionalInfo(kACMatchPropertyContentsStartIndex); | |
| 214 int length; | |
|
Peter Kasting
2017/05/10 20:38:12
Nit: Declare as size_t; then no EXPECT_GE is neede
Kevin Bailey
2017/05/11 13:27:37
Done. With the high template usage, they could hav
| |
| 215 EXPECT_TRUE(base::StringToInt(text, &length)); | |
| 216 EXPECT_GE(length, 0); | |
| 217 text = entry.second.GetAdditionalInfo(kACMatchPropertyContentsText); | |
| 218 EXPECT_GE(text.length(), static_cast<unsigned>(length)); | |
| 219 } | |
| 220 } | |
| OLD | NEW |