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

Side by Side Diff: chrome/browser/history/in_memory_url_index_unittest.cc

Issue 11757004: Omnibox: Add Mid-Input Matching to HistoryQuick Provider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix typo in comment Created 7 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
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 <algorithm> 5 #include <algorithm>
6 #include <fstream> 6 #include <fstream>
7 7
8 #include "base/auto_reset.h"
8 #include "base/file_path.h" 9 #include "base/file_path.h"
9 #include "base/file_util.h" 10 #include "base/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
11 #include "base/message_loop.h" 12 #include "base/message_loop.h"
12 #include "base/path_service.h" 13 #include "base/path_service.h"
13 #include "base/string16.h" 14 #include "base/string16.h"
14 #include "base/string_util.h" 15 #include "base/string_util.h"
15 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/autocomplete/autocomplete_provider.h" 17 #include "chrome/browser/autocomplete/autocomplete_provider.h"
17 #include "chrome/browser/history/history_backend.h" 18 #include "chrome/browser/history/history_backend.h"
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 URLIndexPrivateData& private_data(*GetPrivateData()); 407 URLIndexPrivateData& private_data(*GetPrivateData());
407 408
408 // history_info_map_ should have the same number of items as were filtered. 409 // history_info_map_ should have the same number of items as were filtered.
409 EXPECT_EQ(1U, private_data.history_info_map_.size()); 410 EXPECT_EQ(1U, private_data.history_info_map_.size());
410 EXPECT_EQ(35U, private_data.char_word_map_.size()); 411 EXPECT_EQ(35U, private_data.char_word_map_.size());
411 EXPECT_EQ(17U, private_data.word_map_.size()); 412 EXPECT_EQ(17U, private_data.word_map_.size());
412 } 413 }
413 414
414 TEST_F(InMemoryURLIndexTest, Retrieval) { 415 TEST_F(InMemoryURLIndexTest, Retrieval) {
415 // See if a very specific term gives a single result. 416 // See if a very specific term gives a single result.
416 ScoredHistoryMatches matches = 417 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
417 url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport")); 418 ASCIIToUTF16("DrudgeReport"), string16::npos);
418 ASSERT_EQ(1U, matches.size()); 419 ASSERT_EQ(1U, matches.size());
419 420
420 // Verify that we got back the result we expected. 421 // Verify that we got back the result we expected.
421 EXPECT_EQ(5, matches[0].url_info.id()); 422 EXPECT_EQ(5, matches[0].url_info.id());
422 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec()); 423 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec());
423 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title()); 424 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title());
424 EXPECT_TRUE(matches[0].can_inline); 425 EXPECT_TRUE(matches[0].can_inline);
425 426
426 // Make sure a trailing space prevents inline-ability but still results 427 // Make sure a trailing space prevents inline-ability but still results
427 // in the expected result. 428 // in the expected result.
428 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport ")); 429 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport "),
430 string16::npos);
429 ASSERT_EQ(1U, matches.size()); 431 ASSERT_EQ(1U, matches.size());
430 EXPECT_EQ(5, matches[0].url_info.id()); 432 EXPECT_EQ(5, matches[0].url_info.id());
431 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec()); 433 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec());
432 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title()); 434 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title());
433 EXPECT_FALSE(matches[0].can_inline); 435 EXPECT_FALSE(matches[0].can_inline);
434 436
435 // Search which should result in multiple results. 437 // Search which should result in multiple results.
436 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("drudge")); 438 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("drudge"),
439 string16::npos);
437 ASSERT_EQ(2U, matches.size()); 440 ASSERT_EQ(2U, matches.size());
438 // The results should be in descending score order. 441 // The results should be in descending score order.
439 EXPECT_GE(matches[0].raw_score, matches[1].raw_score); 442 EXPECT_GE(matches[0].raw_score, matches[1].raw_score);
440 443
441 // Search which should result in nearly perfect result. 444 // Search which should result in nearly perfect result.
442 matches = url_index_->HistoryItemsForTerms( 445 matches = url_index_->HistoryItemsForTerms(
443 ASCIIToUTF16("https NearlyPerfectResult")); 446 ASCIIToUTF16("https NearlyPerfectResult"), string16::npos);
444 ASSERT_EQ(1U, matches.size()); 447 ASSERT_EQ(1U, matches.size());
445 // The results should have a very high score. 448 // The results should have a very high score.
446 EXPECT_GT(matches[0].raw_score, 900); 449 EXPECT_GT(matches[0].raw_score, 900);
447 EXPECT_EQ(32, matches[0].url_info.id()); 450 EXPECT_EQ(32, matches[0].url_info.id());
448 EXPECT_EQ("https://nearlyperfectresult.com/", 451 EXPECT_EQ("https://nearlyperfectresult.com/",
449 matches[0].url_info.url().spec()); // Note: URL gets lowercased. 452 matches[0].url_info.url().spec()); // Note: URL gets lowercased.
450 EXPECT_EQ(ASCIIToUTF16("Practically Perfect Search Result"), 453 EXPECT_EQ(ASCIIToUTF16("Practically Perfect Search Result"),
451 matches[0].url_info.title()); 454 matches[0].url_info.title());
452 EXPECT_FALSE(matches[0].can_inline); 455 EXPECT_FALSE(matches[0].can_inline);
453 456
454 // Search which should result in very poor result. 457 // Search which should result in very poor result.
455 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("z y x")); 458 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("z y x"),
459 string16::npos);
456 ASSERT_EQ(1U, matches.size()); 460 ASSERT_EQ(1U, matches.size());
457 // The results should have a poor score. 461 // The results should have a poor score.
458 EXPECT_LT(matches[0].raw_score, 500); 462 EXPECT_LT(matches[0].raw_score, 500);
459 EXPECT_EQ(33, matches[0].url_info.id()); 463 EXPECT_EQ(33, matches[0].url_info.id());
460 EXPECT_EQ("http://quiteuselesssearchresultxyz.com/", 464 EXPECT_EQ("http://quiteuselesssearchresultxyz.com/",
461 matches[0].url_info.url().spec()); // Note: URL gets lowercased. 465 matches[0].url_info.url().spec()); // Note: URL gets lowercased.
462 EXPECT_EQ(ASCIIToUTF16("Practically Useless Search Result"), 466 EXPECT_EQ(ASCIIToUTF16("Practically Useless Search Result"),
463 matches[0].url_info.title()); 467 matches[0].url_info.title());
464 EXPECT_FALSE(matches[0].can_inline); 468 EXPECT_FALSE(matches[0].can_inline);
465 469
466 // Search which will match at the end of an URL with encoded characters. 470 // Search which will match at the end of an URL with encoded characters.
467 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("Mice")); 471 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("Mice"),
472 string16::npos);
468 ASSERT_EQ(1U, matches.size()); 473 ASSERT_EQ(1U, matches.size());
469 EXPECT_EQ(30, matches[0].url_info.id()); 474 EXPECT_EQ(30, matches[0].url_info.id());
470 EXPECT_FALSE(matches[0].can_inline); 475 EXPECT_FALSE(matches[0].can_inline);
471 476
472 // Verify that a single term can appear multiple times in the URL and as long 477 // Verify that a single term can appear multiple times in the URL and as long
473 // as one starts the URL it is still inlined. 478 // as one starts the URL it is still inlined.
474 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("fubar")); 479 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("fubar"),
480 string16::npos);
475 ASSERT_EQ(1U, matches.size()); 481 ASSERT_EQ(1U, matches.size());
476 EXPECT_EQ(34, matches[0].url_info.id()); 482 EXPECT_EQ(34, matches[0].url_info.id());
477 EXPECT_EQ("http://fubarfubarandfubar.com/", matches[0].url_info.url().spec()); 483 EXPECT_EQ("http://fubarfubarandfubar.com/", matches[0].url_info.url().spec());
478 EXPECT_EQ(ASCIIToUTF16("Situation Normal -- FUBARED"), 484 EXPECT_EQ(ASCIIToUTF16("Situation Normal -- FUBARED"),
479 matches[0].url_info.title()); 485 matches[0].url_info.title());
480 EXPECT_TRUE(matches[0].can_inline); 486 EXPECT_TRUE(matches[0].can_inline);
481 } 487 }
482 488
489 TEST_F(InMemoryURLIndexTest, CursorPositionRetrieval) {
490 base::AutoReset<bool> use_cursor_position(
491 &GetPrivateData()->use_cursor_position_, true);
492
493 // See if a very specific term with no cursor gives an empty result.
494 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
495 ASCIIToUTF16("DrudReport"), string16::npos);
496 ASSERT_EQ(0U, matches.size());
497
498 // The same test with the cursor at the end should give an empty result.
499 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudReport"), 10u);
500 ASSERT_EQ(0U, matches.size());
501
502 // If the cursor is between Drud and Report, we should find the desired
503 // result.
504 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudReport"), 4u);
505 ASSERT_EQ(1U, matches.size());
506 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec());
507 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title());
508
509 // Now check multi-word inputs. No cursor should fail to find a
510 // result on this input.
511 matches = url_index_->HistoryItemsForTerms(
512 ASCIIToUTF16("MORTGAGERATE DROPS"), string16::npos);
513 ASSERT_EQ(0U, matches.size());
514
515 // Ditto with cursor at end.
516 matches = url_index_->HistoryItemsForTerms(
517 ASCIIToUTF16("MORTGAGERATE DROPS"), 18u);
518 ASSERT_EQ(0U, matches.size());
519
520 // If the cursor is between MORTAGE And RATE, we should find the
521 // desired result.
522 matches = url_index_->HistoryItemsForTerms(
523 ASCIIToUTF16("MORTGAGERATE DROPS"), 8u);
524 ASSERT_EQ(1U, matches.size());
525 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708",
526 matches[0].url_info.url().spec());
527 EXPECT_EQ(ASCIIToUTF16(
528 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"),
529 matches[0].url_info.title());
530 }
531
483 TEST_F(InMemoryURLIndexTest, URLPrefixMatching) { 532 TEST_F(InMemoryURLIndexTest, URLPrefixMatching) {
484 // "drudgere" - found, can inline 533 // "drudgere" - found, can inline
485 ScoredHistoryMatches matches = 534 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
486 url_index_->HistoryItemsForTerms(ASCIIToUTF16("drudgere")); 535 ASCIIToUTF16("drudgere"), string16::npos);
487 ASSERT_EQ(1U, matches.size()); 536 ASSERT_EQ(1U, matches.size());
488 EXPECT_TRUE(matches[0].can_inline); 537 EXPECT_TRUE(matches[0].can_inline);
489 538
490 // "http://drudgere" - found, can inline 539 // "http://drudgere" - found, can inline
491 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("http://drudgere")); 540 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("http://drudgere"),
541 string16::npos);
492 ASSERT_EQ(1U, matches.size()); 542 ASSERT_EQ(1U, matches.size());
493 EXPECT_TRUE(matches[0].can_inline); 543 EXPECT_TRUE(matches[0].can_inline);
494 544
495 // "www.atdmt" - not found 545 // "www.atdmt" - not found
496 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("www.atdmt")); 546 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("www.atdmt"),
547 string16::npos);
497 EXPECT_EQ(0U, matches.size()); 548 EXPECT_EQ(0U, matches.size());
498 549
499 // "atdmt" - found, cannot inline 550 // "atdmt" - found, cannot inline
500 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("atdmt")); 551 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("atdmt"),
552 string16::npos);
501 ASSERT_EQ(1U, matches.size()); 553 ASSERT_EQ(1U, matches.size());
502 EXPECT_FALSE(matches[0].can_inline); 554 EXPECT_FALSE(matches[0].can_inline);
503 555
504 // "view.atdmt" - found, can inline 556 // "view.atdmt" - found, can inline
505 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("view.atdmt")); 557 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("view.atdmt"),
558 string16::npos);
506 ASSERT_EQ(1U, matches.size()); 559 ASSERT_EQ(1U, matches.size());
507 EXPECT_TRUE(matches[0].can_inline); 560 EXPECT_TRUE(matches[0].can_inline);
508 561
509 // "http://view.atdmt" - found, can inline 562 // "http://view.atdmt" - found, can inline
510 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("http://view.atdmt")); 563 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("http://view.atdmt"),
564 string16::npos);
511 ASSERT_EQ(1U, matches.size()); 565 ASSERT_EQ(1U, matches.size());
512 EXPECT_TRUE(matches[0].can_inline); 566 EXPECT_TRUE(matches[0].can_inline);
513 567
514 // "cnn.com" - found, can inline 568 // "cnn.com" - found, can inline
515 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("cnn.com")); 569 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("cnn.com"),
570 string16::npos);
516 ASSERT_EQ(2U, matches.size()); 571 ASSERT_EQ(2U, matches.size());
517 // One match should be inline-able, the other not. 572 // One match should be inline-able, the other not.
518 EXPECT_TRUE(matches[0].can_inline != matches[1].can_inline); 573 EXPECT_TRUE(matches[0].can_inline != matches[1].can_inline);
519 574
520 // "www.cnn.com" - found, can inline 575 // "www.cnn.com" - found, can inline
521 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("www.cnn.com")); 576 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("www.cnn.com"),
577 string16::npos);
522 ASSERT_EQ(1U, matches.size()); 578 ASSERT_EQ(1U, matches.size());
523 EXPECT_TRUE(matches[0].can_inline); 579 EXPECT_TRUE(matches[0].can_inline);
524 580
525 // "www.cnn.com" - found, cannot inline 581 // "www.cnn.com" - found, cannot inline
526 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ww.cnn.com")); 582 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ww.cnn.com"),
583 string16::npos);
527 ASSERT_EQ(1U, matches.size()); 584 ASSERT_EQ(1U, matches.size());
528 EXPECT_TRUE(!matches[0].can_inline); 585 EXPECT_TRUE(!matches[0].can_inline);
529 586
530 // "http://www.cnn.com" - found, can inline 587 // "http://www.cnn.com" - found, can inline
531 matches = 588 matches =
532 url_index_->HistoryItemsForTerms(ASCIIToUTF16("http://www.cnn.com")); 589 url_index_->HistoryItemsForTerms(ASCIIToUTF16("http://www.cnn.com"),
590 string16::npos);
533 ASSERT_EQ(1U, matches.size()); 591 ASSERT_EQ(1U, matches.size());
534 EXPECT_TRUE(matches[0].can_inline); 592 EXPECT_TRUE(matches[0].can_inline);
535 593
536 // "tp://www.cnn.com" - found, cannot inline 594 // "tp://www.cnn.com" - found, cannot inline
537 matches = 595 matches =
538 url_index_->HistoryItemsForTerms(ASCIIToUTF16("tp://www.cnn.com")); 596 url_index_->HistoryItemsForTerms(ASCIIToUTF16("tp://www.cnn.com"),
597 string16::npos);
539 ASSERT_EQ(1U, matches.size()); 598 ASSERT_EQ(1U, matches.size());
540 EXPECT_TRUE(!matches[0].can_inline); 599 EXPECT_TRUE(!matches[0].can_inline);
541 } 600 }
542 601
543 TEST_F(InMemoryURLIndexTest, ProperStringMatching) { 602 TEST_F(InMemoryURLIndexTest, ProperStringMatching) {
544 // Search for the following with the expected results: 603 // Search for the following with the expected results:
545 // "atdmt view" - found 604 // "atdmt view" - found
546 // "atdmt.view" - not found 605 // "atdmt.view" - not found
547 // "view.atdmt" - found 606 // "view.atdmt" - found
548 ScoredHistoryMatches matches = 607 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
549 url_index_->HistoryItemsForTerms(ASCIIToUTF16("atdmt view")); 608 ASCIIToUTF16("atdmt view"), string16::npos);
550 ASSERT_EQ(1U, matches.size()); 609 ASSERT_EQ(1U, matches.size());
551 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("atdmt.view")); 610 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("atdmt.view"),
611 string16::npos);
552 ASSERT_EQ(0U, matches.size()); 612 ASSERT_EQ(0U, matches.size());
553 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("view.atdmt")); 613 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("view.atdmt"),
614 string16::npos);
554 ASSERT_EQ(1U, matches.size()); 615 ASSERT_EQ(1U, matches.size());
555 } 616 }
556 617
557 TEST_F(InMemoryURLIndexTest, HugeResultSet) { 618 TEST_F(InMemoryURLIndexTest, HugeResultSet) {
558 // Create a huge set of qualifying history items. 619 // Create a huge set of qualifying history items.
559 for (URLID row_id = 5000; row_id < 6000; ++row_id) { 620 for (URLID row_id = 5000; row_id < 6000; ++row_id) {
560 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), row_id); 621 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), row_id);
561 new_row.set_last_visit(base::Time::Now()); 622 new_row.set_last_visit(base::Time::Now());
562 EXPECT_TRUE(UpdateURL(new_row)); 623 EXPECT_TRUE(UpdateURL(new_row));
563 } 624 }
564 625
565 ScoredHistoryMatches matches = 626 ScoredHistoryMatches matches =
566 url_index_->HistoryItemsForTerms(ASCIIToUTF16("b")); 627 url_index_->HistoryItemsForTerms(ASCIIToUTF16("b"), string16::npos);
567 URLIndexPrivateData& private_data(*GetPrivateData()); 628 URLIndexPrivateData& private_data(*GetPrivateData());
568 ASSERT_EQ(AutocompleteProvider::kMaxMatches, matches.size()); 629 ASSERT_EQ(AutocompleteProvider::kMaxMatches, matches.size());
569 // There are 7 matches already in the database. 630 // There are 7 matches already in the database.
570 ASSERT_EQ(1008U, private_data.pre_filter_item_count_); 631 ASSERT_EQ(1008U, private_data.pre_filter_item_count_);
571 ASSERT_EQ(500U, private_data.post_filter_item_count_); 632 ASSERT_EQ(500U, private_data.post_filter_item_count_);
572 ASSERT_EQ(AutocompleteProvider::kMaxMatches, 633 ASSERT_EQ(AutocompleteProvider::kMaxMatches,
573 private_data.post_scoring_item_count_); 634 private_data.post_scoring_item_count_);
574 } 635 }
575 636
576 TEST_F(InMemoryURLIndexTest, TitleSearch) { 637 TEST_F(InMemoryURLIndexTest, TitleSearch) {
577 // Signal if someone has changed the test DB. 638 // Signal if someone has changed the test DB.
578 EXPECT_EQ(28U, GetPrivateData()->history_info_map_.size()); 639 EXPECT_EQ(28U, GetPrivateData()->history_info_map_.size());
579 640
580 // Ensure title is being searched. 641 // Ensure title is being searched.
581 ScoredHistoryMatches matches = 642 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
582 url_index_->HistoryItemsForTerms(ASCIIToUTF16("MORTGAGE RATE DROPS")); 643 ASCIIToUTF16("MORTGAGE RATE DROPS"), string16::npos);
583 ASSERT_EQ(1U, matches.size()); 644 ASSERT_EQ(1U, matches.size());
584 645
585 // Verify that we got back the result we expected. 646 // Verify that we got back the result we expected.
586 EXPECT_EQ(1, matches[0].url_info.id()); 647 EXPECT_EQ(1, matches[0].url_info.id());
587 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708", 648 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708",
588 matches[0].url_info.url().spec()); 649 matches[0].url_info.url().spec());
589 EXPECT_EQ(ASCIIToUTF16( 650 EXPECT_EQ(ASCIIToUTF16(
590 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"), 651 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"),
591 matches[0].url_info.title()); 652 matches[0].url_info.title());
592 } 653 }
593 654
594 TEST_F(InMemoryURLIndexTest, TitleChange) { 655 TEST_F(InMemoryURLIndexTest, TitleChange) {
595 // Verify current title terms retrieves desired item. 656 // Verify current title terms retrieves desired item.
596 string16 original_terms = 657 string16 original_terms =
597 ASCIIToUTF16("lebronomics could high taxes influence"); 658 ASCIIToUTF16("lebronomics could high taxes influence");
598 ScoredHistoryMatches matches = 659 ScoredHistoryMatches matches =
599 url_index_->HistoryItemsForTerms(original_terms); 660 url_index_->HistoryItemsForTerms(original_terms, string16::npos);
600 ASSERT_EQ(1U, matches.size()); 661 ASSERT_EQ(1U, matches.size());
601 662
602 // Verify that we got back the result we expected. 663 // Verify that we got back the result we expected.
603 const URLID expected_id = 3; 664 const URLID expected_id = 3;
604 EXPECT_EQ(expected_id, matches[0].url_info.id()); 665 EXPECT_EQ(expected_id, matches[0].url_info.id());
605 EXPECT_EQ("http://www.businessandmedia.org/articles/2010/20100708120415.aspx", 666 EXPECT_EQ("http://www.businessandmedia.org/articles/2010/20100708120415.aspx",
606 matches[0].url_info.url().spec()); 667 matches[0].url_info.url().spec());
607 EXPECT_EQ(ASCIIToUTF16( 668 EXPECT_EQ(ASCIIToUTF16(
608 "LeBronomics: Could High Taxes Influence James' Team Decision?"), 669 "LeBronomics: Could High Taxes Influence James' Team Decision?"),
609 matches[0].url_info.title()); 670 matches[0].url_info.title());
610 URLRow old_row(matches[0].url_info); 671 URLRow old_row(matches[0].url_info);
611 672
612 // Verify new title terms retrieves nothing. 673 // Verify new title terms retrieves nothing.
613 string16 new_terms = ASCIIToUTF16("does eat oats little lambs ivy"); 674 string16 new_terms = ASCIIToUTF16("does eat oats little lambs ivy");
614 matches = url_index_->HistoryItemsForTerms(new_terms); 675 matches = url_index_->HistoryItemsForTerms(new_terms, string16::npos);
615 ASSERT_EQ(0U, matches.size()); 676 ASSERT_EQ(0U, matches.size());
616 677
617 // Update the row. 678 // Update the row.
618 old_row.set_title(ASCIIToUTF16("Does eat oats and little lambs eat ivy")); 679 old_row.set_title(ASCIIToUTF16("Does eat oats and little lambs eat ivy"));
619 EXPECT_TRUE(UpdateURL(old_row)); 680 EXPECT_TRUE(UpdateURL(old_row));
620 681
621 // Verify we get the row using the new terms but not the original terms. 682 // Verify we get the row using the new terms but not the original terms.
622 matches = url_index_->HistoryItemsForTerms(new_terms); 683 matches = url_index_->HistoryItemsForTerms(new_terms, string16::npos);
623 ASSERT_EQ(1U, matches.size()); 684 ASSERT_EQ(1U, matches.size());
624 EXPECT_EQ(expected_id, matches[0].url_info.id()); 685 EXPECT_EQ(expected_id, matches[0].url_info.id());
625 matches = url_index_->HistoryItemsForTerms(original_terms); 686 matches = url_index_->HistoryItemsForTerms(original_terms, string16::npos);
626 ASSERT_EQ(0U, matches.size()); 687 ASSERT_EQ(0U, matches.size());
627 } 688 }
628 689
629 TEST_F(InMemoryURLIndexTest, NonUniqueTermCharacterSets) { 690 TEST_F(InMemoryURLIndexTest, NonUniqueTermCharacterSets) {
630 // The presence of duplicate characters should succeed. Exercise by cycling 691 // The presence of duplicate characters should succeed. Exercise by cycling
631 // through a string with several duplicate characters. 692 // through a string with several duplicate characters.
632 ScoredHistoryMatches matches = 693 ScoredHistoryMatches matches =
633 url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRA")); 694 url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRA"), string16::npos);
634 ASSERT_EQ(1U, matches.size()); 695 ASSERT_EQ(1U, matches.size());
635 EXPECT_EQ(28, matches[0].url_info.id()); 696 EXPECT_EQ(28, matches[0].url_info.id());
636 EXPECT_EQ("http://www.ddj.com/windows/184416623", 697 EXPECT_EQ("http://www.ddj.com/windows/184416623",
637 matches[0].url_info.url().spec()); 698 matches[0].url_info.url().spec());
638 699
639 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACAD")); 700 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACAD"),
701 string16::npos);
640 ASSERT_EQ(1U, matches.size()); 702 ASSERT_EQ(1U, matches.size());
641 EXPECT_EQ(28, matches[0].url_info.id()); 703 EXPECT_EQ(28, matches[0].url_info.id());
642 704
643 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACADABRA")); 705 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACADABRA"),
706 string16::npos);
644 ASSERT_EQ(1U, matches.size()); 707 ASSERT_EQ(1U, matches.size());
645 EXPECT_EQ(28, matches[0].url_info.id()); 708 EXPECT_EQ(28, matches[0].url_info.id());
646 709
647 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACADABR")); 710 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACADABR"),
711 string16::npos);
648 ASSERT_EQ(1U, matches.size()); 712 ASSERT_EQ(1U, matches.size());
649 EXPECT_EQ(28, matches[0].url_info.id()); 713 EXPECT_EQ(28, matches[0].url_info.id());
650 714
651 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACA")); 715 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACA"),
716 string16::npos);
652 ASSERT_EQ(1U, matches.size()); 717 ASSERT_EQ(1U, matches.size());
653 EXPECT_EQ(28, matches[0].url_info.id()); 718 EXPECT_EQ(28, matches[0].url_info.id());
654 } 719 }
655 720
656 TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) { 721 TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) {
657 // Verify that match results for previously typed characters are retained 722 // Verify that match results for previously typed characters are retained
658 // (in the term_char_word_set_cache_) and reused, if possible, in future 723 // (in the term_char_word_set_cache_) and reused, if possible, in future
659 // autocompletes. 724 // autocompletes.
660 typedef URLIndexPrivateData::SearchTermCacheMap::iterator CacheIter; 725 typedef URLIndexPrivateData::SearchTermCacheMap::iterator CacheIter;
661 typedef URLIndexPrivateData::SearchTermCacheItem CacheItem; 726 typedef URLIndexPrivateData::SearchTermCacheItem CacheItem;
662 727
663 URLIndexPrivateData::SearchTermCacheMap& cache( 728 URLIndexPrivateData::SearchTermCacheMap& cache(
664 GetPrivateData()->search_term_cache_); 729 GetPrivateData()->search_term_cache_);
665 730
666 // The cache should be empty at this point. 731 // The cache should be empty at this point.
667 EXPECT_EQ(0U, cache.size()); 732 EXPECT_EQ(0U, cache.size());
668 733
669 // Now simulate typing search terms into the omnibox and check the state of 734 // Now simulate typing search terms into the omnibox and check the state of
670 // the cache as each item is 'typed'. 735 // the cache as each item is 'typed'.
671 736
672 // Simulate typing "r" giving "r" in the simulated omnibox. The results for 737 // Simulate typing "r" giving "r" in the simulated omnibox. The results for
673 // 'r' will be not cached because it is only 1 character long. 738 // 'r' will be not cached because it is only 1 character long.
674 url_index_->HistoryItemsForTerms(ASCIIToUTF16("r")); 739 url_index_->HistoryItemsForTerms(ASCIIToUTF16("r"), string16::npos);
675 EXPECT_EQ(0U, cache.size()); 740 EXPECT_EQ(0U, cache.size());
676 741
677 // Simulate typing "re" giving "r re" in the simulated omnibox. 742 // Simulate typing "re" giving "r re" in the simulated omnibox.
678 // 're' should be cached at this point but not 'r' as it is a single 743 // 're' should be cached at this point but not 'r' as it is a single
679 // character. 744 // character.
680 url_index_->HistoryItemsForTerms(ASCIIToUTF16("r re")); 745 url_index_->HistoryItemsForTerms(ASCIIToUTF16("r re"), string16::npos);
681 ASSERT_EQ(1U, cache.size()); 746 ASSERT_EQ(1U, cache.size());
682 CheckTerm(cache, ASCIIToUTF16("re")); 747 CheckTerm(cache, ASCIIToUTF16("re"));
683 748
684 // Simulate typing "reco" giving "r re reco" in the simulated omnibox. 749 // Simulate typing "reco" giving "r re reco" in the simulated omnibox.
685 // 're' and 'reco' should be cached at this point but not 'r' as it is a 750 // 're' and 'reco' should be cached at this point but not 'r' as it is a
686 // single character. 751 // single character.
687 url_index_->HistoryItemsForTerms(ASCIIToUTF16("r re reco")); 752 url_index_->HistoryItemsForTerms(ASCIIToUTF16("r re reco"), string16::npos);
688 ASSERT_EQ(2U, cache.size()); 753 ASSERT_EQ(2U, cache.size());
689 CheckTerm(cache, ASCIIToUTF16("re")); 754 CheckTerm(cache, ASCIIToUTF16("re"));
690 CheckTerm(cache, ASCIIToUTF16("reco")); 755 CheckTerm(cache, ASCIIToUTF16("reco"));
691 756
692 // Simulate typing "mort". 757 // Simulate typing "mort".
693 // Since we now have only one search term, the cached results for 're' and 758 // Since we now have only one search term, the cached results for 're' and
694 // 'reco' should be purged, giving us only 1 item in the cache (for 'mort'). 759 // 'reco' should be purged, giving us only 1 item in the cache (for 'mort').
695 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort")); 760 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort"), string16::npos);
696 ASSERT_EQ(1U, cache.size()); 761 ASSERT_EQ(1U, cache.size());
697 CheckTerm(cache, ASCIIToUTF16("mort")); 762 CheckTerm(cache, ASCIIToUTF16("mort"));
698 763
699 // Simulate typing "reco" giving "mort reco" in the simulated omnibox. 764 // Simulate typing "reco" giving "mort reco" in the simulated omnibox.
700 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort reco")); 765 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort reco"), string16::npos);
701 ASSERT_EQ(2U, cache.size()); 766 ASSERT_EQ(2U, cache.size());
702 CheckTerm(cache, ASCIIToUTF16("mort")); 767 CheckTerm(cache, ASCIIToUTF16("mort"));
703 CheckTerm(cache, ASCIIToUTF16("reco")); 768 CheckTerm(cache, ASCIIToUTF16("reco"));
704 769
705 // Simulate a <DELETE> by removing the 'reco' and adding back the 'rec'. 770 // Simulate a <DELETE> by removing the 'reco' and adding back the 'rec'.
706 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort rec")); 771 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort rec"), string16::npos);
707 ASSERT_EQ(2U, cache.size()); 772 ASSERT_EQ(2U, cache.size());
708 CheckTerm(cache, ASCIIToUTF16("mort")); 773 CheckTerm(cache, ASCIIToUTF16("mort"));
709 CheckTerm(cache, ASCIIToUTF16("rec")); 774 CheckTerm(cache, ASCIIToUTF16("rec"));
710 } 775 }
711 776
712 TEST_F(InMemoryURLIndexTest, AddNewRows) { 777 TEST_F(InMemoryURLIndexTest, AddNewRows) {
713 // Verify that the row we're going to add does not already exist. 778 // Verify that the row we're going to add does not already exist.
714 URLID new_row_id = 87654321; 779 URLID new_row_id = 87654321;
715 // Newly created URLRows get a last_visit time of 'right now' so it should 780 // Newly created URLRows get a last_visit time of 'right now' so it should
716 // qualify as a quick result candidate. 781 // qualify as a quick result candidate.
717 EXPECT_TRUE(url_index_->HistoryItemsForTerms( 782 EXPECT_TRUE(url_index_->HistoryItemsForTerms(
718 ASCIIToUTF16("brokeandalone")).empty()); 783 ASCIIToUTF16("brokeandalone"), string16::npos).empty());
719 784
720 // Add a new row. 785 // Add a new row.
721 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id++); 786 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id++);
722 new_row.set_last_visit(base::Time::Now()); 787 new_row.set_last_visit(base::Time::Now());
723 EXPECT_TRUE(UpdateURL(new_row)); 788 EXPECT_TRUE(UpdateURL(new_row));
724 789
725 // Verify that we can retrieve it. 790 // Verify that we can retrieve it.
726 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms( 791 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(
727 ASCIIToUTF16("brokeandalone")).size()); 792 ASCIIToUTF16("brokeandalone"), string16::npos).size());
728 793
729 // Add it again just to be sure that is harmless and that it does not update 794 // Add it again just to be sure that is harmless and that it does not update
730 // the index. 795 // the index.
731 EXPECT_FALSE(UpdateURL(new_row)); 796 EXPECT_FALSE(UpdateURL(new_row));
732 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms( 797 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(
733 ASCIIToUTF16("brokeandalone")).size()); 798 ASCIIToUTF16("brokeandalone"), string16::npos).size());
734 799
735 // Make up an URL that does not qualify and try to add it. 800 // Make up an URL that does not qualify and try to add it.
736 URLRow unqualified_row(GURL("http://www.brokeandaloneinmanitoba.com/"), 801 URLRow unqualified_row(GURL("http://www.brokeandaloneinmanitoba.com/"),
737 new_row_id++); 802 new_row_id++);
738 EXPECT_FALSE(UpdateURL(new_row)); 803 EXPECT_FALSE(UpdateURL(new_row));
739 } 804 }
740 805
741 TEST_F(InMemoryURLIndexTest, DeleteRows) { 806 TEST_F(InMemoryURLIndexTest, DeleteRows) {
742 ScoredHistoryMatches matches = 807 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
743 url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport")); 808 ASCIIToUTF16("DrudgeReport"), string16::npos);
744 ASSERT_EQ(1U, matches.size()); 809 ASSERT_EQ(1U, matches.size());
745 810
746 // Delete the URL then search again. 811 // Delete the URL then search again.
747 EXPECT_TRUE(DeleteURL(matches[0].url_info.url())); 812 EXPECT_TRUE(DeleteURL(matches[0].url_info.url()));
748 EXPECT_TRUE(url_index_->HistoryItemsForTerms( 813 EXPECT_TRUE(url_index_->HistoryItemsForTerms(
749 ASCIIToUTF16("DrudgeReport")).empty()); 814 ASCIIToUTF16("DrudgeReport"), string16::npos).empty());
750 815
751 // Make up an URL that does not exist in the database and delete it. 816 // Make up an URL that does not exist in the database and delete it.
752 GURL url("http://www.hokeypokey.com/putyourrightfootin.html"); 817 GURL url("http://www.hokeypokey.com/putyourrightfootin.html");
753 EXPECT_FALSE(DeleteURL(url)); 818 EXPECT_FALSE(DeleteURL(url));
754 } 819 }
755 820
756 TEST_F(InMemoryURLIndexTest, ExpireRow) { 821 TEST_F(InMemoryURLIndexTest, ExpireRow) {
757 ScoredHistoryMatches matches = 822 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
758 url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport")); 823 ASCIIToUTF16("DrudgeReport"), string16::npos);
759 ASSERT_EQ(1U, matches.size()); 824 ASSERT_EQ(1U, matches.size());
760 825
761 // Determine the row id for the result, remember that id, broadcast a 826 // Determine the row id for the result, remember that id, broadcast a
762 // delete notification, then ensure that the row has been deleted. 827 // delete notification, then ensure that the row has been deleted.
763 URLsDeletedDetails deleted_details; 828 URLsDeletedDetails deleted_details;
764 deleted_details.all_history = false; 829 deleted_details.all_history = false;
765 deleted_details.rows.push_back(matches[0].url_info); 830 deleted_details.rows.push_back(matches[0].url_info);
766 Observe(chrome::NOTIFICATION_HISTORY_URLS_DELETED, 831 Observe(chrome::NOTIFICATION_HISTORY_URLS_DELETED,
767 content::Source<InMemoryURLIndexTest>(this), 832 content::Source<InMemoryURLIndexTest>(this),
768 content::Details<history::HistoryDetails>(&deleted_details)); 833 content::Details<history::HistoryDetails>(&deleted_details));
769 EXPECT_TRUE(url_index_->HistoryItemsForTerms( 834 EXPECT_TRUE(url_index_->HistoryItemsForTerms(
770 ASCIIToUTF16("DrudgeReport")).empty()); 835 ASCIIToUTF16("DrudgeReport"), string16::npos).empty());
771 } 836 }
772 837
773 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { 838 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) {
774 struct TestData { 839 struct TestData {
775 const std::string url_spec; 840 const std::string url_spec;
776 const bool expected_is_whitelisted; 841 const bool expected_is_whitelisted;
777 } data[] = { 842 } data[] = {
778 // URLs with whitelisted schemes. 843 // URLs with whitelisted schemes.
779 { "about:histograms", true }, 844 { "about:histograms", true },
780 { "chrome://settings", true }, 845 { "chrome://settings", true },
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 full_file_path.GetComponents(&actual_parts); 1013 full_file_path.GetComponents(&actual_parts);
949 ASSERT_EQ(expected_parts.size(), actual_parts.size()); 1014 ASSERT_EQ(expected_parts.size(), actual_parts.size());
950 size_t count = expected_parts.size(); 1015 size_t count = expected_parts.size();
951 for (size_t i = 0; i < count; ++i) 1016 for (size_t i = 0; i < count; ++i)
952 EXPECT_EQ(expected_parts[i], actual_parts[i]); 1017 EXPECT_EQ(expected_parts[i], actual_parts[i]);
953 // Must clear the history_dir_ to satisfy the dtor's DCHECK. 1018 // Must clear the history_dir_ to satisfy the dtor's DCHECK.
954 set_history_dir(FilePath()); 1019 set_history_dir(FilePath());
955 } 1020 }
956 1021
957 } // namespace history 1022 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/in_memory_url_index.cc ('k') | chrome/browser/history/url_index_private_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698