OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/gfx/jpeg_codec.h" | 8 #include "base/gfx/jpeg_codec.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 // Verify the URL no longer exists. | 285 // Verify the URL no longer exists. |
286 URLRow temp_row; | 286 URLRow temp_row; |
287 EXPECT_FALSE(main_db_->GetURLRow(row.id(), &temp_row)); | 287 EXPECT_FALSE(main_db_->GetURLRow(row.id(), &temp_row)); |
288 | 288 |
289 // The indexed data should be gone. | 289 // The indexed data should be gone. |
290 EXPECT_EQ(0, CountTextMatchesForURL(row.url())); | 290 EXPECT_EQ(0, CountTextMatchesForURL(row.url())); |
291 | 291 |
292 // There should be no visits. | 292 // There should be no visits. |
293 VisitVector visits; | 293 VisitVector visits; |
294 main_db_->GetVisitsForURL(row.id(), &visits); | 294 main_db_->GetVisitsForURL(row.id(), &visits); |
295 EXPECT_EQ(0, visits.size()); | 295 EXPECT_EQ(0U, visits.size()); |
296 | 296 |
297 // Thumbnail should be gone. | 297 // Thumbnail should be gone. |
298 EXPECT_FALSE(HasThumbnail(row.id())); | 298 EXPECT_FALSE(HasThumbnail(row.id())); |
299 | 299 |
300 // Check the notifications. There should be a delete notification with this | 300 // Check the notifications. There should be a delete notification with this |
301 // URL in it. There should also be a "typed URL changed" notification if the | 301 // URL in it. There should also be a "typed URL changed" notification if the |
302 // row is marked typed. | 302 // row is marked typed. |
303 bool found_delete_notification = false; | 303 bool found_delete_notification = false; |
304 bool found_typed_changed_notification = false; | 304 bool found_typed_changed_notification = false; |
305 for (size_t i = 0; i < notifications_.size(); i++) { | 305 for (size_t i = 0; i < notifications_.size(); i++) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 AddExampleData(url_ids, visit_times); | 378 AddExampleData(url_ids, visit_times); |
379 | 379 |
380 // Verify things are the way we expect with a URL row, favicon, thumbnail. | 380 // Verify things are the way we expect with a URL row, favicon, thumbnail. |
381 URLRow last_row; | 381 URLRow last_row; |
382 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &last_row)); | 382 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &last_row)); |
383 EXPECT_TRUE(HasFavIcon(last_row.favicon_id())); | 383 EXPECT_TRUE(HasFavIcon(last_row.favicon_id())); |
384 EXPECT_TRUE(HasThumbnail(url_ids[2])); | 384 EXPECT_TRUE(HasThumbnail(url_ids[2])); |
385 | 385 |
386 VisitVector visits; | 386 VisitVector visits; |
387 main_db_->GetVisitsForURL(url_ids[2], &visits); | 387 main_db_->GetVisitsForURL(url_ids[2], &visits); |
388 ASSERT_EQ(1, visits.size()); | 388 ASSERT_EQ(1U, visits.size()); |
389 EXPECT_EQ(1, CountTextMatchesForURL(last_row.url())); | 389 EXPECT_EQ(1, CountTextMatchesForURL(last_row.url())); |
390 | 390 |
391 // In this test we also make sure that any pending entries in the text | 391 // In this test we also make sure that any pending entries in the text |
392 // database manager are removed. | 392 // database manager are removed. |
393 text_db_->AddPageURL(last_row.url(), last_row.id(), visits[0].visit_id, | 393 text_db_->AddPageURL(last_row.url(), last_row.id(), visits[0].visit_id, |
394 visits[0].visit_time); | 394 visits[0].visit_time); |
395 | 395 |
396 // Compute the text DB filename. | 396 // Compute the text DB filename. |
397 std::wstring fts_filename = dir_; | 397 std::wstring fts_filename = dir_; |
398 file_util::AppendToPath(&fts_filename, | 398 file_util::AppendToPath(&fts_filename, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 AddExampleData(url_ids, visit_times); | 438 AddExampleData(url_ids, visit_times); |
439 | 439 |
440 // Verify things are the way we expect with a URL row, favicon, thumbnail. | 440 // Verify things are the way we expect with a URL row, favicon, thumbnail. |
441 URLRow last_row; | 441 URLRow last_row; |
442 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &last_row)); | 442 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &last_row)); |
443 EXPECT_TRUE(HasFavIcon(last_row.favicon_id())); | 443 EXPECT_TRUE(HasFavIcon(last_row.favicon_id())); |
444 EXPECT_TRUE(HasThumbnail(url_ids[1])); | 444 EXPECT_TRUE(HasThumbnail(url_ids[1])); |
445 | 445 |
446 VisitVector visits; | 446 VisitVector visits; |
447 main_db_->GetVisitsForURL(url_ids[1], &visits); | 447 main_db_->GetVisitsForURL(url_ids[1], &visits); |
448 EXPECT_EQ(2, visits.size()); | 448 EXPECT_EQ(2U, visits.size()); |
449 EXPECT_EQ(1, CountTextMatchesForURL(last_row.url())); | 449 EXPECT_EQ(1, CountTextMatchesForURL(last_row.url())); |
450 | 450 |
451 // Delete the URL and its dependencies. | 451 // Delete the URL and its dependencies. |
452 expirer_.DeleteURL(last_row.url()); | 452 expirer_.DeleteURL(last_row.url()); |
453 | 453 |
454 // All the normal data + the favicon should be gone. | 454 // All the normal data + the favicon should be gone. |
455 EnsureURLInfoGone(last_row); | 455 EnsureURLInfoGone(last_row); |
456 EXPECT_TRUE(HasFavIcon(last_row.favicon_id())); | 456 EXPECT_TRUE(HasFavIcon(last_row.favicon_id())); |
457 } | 457 } |
458 | 458 |
(...skipping 12 matching lines...) Expand all Loading... |
471 // Attempt to delete the url. | 471 // Attempt to delete the url. |
472 expirer_.DeleteURL(url_row.url()); | 472 expirer_.DeleteURL(url_row.url()); |
473 | 473 |
474 // Because the url is starred, it shouldn't be deleted. | 474 // Because the url is starred, it shouldn't be deleted. |
475 GURL url = url_row.url(); | 475 GURL url = url_row.url(); |
476 ASSERT_TRUE(main_db_->GetRowForURL(url, &url_row)); | 476 ASSERT_TRUE(main_db_->GetRowForURL(url, &url_row)); |
477 | 477 |
478 // And the favicon should exist. | 478 // And the favicon should exist. |
479 EXPECT_TRUE(HasFavIcon(url_row.favicon_id())); | 479 EXPECT_TRUE(HasFavIcon(url_row.favicon_id())); |
480 | 480 |
481 // But there should be no fts. | 481 // But there should be no fts. |
482 ASSERT_EQ(0, CountTextMatchesForURL(url_row.url())); | 482 ASSERT_EQ(0, CountTextMatchesForURL(url_row.url())); |
483 | 483 |
484 // And no visits. | 484 // And no visits. |
485 VisitVector visits; | 485 VisitVector visits; |
486 main_db_->GetVisitsForURL(url_row.id(), &visits); | 486 main_db_->GetVisitsForURL(url_row.id(), &visits); |
487 ASSERT_EQ(0, visits.size()); | 487 ASSERT_EQ(0U, visits.size()); |
488 | 488 |
489 // Should still have the thumbnail. | 489 // Should still have the thumbnail. |
490 ASSERT_TRUE(HasThumbnail(url_row.id())); | 490 ASSERT_TRUE(HasThumbnail(url_row.id())); |
491 | 491 |
492 // Unstar the URL and delete again. | 492 // Unstar the URL and delete again. |
493 bookmark_model_.SetURLStarred(url, std::wstring(), false); | 493 bookmark_model_.SetURLStarred(url, std::wstring(), false); |
494 expirer_.DeleteURL(url); | 494 expirer_.DeleteURL(url); |
495 | 495 |
496 // Now it should be completely deleted. | 496 // Now it should be completely deleted. |
497 EnsureURLInfoGone(url_row); | 497 EnsureURLInfoGone(url_row); |
498 } | 498 } |
499 | 499 |
500 // Expires all URLs more recent than a given time, with no starred items. | 500 // Expires all URLs more recent than a given time, with no starred items. |
501 // Our time threshold is such that one URL should be updated (we delete one of | 501 // Our time threshold is such that one URL should be updated (we delete one of |
502 // the two visits) and one is deleted. | 502 // the two visits) and one is deleted. |
503 TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarred) { | 503 TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarred) { |
504 URLID url_ids[3]; | 504 URLID url_ids[3]; |
505 Time visit_times[4]; | 505 Time visit_times[4]; |
506 AddExampleData(url_ids, visit_times); | 506 AddExampleData(url_ids, visit_times); |
507 | 507 |
508 URLRow url_row1, url_row2; | 508 URLRow url_row1, url_row2; |
509 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); | 509 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); |
510 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); | 510 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); |
511 | 511 |
512 // In this test we also make sure that any pending entries in the text | 512 // In this test we also make sure that any pending entries in the text |
513 // database manager are removed. | 513 // database manager are removed. |
514 VisitVector visits; | 514 VisitVector visits; |
515 main_db_->GetVisitsForURL(url_ids[2], &visits); | 515 main_db_->GetVisitsForURL(url_ids[2], &visits); |
516 ASSERT_EQ(1, visits.size()); | 516 ASSERT_EQ(1U, visits.size()); |
517 text_db_->AddPageURL(url_row2.url(), url_row2.id(), visits[0].visit_id, | 517 text_db_->AddPageURL(url_row2.url(), url_row2.id(), visits[0].visit_id, |
518 visits[0].visit_time); | 518 visits[0].visit_time); |
519 | 519 |
520 // This should delete the last two visits. | 520 // This should delete the last two visits. |
521 expirer_.ExpireHistoryBetween(visit_times[2], Time()); | 521 expirer_.ExpireHistoryBetween(visit_times[2], Time()); |
522 | 522 |
523 // Run the text database expirer. This will flush any pending entries so we | 523 // Run the text database expirer. This will flush any pending entries so we |
524 // can check that nothing was committed. We use a time far in the future so | 524 // can check that nothing was committed. We use a time far in the future so |
525 // that anything added recently will get flushed. | 525 // that anything added recently will get flushed. |
526 TimeTicks expiration_time = TimeTicks::Now() + TimeDelta::FromDays(1); | 526 TimeTicks expiration_time = TimeTicks::Now() + TimeDelta::FromDays(1); |
527 text_db_->FlushOldChangesForTime(expiration_time); | 527 text_db_->FlushOldChangesForTime(expiration_time); |
528 | 528 |
529 // Verify that the middle URL had its last visit deleted only. | 529 // Verify that the middle URL had its last visit deleted only. |
530 visits.clear(); | 530 visits.clear(); |
531 main_db_->GetVisitsForURL(url_ids[1], &visits); | 531 main_db_->GetVisitsForURL(url_ids[1], &visits); |
532 EXPECT_EQ(1, visits.size()); | 532 EXPECT_EQ(1U, visits.size()); |
533 EXPECT_EQ(0, CountTextMatchesForURL(url_row1.url())); | 533 EXPECT_EQ(0, CountTextMatchesForURL(url_row1.url())); |
534 | 534 |
535 // Verify that the middle URL visit time and visit counts were updated. | 535 // Verify that the middle URL visit time and visit counts were updated. |
536 URLRow temp_row; | 536 URLRow temp_row; |
537 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); | 537 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); |
538 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. | 538 EXPECT_TRUE(visit_times[2] == url_row1.last_visit()); // Previous value. |
539 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. | 539 EXPECT_TRUE(visit_times[1] == temp_row.last_visit()); // New value. |
540 EXPECT_EQ(2, url_row1.visit_count()); | 540 EXPECT_EQ(2, url_row1.visit_count()); |
541 EXPECT_EQ(1, temp_row.visit_count()); | 541 EXPECT_EQ(1, temp_row.visit_count()); |
542 EXPECT_EQ(1, url_row1.typed_count()); | 542 EXPECT_EQ(1, url_row1.typed_count()); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 expirer_.ArchiveHistoryBefore(visit_times[2]); | 622 expirer_.ArchiveHistoryBefore(visit_times[2]); |
623 EXPECT_FALSE(main_db_->GetURLRow(url_ids[1], &temp_row)); | 623 EXPECT_FALSE(main_db_->GetURLRow(url_ids[1], &temp_row)); |
624 EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row)); | 624 EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row)); |
625 | 625 |
626 // Make sure the archived database has an entry for the second URL. | 626 // Make sure the archived database has an entry for the second URL. |
627 URLRow archived_row; | 627 URLRow archived_row; |
628 // Note that the ID is different in the archived DB, so look up by URL. | 628 // Note that the ID is different in the archived DB, so look up by URL. |
629 EXPECT_TRUE(archived_db_->GetRowForURL(url_row1.url(), &archived_row)); | 629 EXPECT_TRUE(archived_db_->GetRowForURL(url_row1.url(), &archived_row)); |
630 VisitVector archived_visits; | 630 VisitVector archived_visits; |
631 archived_db_->GetVisitsForURL(archived_row.id(), &archived_visits); | 631 archived_db_->GetVisitsForURL(archived_row.id(), &archived_visits); |
632 EXPECT_EQ(1, archived_visits.size()); | 632 EXPECT_EQ(1U, archived_visits.size()); |
633 } | 633 } |
634 | 634 |
635 TEST_F(ExpireHistoryTest, ArchiveHistoryBeforeStarred) { | 635 TEST_F(ExpireHistoryTest, ArchiveHistoryBeforeStarred) { |
636 URLID url_ids[3]; | 636 URLID url_ids[3]; |
637 Time visit_times[4]; | 637 Time visit_times[4]; |
638 AddExampleData(url_ids, visit_times); | 638 AddExampleData(url_ids, visit_times); |
639 | 639 |
640 URLRow url_row0, url_row1; | 640 URLRow url_row0, url_row1; |
641 ASSERT_TRUE(main_db_->GetURLRow(url_ids[0], &url_row0)); | 641 ASSERT_TRUE(main_db_->GetURLRow(url_ids[0], &url_row0)); |
642 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); | 642 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); |
643 | 643 |
644 // Star the URLs. | 644 // Star the URLs. |
645 StarURL(url_row0.url()); | 645 StarURL(url_row0.url()); |
646 StarURL(url_row1.url()); | 646 StarURL(url_row1.url()); |
647 | 647 |
648 // Now archive the first three visits (first two URLs). The first two visits | 648 // Now archive the first three visits (first two URLs). The first two visits |
649 // should be, the third deleted, but the URL records should not. | 649 // should be, the third deleted, but the URL records should not. |
650 expirer_.ArchiveHistoryBefore(visit_times[2]); | 650 expirer_.ArchiveHistoryBefore(visit_times[2]); |
651 | 651 |
652 // The first URL should have its visit deleted, but it should still be present | 652 // The first URL should have its visit deleted, but it should still be present |
653 // in the main DB and not in the archived one since it is starred. | 653 // in the main DB and not in the archived one since it is starred. |
654 URLRow temp_row; | 654 URLRow temp_row; |
655 ASSERT_TRUE(main_db_->GetURLRow(url_ids[0], &temp_row)); | 655 ASSERT_TRUE(main_db_->GetURLRow(url_ids[0], &temp_row)); |
656 // Note that the ID is different in the archived DB, so look up by URL. | 656 // Note that the ID is different in the archived DB, so look up by URL. |
657 EXPECT_FALSE(archived_db_->GetRowForURL(temp_row.url(), NULL)); | 657 EXPECT_FALSE(archived_db_->GetRowForURL(temp_row.url(), NULL)); |
658 VisitVector visits; | 658 VisitVector visits; |
659 main_db_->GetVisitsForURL(temp_row.id(), &visits); | 659 main_db_->GetVisitsForURL(temp_row.id(), &visits); |
660 EXPECT_EQ(0, visits.size()); | 660 EXPECT_EQ(0U, visits.size()); |
661 | 661 |
662 // The second URL should have its first visit deleted and its second visit | 662 // The second URL should have its first visit deleted and its second visit |
663 // archived. It should be present in both the main DB (because it's starred) | 663 // archived. It should be present in both the main DB (because it's starred) |
664 // and the archived DB (for the archived visit). | 664 // and the archived DB (for the archived visit). |
665 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); | 665 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); |
666 main_db_->GetVisitsForURL(temp_row.id(), &visits); | 666 main_db_->GetVisitsForURL(temp_row.id(), &visits); |
667 EXPECT_EQ(0, visits.size()); | 667 EXPECT_EQ(0U, visits.size()); |
668 | 668 |
669 // Note that the ID is different in the archived DB, so look up by URL. | 669 // Note that the ID is different in the archived DB, so look up by URL. |
670 ASSERT_TRUE(archived_db_->GetRowForURL(temp_row.url(), &temp_row)); | 670 ASSERT_TRUE(archived_db_->GetRowForURL(temp_row.url(), &temp_row)); |
671 archived_db_->GetVisitsForURL(temp_row.id(), &visits); | 671 archived_db_->GetVisitsForURL(temp_row.id(), &visits); |
672 ASSERT_EQ(1, visits.size()); | 672 ASSERT_EQ(1U, visits.size()); |
673 EXPECT_TRUE(visit_times[2] == visits[0].visit_time); | 673 EXPECT_TRUE(visit_times[2] == visits[0].visit_time); |
674 | 674 |
675 // The third URL should be unchanged. | 675 // The third URL should be unchanged. |
676 EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row)); | 676 EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row)); |
677 EXPECT_FALSE(archived_db_->GetRowForURL(temp_row.url(), NULL)); | 677 EXPECT_FALSE(archived_db_->GetRowForURL(temp_row.url(), NULL)); |
678 } | 678 } |
679 | 679 |
680 // Tests the return values from ArchiveSomeOldHistory. The rest of the | 680 // Tests the return values from ArchiveSomeOldHistory. The rest of the |
681 // functionality of this function is tested by the ArchiveHistoryBefore* | 681 // functionality of this function is tested by the ArchiveHistoryBefore* |
682 // tests which use this function internally. | 682 // tests which use this function internally. |
(...skipping 14 matching lines...) Expand all Loading... |
697 // (max deleted). | 697 // (max deleted). |
698 EXPECT_TRUE(expirer_.ArchiveSomeOldHistory(visit_times[2], 1)); | 698 EXPECT_TRUE(expirer_.ArchiveSomeOldHistory(visit_times[2], 1)); |
699 } | 699 } |
700 | 700 |
701 // TODO(brettw) add some visits with no URL to make sure everything is updated | 701 // TODO(brettw) add some visits with no URL to make sure everything is updated |
702 // properly. Have the visits also refer to nonexistant FTS rows. | 702 // properly. Have the visits also refer to nonexistant FTS rows. |
703 // | 703 // |
704 // Maybe also refer to invalid favicons. | 704 // Maybe also refer to invalid favicons. |
705 | 705 |
706 } // namespace history | 706 } // namespace history |
OLD | NEW |