| 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" |
| 19 #include "components/omnibox/browser/test_scheme_classifier.h" |
| 18 #include "components/search_engines/search_terms_data.h" | 20 #include "components/search_engines/search_terms_data.h" |
| 19 #include "components/search_engines/template_url_service.h" | 21 #include "components/search_engines/template_url_service.h" |
| 20 #include "components/search_engines/template_url_service_client.h" | 22 #include "components/search_engines/template_url_service_client.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 25 |
| 24 using testing::NiceMock; | 26 using testing::NiceMock; |
| 25 using testing::Return; | 27 using testing::Return; |
| 26 using testing::_; | 28 using testing::_; |
| 27 | 29 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 AutocompleteProvider::TYPE_SEARCH, client_.get()); | 82 AutocompleteProvider::TYPE_SEARCH, client_.get()); |
| 81 } | 83 } |
| 82 | 84 |
| 83 scoped_refptr<NiceMock<TestBaseSearchProvider> > provider_; | 85 scoped_refptr<NiceMock<TestBaseSearchProvider> > provider_; |
| 84 std::unique_ptr<NiceMock<MockAutocompleteProviderClient>> client_; | 86 std::unique_ptr<NiceMock<MockAutocompleteProviderClient>> client_; |
| 85 }; | 87 }; |
| 86 | 88 |
| 87 TEST_F(BaseSearchProviderTest, PreserveAnswersWhenDeduplicating) { | 89 TEST_F(BaseSearchProviderTest, PreserveAnswersWhenDeduplicating) { |
| 88 TemplateURLData data; | 90 TemplateURLData data; |
| 89 data.SetURL("http://foo.com/url?bar={searchTerms}"); | 91 data.SetURL("http://foo.com/url?bar={searchTerms}"); |
| 90 std::unique_ptr<TemplateURL> template_url(new TemplateURL(data)); | 92 auto template_url = base::MakeUnique<TemplateURL>(data); |
| 91 | 93 |
| 92 TestBaseSearchProvider::MatchMap map; | 94 TestBaseSearchProvider::MatchMap map; |
| 93 base::string16 query = base::ASCIIToUTF16("weather los angeles"); | 95 base::string16 query = base::ASCIIToUTF16("weather los angeles"); |
| 94 base::string16 answer_contents = base::ASCIIToUTF16("some answer content"); | 96 base::string16 answer_contents = base::ASCIIToUTF16("some answer content"); |
| 95 base::string16 answer_type = base::ASCIIToUTF16("2334"); | 97 base::string16 answer_type = base::ASCIIToUTF16("2334"); |
| 96 std::unique_ptr<SuggestionAnswer> answer(new SuggestionAnswer()); | 98 std::unique_ptr<SuggestionAnswer> answer(new SuggestionAnswer()); |
| 97 answer->set_type(2334); | 99 answer->set_type(2334); |
| 98 | 100 |
| 99 EXPECT_CALL(*provider_, GetInput(_)) | 101 EXPECT_CALL(*provider_, GetInput(_)) |
| 100 .WillRepeatedly(Return(AutocompleteInput())); | 102 .WillRepeatedly(Return(AutocompleteInput())); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 EXPECT_TRUE(answer2->Equals(*match.answer)); | 164 EXPECT_TRUE(answer2->Equals(*match.answer)); |
| 163 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, match.type); | 165 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, match.type); |
| 164 EXPECT_EQ(1300, match.relevance); | 166 EXPECT_EQ(1300, match.relevance); |
| 165 | 167 |
| 166 EXPECT_EQ(answer_contents, duplicate.answer_contents); | 168 EXPECT_EQ(answer_contents, duplicate.answer_contents); |
| 167 EXPECT_EQ(answer_type, duplicate.answer_type); | 169 EXPECT_EQ(answer_type, duplicate.answer_type); |
| 168 EXPECT_TRUE(answer->Equals(*duplicate.answer)); | 170 EXPECT_TRUE(answer->Equals(*duplicate.answer)); |
| 169 EXPECT_EQ(AutocompleteMatchType::SEARCH_SUGGEST, duplicate.type); | 171 EXPECT_EQ(AutocompleteMatchType::SEARCH_SUGGEST, duplicate.type); |
| 170 EXPECT_EQ(850, duplicate.relevance); | 172 EXPECT_EQ(850, duplicate.relevance); |
| 171 } | 173 } |
| 174 |
| 175 TEST_F(BaseSearchProviderTest, MatchTailSuggestionProperly) { |
| 176 TemplateURLData data; |
| 177 data.SetURL("http://foo.com/url?bar={searchTerms}"); |
| 178 auto template_url = base::MakeUnique<TemplateURL>(data); |
| 179 |
| 180 AutocompleteInput autocomplete_input( |
| 181 base::ASCIIToUTF16("weather"), 7, std::string(), GURL(), base::string16(), |
| 182 metrics::OmniboxEventProto::BLANK, false, false, false, false, false, |
| 183 TestSchemeClassifier()); |
| 184 |
| 185 EXPECT_CALL(*provider_, GetInput(_)) |
| 186 .WillRepeatedly(Return(autocomplete_input)); |
| 187 EXPECT_CALL(*provider_, GetTemplateURL(_)) |
| 188 .WillRepeatedly(Return(template_url.get())); |
| 189 |
| 190 base::string16 query = base::ASCIIToUTF16("angeles now"); |
| 191 base::string16 suggestion = base::ASCIIToUTF16("weather los ") + query; |
| 192 SearchSuggestionParser::SuggestResult suggest_result( |
| 193 suggestion, AutocompleteMatchType::SEARCH_SUGGEST_TAIL, 0, query, |
| 194 base::ASCIIToUTF16("..."), base::string16(), base::string16(), |
| 195 base::string16(), nullptr, std::string(), std::string(), false, 1300, |
| 196 true, false, query); |
| 197 |
| 198 TestBaseSearchProvider::MatchMap map; |
| 199 provider_->AddMatchToMap(suggest_result, std::string(), |
| 200 TemplateURLRef::NO_SUGGESTION_CHOSEN, false, false, |
| 201 &map); |
| 202 |
| 203 ASSERT_EQ(1UL, map.size()); |
| 204 const auto& entry = *(map.begin()); |
| 205 std::string text = |
| 206 entry.second.GetAdditionalInfo(kACMatchPropertyContentsStartIndex); |
| 207 size_t length; |
| 208 EXPECT_TRUE(base::StringToSizeT(text, &length)); |
| 209 text = entry.second.GetAdditionalInfo(kACMatchPropertySuggestionText); |
| 210 EXPECT_GE(text.length(), length); |
| 211 } |
| OLD | NEW |