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

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

Issue 169463011: Omnibox: Fixes Allow-To-Be-Default-Match Code for HistoryQuick Provider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | « chrome/browser/autocomplete/history_quick_provider.cc ('k') | no next file » | 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 127
128 virtual void GetTestData(size_t* data_count, TestURLInfo** test_data); 128 virtual void GetTestData(size_t* data_count, TestURLInfo** test_data);
129 129
130 // Fills test data into the history system. 130 // Fills test data into the history system.
131 void FillData(); 131 void FillData();
132 132
133 // Runs an autocomplete query on |text| and checks to see that the returned 133 // Runs an autocomplete query on |text| and checks to see that the returned
134 // results' destination URLs match those provided. |expected_urls| does not 134 // results' destination URLs match those provided. |expected_urls| does not
135 // need to be in sorted order. 135 // need to be in sorted order.
136 void RunTest(const base::string16 text, 136 void RunTest(const base::string16 text,
137 bool prevent_inline_autocomplete,
137 std::vector<std::string> expected_urls, 138 std::vector<std::string> expected_urls,
138 bool can_inline_top_result, 139 bool can_inline_top_result,
139 base::string16 expected_fill_into_edit); 140 base::string16 expected_fill_into_edit,
141 base::string16 autocompletion);
140 142
141 base::MessageLoopForUI message_loop_; 143 base::MessageLoopForUI message_loop_;
142 content::TestBrowserThread ui_thread_; 144 content::TestBrowserThread ui_thread_;
143 content::TestBrowserThread file_thread_; 145 content::TestBrowserThread file_thread_;
144 146
145 scoped_ptr<TestingProfile> profile_; 147 scoped_ptr<TestingProfile> profile_;
146 HistoryService* history_service_; 148 HistoryService* history_service_;
147 149
148 ACMatches ac_matches_; // The resulting matches after running RunTest. 150 ACMatches ac_matches_; // The resulting matches after running RunTest.
149 151
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 234 }
233 235
234 void HistoryQuickProviderTest::SetShouldContain::operator()( 236 void HistoryQuickProviderTest::SetShouldContain::operator()(
235 const std::string& expected) { 237 const std::string& expected) {
236 EXPECT_EQ(1U, matches_.erase(expected)) 238 EXPECT_EQ(1U, matches_.erase(expected))
237 << "Results did not contain '" << expected << "' but should have."; 239 << "Results did not contain '" << expected << "' but should have.";
238 } 240 }
239 241
240 242
241 void HistoryQuickProviderTest::RunTest(const base::string16 text, 243 void HistoryQuickProviderTest::RunTest(const base::string16 text,
244 bool prevent_inline_autocomplete,
242 std::vector<std::string> expected_urls, 245 std::vector<std::string> expected_urls,
243 bool can_inline_top_result, 246 bool can_inline_top_result,
244 base::string16 expected_fill_into_edit) { 247 base::string16 expected_fill_into_edit,
248 base::string16 expected_autocompletion) {
245 SCOPED_TRACE(text); // Minimal hint to query being run. 249 SCOPED_TRACE(text); // Minimal hint to query being run.
246 base::MessageLoop::current()->RunUntilIdle(); 250 base::MessageLoop::current()->RunUntilIdle();
247 AutocompleteInput input(text, base::string16::npos, base::string16(), 251 AutocompleteInput input(text, base::string16::npos, base::string16(),
248 GURL(), AutocompleteInput::INVALID_SPEC, false, 252 GURL(), AutocompleteInput::INVALID_SPEC,
249 false, true, AutocompleteInput::ALL_MATCHES); 253 prevent_inline_autocomplete, false, true,
254 AutocompleteInput::ALL_MATCHES);
250 provider_->Start(input, false); 255 provider_->Start(input, false);
251 EXPECT_TRUE(provider_->done()); 256 EXPECT_TRUE(provider_->done());
252 257
253 ac_matches_ = provider_->matches(); 258 ac_matches_ = provider_->matches();
254 259
255 // We should have gotten back at most AutocompleteProvider::kMaxMatches. 260 // We should have gotten back at most AutocompleteProvider::kMaxMatches.
256 EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches); 261 EXPECT_LE(ac_matches_.size(), AutocompleteProvider::kMaxMatches);
257 262
258 // If the number of expected and actual matches aren't equal then we need 263 // If the number of expected and actual matches aren't equal then we need
259 // test no further, but let's do anyway so that we know which URLs failed. 264 // test no further, but let's do anyway so that we know which URLs failed.
(...skipping 21 matching lines...) Expand all
281 EXPECT_EQ(*expected, actual->destination_url.spec()) 286 EXPECT_EQ(*expected, actual->destination_url.spec())
282 << "For result #" << i << " we got '" << actual->destination_url.spec() 287 << "For result #" << i << " we got '" << actual->destination_url.spec()
283 << "' but expected '" << *expected << "'."; 288 << "' but expected '" << *expected << "'.";
284 EXPECT_LT(actual->relevance, best_score) 289 EXPECT_LT(actual->relevance, best_score)
285 << "At result #" << i << " (url=" << actual->destination_url.spec() 290 << "At result #" << i << " (url=" << actual->destination_url.spec()
286 << "), we noticed scores are not monotonically decreasing."; 291 << "), we noticed scores are not monotonically decreasing.";
287 best_score = actual->relevance; 292 best_score = actual->relevance;
288 } 293 }
289 294
290 EXPECT_EQ(can_inline_top_result, ac_matches_[0].allowed_to_be_default_match); 295 EXPECT_EQ(can_inline_top_result, ac_matches_[0].allowed_to_be_default_match);
291 if (can_inline_top_result) { 296 if (can_inline_top_result)
Mark P 2014/02/22 00:01:05 I revised all the tests here so fill_into_edit is
292 // When the top scorer is inline-able make sure we get the expected 297 EXPECT_EQ(expected_autocompletion, ac_matches_[0].inline_autocompletion);
293 // fill_into_edit and autocomplete offset. 298 EXPECT_EQ(expected_fill_into_edit, ac_matches_[0].fill_into_edit);
294 EXPECT_EQ(expected_fill_into_edit, ac_matches_[0].fill_into_edit)
295 << "fill_into_edit was: '" << ac_matches_[0].fill_into_edit
296 << "' but we expected '" << expected_fill_into_edit << "'.";
297 size_t text_pos = expected_fill_into_edit.find(text);
298 ASSERT_NE(base::string16::npos, text_pos);
299 EXPECT_EQ(ac_matches_[0].fill_into_edit.substr(text_pos + text.size()),
300 ac_matches_[0].inline_autocompletion);
301 } else {
302 // When the top scorer is not inline-able autocomplete offset must be npos.
303 EXPECT_TRUE(ac_matches_[0].inline_autocompletion.empty());
304 }
305 } 299 }
306 300
307 TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) { 301 TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) {
308 std::vector<std::string> expected_urls; 302 std::vector<std::string> expected_urls;
309 expected_urls.push_back("http://slashdot.org/favorite_page.html"); 303 expected_urls.push_back("http://slashdot.org/favorite_page.html");
310 RunTest(ASCIIToUTF16("slashdot"), expected_urls, true, 304 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true,
311 ASCIIToUTF16("slashdot.org/favorite_page.html")); 305 ASCIIToUTF16("slashdot.org/favorite_page.html"),
306 ASCIIToUTF16(".org/favorite_page.html"));
312 } 307 }
313 308
314 TEST_F(HistoryQuickProviderTest, MultiTermTitleMatch) { 309 TEST_F(HistoryQuickProviderTest, MultiTermTitleMatch) {
315 std::vector<std::string> expected_urls; 310 std::vector<std::string> expected_urls;
316 expected_urls.push_back( 311 expected_urls.push_back(
317 "http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice"); 312 "http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice");
318 RunTest(ASCIIToUTF16("mice other animals"), expected_urls, false, 313 RunTest(ASCIIToUTF16("mice other animals"), false, expected_urls, false,
319 ASCIIToUTF16("cda.com/Dogs Cats Gorillas Sea Slugs and Mice")); 314 ASCIIToUTF16("cda.com/Dogs Cats Gorillas Sea Slugs and Mice"),
315 base::string16());
320 } 316 }
321 317
322 TEST_F(HistoryQuickProviderTest, NonWordLastCharacterMatch) { 318 TEST_F(HistoryQuickProviderTest, NonWordLastCharacterMatch) {
323 std::string expected_url("http://slashdot.org/favorite_page.html"); 319 std::string expected_url("http://slashdot.org/favorite_page.html");
324 std::vector<std::string> expected_urls; 320 std::vector<std::string> expected_urls;
325 expected_urls.push_back(expected_url); 321 expected_urls.push_back(expected_url);
326 RunTest(ASCIIToUTF16("slashdot.org/"), expected_urls, true, 322 RunTest(ASCIIToUTF16("slashdot.org/"), false, expected_urls, true,
327 ASCIIToUTF16("slashdot.org/favorite_page.html")); 323 ASCIIToUTF16("slashdot.org/favorite_page.html"),
324 ASCIIToUTF16("favorite_page.html"));
328 } 325 }
329 326
330 TEST_F(HistoryQuickProviderTest, MultiMatch) { 327 TEST_F(HistoryQuickProviderTest, MultiMatch) {
331 std::vector<std::string> expected_urls; 328 std::vector<std::string> expected_urls;
332 // Scores high because of typed_count. 329 // Scores high because of typed_count.
333 expected_urls.push_back("http://foo.com/"); 330 expected_urls.push_back("http://foo.com/");
334 // Scores high because of visit count. 331 // Scores high because of visit count.
335 expected_urls.push_back("http://foo.com/dir/another/"); 332 expected_urls.push_back("http://foo.com/dir/another/");
336 // Scores high because of high visit count. 333 // Scores high because of high visit count.
337 expected_urls.push_back("http://foo.com/dir/another/again/"); 334 expected_urls.push_back("http://foo.com/dir/another/again/");
338 RunTest(ASCIIToUTF16("foo"), expected_urls, true, ASCIIToUTF16("foo.com")); 335 RunTest(ASCIIToUTF16("foo"), false, expected_urls, true,
336 ASCIIToUTF16("foo.com"), ASCIIToUTF16(".com"));
339 } 337 }
340 338
341 TEST_F(HistoryQuickProviderTest, StartRelativeMatch) { 339 TEST_F(HistoryQuickProviderTest, StartRelativeMatch) {
342 std::vector<std::string> expected_urls; 340 std::vector<std::string> expected_urls;
343 expected_urls.push_back("http://xyzabcdefghijklmnopqrstuvw.com/a"); 341 expected_urls.push_back("http://xyzabcdefghijklmnopqrstuvw.com/a");
344 RunTest(ASCIIToUTF16("xyza"), expected_urls, true, 342 RunTest(ASCIIToUTF16("xyza"), false, expected_urls, true,
345 ASCIIToUTF16("xyzabcdefghijklmnopqrstuvw.com/a")); 343 ASCIIToUTF16("xyzabcdefghijklmnopqrstuvw.com/a"),
344 ASCIIToUTF16("bcdefghijklmnopqrstuvw.com/a"));
346 } 345 }
347 346
348 TEST_F(HistoryQuickProviderTest, EncodingMatch) { 347 TEST_F(HistoryQuickProviderTest, EncodingMatch) {
349 std::vector<std::string> expected_urls; 348 std::vector<std::string> expected_urls;
350 expected_urls.push_back("http://spaces.com/path%20with%20spaces/foo.html"); 349 expected_urls.push_back("http://spaces.com/path%20with%20spaces/foo.html");
351 RunTest(ASCIIToUTF16("path with spaces"), expected_urls, false, 350 RunTest(ASCIIToUTF16("path with spaces"), false, expected_urls, false,
352 ASCIIToUTF16("CANNOT AUTOCOMPLETE")); 351 ASCIIToUTF16("spaces.com/path with spaces/foo.html"),
352 base::string16());
353 } 353 }
354 354
355 TEST_F(HistoryQuickProviderTest, VisitCountMatches) { 355 TEST_F(HistoryQuickProviderTest, VisitCountMatches) {
356 std::vector<std::string> expected_urls; 356 std::vector<std::string> expected_urls;
357 expected_urls.push_back("http://visitedest.com/y/a"); 357 expected_urls.push_back("http://visitedest.com/y/a");
358 expected_urls.push_back("http://visitedest.com/y/b"); 358 expected_urls.push_back("http://visitedest.com/y/b");
359 expected_urls.push_back("http://visitedest.com/x/c"); 359 expected_urls.push_back("http://visitedest.com/x/c");
360 RunTest(ASCIIToUTF16("visitedest"), expected_urls, true, 360 RunTest(ASCIIToUTF16("visitedest"), false, expected_urls, true,
361 ASCIIToUTF16("visitedest.com/y/a")); 361 ASCIIToUTF16("visitedest.com/y/a"),
362 ASCIIToUTF16(".com/y/a"));
362 } 363 }
363 364
364 TEST_F(HistoryQuickProviderTest, TypedCountMatches) { 365 TEST_F(HistoryQuickProviderTest, TypedCountMatches) {
365 std::vector<std::string> expected_urls; 366 std::vector<std::string> expected_urls;
366 expected_urls.push_back("http://typeredest.com/y/a"); 367 expected_urls.push_back("http://typeredest.com/y/a");
367 expected_urls.push_back("http://typeredest.com/y/b"); 368 expected_urls.push_back("http://typeredest.com/y/b");
368 expected_urls.push_back("http://typeredest.com/x/c"); 369 expected_urls.push_back("http://typeredest.com/x/c");
369 RunTest(ASCIIToUTF16("typeredest"), expected_urls, true, 370 RunTest(ASCIIToUTF16("typeredest"), false, expected_urls, true,
370 ASCIIToUTF16("typeredest.com/y/a")); 371 ASCIIToUTF16("typeredest.com/y/a"),
372 ASCIIToUTF16(".com/y/a"));
371 } 373 }
372 374
373 TEST_F(HistoryQuickProviderTest, DaysAgoMatches) { 375 TEST_F(HistoryQuickProviderTest, DaysAgoMatches) {
374 std::vector<std::string> expected_urls; 376 std::vector<std::string> expected_urls;
375 expected_urls.push_back("http://daysagoest.com/y/a"); 377 expected_urls.push_back("http://daysagoest.com/y/a");
376 expected_urls.push_back("http://daysagoest.com/y/b"); 378 expected_urls.push_back("http://daysagoest.com/y/b");
377 expected_urls.push_back("http://daysagoest.com/x/c"); 379 expected_urls.push_back("http://daysagoest.com/x/c");
378 RunTest(ASCIIToUTF16("daysagoest"), expected_urls, true, 380 RunTest(ASCIIToUTF16("daysagoest"), false, expected_urls, true,
379 ASCIIToUTF16("daysagoest.com/y/a")); 381 ASCIIToUTF16("daysagoest.com/y/a"),
382 ASCIIToUTF16(".com/y/a"));
380 } 383 }
381 384
382 TEST_F(HistoryQuickProviderTest, EncodingLimitMatch) { 385 TEST_F(HistoryQuickProviderTest, EncodingLimitMatch) {
383 std::vector<std::string> expected_urls; 386 std::vector<std::string> expected_urls;
384 std::string url( 387 std::string url(
385 "http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice"); 388 "http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice");
386 // First check that a mid-word match yield no results. 389 // First check that a mid-word match yield no results.
387 RunTest(ASCIIToUTF16("ice"), expected_urls, false, 390 RunTest(ASCIIToUTF16("ice"), false, expected_urls, false,
388 ASCIIToUTF16("cda.com/Dogs Cats Gorillas Sea Slugs and Mice")); 391 ASCIIToUTF16("cda.com/Dogs Cats Gorillas Sea Slugs and Mice"),
392 base::string16());
389 // Then check that we get results when the match is at a word start 393 // Then check that we get results when the match is at a word start
390 // that is present because of an encoded separate (%20 = space). 394 // that is present because of an encoded separate (%20 = space).
391 expected_urls.push_back(url); 395 expected_urls.push_back(url);
392 RunTest(ASCIIToUTF16("Mice"), expected_urls, false, 396 RunTest(ASCIIToUTF16("Mice"), false, expected_urls, false,
393 ASCIIToUTF16("cda.com/Dogs Cats Gorillas Sea Slugs and Mice")); 397 ASCIIToUTF16("cda.com/Dogs Cats Gorillas Sea Slugs and Mice"),
398 base::string16());
394 // Verify that the matches' ACMatchClassifications offsets are in range. 399 // Verify that the matches' ACMatchClassifications offsets are in range.
395 ACMatchClassifications content(ac_matches_[0].contents_class); 400 ACMatchClassifications content(ac_matches_[0].contents_class);
396 // The max offset accounts for 6 occurrences of '%20' plus the 'http://'. 401 // The max offset accounts for 6 occurrences of '%20' plus the 'http://'.
397 const size_t max_offset = url.length() - ((6 * 2) + 7); 402 const size_t max_offset = url.length() - ((6 * 2) + 7);
398 for (ACMatchClassifications::const_iterator citer = content.begin(); 403 for (ACMatchClassifications::const_iterator citer = content.begin();
399 citer != content.end(); ++citer) 404 citer != content.end(); ++citer)
400 EXPECT_LT(citer->offset, max_offset); 405 EXPECT_LT(citer->offset, max_offset);
401 ACMatchClassifications description(ac_matches_[0].description_class); 406 ACMatchClassifications description(ac_matches_[0].description_class);
402 std::string page_title("Dogs & Cats & Mice & Other Animals"); 407 std::string page_title("Dogs & Cats & Mice & Other Animals");
403 for (ACMatchClassifications::const_iterator diter = description.begin(); 408 for (ACMatchClassifications::const_iterator diter = description.begin();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 EXPECT_EQ(ACMatchClassification::URL, spans_b[1].style); 458 EXPECT_EQ(ACMatchClassification::URL, spans_b[1].style);
454 EXPECT_EQ(3U, spans_b[2].offset); 459 EXPECT_EQ(3U, spans_b[2].offset);
455 EXPECT_EQ(ACMatchClassification::MATCH | ACMatchClassification::URL, 460 EXPECT_EQ(ACMatchClassification::MATCH | ACMatchClassification::URL,
456 spans_b[2].style); 461 spans_b[2].style);
457 } 462 }
458 463
459 TEST_F(HistoryQuickProviderTest, DeleteMatch) { 464 TEST_F(HistoryQuickProviderTest, DeleteMatch) {
460 std::vector<std::string> expected_urls; 465 std::vector<std::string> expected_urls;
461 expected_urls.push_back("http://slashdot.org/favorite_page.html"); 466 expected_urls.push_back("http://slashdot.org/favorite_page.html");
462 // Fill up ac_matches_; we don't really care about the test yet. 467 // Fill up ac_matches_; we don't really care about the test yet.
463 RunTest(ASCIIToUTF16("slashdot"), expected_urls, true, 468 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true,
464 ASCIIToUTF16("slashdot.org/favorite_page.html")); 469 ASCIIToUTF16("slashdot.org/favorite_page.html"),
470 ASCIIToUTF16(".org/favorite_page.html"));
465 EXPECT_EQ(1U, ac_matches_.size()); 471 EXPECT_EQ(1U, ac_matches_.size());
466 provider_->DeleteMatch(ac_matches_[0]); 472 provider_->DeleteMatch(ac_matches_[0]);
467 // Verify it's no longer an indexed visit. 473 // Verify it's no longer an indexed visit.
468 expected_urls.clear(); 474 expected_urls.clear();
469 RunTest(ASCIIToUTF16("slashdot"), expected_urls, true, 475 RunTest(ASCIIToUTF16("slashdot"), false, expected_urls, true,
470 ASCIIToUTF16("NONE EXPECTED")); 476 ASCIIToUTF16("NONE EXPECTED"), base::string16());
471 } 477 }
472 478
473 TEST_F(HistoryQuickProviderTest, PreventBeatingURLWhatYouTypedMatch) { 479 TEST_F(HistoryQuickProviderTest, PreventBeatingURLWhatYouTypedMatch) {
474 std::vector<std::string> expected_urls; 480 std::vector<std::string> expected_urls;
475 481
476 expected_urls.clear(); 482 expected_urls.clear();
477 expected_urls.push_back("http://popularsitewithroot.com/"); 483 expected_urls.push_back("http://popularsitewithroot.com/");
478 // If the user enters a hostname (no path) that he/she has visited 484 // If the user enters a hostname (no path) that he/she has visited
479 // before, we should make sure that all HistoryQuickProvider results 485 // before, we should make sure that all HistoryQuickProvider results
480 // have scores less than what HistoryURLProvider will assign the 486 // have scores less than what HistoryURLProvider will assign the
481 // URL-what-you-typed match. 487 // URL-what-you-typed match.
482 RunTest(ASCIIToUTF16("popularsitewithroot.com"), expected_urls, true, 488 RunTest(ASCIIToUTF16("popularsitewithroot.com"), false, expected_urls, true,
483 ASCIIToUTF16("popularsitewithroot.com")); 489 ASCIIToUTF16("popularsitewithroot.com"), base::string16());
484 EXPECT_LT(ac_matches_[0].relevance, 490 EXPECT_LT(ac_matches_[0].relevance,
485 HistoryURLProvider::kScoreForBestInlineableResult); 491 HistoryURLProvider::kScoreForBestInlineableResult);
486 492
487 // Check that if the user didn't quite enter the full hostname, this 493 // Check that if the user didn't quite enter the full hostname, this
488 // hostname would've normally scored above the URL-what-you-typed match. 494 // hostname would've normally scored above the URL-what-you-typed match.
489 RunTest(ASCIIToUTF16("popularsitewithroot.c"), expected_urls, true, 495 RunTest(ASCIIToUTF16("popularsitewithroot.c"), false, expected_urls, true,
490 ASCIIToUTF16("popularsitewithroot.com")); 496 ASCIIToUTF16("popularsitewithroot.com"),
497 ASCIIToUTF16("om"));
491 EXPECT_GE(ac_matches_[0].relevance, 498 EXPECT_GE(ac_matches_[0].relevance,
492 HistoryURLProvider::kScoreForWhatYouTypedResult); 499 HistoryURLProvider::kScoreForWhatYouTypedResult);
493 500
494 expected_urls.clear(); 501 expected_urls.clear();
495 expected_urls.push_back("http://popularsitewithpathonly.com/moo"); 502 expected_urls.push_back("http://popularsitewithpathonly.com/moo");
496 // If the user enters a hostname of a host that he/she has visited 503 // If the user enters a hostname of a host that he/she has visited
497 // but never visited the root page of, we should make sure that all 504 // but never visited the root page of, we should make sure that all
498 // HistoryQuickProvider results have scores less than what the 505 // HistoryQuickProvider results have scores less than what the
499 // HistoryURLProvider will assign the URL-what-you-typed match. 506 // HistoryURLProvider will assign the URL-what-you-typed match.
500 RunTest(ASCIIToUTF16("popularsitewithpathonly.com"), expected_urls, true, 507 RunTest(ASCIIToUTF16("popularsitewithpathonly.com"), false, expected_urls,
501 ASCIIToUTF16("popularsitewithpathonly.com/moo")); 508 true,
509 ASCIIToUTF16("popularsitewithpathonly.com/moo"),
510 ASCIIToUTF16("/moo"));
502 EXPECT_LT(ac_matches_[0].relevance, 511 EXPECT_LT(ac_matches_[0].relevance,
503 HistoryURLProvider::kScoreForUnvisitedIntranetResult); 512 HistoryURLProvider::kScoreForUnvisitedIntranetResult);
504 513
505 // Verify the same thing happens if the user adds a / to end of the 514 // Verify the same thing happens if the user adds a / to end of the
506 // hostname. 515 // hostname.
507 RunTest(ASCIIToUTF16("popularsitewithpathonly.com/"), expected_urls, true, 516 RunTest(ASCIIToUTF16("popularsitewithpathonly.com/"), false, expected_urls,
508 ASCIIToUTF16("popularsitewithpathonly.com/moo")); 517 true, ASCIIToUTF16("popularsitewithpathonly.com/moo"),
518 ASCIIToUTF16("moo"));
509 EXPECT_LT(ac_matches_[0].relevance, 519 EXPECT_LT(ac_matches_[0].relevance,
510 HistoryURLProvider::kScoreForUnvisitedIntranetResult); 520 HistoryURLProvider::kScoreForUnvisitedIntranetResult);
511 521
512 // Check that if the user didn't quite enter the full hostname, this 522 // Check that if the user didn't quite enter the full hostname, this
513 // page would've normally scored above the URL-what-you-typed match. 523 // page would've normally scored above the URL-what-you-typed match.
514 RunTest(ASCIIToUTF16("popularsitewithpathonly.co"), expected_urls, true, 524 RunTest(ASCIIToUTF16("popularsitewithpathonly.co"), false, expected_urls,
515 ASCIIToUTF16("popularsitewithpathonly.com/moo")); 525 true, ASCIIToUTF16("popularsitewithpathonly.com/moo"),
526 ASCIIToUTF16("m/moo"));
516 EXPECT_GE(ac_matches_[0].relevance, 527 EXPECT_GE(ac_matches_[0].relevance,
517 HistoryURLProvider::kScoreForWhatYouTypedResult); 528 HistoryURLProvider::kScoreForWhatYouTypedResult);
518 529
519 // If the user enters a hostname + path that he/she has not visited 530 // If the user enters a hostname + path that he/she has not visited
520 // before (but visited other things on the host), we can allow 531 // before (but visited other things on the host), we can allow
521 // inline autocompletions. 532 // inline autocompletions.
522 RunTest(ASCIIToUTF16("popularsitewithpathonly.com/mo"), expected_urls, true, 533 RunTest(ASCIIToUTF16("popularsitewithpathonly.com/mo"), false, expected_urls,
523 ASCIIToUTF16("popularsitewithpathonly.com/moo")); 534 true,
535 ASCIIToUTF16("popularsitewithpathonly.com/moo"),
536 ASCIIToUTF16("o"));
524 EXPECT_GE(ac_matches_[0].relevance, 537 EXPECT_GE(ac_matches_[0].relevance,
525 HistoryURLProvider::kScoreForWhatYouTypedResult); 538 HistoryURLProvider::kScoreForWhatYouTypedResult);
526 539
527 // If the user enters a hostname + path that he/she has visited 540 // If the user enters a hostname + path that he/she has visited
528 // before, we should make sure that all HistoryQuickProvider results 541 // before, we should make sure that all HistoryQuickProvider results
529 // have scores less than what the HistoryURLProvider will assign 542 // have scores less than what the HistoryURLProvider will assign
530 // the URL-what-you-typed match. 543 // the URL-what-you-typed match.
531 RunTest(ASCIIToUTF16("popularsitewithpathonly.com/moo"), 544 RunTest(ASCIIToUTF16("popularsitewithpathonly.com/moo"), false,
532 expected_urls, true, 545 expected_urls, true,
533 ASCIIToUTF16("popularsitewithpathonly.com/moo")); 546 ASCIIToUTF16("popularsitewithpathonly.com/moo"), base::string16());
534 EXPECT_LT(ac_matches_[0].relevance, 547 EXPECT_LT(ac_matches_[0].relevance,
535 HistoryURLProvider::kScoreForBestInlineableResult); 548 HistoryURLProvider::kScoreForBestInlineableResult);
536 } 549 }
537 550
551 TEST_F(HistoryQuickProviderTest, PreventInlineAutocomplete) {
552 std::vector<std::string> expected_urls;
553 expected_urls.push_back("http://popularsitewithroot.com/");
554
555 // Check that the desired URL is normally allowed to be the default match
556 // against input that is a prefex of the URL.
557 RunTest(ASCIIToUTF16("popularsitewithr"), false, expected_urls, true,
558 ASCIIToUTF16("popularsitewithroot.com"),
559 ASCIIToUTF16("oot.com"));
560
561 // Check that it's not allowed to be the default match if
562 // prevent_inline_autocomplete is true.
563 RunTest(ASCIIToUTF16("popularsitewithr"), true, expected_urls, false,
564 ASCIIToUTF16("popularsitewithroot.com"),
565 ASCIIToUTF16("oot.com"));
566
567 // But the exact hostname can still match even if prevent inline autocomplete
568 // is true. i.e., there's no autocompletion necessary; this is effectively
569 // URL-what-you-typed.
570 RunTest(ASCIIToUTF16("popularsitewithroot.com"), true, expected_urls, true,
571 ASCIIToUTF16("popularsitewithroot.com"), base::string16());
572
573 // The above still holds even with an extra trailing slash.
574 RunTest(ASCIIToUTF16("popularsitewithroot.com/"), true, expected_urls, true,
575 ASCIIToUTF16("popularsitewithroot.com"), base::string16());
576 }
577
538 TEST_F(HistoryQuickProviderTest, CullSearchResults) { 578 TEST_F(HistoryQuickProviderTest, CullSearchResults) {
539 // Set up a default search engine. 579 // Set up a default search engine.
540 TemplateURLData data; 580 TemplateURLData data;
541 data.SetKeyword(ASCIIToUTF16("TestEngine")); 581 data.SetKeyword(ASCIIToUTF16("TestEngine"));
542 data.SetURL("http://testsearch.com/?q={searchTerms}"); 582 data.SetURL("http://testsearch.com/?q={searchTerms}");
543 TemplateURLService* template_url_service = 583 TemplateURLService* template_url_service =
544 TemplateURLServiceFactory::GetForProfile(profile_.get()); 584 TemplateURLServiceFactory::GetForProfile(profile_.get());
545 TemplateURL* template_url = new TemplateURL(profile_.get(), data); 585 TemplateURL* template_url = new TemplateURL(profile_.get(), data);
546 template_url_service->Add(template_url); 586 template_url_service->Add(template_url);
547 template_url_service->SetDefaultSearchProvider(template_url); 587 template_url_service->SetDefaultSearchProvider(template_url);
548 template_url_service->Load(); 588 template_url_service->Load();
549 589
550 // A search results page should not be returned when typing a query. 590 // A search results page should not be returned when typing a query.
551 std::vector<std::string> expected_urls; 591 std::vector<std::string> expected_urls;
552 expected_urls.push_back("http://anotherengine.com/?q=thequery"); 592 expected_urls.push_back("http://anotherengine.com/?q=thequery");
553 RunTest(ASCIIToUTF16("thequery"), expected_urls, false, base::string16()); 593 RunTest(ASCIIToUTF16("thequery"), false, expected_urls, false,
594 ASCIIToUTF16("anotherengine.com/?q=thequery"), base::string16());
554 595
555 // A search results page should not be returned when typing the engine URL. 596 // A search results page should not be returned when typing the engine URL.
556 expected_urls.clear(); 597 expected_urls.clear();
557 expected_urls.push_back("http://testsearch.com/"); 598 expected_urls.push_back("http://testsearch.com/");
558 RunTest(ASCIIToUTF16("testsearch"), expected_urls, true, 599 RunTest(ASCIIToUTF16("testsearch"), false, expected_urls, true,
559 ASCIIToUTF16("testsearch.com")); 600 ASCIIToUTF16("testsearch.com"),
601 ASCIIToUTF16(".com"));
560 } 602 }
561 603
562 // HQPOrderingTest ------------------------------------------------------------- 604 // HQPOrderingTest -------------------------------------------------------------
563 605
564 TestURLInfo ordering_test_db[] = { 606 TestURLInfo ordering_test_db[] = {
565 {"http://www.teamliquid.net/tlpd/korean/games/21648_bisu_vs_iris", "", 6, 3, 607 {"http://www.teamliquid.net/tlpd/korean/games/21648_bisu_vs_iris", "", 6, 3,
566 256}, 608 256},
567 {"http://www.amazon.com/", "amazon.com: online shopping for electronics, " 609 {"http://www.amazon.com/", "amazon.com: online shopping for electronics, "
568 "apparel, computers, books, dvds & more", 20, 20, 10}, 610 "apparel, computers, books, dvds & more", 20, 20, 10},
569 {"http://www.teamliquid.net/forum/viewmessage.php?topic_id=52045&" 611 {"http://www.teamliquid.net/forum/viewmessage.php?topic_id=52045&"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 DCHECK(test_data); 649 DCHECK(test_data);
608 *data_count = arraysize(ordering_test_db); 650 *data_count = arraysize(ordering_test_db);
609 *test_data = &ordering_test_db[0]; 651 *test_data = &ordering_test_db[0];
610 } 652 }
611 653
612 TEST_F(HQPOrderingTest, TEMatch) { 654 TEST_F(HQPOrderingTest, TEMatch) {
613 std::vector<std::string> expected_urls; 655 std::vector<std::string> expected_urls;
614 expected_urls.push_back("http://techmeme.com/"); 656 expected_urls.push_back("http://techmeme.com/");
615 expected_urls.push_back("http://www.teamliquid.net/"); 657 expected_urls.push_back("http://www.teamliquid.net/");
616 expected_urls.push_back("http://www.teamliquid.net/tlpd"); 658 expected_urls.push_back("http://www.teamliquid.net/tlpd");
617 RunTest(ASCIIToUTF16("te"), expected_urls, true, 659 RunTest(ASCIIToUTF16("te"), false, expected_urls, true,
618 ASCIIToUTF16("techmeme.com")); 660 ASCIIToUTF16("techmeme.com"),
661 ASCIIToUTF16("chmeme.com"));
619 } 662 }
620 663
621 TEST_F(HQPOrderingTest, TEAMatch) { 664 TEST_F(HQPOrderingTest, TEAMatch) {
622 std::vector<std::string> expected_urls; 665 std::vector<std::string> expected_urls;
623 expected_urls.push_back("http://www.teamliquid.net/"); 666 expected_urls.push_back("http://www.teamliquid.net/");
624 expected_urls.push_back("http://www.teamliquid.net/tlpd"); 667 expected_urls.push_back("http://www.teamliquid.net/tlpd");
625 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); 668 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players");
626 RunTest(ASCIIToUTF16("tea"), expected_urls, true, 669 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true,
627 ASCIIToUTF16("www.teamliquid.net")); 670 ASCIIToUTF16("www.teamliquid.net"),
671 ASCIIToUTF16("mliquid.net"));
628 } 672 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_quick_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698