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/base_search_provider.h" | 5 #include "components/omnibox/base_search_provider.h" |
6 | 6 |
7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "components/omnibox/autocomplete_match.h" | 9 #include "components/omnibox/autocomplete_match.h" |
10 #include "components/omnibox/autocomplete_match_type.h" | 10 #include "components/omnibox/autocomplete_match_type.h" |
11 #include "components/omnibox/autocomplete_provider_client.h" | 11 #include "components/omnibox/autocomplete_provider_client.h" |
12 #include "components/omnibox/autocomplete_scheme_classifier.h" | 12 #include "components/omnibox/autocomplete_scheme_classifier.h" |
13 #include "components/omnibox/search_suggestion_parser.h" | 13 #include "components/omnibox/search_suggestion_parser.h" |
| 14 #include "components/omnibox/suggestion_answer.h" |
14 #include "components/search_engines/search_terms_data.h" | 15 #include "components/search_engines/search_terms_data.h" |
15 #include "components/search_engines/template_url_service.h" | 16 #include "components/search_engines/template_url_service.h" |
16 #include "components/search_engines/template_url_service_client.h" | 17 #include "components/search_engines/template_url_service_client.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 using testing::NiceMock; | 21 using testing::NiceMock; |
21 using testing::Return; | 22 using testing::Return; |
22 using testing::_; | 23 using testing::_; |
23 | 24 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 118 |
118 TEST_F(BaseSearchProviderTest, PreserveAnswersWhenDeduplicating) { | 119 TEST_F(BaseSearchProviderTest, PreserveAnswersWhenDeduplicating) { |
119 TemplateURLData data; | 120 TemplateURLData data; |
120 data.SetURL("http://foo.com/url?bar={searchTerms}"); | 121 data.SetURL("http://foo.com/url?bar={searchTerms}"); |
121 scoped_ptr<TemplateURL> template_url(new TemplateURL(data)); | 122 scoped_ptr<TemplateURL> template_url(new TemplateURL(data)); |
122 | 123 |
123 TestBaseSearchProvider::MatchMap map; | 124 TestBaseSearchProvider::MatchMap map; |
124 base::string16 query = base::ASCIIToUTF16("weather los angeles"); | 125 base::string16 query = base::ASCIIToUTF16("weather los angeles"); |
125 base::string16 answer_contents = base::ASCIIToUTF16("some answer content"); | 126 base::string16 answer_contents = base::ASCIIToUTF16("some answer content"); |
126 base::string16 answer_type = base::ASCIIToUTF16("2334"); | 127 base::string16 answer_type = base::ASCIIToUTF16("2334"); |
| 128 scoped_ptr<SuggestionAnswer> answer(new SuggestionAnswer()); |
| 129 answer->set_type(2334); |
127 | 130 |
128 EXPECT_CALL(*provider_, GetInput(_)) | 131 EXPECT_CALL(*provider_, GetInput(_)) |
129 .WillRepeatedly(Return(AutocompleteInput())); | 132 .WillRepeatedly(Return(AutocompleteInput())); |
130 EXPECT_CALL(*provider_, GetTemplateURL(_)) | 133 EXPECT_CALL(*provider_, GetTemplateURL(_)) |
131 .WillRepeatedly(Return(template_url.get())); | 134 .WillRepeatedly(Return(template_url.get())); |
132 | 135 |
133 SearchSuggestionParser::SuggestResult more_relevant( | 136 SearchSuggestionParser::SuggestResult more_relevant( |
134 query, AutocompleteMatchType::SEARCH_HISTORY, query, base::string16(), | 137 query, AutocompleteMatchType::SEARCH_HISTORY, query, base::string16(), |
135 base::string16(), base::string16(), base::string16(), std::string(), | 138 base::string16(), base::string16(), base::string16(), nullptr, |
136 std::string(), false, 1300, true, false, query); | 139 std::string(), std::string(), false, 1300, true, false, query); |
137 provider_->AddMatchToMap( | 140 provider_->AddMatchToMap( |
138 more_relevant, std::string(), TemplateURLRef::NO_SUGGESTION_CHOSEN, | 141 more_relevant, std::string(), TemplateURLRef::NO_SUGGESTION_CHOSEN, |
139 false, false, &map); | 142 false, false, &map); |
140 | 143 |
141 SearchSuggestionParser::SuggestResult less_relevant( | 144 SearchSuggestionParser::SuggestResult less_relevant( |
142 query, AutocompleteMatchType::SEARCH_SUGGEST, query, base::string16(), | 145 query, AutocompleteMatchType::SEARCH_SUGGEST, query, base::string16(), |
143 base::string16(), answer_contents, answer_type, std::string(), | 146 base::string16(), answer_contents, answer_type, |
144 std::string(), false, 850, true, false, query); | 147 SuggestionAnswer::copy(answer.get()), std::string(), std::string(), |
| 148 false, 850, true, false, query); |
145 provider_->AddMatchToMap( | 149 provider_->AddMatchToMap( |
146 less_relevant, std::string(), TemplateURLRef::NO_SUGGESTION_CHOSEN, | 150 less_relevant, std::string(), TemplateURLRef::NO_SUGGESTION_CHOSEN, |
147 false, false, &map); | 151 false, false, &map); |
148 | 152 |
149 ASSERT_EQ(1U, map.size()); | 153 ASSERT_EQ(1U, map.size()); |
150 AutocompleteMatch match = map.begin()->second; | 154 AutocompleteMatch match = map.begin()->second; |
151 ASSERT_EQ(1U, match.duplicate_matches.size()); | 155 ASSERT_EQ(1U, match.duplicate_matches.size()); |
152 AutocompleteMatch duplicate = match.duplicate_matches[0]; | 156 AutocompleteMatch duplicate = match.duplicate_matches[0]; |
153 | 157 |
154 EXPECT_EQ(answer_contents, match.answer_contents); | 158 EXPECT_EQ(answer_contents, match.answer_contents); |
155 EXPECT_EQ(answer_type, match.answer_type); | 159 EXPECT_EQ(answer_type, match.answer_type); |
| 160 EXPECT_TRUE(answer->Equals(*match.answer)); |
156 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, match.type); | 161 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, match.type); |
157 EXPECT_EQ(1300, match.relevance); | 162 EXPECT_EQ(1300, match.relevance); |
158 | 163 |
159 EXPECT_EQ(answer_contents, duplicate.answer_contents); | 164 EXPECT_EQ(answer_contents, duplicate.answer_contents); |
160 EXPECT_EQ(answer_type, duplicate.answer_type); | 165 EXPECT_EQ(answer_type, duplicate.answer_type); |
| 166 EXPECT_TRUE(answer->Equals(*duplicate.answer)); |
161 EXPECT_EQ(AutocompleteMatchType::SEARCH_SUGGEST, duplicate.type); | 167 EXPECT_EQ(AutocompleteMatchType::SEARCH_SUGGEST, duplicate.type); |
162 EXPECT_EQ(850, duplicate.relevance); | 168 EXPECT_EQ(850, duplicate.relevance); |
163 | 169 |
164 // Ensure answers are not copied over existing answers. | 170 // Ensure answers are not copied over existing answers. |
165 map.clear(); | 171 map.clear(); |
166 base::string16 answer_contents2 = base::ASCIIToUTF16("different answer"); | 172 base::string16 answer_contents2 = base::ASCIIToUTF16("different answer"); |
| 173 base::string16 answer_type2 = base::ASCIIToUTF16("8242"); |
| 174 scoped_ptr<SuggestionAnswer> answer2(new SuggestionAnswer()); |
| 175 answer2->set_type(8242); |
167 more_relevant = SearchSuggestionParser::SuggestResult( | 176 more_relevant = SearchSuggestionParser::SuggestResult( |
168 query, AutocompleteMatchType::SEARCH_HISTORY, query, base::string16(), | 177 query, AutocompleteMatchType::SEARCH_HISTORY, query, base::string16(), |
169 base::string16(), answer_contents2, answer_type, std::string(), | 178 base::string16(), answer_contents2, answer_type2, |
170 std::string(), false, 1300, true, false, query); | 179 SuggestionAnswer::copy(answer2.get()), std::string(), std::string(), |
| 180 false, 1300, true, false, query); |
171 provider_->AddMatchToMap( | 181 provider_->AddMatchToMap( |
172 more_relevant, std::string(), TemplateURLRef::NO_SUGGESTION_CHOSEN, | 182 more_relevant, std::string(), TemplateURLRef::NO_SUGGESTION_CHOSEN, |
173 false, false, &map); | 183 false, false, &map); |
174 provider_->AddMatchToMap( | 184 provider_->AddMatchToMap( |
175 less_relevant, std::string(), TemplateURLRef::NO_SUGGESTION_CHOSEN, | 185 less_relevant, std::string(), TemplateURLRef::NO_SUGGESTION_CHOSEN, |
176 false, false, &map); | 186 false, false, &map); |
177 ASSERT_EQ(1U, map.size()); | 187 ASSERT_EQ(1U, map.size()); |
178 match = map.begin()->second; | 188 match = map.begin()->second; |
179 ASSERT_EQ(1U, match.duplicate_matches.size()); | 189 ASSERT_EQ(1U, match.duplicate_matches.size()); |
180 duplicate = match.duplicate_matches[0]; | 190 duplicate = match.duplicate_matches[0]; |
181 | 191 |
182 EXPECT_EQ(answer_contents2, match.answer_contents); | 192 EXPECT_EQ(answer_contents2, match.answer_contents); |
183 EXPECT_EQ(answer_type, match.answer_type); | 193 EXPECT_EQ(answer_type2, match.answer_type); |
| 194 EXPECT_TRUE(answer2->Equals(*match.answer)); |
184 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, match.type); | 195 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, match.type); |
185 EXPECT_EQ(1300, match.relevance); | 196 EXPECT_EQ(1300, match.relevance); |
186 | 197 |
187 EXPECT_EQ(answer_contents, duplicate.answer_contents); | 198 EXPECT_EQ(answer_contents, duplicate.answer_contents); |
188 EXPECT_EQ(answer_type, duplicate.answer_type); | 199 EXPECT_EQ(answer_type, duplicate.answer_type); |
| 200 EXPECT_TRUE(answer->Equals(*duplicate.answer)); |
189 EXPECT_EQ(AutocompleteMatchType::SEARCH_SUGGEST, duplicate.type); | 201 EXPECT_EQ(AutocompleteMatchType::SEARCH_SUGGEST, duplicate.type); |
190 EXPECT_EQ(850, duplicate.relevance); | 202 EXPECT_EQ(850, duplicate.relevance); |
191 | |
192 } | 203 } |
OLD | NEW |