 Chromium Code Reviews
 Chromium Code Reviews Issue 296743009:
  Pass AutocompleteProvider::kMaxMatches to InMemoryURLIndex  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 296743009:
  Pass AutocompleteProvider::kMaxMatches to InMemoryURLIndex  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| 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/auto_reset.h" | 
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" | 
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" | 
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 | 440 | 
| 441 // history_info_map_ should have the same number of items as were filtered. | 441 // history_info_map_ should have the same number of items as were filtered. | 
| 442 EXPECT_EQ(1U, private_data.history_info_map_.size()); | 442 EXPECT_EQ(1U, private_data.history_info_map_.size()); | 
| 443 EXPECT_EQ(35U, private_data.char_word_map_.size()); | 443 EXPECT_EQ(35U, private_data.char_word_map_.size()); | 
| 444 EXPECT_EQ(17U, private_data.word_map_.size()); | 444 EXPECT_EQ(17U, private_data.word_map_.size()); | 
| 445 } | 445 } | 
| 446 | 446 | 
| 447 TEST_F(InMemoryURLIndexTest, Retrieval) { | 447 TEST_F(InMemoryURLIndexTest, Retrieval) { | 
| 448 // See if a very specific term gives a single result. | 448 // See if a very specific term gives a single result. | 
| 449 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 449 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 
| 450 ASCIIToUTF16("DrudgeReport"), base::string16::npos); | 450 ASCIIToUTF16("DrudgeReport"), | 
| 451 base::string16::npos, | |
| 452 AutocompleteProvider::kMaxMatches); | |
| 
sdefresne
2014/05/22 15:41:13
Most of the tests don't depends on the value of Au
 
Jiang Jiang
2014/05/23 16:12:52
Done.
 | |
