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