Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Side by Side Diff: components/omnibox/browser/base_search_provider_unittest.cc

Issue 2755503002: Add a new entry to omnibox_event.proto to log specific type of contextual suggestions (Closed)
Patch Set: Small fixes and sync. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 base::string16 answer_type = base::ASCIIToUTF16("2334"); 95 base::string16 answer_type = base::ASCIIToUTF16("2334");
96 std::unique_ptr<SuggestionAnswer> answer(new SuggestionAnswer()); 96 std::unique_ptr<SuggestionAnswer> answer(new SuggestionAnswer());
97 answer->set_type(2334); 97 answer->set_type(2334);
98 98
99 EXPECT_CALL(*provider_, GetInput(_)) 99 EXPECT_CALL(*provider_, GetInput(_))
100 .WillRepeatedly(Return(AutocompleteInput())); 100 .WillRepeatedly(Return(AutocompleteInput()));
101 EXPECT_CALL(*provider_, GetTemplateURL(_)) 101 EXPECT_CALL(*provider_, GetTemplateURL(_))
102 .WillRepeatedly(Return(template_url.get())); 102 .WillRepeatedly(Return(template_url.get()));
103 103
104 SearchSuggestionParser::SuggestResult more_relevant( 104 SearchSuggestionParser::SuggestResult more_relevant(
105 query, AutocompleteMatchType::SEARCH_HISTORY, query, base::string16(), 105 query, AutocompleteMatchType::SEARCH_HISTORY, 0, query, base::string16(),
106 base::string16(), base::string16(), base::string16(), nullptr, 106 base::string16(), base::string16(), base::string16(), nullptr,
107 std::string(), std::string(), false, 1300, true, false, query); 107 std::string(), std::string(), false, 1300, true, false, query);
108 provider_->AddMatchToMap( 108 provider_->AddMatchToMap(
109 more_relevant, std::string(), TemplateURLRef::NO_SUGGESTION_CHOSEN, 109 more_relevant, std::string(), TemplateURLRef::NO_SUGGESTION_CHOSEN,
110 false, false, &map); 110 false, false, &map);
111 111
112 SearchSuggestionParser::SuggestResult less_relevant( 112 SearchSuggestionParser::SuggestResult less_relevant(
113 query, AutocompleteMatchType::SEARCH_SUGGEST, query, base::string16(), 113 query, AutocompleteMatchType::SEARCH_SUGGEST, 0, query, base::string16(),
114 base::string16(), answer_contents, answer_type, 114 base::string16(), answer_contents, answer_type,
115 SuggestionAnswer::copy(answer.get()), std::string(), std::string(), 115 SuggestionAnswer::copy(answer.get()), std::string(), std::string(), false,
116 false, 850, true, false, query); 116 850, true, false, query);
117 provider_->AddMatchToMap( 117 provider_->AddMatchToMap(
118 less_relevant, std::string(), TemplateURLRef::NO_SUGGESTION_CHOSEN, 118 less_relevant, std::string(), TemplateURLRef::NO_SUGGESTION_CHOSEN,
119 false, false, &map); 119 false, false, &map);
120 120
121 ASSERT_EQ(1U, map.size()); 121 ASSERT_EQ(1U, map.size());
122 AutocompleteMatch match = map.begin()->second; 122 AutocompleteMatch match = map.begin()->second;
123 ASSERT_EQ(1U, match.duplicate_matches.size()); 123 ASSERT_EQ(1U, match.duplicate_matches.size());
124 AutocompleteMatch duplicate = match.duplicate_matches[0]; 124 AutocompleteMatch duplicate = match.duplicate_matches[0];
125 125
126 EXPECT_EQ(answer_contents, match.answer_contents); 126 EXPECT_EQ(answer_contents, match.answer_contents);
127 EXPECT_EQ(answer_type, match.answer_type); 127 EXPECT_EQ(answer_type, match.answer_type);
128 EXPECT_TRUE(answer->Equals(*match.answer)); 128 EXPECT_TRUE(answer->Equals(*match.answer));
129 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, match.type); 129 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, match.type);
130 EXPECT_EQ(1300, match.relevance); 130 EXPECT_EQ(1300, match.relevance);
131 131
132 EXPECT_EQ(answer_contents, duplicate.answer_contents); 132 EXPECT_EQ(answer_contents, duplicate.answer_contents);
133 EXPECT_EQ(answer_type, duplicate.answer_type); 133 EXPECT_EQ(answer_type, duplicate.answer_type);
134 EXPECT_TRUE(answer->Equals(*duplicate.answer)); 134 EXPECT_TRUE(answer->Equals(*duplicate.answer));
135 EXPECT_EQ(AutocompleteMatchType::SEARCH_SUGGEST, duplicate.type); 135 EXPECT_EQ(AutocompleteMatchType::SEARCH_SUGGEST, duplicate.type);
136 EXPECT_EQ(850, duplicate.relevance); 136 EXPECT_EQ(850, duplicate.relevance);
137 137
138 // Ensure answers are not copied over existing answers. 138 // Ensure answers are not copied over existing answers.
139 map.clear(); 139 map.clear();
140 base::string16 answer_contents2 = base::ASCIIToUTF16("different answer"); 140 base::string16 answer_contents2 = base::ASCIIToUTF16("different answer");
141 base::string16 answer_type2 = base::ASCIIToUTF16("8242"); 141 base::string16 answer_type2 = base::ASCIIToUTF16("8242");
142 std::unique_ptr<SuggestionAnswer> answer2(new SuggestionAnswer()); 142 std::unique_ptr<SuggestionAnswer> answer2(new SuggestionAnswer());
143 answer2->set_type(8242); 143 answer2->set_type(8242);
144 more_relevant = SearchSuggestionParser::SuggestResult( 144 more_relevant = SearchSuggestionParser::SuggestResult(
145 query, AutocompleteMatchType::SEARCH_HISTORY, query, base::string16(), 145 query, AutocompleteMatchType::SEARCH_HISTORY, 0, query, base::string16(),
146 base::string16(), answer_contents2, answer_type2, 146 base::string16(), answer_contents2, answer_type2,
147 SuggestionAnswer::copy(answer2.get()), std::string(), std::string(), 147 SuggestionAnswer::copy(answer2.get()), std::string(), std::string(),
148 false, 1300, true, false, query); 148 false, 1300, true, false, query);
149 provider_->AddMatchToMap( 149 provider_->AddMatchToMap(
150 more_relevant, std::string(), TemplateURLRef::NO_SUGGESTION_CHOSEN, 150 more_relevant, std::string(), TemplateURLRef::NO_SUGGESTION_CHOSEN,
151 false, false, &map); 151 false, false, &map);
152 provider_->AddMatchToMap( 152 provider_->AddMatchToMap(
153 less_relevant, std::string(), TemplateURLRef::NO_SUGGESTION_CHOSEN, 153 less_relevant, std::string(), TemplateURLRef::NO_SUGGESTION_CHOSEN,
154 false, false, &map); 154 false, false, &map);
155 ASSERT_EQ(1U, map.size()); 155 ASSERT_EQ(1U, map.size());
156 match = map.begin()->second; 156 match = map.begin()->second;
157 ASSERT_EQ(1U, match.duplicate_matches.size()); 157 ASSERT_EQ(1U, match.duplicate_matches.size());
158 duplicate = match.duplicate_matches[0]; 158 duplicate = match.duplicate_matches[0];
159 159
160 EXPECT_EQ(answer_contents2, match.answer_contents); 160 EXPECT_EQ(answer_contents2, match.answer_contents);
161 EXPECT_EQ(answer_type2, match.answer_type); 161 EXPECT_EQ(answer_type2, match.answer_type);
162 EXPECT_TRUE(answer2->Equals(*match.answer)); 162 EXPECT_TRUE(answer2->Equals(*match.answer));
163 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, match.type); 163 EXPECT_EQ(AutocompleteMatchType::SEARCH_HISTORY, match.type);
164 EXPECT_EQ(1300, match.relevance); 164 EXPECT_EQ(1300, match.relevance);
165 165
166 EXPECT_EQ(answer_contents, duplicate.answer_contents); 166 EXPECT_EQ(answer_contents, duplicate.answer_contents);
167 EXPECT_EQ(answer_type, duplicate.answer_type); 167 EXPECT_EQ(answer_type, duplicate.answer_type);
168 EXPECT_TRUE(answer->Equals(*duplicate.answer)); 168 EXPECT_TRUE(answer->Equals(*duplicate.answer));
169 EXPECT_EQ(AutocompleteMatchType::SEARCH_SUGGEST, duplicate.type); 169 EXPECT_EQ(AutocompleteMatchType::SEARCH_SUGGEST, duplicate.type);
170 EXPECT_EQ(850, duplicate.relevance); 170 EXPECT_EQ(850, duplicate.relevance);
171 } 171 }
OLDNEW
« no previous file with comments | « components/omnibox/browser/base_search_provider.cc ('k') | components/omnibox/browser/omnibox_metrics_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698