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

Side by Side Diff: chrome/browser/autocomplete/history_quick_provider_unittest.cc

Issue 9359056: Merge 120346 - Fine-tune HQP Candidate Result Scoring (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1025/src/
Patch Set: Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/history/in_memory_url_index_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "chrome/browser/autocomplete/history_quick_provider.h" 5 #include "chrome/browser/autocomplete/history_quick_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 27 matching lines...) Expand all
38 int days_from_now; 38 int days_from_now;
39 } quick_test_db[] = { 39 } quick_test_db[] = {
40 {"http://www.google.com/", "Google", 3, 3, 0}, 40 {"http://www.google.com/", "Google", 3, 3, 0},
41 {"http://slashdot.org/favorite_page.html", "Favorite page", 200, 100, 0}, 41 {"http://slashdot.org/favorite_page.html", "Favorite page", 200, 100, 0},
42 {"http://kerneltrap.org/not_very_popular.html", "Less popular", 4, 0, 0}, 42 {"http://kerneltrap.org/not_very_popular.html", "Less popular", 4, 0, 0},
43 {"http://freshmeat.net/unpopular.html", "Unpopular", 1, 1, 0}, 43 {"http://freshmeat.net/unpopular.html", "Unpopular", 1, 1, 0},
44 {"http://news.google.com/?ned=us&topic=n", "Google News - U.S.", 2, 2, 0}, 44 {"http://news.google.com/?ned=us&topic=n", "Google News - U.S.", 2, 2, 0},
45 {"http://news.google.com/", "Google News", 1, 1, 0}, 45 {"http://news.google.com/", "Google News", 1, 1, 0},
46 {"http://foo.com/", "Dir", 200, 100, 0}, 46 {"http://foo.com/", "Dir", 200, 100, 0},
47 {"http://foo.com/dir/", "Dir", 2, 1, 10}, 47 {"http://foo.com/dir/", "Dir", 2, 1, 10},
48 {"http://foo.com/dir/another/", "Dir", 5, 1, 0}, 48 {"http://foo.com/dir/another/", "Dir", 5, 10, 0},
49 {"http://foo.com/dir/another/again/", "Dir", 5, 1, 0}, 49 {"http://foo.com/dir/another/again/", "Dir", 5, 1, 0},
50 {"http://foo.com/dir/another/again/myfile.html", "File", 10, 2, 0}, 50 {"http://foo.com/dir/another/again/myfile.html", "File", 3, 2, 0},
51 {"http://visitedest.com/y/a", "VA", 10, 1, 20}, 51 {"http://visitedest.com/y/a", "VA", 10, 1, 20},
52 {"http://visitedest.com/y/b", "VB", 9, 1, 20}, 52 {"http://visitedest.com/y/b", "VB", 9, 1, 20},
53 {"http://visitedest.com/x/c", "VC", 8, 1, 20}, 53 {"http://visitedest.com/x/c", "VC", 8, 1, 20},
54 {"http://visitedest.com/x/d", "VD", 7, 1, 20}, 54 {"http://visitedest.com/x/d", "VD", 7, 1, 20},
55 {"http://visitedest.com/y/e", "VE", 6, 1, 20}, 55 {"http://visitedest.com/y/e", "VE", 6, 1, 20},
56 {"http://typeredest.com/y/a", "TA", 3, 5, 0}, 56 {"http://typeredest.com/y/a", "TA", 3, 5, 0},
57 {"http://typeredest.com/y/b", "TB", 3, 4, 0}, 57 {"http://typeredest.com/y/b", "TB", 3, 4, 0},
58 {"http://typeredest.com/x/c", "TC", 3, 3, 0}, 58 {"http://typeredest.com/x/c", "TC", 3, 3, 0},
59 {"http://typeredest.com/x/d", "TD", 3, 2, 0}, 59 {"http://typeredest.com/x/d", "TD", 3, 2, 0},
60 {"http://typeredest.com/y/e", "TE", 3, 1, 0}, 60 {"http://typeredest.com/y/e", "TE", 3, 1, 0},
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 private: 97 private:
98 std::set<std::string> matches_; 98 std::set<std::string> matches_;
99 }; 99 };
100 100
101 void SetUp(); 101 void SetUp();
102 102
103 void TearDown() { 103 void TearDown() {
104 provider_ = NULL; 104 provider_ = NULL;
105 } 105 }
106 106
107 virtual void GetTestData(size_t* data_count, TestURLInfo** test_data);
108
107 // Fills test data into the history system. 109 // Fills test data into the history system.
108 void FillData(); 110 void FillData();
109 111
110 // Runs an autocomplete query on |text| and checks to see that the returned 112 // Runs an autocomplete query on |text| and checks to see that the returned
111 // results' destination URLs match those provided. |expected_urls| does not 113 // results' destination URLs match those provided. |expected_urls| does not
112 // need to be in sorted order. 114 // need to be in sorted order.
113 void RunTest(const string16 text, 115 void RunTest(const string16 text,
114 std::vector<std::string> expected_urls, 116 std::vector<std::string> expected_urls,
115 std::string expected_top_result,
116 bool can_inline_top_result, 117 bool can_inline_top_result,
117 string16 expected_fill_into_edit); 118 string16 expected_fill_into_edit);
118 119
119 MessageLoopForUI message_loop_; 120 MessageLoopForUI message_loop_;
120 content::TestBrowserThread ui_thread_; 121 content::TestBrowserThread ui_thread_;
121 content::TestBrowserThread file_thread_; 122 content::TestBrowserThread file_thread_;
122 123
123 scoped_ptr<TestingProfile> profile_; 124 scoped_ptr<TestingProfile> profile_;
124 HistoryService* history_service_; 125 HistoryService* history_service_;
125 126
(...skipping 11 matching lines...) Expand all
137 history_service_ = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 138 history_service_ = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
138 EXPECT_TRUE(history_service_); 139 EXPECT_TRUE(history_service_);
139 provider_ = new HistoryQuickProvider(this, profile_.get()); 140 provider_ = new HistoryQuickProvider(this, profile_.get());
140 FillData(); 141 FillData();
141 } 142 }
142 143
143 void HistoryQuickProviderTest::OnProviderUpdate(bool updated_matches) { 144 void HistoryQuickProviderTest::OnProviderUpdate(bool updated_matches) {
144 MessageLoop::current()->Quit(); 145 MessageLoop::current()->Quit();
145 } 146 }
146 147
148 void HistoryQuickProviderTest::GetTestData(size_t* data_count,
149 TestURLInfo** test_data) {
150 DCHECK(data_count);
151 DCHECK(test_data);
152 *data_count = arraysize(quick_test_db);
153 *test_data = &quick_test_db[0];
154 }
155
147 void HistoryQuickProviderTest::FillData() { 156 void HistoryQuickProviderTest::FillData() {
148 history::URLDatabase* db = history_service_->InMemoryDatabase(); 157 history::URLDatabase* db = history_service_->InMemoryDatabase();
149 ASSERT_TRUE(db != NULL); 158 ASSERT_TRUE(db != NULL);
150 159
151 history::InMemoryURLIndex* index = 160 history::InMemoryURLIndex* index =
152 new history::InMemoryURLIndex(FilePath()); 161 new history::InMemoryURLIndex(FilePath());
153 PrefService* prefs = profile_->GetPrefs(); 162 PrefService* prefs = profile_->GetPrefs();
154 std::string languages(prefs->GetString(prefs::kAcceptLanguages)); 163 std::string languages(prefs->GetString(prefs::kAcceptLanguages));
155 index->Init(db, languages); 164 index->Init(db, languages);
156 for (size_t i = 0; i < arraysize(quick_test_db); ++i) { 165 size_t data_count = 0;
157 const TestURLInfo& cur = quick_test_db[i]; 166 TestURLInfo* test_data = NULL;
167 GetTestData(&data_count, &test_data);
168 for (size_t i = 0; i < data_count; ++i) {
169 const TestURLInfo& cur(test_data[i]);
158 const GURL current_url(cur.url); 170 const GURL current_url(cur.url);
159 Time visit_time = Time::Now() - TimeDelta::FromDays(cur.days_from_now); 171 Time visit_time = Time::Now() - TimeDelta::FromDays(cur.days_from_now);
160 172
161 history::URLRow url_info(current_url); 173 history::URLRow url_info(current_url);
162 url_info.set_title(UTF8ToUTF16(cur.title)); 174 url_info.set_title(UTF8ToUTF16(cur.title));
163 url_info.set_visit_count(cur.visit_count); 175 url_info.set_visit_count(cur.visit_count);
164 url_info.set_typed_count(cur.typed_count); 176 url_info.set_typed_count(cur.typed_count);
165 url_info.set_last_visit(visit_time); 177 url_info.set_last_visit(visit_time);
166 url_info.set_hidden(false); 178 url_info.set_hidden(false);
167 index->UpdateURL(i, url_info); 179 index->UpdateURL(i, url_info);
(...skipping 11 matching lines...) Expand all
179 191
180 void HistoryQuickProviderTest::SetShouldContain::operator()( 192 void HistoryQuickProviderTest::SetShouldContain::operator()(
181 const std::string& expected) { 193 const std::string& expected) {
182 EXPECT_EQ(1U, matches_.erase(expected)) 194 EXPECT_EQ(1U, matches_.erase(expected))
183 << "Results did not contain '" << expected << "' but should have."; 195 << "Results did not contain '" << expected << "' but should have.";
184 } 196 }
185 197
186 198
187 void HistoryQuickProviderTest::RunTest(const string16 text, 199 void HistoryQuickProviderTest::RunTest(const string16 text,
188 std::vector<std::string> expected_urls, 200 std::vector<std::string> expected_urls,
189 std::string expected_top_result,
190 bool can_inline_top_result, 201 bool can_inline_top_result,
191 string16 expected_fill_into_edit) { 202 string16 expected_fill_into_edit) {
192 SCOPED_TRACE(text); // Minimal hint to query being run. 203 SCOPED_TRACE(text); // Minimal hint to query being run.
193 std::sort(expected_urls.begin(), expected_urls.end());
194
195 MessageLoop::current()->RunAllPending(); 204 MessageLoop::current()->RunAllPending();
196 AutocompleteInput input(text, string16(), false, false, true, 205 AutocompleteInput input(text, string16(), false, false, true,
197 AutocompleteInput::ALL_MATCHES); 206 AutocompleteInput::ALL_MATCHES);
198 provider_->Start(input, false); 207 provider_->Start(input, false);
199 EXPECT_TRUE(provider_->done()); 208 EXPECT_TRUE(provider_->done());
200 209
201 ac_matches_ = provider_->matches(); 210 ac_matches_ = provider_->matches();
202 211
203 // We should have gotten back at most AutocompleteProvider::kMaxMatches. 212 // We should have gotten back at most AutocompleteProvider::kMaxMatches.
204 EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches); 213 EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches);
205 214
206 // If the number of expected and actual matches aren't equal then we need 215 // If the number of expected and actual matches aren't equal then we need
207 // test no further, but let's do anyway so that we know which URLs failed. 216 // test no further, but let's do anyway so that we know which URLs failed.
208 EXPECT_EQ(expected_urls.size(), ac_matches_.size()); 217 EXPECT_EQ(expected_urls.size(), ac_matches_.size());
209 218
210 // Verify that all expected URLs were found and that all found URLs 219 // Verify that all expected URLs were found and that all found URLs
211 // were expected. 220 // were expected.
212 std::set<std::string> leftovers = 221 std::set<std::string> leftovers =
213 for_each(expected_urls.begin(), expected_urls.end(), 222 for_each(expected_urls.begin(), expected_urls.end(),
214 SetShouldContain(ac_matches_)).LeftOvers(); 223 SetShouldContain(ac_matches_)).LeftOvers();
215 EXPECT_EQ(0U, leftovers.size()) << "There were " << leftovers.size() 224 EXPECT_EQ(0U, leftovers.size()) << "There were " << leftovers.size()
216 << " unexpected results, one of which was: '" 225 << " unexpected results, one of which was: '"
217 << *(leftovers.begin()) << "'."; 226 << *(leftovers.begin()) << "'.";
218 227
219 // We always expect to get at least one result. 228 // We always expect to get at least one result.
220 ASSERT_FALSE(ac_matches_.empty()); 229 ASSERT_FALSE(ac_matches_.empty());
221 // See if we got the expected top scorer. 230 // Verify that we got the results in the order expected.
222 std::partial_sort(ac_matches_.begin(), ac_matches_.begin() + 1, 231 int i = 0;
223 ac_matches_.end(), AutocompleteMatch::MoreRelevant); 232 std::vector<std::string>::const_iterator expected = expected_urls.begin();
224 EXPECT_EQ(expected_top_result, ac_matches_[0].destination_url.spec()) 233 for (ACMatches::const_iterator actual = ac_matches_.begin();
225 << "Unexpected top result '" << ac_matches_[0].destination_url.spec() 234 actual != ac_matches_.end() && expected != expected_urls.end();
226 << "'."; 235 ++actual, ++expected, ++i) {
227 // If the top scorer is inline-able then validate the autocomplete offset. 236 EXPECT_EQ(*expected, actual->destination_url.spec())
228 EXPECT_EQ(can_inline_top_result ? text.size() : string16::npos, 237 << "For result #" << i << " we got '" << actual->destination_url.spec()
229 ac_matches_[0].inline_autocomplete_offset); 238 << "' but expected '" << *expected << "'.";
230 // And make sure we get the expected fill_into_edit. 239 }
231 EXPECT_EQ(expected_fill_into_edit, ac_matches_[0].fill_into_edit); 240
241 if (can_inline_top_result) {
242 // When the top scorer is inline-able make sure we get the expected
243 // fill_into_edit and autocomplete offset.
244 EXPECT_EQ(expected_fill_into_edit, ac_matches_[0].fill_into_edit)
245 << "fill_into_edit was: '" << ac_matches_[0].fill_into_edit
246 << "' but we expected '" << expected_fill_into_edit << "'.";
247 size_t text_pos = expected_fill_into_edit.find(text);
248 ASSERT_NE(string16::npos, text_pos);
249 EXPECT_EQ(text_pos + text.size(),
250 ac_matches_[0].inline_autocomplete_offset);
251 } else {
252 // When the top scorer is not inline-able autocomplete offset must be npos.
253 EXPECT_EQ(string16::npos, ac_matches_[0].inline_autocomplete_offset);
254 }
232 } 255 }
233 256
234 TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) { 257 TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) {
235 std::string expected_url("http://slashdot.org/favorite_page.html");
236 std::vector<std::string> expected_urls; 258 std::vector<std::string> expected_urls;
237 expected_urls.push_back(expected_url); 259 expected_urls.push_back("http://slashdot.org/favorite_page.html");
238 RunTest(ASCIIToUTF16("slashdot"), expected_urls, expected_url, true, 260 RunTest(ASCIIToUTF16("slashdot"), expected_urls, true,
239 ASCIIToUTF16("slashdot.org/favorite_page.html")); 261 ASCIIToUTF16("slashdot.org/favorite_page.html"));
240 } 262 }
241 263
242 TEST_F(HistoryQuickProviderTest, MultiTermTitleMatch) { 264 TEST_F(HistoryQuickProviderTest, MultiTermTitleMatch) {
243 std::string expected_url( 265 std::vector<std::string> expected_urls;
266 expected_urls.push_back(
244 "http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice"); 267 "http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice");
245 std::vector<std::string> expected_urls; 268 RunTest(ASCIIToUTF16("mice other animals"), expected_urls, false,
246 expected_urls.push_back(expected_url); 269 ASCIIToUTF16("cda.com/Dogs Cats Gorillas Sea Slugs and Mice"));
247 RunTest(ASCIIToUTF16("mice other animals"), expected_urls, expected_url,
248 false, ASCIIToUTF16("cda.com/Dogs Cats Gorillas Sea Slugs and Mice"));
249 } 270 }
250 271
251 TEST_F(HistoryQuickProviderTest, NonWordLastCharacterMatch) { 272 TEST_F(HistoryQuickProviderTest, NonWordLastCharacterMatch) {
252 std::string expected_url("http://slashdot.org/favorite_page.html"); 273 std::string expected_url("http://slashdot.org/favorite_page.html");
253 std::vector<std::string> expected_urls; 274 std::vector<std::string> expected_urls;
254 expected_urls.push_back(expected_url); 275 expected_urls.push_back(expected_url);
255 RunTest(ASCIIToUTF16("slashdot.org/"), expected_urls, expected_url, true, 276 RunTest(ASCIIToUTF16("slashdot.org/"), expected_urls, true,
256 ASCIIToUTF16("slashdot.org/favorite_page.html")); 277 ASCIIToUTF16("slashdot.org/favorite_page.html"));
257 } 278 }
258 279
259 TEST_F(HistoryQuickProviderTest, MultiMatch) { 280 TEST_F(HistoryQuickProviderTest, MultiMatch) {
260 std::vector<std::string> expected_urls; 281 std::vector<std::string> expected_urls;
261 // Scores high because of typed_count. 282 // Scores high because of typed_count.
262 expected_urls.push_back("http://foo.com/"); 283 expected_urls.push_back("http://foo.com/");
263 // Scores high because of visit count. 284 // Scores high because of visit count.
264 expected_urls.push_back("http://foo.com/dir/another/"); 285 expected_urls.push_back("http://foo.com/dir/another/");
265 // Scores high because of high visit count. 286 // Scores high because of high visit count.
266 expected_urls.push_back("http://foo.com/dir/another/again/myfile.html"); 287 expected_urls.push_back("http://foo.com/dir/another/again/");
267 RunTest(ASCIIToUTF16("foo"), expected_urls, "http://foo.com/", true, 288 RunTest(ASCIIToUTF16("foo"), expected_urls, true, ASCIIToUTF16("foo.com"));
268 ASCIIToUTF16("foo.com"));
269 } 289 }
270 290
271 TEST_F(HistoryQuickProviderTest, StartRelativeMatch) { 291 TEST_F(HistoryQuickProviderTest, StartRelativeMatch) {
272 std::vector<std::string> expected_urls; 292 std::vector<std::string> expected_urls;
273 expected_urls.push_back("http://xyzabcdefghijklmnopqrstuvw.com/a"); 293 expected_urls.push_back("http://xyzabcdefghijklmnopqrstuvw.com/a");
274 expected_urls.push_back("http://abcxyzdefghijklmnopqrstuvw.com/a"); 294 expected_urls.push_back("http://abcxyzdefghijklmnopqrstuvw.com/a");
275 expected_urls.push_back("http://abcdefxyzghijklmnopqrstuvw.com/a"); 295 expected_urls.push_back("http://abcdefxyzghijklmnopqrstuvw.com/a");
276 RunTest(ASCIIToUTF16("xyz"), expected_urls, 296 RunTest(ASCIIToUTF16("xyz"), expected_urls, true,
277 "http://xyzabcdefghijklmnopqrstuvw.com/a", true,
278 ASCIIToUTF16("xyzabcdefghijklmnopqrstuvw.com/a")); 297 ASCIIToUTF16("xyzabcdefghijklmnopqrstuvw.com/a"));
279 } 298 }
280 299
281 TEST_F(HistoryQuickProviderTest, PrefixOnlyMatch) { 300 TEST_F(HistoryQuickProviderTest, PrefixOnlyMatch) {
282 std::vector<std::string> expected_urls; 301 std::vector<std::string> expected_urls;
283 expected_urls.push_back("http://foo.com/"); 302 expected_urls.push_back("http://foo.com/");
284 expected_urls.push_back("http://slashdot.org/favorite_page.html"); 303 expected_urls.push_back("http://slashdot.org/favorite_page.html");
285 expected_urls.push_back("http://typeredest.com/y/a"); 304 expected_urls.push_back("http://foo.com/dir/another/");
286 RunTest(ASCIIToUTF16("http://"), expected_urls, "http://foo.com/", true, 305 RunTest(ASCIIToUTF16("http://"), expected_urls, true,
287 ASCIIToUTF16("http://foo.com")); 306 ASCIIToUTF16("http://foo.com"));
288 } 307 }
289 308
290 TEST_F(HistoryQuickProviderTest, VisitCountMatches) { 309 TEST_F(HistoryQuickProviderTest, VisitCountMatches) {
291 std::vector<std::string> expected_urls; 310 std::vector<std::string> expected_urls;
292 expected_urls.push_back("http://visitedest.com/y/a"); 311 expected_urls.push_back("http://visitedest.com/y/a");
293 expected_urls.push_back("http://visitedest.com/y/b"); 312 expected_urls.push_back("http://visitedest.com/y/b");
294 expected_urls.push_back("http://visitedest.com/x/c"); 313 expected_urls.push_back("http://visitedest.com/x/c");
295 RunTest(ASCIIToUTF16("visitedest"), expected_urls, 314 RunTest(ASCIIToUTF16("visitedest"), expected_urls, true,
296 "http://visitedest.com/y/a", true,
297 ASCIIToUTF16("visitedest.com/y/a")); 315 ASCIIToUTF16("visitedest.com/y/a"));
298 } 316 }
299 317
300 TEST_F(HistoryQuickProviderTest, TypedCountMatches) { 318 TEST_F(HistoryQuickProviderTest, TypedCountMatches) {
301 std::vector<std::string> expected_urls; 319 std::vector<std::string> expected_urls;
302 expected_urls.push_back("http://typeredest.com/y/a"); 320 expected_urls.push_back("http://typeredest.com/y/a");
303 expected_urls.push_back("http://typeredest.com/y/b"); 321 expected_urls.push_back("http://typeredest.com/y/b");
304 expected_urls.push_back("http://typeredest.com/x/c"); 322 expected_urls.push_back("http://typeredest.com/x/c");
305 RunTest(ASCIIToUTF16("typeredest"), expected_urls, 323 RunTest(ASCIIToUTF16("typeredest"), expected_urls, true,
306 "http://typeredest.com/y/a", true,
307 ASCIIToUTF16("typeredest.com/y/a")); 324 ASCIIToUTF16("typeredest.com/y/a"));
308 } 325 }
309 326
310 TEST_F(HistoryQuickProviderTest, DaysAgoMatches) { 327 TEST_F(HistoryQuickProviderTest, DaysAgoMatches) {
311 std::vector<std::string> expected_urls; 328 std::vector<std::string> expected_urls;
312 expected_urls.push_back("http://daysagoest.com/y/a"); 329 expected_urls.push_back("http://daysagoest.com/y/a");
313 expected_urls.push_back("http://daysagoest.com/y/b"); 330 expected_urls.push_back("http://daysagoest.com/y/b");
314 expected_urls.push_back("http://daysagoest.com/x/c"); 331 expected_urls.push_back("http://daysagoest.com/x/c");
315 RunTest(ASCIIToUTF16("daysagoest"), expected_urls, 332 RunTest(ASCIIToUTF16("daysagoest"), expected_urls, true,
316 "http://daysagoest.com/y/a", true,
317 ASCIIToUTF16("daysagoest.com/y/a")); 333 ASCIIToUTF16("daysagoest.com/y/a"));
318 } 334 }
319 335
320 TEST_F(HistoryQuickProviderTest, EncodingLimitMatch) { 336 TEST_F(HistoryQuickProviderTest, EncodingLimitMatch) {
321 std::vector<std::string> expected_urls; 337 std::vector<std::string> expected_urls;
322 std::string url( 338 std::string url(
323 "http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice"); 339 "http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice");
324 expected_urls.push_back(url); 340 expected_urls.push_back(url);
325 RunTest(ASCIIToUTF16("ice"), expected_urls, url, false, 341 RunTest(ASCIIToUTF16("ice"), expected_urls, false,
326 ASCIIToUTF16("cda.com/Dogs Cats Gorillas Sea Slugs and Mice")); 342 ASCIIToUTF16("cda.com/Dogs Cats Gorillas Sea Slugs and Mice"));
327 // Verify that the matches' ACMatchClassifications offsets are in range. 343 // Verify that the matches' ACMatchClassifications offsets are in range.
328 ACMatchClassifications content(ac_matches_[0].contents_class); 344 ACMatchClassifications content(ac_matches_[0].contents_class);
329 // The max offset accounts for 6 occurrences of '%20' plus the 'http://'. 345 // The max offset accounts for 6 occurrences of '%20' plus the 'http://'.
330 const size_t max_offset = url.length() - ((6 * 2) + 7); 346 const size_t max_offset = url.length() - ((6 * 2) + 7);
331 for (ACMatchClassifications::const_iterator citer = content.begin(); 347 for (ACMatchClassifications::const_iterator citer = content.begin();
332 citer != content.end(); ++citer) 348 citer != content.end(); ++citer)
333 EXPECT_LT(citer->offset, max_offset); 349 EXPECT_LT(citer->offset, max_offset);
334 ACMatchClassifications description(ac_matches_[0].description_class); 350 ACMatchClassifications description(ac_matches_[0].description_class);
335 std::string page_title("Dogs & Cats & Mice & Other Animals"); 351 std::string page_title("Dogs & Cats & Mice & Other Animals");
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 kMaxNonInliningScore - 1); 464 kMaxNonInliningScore - 1);
449 EXPECT_EQ(next_score, kMaxNonInliningScore - 2); 465 EXPECT_EQ(next_score, kMaxNonInliningScore - 2);
450 466
451 // Low score, can inline, not clamped. 467 // Low score, can inline, not clamped.
452 next_score = 1500; 468 next_score = 1500;
453 match.raw_score = 500; 469 match.raw_score = 500;
454 match.can_inline = true; 470 match.can_inline = true;
455 EXPECT_EQ(HistoryQuickProvider::CalculateRelevance(match, &next_score), 500); 471 EXPECT_EQ(HistoryQuickProvider::CalculateRelevance(match, &next_score), 500);
456 EXPECT_EQ(next_score, 499); 472 EXPECT_EQ(next_score, 499);
457 } 473 }
474
475 // HQPOrderingTest -------------------------------------------------------------
476
477 TestURLInfo ordering_test_db[] = {
478 {"http://www.teamliquid.net/tlpd/korean/games/21648_bisu_vs_iris", "", 6, 3,
479 256},
480 {"http://www.amazon.com/", "amazon.com: online shopping for electronics, "
481 "apparel, computers, books, dvds & more", 20, 20, 10},
482 {"http://www.teamliquid.net/forum/viewmessage.php?topic_id=52045&"
483 "currentpage=83", "google images", 6, 6, 0},
484 {"http://www.tempurpedic.com/", "tempur-pedic", 7, 7, 0},
485 {"http://www.teamfortress.com/", "", 5, 5, 6},
486 {"http://www.rottentomatoes.com/", "", 3, 3, 7},
487 {"http://music.google.com/music/listen?u=0#start_pl", "", 3, 3, 9},
488 {"https://www.emigrantdirect.com/", "high interest savings account, high "
489 "yield savings - emigrantdirect", 5, 5, 3},
490 {"http://store.steampowered.com/", "", 6, 6, 1},
491 {"http://techmeme.com/", "techmeme", 111, 110, 4},
492 {"http://www.teamliquid.net/tlpd", "team liquid progaming database", 15, 15,
493 2},
494 {"http://store.steampowered.com/", "the steam summer camp sale", 6, 6, 1},
495 {"http://www.teamliquid.net/tlpd/korean/players", "tlpd - bw korean - player "
496 "index", 100, 45, 219},
497 {"http://slashdot.org/", "slashdot: news for nerds, stuff that matters", 3, 3,
498 6},
499 {"http://translate.google.com/", "google translate", 3, 3, 0},
500 {"http://arstechnica.com/", "ars technica", 3, 3, 3},
501 {"http://www.rottentomatoes.com/", "movies | movie trailers | reviews - "
502 "rotten tomatoes", 3, 3, 7},
503 {"http://www.teamliquid.net/", "team liquid - starcraft 2 and brood war pro "
504 "gaming news", 26, 25, 3},
505 {"http://metaleater.com/", "metaleater", 4, 3, 8},
506 {"http://half.com/", "half.com: textbooks , books , music , movies , games , "
507 "video games", 4, 4, 6},
508 {"http://teamliquid.net/", "team liquid - starcraft 2 and brood war pro "
509 "gaming news", 8, 5, 9},
510 };
511
512 class HQPOrderingTest : public HistoryQuickProviderTest {
513 protected:
514 virtual void GetTestData(size_t* data_count,
515 TestURLInfo** test_data) OVERRIDE;
516 };
517
518 void HQPOrderingTest::GetTestData(size_t* data_count, TestURLInfo** test_data) {
519 DCHECK(data_count);
520 DCHECK(test_data);
521 *data_count = arraysize(ordering_test_db);
522 *test_data = &ordering_test_db[0];
523 }
524
525 TEST_F(HQPOrderingTest, TEMatch) {
526 std::vector<std::string> expected_urls;
527 expected_urls.push_back("http://techmeme.com/");
528 expected_urls.push_back("http://www.teamliquid.net/");
529 expected_urls.push_back("http://www.teamliquid.net/tlpd");
530 RunTest(ASCIIToUTF16("te"), expected_urls, true,
531 ASCIIToUTF16("techmeme.com"));
532 }
533
534 TEST_F(HQPOrderingTest, TEAMatch) {
535 std::vector<std::string> expected_urls;
536 expected_urls.push_back("http://www.teamliquid.net/");
537 expected_urls.push_back("http://www.teamliquid.net/tlpd");
538 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players");
539 RunTest(ASCIIToUTF16("tea"), expected_urls, true,
540 ASCIIToUTF16("www.teamliquid.net"));
541 }
542
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/history/in_memory_url_index_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698