| 451 ASSERT_EQ(1U, matches.size()); | 453 ASSERT_EQ(1U, matches.size()); | 
| 452 | 454 | 
| 453 // Verify that we got back the result we expected. | 455 // Verify that we got back the result we expected. | 
| 454 EXPECT_EQ(5, matches[0].url_info.id()); | 456 EXPECT_EQ(5, matches[0].url_info.id()); | 
| 455 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec()); | 457 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec()); | 
| 456 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title()); | 458 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title()); | 
| 457 EXPECT_TRUE(matches[0].can_inline()); | 459 EXPECT_TRUE(matches[0].can_inline()); | 
| 458 | 460 | 
| 459 // Make sure a trailing space prevents inline-ability but still results | 461 // Make sure a trailing space prevents inline-ability but still results | 
| 460 // in the expected result. | 462 // in the expected result. | 
| 461 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport "), | 463 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport "), | 
| 462 base::string16::npos); | 464 base::string16::npos, | 
| 465 AutocompleteProvider::kMaxMatches); | |
| 463 ASSERT_EQ(1U, matches.size()); | 466 ASSERT_EQ(1U, matches.size()); | 
| 464 EXPECT_EQ(5, matches[0].url_info.id()); | 467 EXPECT_EQ(5, matches[0].url_info.id()); | 
| 465 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec()); | 468 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec()); | 
| 466 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title()); | 469 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title()); | 
| 467 EXPECT_FALSE(matches[0].can_inline()); | 470 EXPECT_FALSE(matches[0].can_inline()); | 
| 468 | 471 | 
| 469 // Search which should result in multiple results. | 472 // Search which should result in multiple results. | 
| 470 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("drudge"), | 473 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("drudge"), | 
| 471 base::string16::npos); | 474 base::string16::npos, | 
| 475 AutocompleteProvider::kMaxMatches); | |
| 472 ASSERT_EQ(2U, matches.size()); | 476 ASSERT_EQ(2U, matches.size()); | 
| 473 // The results should be in descending score order. | 477 // The results should be in descending score order. | 
| 474 EXPECT_GE(matches[0].raw_score(), matches[1].raw_score()); | 478 EXPECT_GE(matches[0].raw_score(), matches[1].raw_score()); | 
| 475 | 479 | 
| 476 // Search which should result in nearly perfect result. | 480 // Search which should result in nearly perfect result. | 
| 477 matches = url_index_->HistoryItemsForTerms( | 481 matches = url_index_->HistoryItemsForTerms( | 
| 478 ASCIIToUTF16("Nearly Perfect Result"), base::string16::npos); | 482 ASCIIToUTF16("Nearly Perfect Result"), | 
| 483 base::string16::npos, | |
| 484 AutocompleteProvider::kMaxMatches); | |
| 479 ASSERT_EQ(1U, matches.size()); | 485 ASSERT_EQ(1U, matches.size()); | 
| 480 // The results should have a very high score. | 486 // The results should have a very high score. | 
| 481 EXPECT_GT(matches[0].raw_score(), 900); | 487 EXPECT_GT(matches[0].raw_score(), 900); | 
| 482 EXPECT_EQ(32, matches[0].url_info.id()); | 488 EXPECT_EQ(32, matches[0].url_info.id()); | 
| 483 EXPECT_EQ("https://nearlyperfectresult.com/", | 489 EXPECT_EQ("https://nearlyperfectresult.com/", | 
| 484 matches[0].url_info.url().spec()); // Note: URL gets lowercased. | 490 matches[0].url_info.url().spec()); // Note: URL gets lowercased. | 
| 485 EXPECT_EQ(ASCIIToUTF16("Practically Perfect Search Result"), | 491 EXPECT_EQ(ASCIIToUTF16("Practically Perfect Search Result"), | 
| 486 matches[0].url_info.title()); | 492 matches[0].url_info.title()); | 
| 487 EXPECT_FALSE(matches[0].can_inline()); | 493 EXPECT_FALSE(matches[0].can_inline()); | 
| 488 | 494 | 
| 489 // Search which should result in very poor result. | 495 // Search which should result in very poor result. | 
| 490 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("qui c"), | 496 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("qui c"), | 
| 491 base::string16::npos); | 497 base::string16::npos, | 
| 498 AutocompleteProvider::kMaxMatches); | |
| 492 ASSERT_EQ(1U, matches.size()); | 499 ASSERT_EQ(1U, matches.size()); | 
| 493 // The results should have a poor score. | 500 // The results should have a poor score. | 
| 494 EXPECT_LT(matches[0].raw_score(), 500); | 501 EXPECT_LT(matches[0].raw_score(), 500); | 
| 495 EXPECT_EQ(33, matches[0].url_info.id()); | 502 EXPECT_EQ(33, matches[0].url_info.id()); | 
| 496 EXPECT_EQ("http://quiteuselesssearchresultxyz.com/", | 503 EXPECT_EQ("http://quiteuselesssearchresultxyz.com/", | 
| 497 matches[0].url_info.url().spec()); // Note: URL gets lowercased. | 504 matches[0].url_info.url().spec()); // Note: URL gets lowercased. | 
| 498 EXPECT_EQ(ASCIIToUTF16("Practically Useless Search Result"), | 505 EXPECT_EQ(ASCIIToUTF16("Practically Useless Search Result"), | 
| 499 matches[0].url_info.title()); | 506 matches[0].url_info.title()); | 
| 500 EXPECT_FALSE(matches[0].can_inline()); | 507 EXPECT_FALSE(matches[0].can_inline()); | 
| 501 | 508 | 
| 502 // Search which will match at the end of an URL with encoded characters. | 509 // Search which will match at the end of an URL with encoded characters. | 
| 503 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("Mice"), | 510 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("Mice"), | 
| 504 base::string16::npos); | 511 base::string16::npos, | 
| 512 AutocompleteProvider::kMaxMatches); | |
| 505 ASSERT_EQ(1U, matches.size()); | 513 ASSERT_EQ(1U, matches.size()); | 
| 506 EXPECT_EQ(30, matches[0].url_info.id()); | 514 EXPECT_EQ(30, matches[0].url_info.id()); | 
| 507 EXPECT_FALSE(matches[0].can_inline()); | 515 EXPECT_FALSE(matches[0].can_inline()); | 
| 508 | 516 | 
| 509 // Check that URLs are not escaped an escape time. | 517 // Check that URLs are not escaped an escape time. | 
| 510 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("1% wikipedia"), | 518 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("1% wikipedia"), | 
| 511 base::string16::npos); | 519 base::string16::npos, | 
| 520 AutocompleteProvider::kMaxMatches); | |
| 512 ASSERT_EQ(1U, matches.size()); | 521 ASSERT_EQ(1U, matches.size()); | 
| 513 EXPECT_EQ(35, matches[0].url_info.id()); | 522 EXPECT_EQ(35, matches[0].url_info.id()); | 
| 514 EXPECT_EQ("http://en.wikipedia.org/wiki/1%25_rule_(Internet_culture)", | 523 EXPECT_EQ("http://en.wikipedia.org/wiki/1%25_rule_(Internet_culture)", | 
| 515 matches[0].url_info.url().spec()); | 524 matches[0].url_info.url().spec()); | 
| 516 | 525 | 
| 517 // Verify that a single term can appear multiple times in the URL and as long | 526 // Verify that a single term can appear multiple times in the URL and as long | 
| 518 // as one starts the URL it is still inlined. | 527 // as one starts the URL it is still inlined. | 
| 519 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("fubar"), | 528 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("fubar"), | 
| 520 base::string16::npos); | 529 base::string16::npos, | 
| 530 AutocompleteProvider::kMaxMatches); | |
| 521 ASSERT_EQ(1U, matches.size()); | 531 ASSERT_EQ(1U, matches.size()); | 
| 522 EXPECT_EQ(34, matches[0].url_info.id()); | 532 EXPECT_EQ(34, matches[0].url_info.id()); | 
| 523 EXPECT_EQ("http://fubarfubarandfubar.com/", matches[0].url_info.url().spec()); | 533 EXPECT_EQ("http://fubarfubarandfubar.com/", matches[0].url_info.url().spec()); | 
| 524 EXPECT_EQ(ASCIIToUTF16("Situation Normal -- FUBARED"), | 534 EXPECT_EQ(ASCIIToUTF16("Situation Normal -- FUBARED"), | 
| 525 matches[0].url_info.title()); | 535 matches[0].url_info.title()); | 
| 526 EXPECT_TRUE(matches[0].can_inline()); | 536 EXPECT_TRUE(matches[0].can_inline()); | 
| 527 } | 537 } | 
| 528 | 538 | 
| 529 TEST_F(InMemoryURLIndexTest, CursorPositionRetrieval) { | 539 TEST_F(InMemoryURLIndexTest, CursorPositionRetrieval) { | 
| 530 // See if a very specific term with no cursor gives an empty result. | 540 // See if a very specific term with no cursor gives an empty result. | 
| 531 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 541 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 
| 532 ASCIIToUTF16("DrudReport"), base::string16::npos); | 542 ASCIIToUTF16("DrudReport"), | 
| 543 base::string16::npos, | |
| 544 AutocompleteProvider::kMaxMatches); | |
| 533 ASSERT_EQ(0U, matches.size()); | 545 ASSERT_EQ(0U, matches.size()); | 
| 534 | 546 | 
| 535 // The same test with the cursor at the end should give an empty result. | 547 // The same test with the cursor at the end should give an empty result. | 
| 536 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudReport"), 10u); | 548 matches = url_index_->HistoryItemsForTerms( | 
| 549 ASCIIToUTF16("DrudReport"), 10u, AutocompleteProvider::kMaxMatches); | |
| 537 ASSERT_EQ(0U, matches.size()); | 550 ASSERT_EQ(0U, matches.size()); | 
| 538 | 551 | 
| 539 // If the cursor is between Drud and Report, we should find the desired | 552 // If the cursor is between Drud and Report, we should find the desired | 
| 540 // result. | 553 // result. | 
| 541 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudReport"), 4u); | 554 matches = url_index_->HistoryItemsForTerms( | 
| 555 ASCIIToUTF16("DrudReport"), 4u, AutocompleteProvider::kMaxMatches); | |
| 542 ASSERT_EQ(1U, matches.size()); | 556 ASSERT_EQ(1U, matches.size()); | 
| 543 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec()); | 557 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec()); | 
| 544 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title()); | 558 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title()); | 
| 545 | 559 | 
| 546 // Now check multi-word inputs. No cursor should fail to find a | 560 // Now check multi-word inputs. No cursor should fail to find a | 
| 547 // result on this input. | 561 // result on this input. | 
| 548 matches = url_index_->HistoryItemsForTerms( | 562 matches = url_index_->HistoryItemsForTerms( | 
| 549 ASCIIToUTF16("MORTGAGERATE DROPS"), base::string16::npos); | 563 ASCIIToUTF16("MORTGAGERATE DROPS"), | 
| 564 base::string16::npos, | |
| 565 AutocompleteProvider::kMaxMatches); | |
| 550 ASSERT_EQ(0U, matches.size()); | 566 ASSERT_EQ(0U, matches.size()); | 
| 551 | 567 | 
| 552 // Ditto with cursor at end. | 568 // Ditto with cursor at end. | 
| 553 matches = url_index_->HistoryItemsForTerms( | 569 matches = url_index_->HistoryItemsForTerms( | 
| 554 ASCIIToUTF16("MORTGAGERATE DROPS"), 18u); | 570 ASCIIToUTF16("MORTGAGERATE DROPS"), | 
| 571 18u, | |
| 572 AutocompleteProvider::kMaxMatches); | |
| 555 ASSERT_EQ(0U, matches.size()); | 573 ASSERT_EQ(0U, matches.size()); | 
| 556 | 574 | 
| 557 // If the cursor is between MORTAGE And RATE, we should find the | 575 // If the cursor is between MORTAGE And RATE, we should find the | 
| 558 // desired result. | 576 // desired result. | 
| 559 matches = url_index_->HistoryItemsForTerms( | 577 matches = url_index_->HistoryItemsForTerms( | 
| 560 ASCIIToUTF16("MORTGAGERATE DROPS"), 8u); | 578 ASCIIToUTF16("MORTGAGERATE DROPS"), | 
| 579 8u, | |
| 580 AutocompleteProvider::kMaxMatches); | |
| 561 ASSERT_EQ(1U, matches.size()); | 581 ASSERT_EQ(1U, matches.size()); | 
| 562 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708", | 582 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708", | 
| 563 matches[0].url_info.url().spec()); | 583 matches[0].url_info.url().spec()); | 
| 564 EXPECT_EQ(ASCIIToUTF16( | 584 EXPECT_EQ(ASCIIToUTF16( | 
| 565 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"), | 585 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"), | 
| 566 matches[0].url_info.title()); | 586 matches[0].url_info.title()); | 
| 567 } | 587 } | 
| 568 | 588 | 
| 569 TEST_F(InMemoryURLIndexTest, URLPrefixMatching) { | 589 TEST_F(InMemoryURLIndexTest, URLPrefixMatching) { | 
| 570 // "drudgere" - found, can inline | 590 // "drudgere" - found, can inline | 
| 571 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 591 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 
| 572 ASCIIToUTF16("drudgere"), base::string16::npos); | 592 ASCIIToUTF16("drudgere"), | 
| 593 base::string16::npos, | |
| 594 AutocompleteProvider::kMaxMatches); | |
| 573 ASSERT_EQ(1U, matches.size()); | 595 ASSERT_EQ(1U, matches.size()); | 
| 574 EXPECT_TRUE(matches[0].can_inline()); | 596 EXPECT_TRUE(matches[0].can_inline()); | 
| 575 | 597 | 
| 576 // "drudgere" - found, can inline | 598 // "drudgere" - found, can inline | 
| 577 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("drudgere"), | 599 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("drudgere"), | 
| 578 base::string16::npos); | 600 base::string16::npos, | 
| 601 AutocompleteProvider::kMaxMatches); | |
| 579 ASSERT_EQ(1U, matches.size()); | 602 ASSERT_EQ(1U, matches.size()); | 
| 580 EXPECT_TRUE(matches[0].can_inline()); | 603 EXPECT_TRUE(matches[0].can_inline()); | 
| 581 | 604 | 
| 582 // "www.atdmt" - not found | 605 // "www.atdmt" - not found | 
| 583 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("www.atdmt"), | 606 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("www.atdmt"), | 
| 584 base::string16::npos); | 607 base::string16::npos, | 
| 608 AutocompleteProvider::kMaxMatches); | |
| 585 EXPECT_EQ(0U, matches.size()); | 609 EXPECT_EQ(0U, matches.size()); | 
| 586 | 610 | 
| 587 // "atdmt" - found, cannot inline | 611 // "atdmt" - found, cannot inline | 
| 588 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("atdmt"), | 612 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("atdmt"), | 
| 589 base::string16::npos); | 613 base::string16::npos, | 
| 614 AutocompleteProvider::kMaxMatches); | |
| 590 ASSERT_EQ(1U, matches.size()); | 615 ASSERT_EQ(1U, matches.size()); | 
| 591 EXPECT_FALSE(matches[0].can_inline()); | 616 EXPECT_FALSE(matches[0].can_inline()); | 
| 592 | 617 | 
| 593 // "view.atdmt" - found, can inline | 618 // "view.atdmt" - found, can inline | 
| 594 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("view.atdmt"), | 619 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("view.atdmt"), | 
| 595 base::string16::npos); | 620 base::string16::npos, | 
| 621 AutocompleteProvider::kMaxMatches); | |
| 596 ASSERT_EQ(1U, matches.size()); | 622 ASSERT_EQ(1U, matches.size()); | 
| 597 EXPECT_TRUE(matches[0].can_inline()); | 623 EXPECT_TRUE(matches[0].can_inline()); | 
| 598 | 624 | 
| 599 // "view.atdmt" - found, can inline | 625 // "view.atdmt" - found, can inline | 
| 600 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("view.atdmt"), | 626 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("view.atdmt"), | 
| 601 base::string16::npos); | 627 base::string16::npos, | 
| 628 AutocompleteProvider::kMaxMatches); | |
| 602 ASSERT_EQ(1U, matches.size()); | 629 ASSERT_EQ(1U, matches.size()); | 
| 603 EXPECT_TRUE(matches[0].can_inline()); | 630 EXPECT_TRUE(matches[0].can_inline()); | 
| 604 | 631 | 
| 605 // "cnn.com" - found, can inline | 632 // "cnn.com" - found, can inline | 
| 606 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("cnn.com"), | 633 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("cnn.com"), | 
| 607 base::string16::npos); | 634 base::string16::npos, | 
| 635 AutocompleteProvider::kMaxMatches); | |
| 608 ASSERT_EQ(2U, matches.size()); | 636 ASSERT_EQ(2U, matches.size()); | 
| 609 // One match should be inline-able, the other not. | 637 // One match should be inline-able, the other not. | 
| 610 EXPECT_TRUE(matches[0].can_inline() != matches[1].can_inline()); | 638 EXPECT_TRUE(matches[0].can_inline() != matches[1].can_inline()); | 
| 611 | 639 | 
| 612 // "www.cnn.com" - found, can inline | 640 // "www.cnn.com" - found, can inline | 
| 613 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("www.cnn.com"), | 641 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("www.cnn.com"), | 
| 614 base::string16::npos); | 642 base::string16::npos, | 
| 643 AutocompleteProvider::kMaxMatches); | |
| 615 ASSERT_EQ(1U, matches.size()); | 644 ASSERT_EQ(1U, matches.size()); | 
| 616 EXPECT_TRUE(matches[0].can_inline()); | 645 EXPECT_TRUE(matches[0].can_inline()); | 
| 617 | 646 | 
| 618 // "ww.cnn.com" - found because we allow mid-term matches in hostnames | 647 // "ww.cnn.com" - found because we allow mid-term matches in hostnames | 
| 619 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ww.cnn.com"), | 648 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ww.cnn.com"), | 
| 620 base::string16::npos); | 649 base::string16::npos, | 
| 650 AutocompleteProvider::kMaxMatches); | |
| 621 ASSERT_EQ(1U, matches.size()); | 651 ASSERT_EQ(1U, matches.size()); | 
| 622 | 652 | 
| 623 // "www.cnn.com" - found, can inline | 653 // "www.cnn.com" - found, can inline | 
| 624 matches = | 654 matches = | 
| 625 url_index_->HistoryItemsForTerms(ASCIIToUTF16("www.cnn.com"), | 655 url_index_->HistoryItemsForTerms(ASCIIToUTF16("www.cnn.com"), | 
| 626 base::string16::npos); | 656 base::string16::npos, | 
| 657 AutocompleteProvider::kMaxMatches); | |
| 627 ASSERT_EQ(1U, matches.size()); | 658 ASSERT_EQ(1U, matches.size()); | 
| 628 EXPECT_TRUE(matches[0].can_inline()); | 659 EXPECT_TRUE(matches[0].can_inline()); | 
| 629 | 660 | 
| 630 // "tp://www.cnn.com" - not found because we don't allow tp as a mid-term | 661 // "tp://www.cnn.com" - not found because we don't allow tp as a mid-term | 
| 631 // match | 662 // match | 
| 632 matches = | 663 matches = | 
| 633 url_index_->HistoryItemsForTerms(ASCIIToUTF16("tp://www.cnn.com"), | 664 url_index_->HistoryItemsForTerms(ASCIIToUTF16("tp://www.cnn.com"), | 
| 634 base::string16::npos); | 665 base::string16::npos, | 
| 666 AutocompleteProvider::kMaxMatches); | |
| 635 ASSERT_EQ(0U, matches.size()); | 667 ASSERT_EQ(0U, matches.size()); | 
| 636 } | 668 } | 
| 637 | 669 | 
| 638 TEST_F(InMemoryURLIndexTest, ProperStringMatching) { | 670 TEST_F(InMemoryURLIndexTest, ProperStringMatching) { | 
| 639 // Search for the following with the expected results: | 671 // Search for the following with the expected results: | 
| 640 // "atdmt view" - found | 672 // "atdmt view" - found | 
| 641 // "atdmt.view" - not found | 673 // "atdmt.view" - not found | 
| 642 // "view.atdmt" - found | 674 // "view.atdmt" - found | 
| 643 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 675 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 
| 644 ASCIIToUTF16("atdmt view"), base::string16::npos); | 676 ASCIIToUTF16("atdmt view"), | 
| 677 base::string16::npos, | |
| 678 AutocompleteProvider::kMaxMatches); | |
| 645 ASSERT_EQ(1U, matches.size()); | 679 ASSERT_EQ(1U, matches.size()); | 
| 646 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("atdmt.view"), | 680 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("atdmt.view"), | 
| 647 base::string16::npos); | 681 base::string16::npos, | 
| 682 AutocompleteProvider::kMaxMatches); | |
| 648 ASSERT_EQ(0U, matches.size()); | 683 ASSERT_EQ(0U, matches.size()); | 
| 649 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("view.atdmt"), | 684 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("view.atdmt"), | 
| 650 base::string16::npos); | 685 base::string16::npos, | 
| 686 AutocompleteProvider::kMaxMatches); | |
| 651 ASSERT_EQ(1U, matches.size()); | 687 ASSERT_EQ(1U, matches.size()); | 
| 652 } | 688 } | 
| 653 | 689 | 
| 654 TEST_F(InMemoryURLIndexTest, HugeResultSet) { | 690 TEST_F(InMemoryURLIndexTest, HugeResultSet) { | 
| 655 // Create a huge set of qualifying history items. | 691 // Create a huge set of qualifying history items. | 
| 656 for (URLID row_id = 5000; row_id < 6000; ++row_id) { | 692 for (URLID row_id = 5000; row_id < 6000; ++row_id) { | 
| 657 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), row_id); | 693 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), row_id); | 
| 658 new_row.set_last_visit(base::Time::Now()); | 694 new_row.set_last_visit(base::Time::Now()); | 
| 659 EXPECT_TRUE(UpdateURL(new_row)); | 695 EXPECT_TRUE(UpdateURL(new_row)); | 
| 660 } | 696 } | 
| 661 | 697 | 
| 662 ScoredHistoryMatches matches = | 698 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 
| 663 url_index_->HistoryItemsForTerms(ASCIIToUTF16("b"), base::string16::npos); | 699 ASCIIToUTF16("b"), | 
| 700 base::string16::npos, | |
| 701 AutocompleteProvider::kMaxMatches); | |
| 664 URLIndexPrivateData& private_data(*GetPrivateData()); | 702 URLIndexPrivateData& private_data(*GetPrivateData()); | 
| 665 ASSERT_EQ(AutocompleteProvider::kMaxMatches, matches.size()); | 703 ASSERT_EQ(AutocompleteProvider::kMaxMatches, matches.size()); | 
| 666 // There are 7 matches already in the database. | 704 // There are 7 matches already in the database. | 
| 667 ASSERT_EQ(1008U, private_data.pre_filter_item_count_); | 705 ASSERT_EQ(1008U, private_data.pre_filter_item_count_); | 
| 668 ASSERT_EQ(500U, private_data.post_filter_item_count_); | 706 ASSERT_EQ(500U, private_data.post_filter_item_count_); | 
| 669 ASSERT_EQ(AutocompleteProvider::kMaxMatches, | 707 ASSERT_EQ(AutocompleteProvider::kMaxMatches, | 
| 670 private_data.post_scoring_item_count_); | 708 private_data.post_scoring_item_count_); | 
| 671 } | 709 } | 
| 672 | 710 | 
| 673 TEST_F(InMemoryURLIndexTest, TitleSearch) { | 711 TEST_F(InMemoryURLIndexTest, TitleSearch) { | 
| 674 // Signal if someone has changed the test DB. | 712 // Signal if someone has changed the test DB. | 
| 675 EXPECT_EQ(29U, GetPrivateData()->history_info_map_.size()); | 713 EXPECT_EQ(29U, GetPrivateData()->history_info_map_.size()); | 
| 676 | 714 | 
| 677 // Ensure title is being searched. | 715 // Ensure title is being searched. | 
| 678 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 716 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 
| 679 ASCIIToUTF16("MORTGAGE RATE DROPS"), base::string16::npos); | 717 ASCIIToUTF16("MORTGAGE RATE DROPS"), | 
| 718 base::string16::npos, | |
| 719 AutocompleteProvider::kMaxMatches); | |
| 680 ASSERT_EQ(1U, matches.size()); | 720 ASSERT_EQ(1U, matches.size()); | 
| 681 | 721 | 
| 682 // Verify that we got back the result we expected. | 722 // Verify that we got back the result we expected. | 
| 683 EXPECT_EQ(1, matches[0].url_info.id()); | 723 EXPECT_EQ(1, matches[0].url_info.id()); | 
| 684 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708", | 724 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708", | 
| 685 matches[0].url_info.url().spec()); | 725 matches[0].url_info.url().spec()); | 
| 686 EXPECT_EQ(ASCIIToUTF16( | 726 EXPECT_EQ(ASCIIToUTF16( | 
| 687 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"), | 727 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"), | 
| 688 matches[0].url_info.title()); | 728 matches[0].url_info.title()); | 
| 689 } | 729 } | 
| 690 | 730 | 
| 691 TEST_F(InMemoryURLIndexTest, TitleChange) { | 731 TEST_F(InMemoryURLIndexTest, TitleChange) { | 
| 692 // Verify current title terms retrieves desired item. | 732 // Verify current title terms retrieves desired item. | 
| 693 base::string16 original_terms = | 733 base::string16 original_terms = | 
| 694 ASCIIToUTF16("lebronomics could high taxes influence"); | 734 ASCIIToUTF16("lebronomics could high taxes influence"); | 
| 695 ScoredHistoryMatches matches = | 735 ScoredHistoryMatches matches = | 
| 696 url_index_->HistoryItemsForTerms(original_terms, base::string16::npos); | 736 url_index_->HistoryItemsForTerms(original_terms, | 
| 737 base::string16::npos, | |
| 738 AutocompleteProvider::kMaxMatches); | |
| 697 ASSERT_EQ(1U, matches.size()); | 739 ASSERT_EQ(1U, matches.size()); | 
| 698 | 740 | 
| 699 // Verify that we got back the result we expected. | 741 // Verify that we got back the result we expected. | 
| 700 const URLID expected_id = 3; | 742 const URLID expected_id = 3; | 
| 701 EXPECT_EQ(expected_id, matches[0].url_info.id()); | 743 EXPECT_EQ(expected_id, matches[0].url_info.id()); | 
| 702 EXPECT_EQ("http://www.businessandmedia.org/articles/2010/20100708120415.aspx", | 744 EXPECT_EQ("http://www.businessandmedia.org/articles/2010/20100708120415.aspx", | 
| 703 matches[0].url_info.url().spec()); | 745 matches[0].url_info.url().spec()); | 
| 704 EXPECT_EQ(ASCIIToUTF16( | 746 EXPECT_EQ(ASCIIToUTF16( | 
| 705 "LeBronomics: Could High Taxes Influence James' Team Decision?"), | 747 "LeBronomics: Could High Taxes Influence James' Team Decision?"), | 
| 706 matches[0].url_info.title()); | 748 matches[0].url_info.title()); | 
| 707 URLRow old_row(matches[0].url_info); | 749 URLRow old_row(matches[0].url_info); | 
| 708 | 750 | 
| 709 // Verify new title terms retrieves nothing. | 751 // Verify new title terms retrieves nothing. | 
| 710 base::string16 new_terms = ASCIIToUTF16("does eat oats little lambs ivy"); | 752 base::string16 new_terms = ASCIIToUTF16("does eat oats little lambs ivy"); | 
| 711 matches = url_index_->HistoryItemsForTerms(new_terms, base::string16::npos); | 753 matches = url_index_->HistoryItemsForTerms( | 
| 754 new_terms, base::string16::npos, AutocompleteProvider::kMaxMatches); | |
| 712 ASSERT_EQ(0U, matches.size()); | 755 ASSERT_EQ(0U, matches.size()); | 
| 713 | 756 | 
| 714 // Update the row. | 757 // Update the row. | 
| 715 old_row.set_title(ASCIIToUTF16("Does eat oats and little lambs eat ivy")); | 758 old_row.set_title(ASCIIToUTF16("Does eat oats and little lambs eat ivy")); | 
| 716 EXPECT_TRUE(UpdateURL(old_row)); | 759 EXPECT_TRUE(UpdateURL(old_row)); | 
| 717 | 760 | 
| 718 // Verify we get the row using the new terms but not the original terms. | 761 // Verify we get the row using the new terms but not the original terms. | 
| 719 matches = url_index_->HistoryItemsForTerms(new_terms, base::string16::npos); | 762 matches = url_index_->HistoryItemsForTerms( | 
| 763 new_terms, base::string16::npos, AutocompleteProvider::kMaxMatches); | |
| 720 ASSERT_EQ(1U, matches.size()); | 764 ASSERT_EQ(1U, matches.size()); | 
| 721 EXPECT_EQ(expected_id, matches[0].url_info.id()); | 765 EXPECT_EQ(expected_id, matches[0].url_info.id()); | 
| 722 matches = | 766 matches = url_index_->HistoryItemsForTerms( | 
| 723 url_index_->HistoryItemsForTerms(original_terms, base::string16::npos); | 767 original_terms, base::string16::npos, AutocompleteProvider::kMaxMatches); | 
| 724 ASSERT_EQ(0U, matches.size()); | 768 ASSERT_EQ(0U, matches.size()); | 
| 725 } | 769 } | 
| 726 | 770 | 
| 727 TEST_F(InMemoryURLIndexTest, NonUniqueTermCharacterSets) { | 771 TEST_F(InMemoryURLIndexTest, NonUniqueTermCharacterSets) { | 
| 728 // The presence of duplicate characters should succeed. Exercise by cycling | 772 // The presence of duplicate characters should succeed. Exercise by cycling | 
| 729 // through a string with several duplicate characters. | 773 // through a string with several duplicate characters. | 
| 730 ScoredHistoryMatches matches = | 774 ScoredHistoryMatches matches = | 
| 731 url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRA"), | 775 url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRA"), | 
| 732 base::string16::npos); | 776 base::string16::npos, | 
| 777 AutocompleteProvider::kMaxMatches); | |
| 733 ASSERT_EQ(1U, matches.size()); | 778 ASSERT_EQ(1U, matches.size()); | 
| 734 EXPECT_EQ(28, matches[0].url_info.id()); | 779 EXPECT_EQ(28, matches[0].url_info.id()); | 
| 735 EXPECT_EQ("http://www.ddj.com/windows/184416623", | 780 EXPECT_EQ("http://www.ddj.com/windows/184416623", | 
| 736 matches[0].url_info.url().spec()); | 781 matches[0].url_info.url().spec()); | 
| 737 | 782 | 
| 738 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACAD"), | 783 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACAD"), | 
| 739 base::string16::npos); | 784 base::string16::npos, | 
| 785 AutocompleteProvider::kMaxMatches); | |
| 740 ASSERT_EQ(1U, matches.size()); | 786 ASSERT_EQ(1U, matches.size()); | 
| 741 EXPECT_EQ(28, matches[0].url_info.id()); | 787 EXPECT_EQ(28, matches[0].url_info.id()); | 
| 742 | 788 | 
| 743 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACADABRA"), | 789 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACADABRA"), | 
| 744 base::string16::npos); | 790 base::string16::npos, | 
| 791 AutocompleteProvider::kMaxMatches); | |
| 745 ASSERT_EQ(1U, matches.size()); | 792 ASSERT_EQ(1U, matches.size()); | 
| 746 EXPECT_EQ(28, matches[0].url_info.id()); | 793 EXPECT_EQ(28, matches[0].url_info.id()); | 
| 747 | 794 | 
| 748 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACADABR"), | 795 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACADABR"), | 
| 749 base::string16::npos); | 796 base::string16::npos, | 
| 797 AutocompleteProvider::kMaxMatches); | |
| 750 ASSERT_EQ(1U, matches.size()); | 798 ASSERT_EQ(1U, matches.size()); | 
| 751 EXPECT_EQ(28, matches[0].url_info.id()); | 799 EXPECT_EQ(28, matches[0].url_info.id()); | 
| 752 | 800 | 
| 753 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACA"), | 801 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACA"), | 
| 754 base::string16::npos); | 802 base::string16::npos, | 
| 803 AutocompleteProvider::kMaxMatches); | |
| 755 ASSERT_EQ(1U, matches.size()); | 804 ASSERT_EQ(1U, matches.size()); | 
| 756 EXPECT_EQ(28, matches[0].url_info.id()); | 805 EXPECT_EQ(28, matches[0].url_info.id()); | 
| 757 } | 806 } | 
| 758 | 807 | 
| 759 TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) { | 808 TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) { | 
| 760 // Verify that match results for previously typed characters are retained | 809 // Verify that match results for previously typed characters are retained | 
| 761 // (in the term_char_word_set_cache_) and reused, if possible, in future | 810 // (in the term_char_word_set_cache_) and reused, if possible, in future | 
| 762 // autocompletes. | 811 // autocompletes. | 
| 763 | 812 | 
| 764 URLIndexPrivateData::SearchTermCacheMap& cache( | 813 URLIndexPrivateData::SearchTermCacheMap& cache( | 
| 765 GetPrivateData()->search_term_cache_); | 814 GetPrivateData()->search_term_cache_); | 
| 766 | 815 | 
| 767 // The cache should be empty at this point. | 816 // The cache should be empty at this point. | 
| 768 EXPECT_EQ(0U, cache.size()); | 817 EXPECT_EQ(0U, cache.size()); | 
| 769 | 818 | 
| 770 // Now simulate typing search terms into the omnibox and check the state of | 819 // Now simulate typing search terms into the omnibox and check the state of | 
| 771 // the cache as each item is 'typed'. | 820 // the cache as each item is 'typed'. | 
| 772 | 821 | 
| 773 // Simulate typing "r" giving "r" in the simulated omnibox. The results for | 822 // Simulate typing "r" giving "r" in the simulated omnibox. The results for | 
| 774 // 'r' will be not cached because it is only 1 character long. | 823 // 'r' will be not cached because it is only 1 character long. | 
| 775 url_index_->HistoryItemsForTerms(ASCIIToUTF16("r"), base::string16::npos); | 824 url_index_->HistoryItemsForTerms(ASCIIToUTF16("r"), | 
| 825 base::string16::npos, | |
| 826 AutocompleteProvider::kMaxMatches); | |
| 776 EXPECT_EQ(0U, cache.size()); | 827 EXPECT_EQ(0U, cache.size()); | 
| 777 | 828 | 
| 778 // Simulate typing "re" giving "r re" in the simulated omnibox. | 829 // Simulate typing "re" giving "r re" in the simulated omnibox. | 
| 779 // 're' should be cached at this point but not 'r' as it is a single | 830 // 're' should be cached at this point but not 'r' as it is a single | 
| 780 // character. | 831 // character. | 
| 781 url_index_->HistoryItemsForTerms(ASCIIToUTF16("r re"), base::string16::npos); | 832 url_index_->HistoryItemsForTerms(ASCIIToUTF16("r re"), | 
| 833 base::string16::npos, | |
| 834 AutocompleteProvider::kMaxMatches); | |
| 782 ASSERT_EQ(1U, cache.size()); | 835 ASSERT_EQ(1U, cache.size()); | 
| 783 CheckTerm(cache, ASCIIToUTF16("re")); | 836 CheckTerm(cache, ASCIIToUTF16("re")); | 
| 784 | 837 | 
| 785 // Simulate typing "reco" giving "r re reco" in the simulated omnibox. | 838 // Simulate typing "reco" giving "r re reco" in the simulated omnibox. | 
| 786 // 're' and 'reco' should be cached at this point but not 'r' as it is a | 839 // 're' and 'reco' should be cached at this point but not 'r' as it is a | 
| 787 // single character. | 840 // single character. | 
| 788 url_index_->HistoryItemsForTerms(ASCIIToUTF16("r re reco"), | 841 url_index_->HistoryItemsForTerms(ASCIIToUTF16("r re reco"), | 
| 789 base::string16::npos); | 842 base::string16::npos, | 
| 843 AutocompleteProvider::kMaxMatches); | |
| 790 ASSERT_EQ(2U, cache.size()); | 844 ASSERT_EQ(2U, cache.size()); | 
| 791 CheckTerm(cache, ASCIIToUTF16("re")); | 845 CheckTerm(cache, ASCIIToUTF16("re")); | 
| 792 CheckTerm(cache, ASCIIToUTF16("reco")); | 846 CheckTerm(cache, ASCIIToUTF16("reco")); | 
| 793 | 847 | 
| 794 // Simulate typing "mort". | 848 // Simulate typing "mort". | 
| 795 // Since we now have only one search term, the cached results for 're' and | 849 // Since we now have only one search term, the cached results for 're' and | 
| 796 // 'reco' should be purged, giving us only 1 item in the cache (for 'mort'). | 850 // 'reco' should be purged, giving us only 1 item in the cache (for 'mort'). | 
| 797 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort"), base::string16::npos); | 851 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort"), | 
| 852 base::string16::npos, | |
| 853 AutocompleteProvider::kMaxMatches); | |
| 798 ASSERT_EQ(1U, cache.size()); | 854 ASSERT_EQ(1U, cache.size()); | 
| 799 CheckTerm(cache, ASCIIToUTF16("mort")); | 855 CheckTerm(cache, ASCIIToUTF16("mort")); | 
| 800 | 856 | 
| 801 // Simulate typing "reco" giving "mort reco" in the simulated omnibox. | 857 // Simulate typing "reco" giving "mort reco" in the simulated omnibox. | 
| 802 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort reco"), | 858 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort reco"), | 
| 803 base::string16::npos); | 859 base::string16::npos, | 
| 860 AutocompleteProvider::kMaxMatches); | |
| 804 ASSERT_EQ(2U, cache.size()); | 861 ASSERT_EQ(2U, cache.size()); | 
| 805 CheckTerm(cache, ASCIIToUTF16("mort")); | 862 CheckTerm(cache, ASCIIToUTF16("mort")); | 
| 806 CheckTerm(cache, ASCIIToUTF16("reco")); | 863 CheckTerm(cache, ASCIIToUTF16("reco")); | 
| 807 | 864 | 
| 808 // Simulate a <DELETE> by removing the 'reco' and adding back the 'rec'. | 865 // Simulate a <DELETE> by removing the 'reco' and adding back the 'rec'. | 
| 809 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort rec"), | 866 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort rec"), | 
| 810 base::string16::npos); | 867 base::string16::npos, | 
| 868 AutocompleteProvider::kMaxMatches); | |
| 811 ASSERT_EQ(2U, cache.size()); | 869 ASSERT_EQ(2U, cache.size()); | 
| 812 CheckTerm(cache, ASCIIToUTF16("mort")); | 870 CheckTerm(cache, ASCIIToUTF16("mort")); | 
| 813 CheckTerm(cache, ASCIIToUTF16("rec")); | 871 CheckTerm(cache, ASCIIToUTF16("rec")); | 
| 814 } | 872 } | 
| 815 | 873 | 
| 816 TEST_F(InMemoryURLIndexTest, AddNewRows) { | 874 TEST_F(InMemoryURLIndexTest, AddNewRows) { | 
| 817 // Verify that the row we're going to add does not already exist. | 875 // Verify that the row we're going to add does not already exist. | 
| 818 URLID new_row_id = 87654321; | 876 URLID new_row_id = 87654321; | 
| 819 // Newly created URLRows get a last_visit time of 'right now' so it should | 877 // Newly created URLRows get a last_visit time of 'right now' so it should | 
| 820 // qualify as a quick result candidate. | 878 // qualify as a quick result candidate. | 
| 821 EXPECT_TRUE(url_index_->HistoryItemsForTerms( | 879 EXPECT_TRUE(url_index_->HistoryItemsForTerms( | 
| 822 ASCIIToUTF16("brokeandalone"), base::string16::npos).empty()); | 880 ASCIIToUTF16("brokeandalone"), | 
| 881 base::string16::npos, | |
| 882 AutocompleteProvider::kMaxMatches).empty()); | |
| 823 | 883 | 
| 824 // Add a new row. | 884 // Add a new row. | 
| 825 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id++); | 885 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id++); | 
| 826 new_row.set_last_visit(base::Time::Now()); | 886 new_row.set_last_visit(base::Time::Now()); | 
| 827 EXPECT_TRUE(UpdateURL(new_row)); | 887 EXPECT_TRUE(UpdateURL(new_row)); | 
| 828 | 888 | 
| 829 // Verify that we can retrieve it. | 889 // Verify that we can retrieve it. | 
| 830 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms( | 890 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms( | 
| 831 ASCIIToUTF16("brokeandalone"), base::string16::npos).size()); | 891 ASCIIToUTF16("brokeandalone"), | 
| 892 base::string16::npos, | |
| 893 AutocompleteProvider::kMaxMatches).size()); | |
| 832 | 894 | 
| 833 // Add it again just to be sure that is harmless and that it does not update | 895 // Add it again just to be sure that is harmless and that it does not update | 
| 834 // the index. | 896 // the index. | 
| 835 EXPECT_FALSE(UpdateURL(new_row)); | 897 EXPECT_FALSE(UpdateURL(new_row)); | 
| 836 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms( | 898 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms( | 
| 837 ASCIIToUTF16("brokeandalone"), base::string16::npos).size()); | 899 ASCIIToUTF16("brokeandalone"), | 
| 900 base::string16::npos, | |
| 901 AutocompleteProvider::kMaxMatches).size()); | |
| 838 | 902 | 
| 839 // Make up an URL that does not qualify and try to add it. | 903 // Make up an URL that does not qualify and try to add it. | 
| 840 URLRow unqualified_row(GURL("http://www.brokeandaloneinmanitoba.com/"), | 904 URLRow unqualified_row(GURL("http://www.brokeandaloneinmanitoba.com/"), | 
| 841 new_row_id++); | 905 new_row_id++); | 
| 842 EXPECT_FALSE(UpdateURL(new_row)); | 906 EXPECT_FALSE(UpdateURL(new_row)); | 
| 843 } | 907 } | 
| 844 | 908 | 
| 845 TEST_F(InMemoryURLIndexTest, DeleteRows) { | 909 TEST_F(InMemoryURLIndexTest, DeleteRows) { | 
| 846 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 910 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 
| 847 ASCIIToUTF16("DrudgeReport"), base::string16::npos); | 911 ASCIIToUTF16("DrudgeReport"), | 
| 912 base::string16::npos, | |
| 913 AutocompleteProvider::kMaxMatches); | |
| 848 ASSERT_EQ(1U, matches.size()); | 914 ASSERT_EQ(1U, matches.size()); | 
| 849 | 915 | 
| 850 // Delete the URL then search again. | 916 // Delete the URL then search again. | 
| 851 EXPECT_TRUE(DeleteURL(matches[0].url_info.url())); | 917 EXPECT_TRUE(DeleteURL(matches[0].url_info.url())); | 
| 852 EXPECT_TRUE(url_index_->HistoryItemsForTerms( | 918 EXPECT_TRUE(url_index_->HistoryItemsForTerms( | 
| 853 ASCIIToUTF16("DrudgeReport"), base::string16::npos).empty()); | 919 ASCIIToUTF16("DrudgeReport"), | 
| 920 base::string16::npos, | |
| 921 AutocompleteProvider::kMaxMatches).empty()); | |
| 854 | 922 | 
| 855 // Make up an URL that does not exist in the database and delete it. | 923 // Make up an URL that does not exist in the database and delete it. | 
| 856 GURL url("http://www.hokeypokey.com/putyourrightfootin.html"); | 924 GURL url("http://www.hokeypokey.com/putyourrightfootin.html"); | 
| 857 EXPECT_FALSE(DeleteURL(url)); | 925 EXPECT_FALSE(DeleteURL(url)); | 
| 858 } | 926 } | 
| 859 | 927 | 
| 860 TEST_F(InMemoryURLIndexTest, ExpireRow) { | 928 TEST_F(InMemoryURLIndexTest, ExpireRow) { | 
| 861 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 929 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 
| 862 ASCIIToUTF16("DrudgeReport"), base::string16::npos); | 930 ASCIIToUTF16("DrudgeReport"), | 
| 931 base::string16::npos, | |
| 932 AutocompleteProvider::kMaxMatches); | |
| 863 ASSERT_EQ(1U, matches.size()); | 933 ASSERT_EQ(1U, matches.size()); | 
| 864 | 934 | 
| 865 // Determine the row id for the result, remember that id, broadcast a | 935 // Determine the row id for the result, remember that id, broadcast a | 
| 866 // delete notification, then ensure that the row has been deleted. | 936 // delete notification, then ensure that the row has been deleted. | 
| 867 URLsDeletedDetails deleted_details; | 937 URLsDeletedDetails deleted_details; | 
| 868 deleted_details.all_history = false; | 938 deleted_details.all_history = false; | 
| 869 deleted_details.rows.push_back(matches[0].url_info); | 939 deleted_details.rows.push_back(matches[0].url_info); | 
| 870 Observe(chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 940 Observe(chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 
| 871 content::Source<InMemoryURLIndexTest>(this), | 941 content::Source<InMemoryURLIndexTest>(this), | 
| 872 content::Details<history::HistoryDetails>(&deleted_details)); | 942 content::Details<history::HistoryDetails>(&deleted_details)); | 
| 873 EXPECT_TRUE(url_index_->HistoryItemsForTerms( | 943 EXPECT_TRUE(url_index_->HistoryItemsForTerms( | 
| 874 ASCIIToUTF16("DrudgeReport"), base::string16::npos).empty()); | 944 ASCIIToUTF16("DrudgeReport"), | 
| 945 base::string16::npos, | |
| 946 AutocompleteProvider::kMaxMatches).empty()); | |
| 875 } | 947 } | 
| 876 | 948 | 
| 877 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { | 949 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { | 
| 878 struct TestData { | 950 struct TestData { | 
| 879 const std::string url_spec; | 951 const std::string url_spec; | 
| 880 const bool expected_is_whitelisted; | 952 const bool expected_is_whitelisted; | 
| 881 } data[] = { | 953 } data[] = { | 
| 882 // URLs with whitelisted schemes. | 954 // URLs with whitelisted schemes. | 
| 883 { "about:histograms", true }, | 955 { "about:histograms", true }, | 
| 884 { "chrome://settings", true }, | 956 { "chrome://settings", true }, | 
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1177 full_file_path.GetComponents(&actual_parts); | 1249 full_file_path.GetComponents(&actual_parts); | 
| 1178 ASSERT_EQ(expected_parts.size(), actual_parts.size()); | 1250 ASSERT_EQ(expected_parts.size(), actual_parts.size()); | 
| 1179 size_t count = expected_parts.size(); | 1251 size_t count = expected_parts.size(); | 
| 1180 for (size_t i = 0; i < count; ++i) | 1252 for (size_t i = 0; i < count; ++i) | 
| 1181 EXPECT_EQ(expected_parts[i], actual_parts[i]); | 1253 EXPECT_EQ(expected_parts[i], actual_parts[i]); | 
| 1182 // Must clear the history_dir_ to satisfy the dtor's DCHECK. | 1254 // Must clear the history_dir_ to satisfy the dtor's DCHECK. | 
| 1183 set_history_dir(base::FilePath()); | 1255 set_history_dir(base::FilePath()); | 
| 1184 } | 1256 } | 
| 1185 | 1257 | 
| 1186 } // namespace history | 1258 } // namespace history | 
| OLD | NEW |