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

Side by Side Diff: trunk/src/chrome/browser/history/history_backend_unittest.cc

Issue 19637009: Revert 212459 "Remove TextDatabase from the history service." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 #include <vector> 7 #include <vector>
8 #include <fstream>
9 8
10 #include "base/basictypes.h" 9 #include "base/basictypes.h"
11 #include "base/bind.h" 10 #include "base/bind.h"
12 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 12 #include "base/command_line.h"
14 #include "base/file_util.h" 13 #include "base/file_util.h"
15 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
16 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
18 #include "base/path_service.h" 17 #include "base/path_service.h"
19 #include "base/platform_file.h"
20 #include "base/strings/string16.h" 18 #include "base/strings/string16.h"
21 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
23 #include "chrome/browser/bookmarks/bookmark_model.h" 21 #include "chrome/browser/bookmarks/bookmark_model.h"
24 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 22 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
25 #include "chrome/browser/bookmarks/bookmark_utils.h" 23 #include "chrome/browser/bookmarks/bookmark_utils.h"
26 #include "chrome/browser/history/history_backend.h" 24 #include "chrome/browser/history/history_backend.h"
27 #include "chrome/browser/history/history_notifications.h" 25 #include "chrome/browser/history/history_notifications.h"
28 #include "chrome/browser/history/history_service.h" 26 #include "chrome/browser/history/history_service.h"
29 #include "chrome/browser/history/history_service_factory.h" 27 #include "chrome/browser/history/history_service_factory.h"
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 rows.push_back(row1); 497 rows.push_back(row1);
500 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); 498 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED);
501 499
502 URLID row1_id = backend_->db_->GetRowForURL(row1.url(), NULL); 500 URLID row1_id = backend_->db_->GetRowForURL(row1.url(), NULL);
503 URLID row2_id = backend_->db_->GetRowForURL(row2.url(), NULL); 501 URLID row2_id = backend_->db_->GetRowForURL(row2.url(), NULL);
504 502
505 // Get the two visits for the URLs we just added. 503 // Get the two visits for the URLs we just added.
506 VisitVector visits; 504 VisitVector visits;
507 backend_->db_->GetVisitsForURL(row1_id, &visits); 505 backend_->db_->GetVisitsForURL(row1_id, &visits);
508 ASSERT_EQ(1U, visits.size()); 506 ASSERT_EQ(1U, visits.size());
507 VisitID visit1_id = visits[0].visit_id;
509 508
510 visits.clear(); 509 visits.clear();
511 backend_->db_->GetVisitsForURL(row2_id, &visits); 510 backend_->db_->GetVisitsForURL(row2_id, &visits);
512 ASSERT_EQ(1U, visits.size()); 511 ASSERT_EQ(1U, visits.size());
512 VisitID visit2_id = visits[0].visit_id;
513 513
514 // The in-memory backend should have been set and it should have gotten the 514 // The in-memory backend should have been set and it should have gotten the
515 // typed URL. 515 // typed URL.
516 ASSERT_TRUE(mem_backend_.get()); 516 ASSERT_TRUE(mem_backend_.get());
517 URLRow outrow1; 517 URLRow outrow1;
518 EXPECT_TRUE(mem_backend_->db_->GetRowForURL(row1.url(), NULL)); 518 EXPECT_TRUE(mem_backend_->db_->GetRowForURL(row1.url(), NULL));
519 519
520 // Add thumbnails for each page. The |Images| take ownership of SkBitmap 520 // Add thumbnails for each page. The |Images| take ownership of SkBitmap
521 // created from decoding the images. 521 // created from decoding the images.
522 ThumbnailScore score(0.25, true, true); 522 ThumbnailScore score(0.25, true, true);
523 scoped_ptr<SkBitmap> google_bitmap( 523 scoped_ptr<SkBitmap> google_bitmap(
524 gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail))); 524 gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail)));
525 525
526 gfx::Image google_image = gfx::Image::CreateFrom1xBitmap(*google_bitmap); 526 gfx::Image google_image = gfx::Image::CreateFrom1xBitmap(*google_bitmap);
527 527
528 Time time; 528 Time time;
529 GURL gurl; 529 GURL gurl;
530 backend_->thumbnail_db_->SetPageThumbnail(gurl, row1_id, &google_image, 530 backend_->thumbnail_db_->SetPageThumbnail(gurl, row1_id, &google_image,
531 score, time); 531 score, time);
532 scoped_ptr<SkBitmap> weewar_bitmap( 532 scoped_ptr<SkBitmap> weewar_bitmap(
533 gfx::JPEGCodec::Decode(kWeewarThumbnail, sizeof(kWeewarThumbnail))); 533 gfx::JPEGCodec::Decode(kWeewarThumbnail, sizeof(kWeewarThumbnail)));
534 gfx::Image weewar_image = gfx::Image::CreateFrom1xBitmap(*weewar_bitmap); 534 gfx::Image weewar_image = gfx::Image::CreateFrom1xBitmap(*weewar_bitmap);
535 backend_->thumbnail_db_->SetPageThumbnail(gurl, row2_id, &weewar_image, 535 backend_->thumbnail_db_->SetPageThumbnail(gurl, row2_id, &weewar_image,
536 score, time); 536 score, time);
537 537
538 // Star row1. 538 // Star row1.
539 bookmark_model_.AddURL( 539 bookmark_model_.AddURL(
540 bookmark_model_.bookmark_bar_node(), 0, string16(), row1.url()); 540 bookmark_model_.bookmark_bar_node(), 0, string16(), row1.url());
541 541
542 // Set full text index for each one.
543 backend_->text_database_->AddPageData(row1.url(), row1_id, visit1_id,
544 row1.last_visit(),
545 UTF8ToUTF16("Title 1"),
546 UTF8ToUTF16("Body 1"));
547 backend_->text_database_->AddPageData(row2.url(), row2_id, visit2_id,
548 row2.last_visit(),
549 UTF8ToUTF16("Title 2"),
550 UTF8ToUTF16("Body 2"));
551
542 // Now finally clear all history. 552 // Now finally clear all history.
543 backend_->DeleteAllHistory(); 553 backend_->DeleteAllHistory();
544 554
545 // The first URL should be preserved but the time should be cleared. 555 // The first URL should be preserved but the time should be cleared.
546 EXPECT_TRUE(backend_->db_->GetRowForURL(row1.url(), &outrow1)); 556 EXPECT_TRUE(backend_->db_->GetRowForURL(row1.url(), &outrow1));
547 EXPECT_EQ(row1.url(), outrow1.url()); 557 EXPECT_EQ(row1.url(), outrow1.url());
548 EXPECT_EQ(0, outrow1.visit_count()); 558 EXPECT_EQ(0, outrow1.visit_count());
549 EXPECT_EQ(0, outrow1.typed_count()); 559 EXPECT_EQ(0, outrow1.typed_count());
550 EXPECT_TRUE(Time() == outrow1.last_visit()); 560 EXPECT_TRUE(Time() == outrow1.last_visit());
551 561
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 // The remaining URL should still reference the same favicon, even if its 608 // The remaining URL should still reference the same favicon, even if its
599 // ID has changed. 609 // ID has changed.
600 std::vector<IconMapping> mappings; 610 std::vector<IconMapping> mappings;
601 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL( 611 EXPECT_TRUE(backend_->thumbnail_db_->GetIconMappingsForPageURL(
602 outrow1.url(), chrome::FAVICON, &mappings)); 612 outrow1.url(), chrome::FAVICON, &mappings));
603 EXPECT_EQ(1u, mappings.size()); 613 EXPECT_EQ(1u, mappings.size());
604 EXPECT_EQ(out_favicon1, mappings[0].icon_id); 614 EXPECT_EQ(out_favicon1, mappings[0].icon_id);
605 615
606 // The first URL should still be bookmarked. 616 // The first URL should still be bookmarked.
607 EXPECT_TRUE(bookmark_model_.IsBookmarked(row1.url())); 617 EXPECT_TRUE(bookmark_model_.IsBookmarked(row1.url()));
618
619 // The full text database should have no data.
620 std::vector<TextDatabase::Match> text_matches;
621 Time first_time_searched;
622 backend_->text_database_->GetTextMatches(UTF8ToUTF16("Body"),
623 QueryOptions(),
624 &text_matches,
625 &first_time_searched);
626 EXPECT_EQ(0U, text_matches.size());
608 } 627 }
609 628
610 // Checks that adding a visit, then calling DeleteAll, and then trying to add 629 // Checks that adding a visit, then calling DeleteAll, and then trying to add
611 // data for the visited page works. This can happen when clearing the history 630 // data for the visited page works. This can happen when clearing the history
612 // immediately after visiting a page. 631 // immediately after visiting a page.
613 TEST_F(HistoryBackendTest, DeleteAllThenAddData) { 632 TEST_F(HistoryBackendTest, DeleteAllThenAddData) {
614 ASSERT_TRUE(backend_.get()); 633 ASSERT_TRUE(backend_.get());
615 634
616 Time visit_time = Time::Now(); 635 Time visit_time = Time::Now();
617 GURL url("http://www.google.com/"); 636 GURL url("http://www.google.com/");
(...skipping 15 matching lines...) Expand all
633 // Clear all history. 652 // Clear all history.
634 backend_->DeleteAllHistory(); 653 backend_->DeleteAllHistory();
635 654
636 // The row should be deleted. 655 // The row should be deleted.
637 EXPECT_FALSE(backend_->db_->GetRowForURL(url, &outrow)); 656 EXPECT_FALSE(backend_->db_->GetRowForURL(url, &outrow));
638 657
639 // The visit should be deleted. 658 // The visit should be deleted.
640 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits); 659 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits);
641 ASSERT_EQ(0U, all_visits.size()); 660 ASSERT_EQ(0U, all_visits.size());
642 661
643 // Try and set the title. 662 // Try and set the full text index.
644 backend_->SetPageTitle(url, UTF8ToUTF16("Title")); 663 backend_->SetPageTitle(url, UTF8ToUTF16("Title"));
664 backend_->SetPageContents(url, UTF8ToUTF16("Body"));
645 665
646 // The row should still be deleted. 666 // The row should still be deleted.
647 EXPECT_FALSE(backend_->db_->GetRowForURL(url, &outrow)); 667 EXPECT_FALSE(backend_->db_->GetRowForURL(url, &outrow));
648 668
649 // The visit should still be deleted. 669 // The visit should still be deleted.
650 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits); 670 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits);
651 ASSERT_EQ(0U, all_visits.size()); 671 ASSERT_EQ(0U, all_visits.size());
672
673 // The full text database should have no data.
674 std::vector<TextDatabase::Match> text_matches;
675 Time first_time_searched;
676 backend_->text_database_->GetTextMatches(UTF8ToUTF16("Body"),
677 QueryOptions(),
678 &text_matches,
679 &first_time_searched);
680 EXPECT_EQ(0U, text_matches.size());
652 } 681 }
653 682
654 TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) { 683 TEST_F(HistoryBackendTest, URLsNoLongerBookmarked) {
655 GURL favicon_url1("http://www.google.com/favicon.ico"); 684 GURL favicon_url1("http://www.google.com/favicon.ico");
656 GURL favicon_url2("http://news.google.com/favicon.ico"); 685 GURL favicon_url2("http://news.google.com/favicon.ico");
657 686
658 std::vector<unsigned char> data; 687 std::vector<unsigned char> data;
659 data.push_back('1'); 688 data.push_back('1');
660 chrome::FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon( 689 chrome::FaviconID favicon1 = backend_->thumbnail_db_->AddFavicon(
661 favicon_url1, 690 favicon_url1,
(...skipping 2114 matching lines...) Expand 10 before | Expand all | Expand 10 after
2776 2805
2777 service->AddPage( 2806 service->AddPage(
2778 url, base::Time::Now(), NULL, 1, GURL(), RedirectList(), 2807 url, base::Time::Now(), NULL, 1, GURL(), RedirectList(),
2779 content::PAGE_TRANSITION_TYPED, SOURCE_BROWSED, false); 2808 content::PAGE_TRANSITION_TYPED, SOURCE_BROWSED, false);
2780 2809
2781 // This won't actually delete the URL, rather it'll empty out the visits. 2810 // This won't actually delete the URL, rather it'll empty out the visits.
2782 // This triggers blocking on the BookmarkModel. 2811 // This triggers blocking on the BookmarkModel.
2783 service->DeleteURL(url); 2812 service->DeleteURL(url);
2784 } 2813 }
2785 2814
2786 // Simple function to create a new dummy file.
2787 void CreateDummyFile(const base::FilePath& filename) {
2788 std::wofstream file;
2789 file.open(filename.value().c_str());
2790 ASSERT_TRUE(file.is_open());
2791 file << L"Dummy";
2792 file.close();
2793 }
2794
2795 // Test DeleteFTSIndexDatabases deletes expected files.
2796 TEST_F(HistoryBackendTest, DeleteFTSIndexDatabases) {
2797 ASSERT_TRUE(backend_.get());
2798
2799 base::FilePath history_path(getTestDir());
2800 base::FilePath db1(history_path.AppendASCII("History Index 2013-05"));
2801 base::FilePath db1_journal(db1.InsertBeforeExtensionASCII("-journal"));
2802 base::FilePath db1_wal(db1.InsertBeforeExtensionASCII("-wal"));
2803 base::FilePath db2_symlink(history_path.AppendASCII("History Index 2013-06"));
2804 base::FilePath db2_actual(history_path.AppendASCII("Underlying DB"));
2805
2806 // Setup dummy index database files.
2807 CreateDummyFile(db1);
2808 CreateDummyFile(db1_journal);
2809 CreateDummyFile(db1_wal);
2810 CreateDummyFile(db2_actual);
2811 #if defined(OS_POSIX)
2812 EXPECT_TRUE(file_util::CreateSymbolicLink(db2_actual, db2_symlink));
2813 #endif
2814
2815 // Delete all DTS index databases.
2816 backend_->DeleteFTSIndexDatabases();
2817 EXPECT_FALSE(base::PathExists(db1));
2818 EXPECT_FALSE(base::PathExists(db1_wal));
2819 EXPECT_FALSE(base::PathExists(db1_journal));
2820 EXPECT_FALSE(base::PathExists(db2_symlink));
2821 EXPECT_TRUE(base::PathExists(db2_actual)); // Symlinks shouldn't be followed.
2822 }
2823
2824 } // namespace history 2815 } // namespace history
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/history/history_backend.cc ('k') | trunk/src/chrome/browser/history/history_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698