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

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

Issue 235863023: Eliminate the archived history database and clean up related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 "chrome/browser/history/history_backend.h" 5 #include "chrome/browser/history/history_backend.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 row4.set_typed_count(1); 815 row4.set_typed_count(1);
816 row4.set_last_visit(Time::Now() - base::TimeDelta::FromDays(365 + 2)); 816 row4.set_last_visit(Time::Now() - base::TimeDelta::FromDays(365 + 2));
817 817
818 URLRows rows; 818 URLRows rows;
819 rows.push_back(row1); 819 rows.push_back(row1);
820 rows.push_back(row2); 820 rows.push_back(row2);
821 rows.push_back(row3); 821 rows.push_back(row3);
822 rows.push_back(row4); 822 rows.push_back(row4);
823 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); 823 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED);
824 824
825 // Verify that recent URLs have ended up in the main |db_|, while expired URLs 825 // Verify that recent URLs have ended up in the main |db_|, while the expired
826 // have ended up in the |archived_db_|. 826 // URL has not.
827 URLRow stored_row1, stored_row2, stored_row3, stored_row4; 827 URLRow stored_row1, stored_row2, stored_row3, stored_row4;
828 EXPECT_NE(0, backend_->db_->GetRowForURL(row1.url(), &stored_row1)); 828 EXPECT_NE(0, backend_->db_->GetRowForURL(row1.url(), &stored_row1));
829 EXPECT_NE(0, backend_->db_->GetRowForURL(row2.url(), &stored_row2)); 829 EXPECT_NE(0, backend_->db_->GetRowForURL(row2.url(), &stored_row2));
830 EXPECT_NE(0, backend_->db_->GetRowForURL(row3.url(), &stored_row3)); 830 EXPECT_NE(0, backend_->db_->GetRowForURL(row3.url(), &stored_row3));
831 EXPECT_EQ(0, backend_->db_->GetRowForURL(row4.url(), &stored_row4)); 831 EXPECT_EQ(0, backend_->db_->GetRowForURL(row4.url(), &stored_row4));
832 832
833 EXPECT_EQ(0, backend_->archived_db_->GetRowForURL(row1.url(), &stored_row1));
834 EXPECT_EQ(0, backend_->archived_db_->GetRowForURL(row2.url(), &stored_row2));
835 EXPECT_EQ(0, backend_->archived_db_->GetRowForURL(row3.url(), &stored_row3));
836 EXPECT_NE(0, backend_->archived_db_->GetRowForURL(row4.url(), &stored_row4));
837
838 ASSERT_EQ(1u, broadcasted_notifications().size()); 833 ASSERT_EQ(1u, broadcasted_notifications().size());
839 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, 834 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
840 broadcasted_notifications()[0].first); 835 broadcasted_notifications()[0].first);
841 const URLsModifiedDetails* details = static_cast<const URLsModifiedDetails*>( 836 const URLsModifiedDetails* details = static_cast<const URLsModifiedDetails*>(
842 broadcasted_notifications()[0].second); 837 broadcasted_notifications()[0].second);
843 EXPECT_EQ(2u, details->changed_urls.size()); 838 EXPECT_EQ(2u, details->changed_urls.size());
844 839
845 URLRows::const_iterator it_row2 = std::find_if( 840 URLRows::const_iterator it_row2 = std::find_if(
846 details->changed_urls.begin(), 841 details->changed_urls.begin(),
847 details->changed_urls.end(), 842 details->changed_urls.end(),
(...skipping 1753 matching lines...) Expand 10 before | Expand all | Expand 10 after
2601 // Remove the visit to cnn.com. 2596 // Remove the visit to cnn.com.
2602 ASSERT_TRUE(backend_->RemoveVisits(visits1)); 2597 ASSERT_TRUE(backend_->RemoveVisits(visits1));
2603 } 2598 }
2604 2599
2605 // Test for migration of adding visit_duration column. 2600 // Test for migration of adding visit_duration column.
2606 TEST_F(HistoryBackendTest, MigrationVisitDuration) { 2601 TEST_F(HistoryBackendTest, MigrationVisitDuration) {
2607 ASSERT_TRUE(backend_.get()); 2602 ASSERT_TRUE(backend_.get());
2608 backend_->Closing(); 2603 backend_->Closing();
2609 backend_ = NULL; 2604 backend_ = NULL;
2610 2605
2611 base::FilePath old_history_path, old_history, old_archived; 2606 base::FilePath old_history_path, old_history;
2612 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &old_history_path)); 2607 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &old_history_path));
2613 old_history_path = old_history_path.AppendASCII("History"); 2608 old_history_path = old_history_path.AppendASCII("History");
2614 old_history = old_history_path.AppendASCII("HistoryNoDuration"); 2609 old_history = old_history_path.AppendASCII("HistoryNoDuration");
2615 old_archived = old_history_path.AppendASCII("ArchivedNoDuration");
2616 2610
2617 // Copy history database file to current directory so that it will be deleted 2611 // Copy history database file to current directory so that it will be deleted
2618 // in Teardown. 2612 // in Teardown.
2619 base::FilePath new_history_path(getTestDir()); 2613 base::FilePath new_history_path(getTestDir());
2620 base::DeleteFile(new_history_path, true); 2614 base::DeleteFile(new_history_path, true);
2621 base::CreateDirectory(new_history_path); 2615 base::CreateDirectory(new_history_path);
2622 base::FilePath new_history_file = 2616 base::FilePath new_history_file =
2623 new_history_path.Append(chrome::kHistoryFilename); 2617 new_history_path.Append(chrome::kHistoryFilename);
2624 base::FilePath new_archived_file =
2625 new_history_path.Append(chrome::kArchivedHistoryFilename);
2626 ASSERT_TRUE(base::CopyFile(old_history, new_history_file)); 2618 ASSERT_TRUE(base::CopyFile(old_history, new_history_file));
2627 ASSERT_TRUE(base::CopyFile(old_archived, new_archived_file));
2628 2619
2629 backend_ = new HistoryBackend(new_history_path, 2620 backend_ = new HistoryBackend(new_history_path,
2630 new HistoryBackendTestDelegate(this), 2621 new HistoryBackendTestDelegate(this),
2631 &bookmark_model_); 2622 &bookmark_model_);
2632 backend_->Init(std::string(), false); 2623 backend_->Init(std::string(), false);
2633 backend_->Closing(); 2624 backend_->Closing();
2634 backend_ = NULL; 2625 backend_ = NULL;
2635 2626
2636 // Now both history and archived_history databases should already be migrated. 2627 // Now the history database should already be migrated.
2637 2628
2638 // Check version in history database first. 2629 // Check version in history database first.
2639 int cur_version = HistoryDatabase::GetCurrentVersion(); 2630 int cur_version = HistoryDatabase::GetCurrentVersion();
2640 sql::Connection db; 2631 sql::Connection db;
2641 ASSERT_TRUE(db.Open(new_history_file)); 2632 ASSERT_TRUE(db.Open(new_history_file));
2642 sql::Statement s(db.GetUniqueStatement( 2633 sql::Statement s(db.GetUniqueStatement(
2643 "SELECT value FROM meta WHERE key = 'version'")); 2634 "SELECT value FROM meta WHERE key = 'version'"));
2644 ASSERT_TRUE(s.Step()); 2635 ASSERT_TRUE(s.Step());
2645 int file_version = s.ColumnInt(0); 2636 int file_version = s.ColumnInt(0);
2646 EXPECT_EQ(cur_version, file_version); 2637 EXPECT_EQ(cur_version, file_version);
2647 2638
2648 // Check visit_duration column in visits table is created and set to 0. 2639 // Check visit_duration column in visits table is created and set to 0.
2649 s.Assign(db.GetUniqueStatement( 2640 s.Assign(db.GetUniqueStatement(
2650 "SELECT visit_duration FROM visits LIMIT 1")); 2641 "SELECT visit_duration FROM visits LIMIT 1"));
2651 ASSERT_TRUE(s.Step()); 2642 ASSERT_TRUE(s.Step());
2652 EXPECT_EQ(0, s.ColumnInt(0)); 2643 EXPECT_EQ(0, s.ColumnInt(0));
2653
2654 // Repeat version and visit_duration checks in archived history database
2655 // also.
2656 cur_version = ArchivedDatabase::GetCurrentVersion();
2657 sql::Connection archived_db;
2658 ASSERT_TRUE(archived_db.Open(new_archived_file));
2659 sql::Statement s1(archived_db.GetUniqueStatement(
2660 "SELECT value FROM meta WHERE key = 'version'"));
2661 ASSERT_TRUE(s1.Step());
2662 file_version = s1.ColumnInt(0);
2663 EXPECT_EQ(cur_version, file_version);
2664
2665 // Check visit_duration column in visits table is created and set to 0.
2666 s1.Assign(archived_db.GetUniqueStatement(
2667 "SELECT visit_duration FROM visits LIMIT 1"));
2668 ASSERT_TRUE(s1.Step());
2669 EXPECT_EQ(0, s1.ColumnInt(0));
2670 } 2644 }
2671 2645
2672 TEST_F(HistoryBackendTest, AddPageNoVisitForBookmark) { 2646 TEST_F(HistoryBackendTest, AddPageNoVisitForBookmark) {
2673 ASSERT_TRUE(backend_.get()); 2647 ASSERT_TRUE(backend_.get());
2674 2648
2675 GURL url("http://www.google.com"); 2649 GURL url("http://www.google.com");
2676 base::string16 title(base::UTF8ToUTF16("Bookmark title")); 2650 base::string16 title(base::UTF8ToUTF16("Bookmark title"));
2677 backend_->AddPageNoVisitForBookmark(url, title); 2651 backend_->AddPageNoVisitForBookmark(url, title);
2678 2652
2679 URLRow row; 2653 URLRow row;
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
2909 2883
2910 // Delete all DTS index databases. 2884 // Delete all DTS index databases.
2911 backend_->DeleteFTSIndexDatabases(); 2885 backend_->DeleteFTSIndexDatabases();
2912 EXPECT_FALSE(base::PathExists(db1)); 2886 EXPECT_FALSE(base::PathExists(db1));
2913 EXPECT_FALSE(base::PathExists(db1_wal)); 2887 EXPECT_FALSE(base::PathExists(db1_wal));
2914 EXPECT_FALSE(base::PathExists(db1_journal)); 2888 EXPECT_FALSE(base::PathExists(db1_journal));
2915 EXPECT_FALSE(base::PathExists(db2_symlink)); 2889 EXPECT_FALSE(base::PathExists(db2_symlink));
2916 EXPECT_TRUE(base::PathExists(db2_actual)); // Symlinks shouldn't be followed. 2890 EXPECT_TRUE(base::PathExists(db2_actual)); // Symlinks shouldn't be followed.
2917 } 2891 }
2918 2892
2893 TEST_F(HistoryBackendTest, ArchiveDatabaseGetsPurged) {
2894 ASSERT_TRUE(backend_.get());
2895 backend_->Closing();
2896 backend_ = NULL;
2897
2898 // kArchivedHistoryFilename
2899
2900 base::FilePath old_history_path;
2901 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &old_history_path));
2902 old_history_path = old_history_path.AppendASCII("History");
2903 old_history_path = old_history_path.AppendASCII("HistoryNoSource");
2904
2905 // Copy history database file to current directory so that it will be deleted
2906 // in Teardown.
2907 base::FilePath new_history_path(getTestDir());
2908 base::DeleteFile(new_history_path, true);
2909 base::CreateDirectory(new_history_path);
2910 base::FilePath new_history_file =
2911 new_history_path.Append(chrome::kHistoryFilename);
2912 ASSERT_TRUE(base::CopyFile(old_history_path, new_history_file));
2913
2914 backend_ = new HistoryBackend(new_history_path,
2915 new HistoryBackendTestDelegate(this),
2916 &bookmark_model_);
2917 backend_->Init(std::string(), false);
2918 backend_->Closing();
2919 backend_ = NULL;
2920
2921 // Now the database should already be migrated.
2922 // Check version first.
2923 int cur_version = HistoryDatabase::GetCurrentVersion();
2924 sql::Connection db;
2925 ASSERT_TRUE(db.Open(new_history_file));
2926 sql::Statement s(db.GetUniqueStatement(
2927 "SELECT value FROM meta WHERE key = 'version'"));
2928 ASSERT_TRUE(s.Step());
2929 int file_version = s.ColumnInt(0);
2930 EXPECT_EQ(cur_version, file_version);
2931
2932 // Check visit_source table is created and empty.
2933 s.Assign(db.GetUniqueStatement(
2934 "SELECT name FROM sqlite_master WHERE name=\"visit_source\""));
2935 ASSERT_TRUE(s.Step());
2936 s.Assign(db.GetUniqueStatement("SELECT * FROM visit_source LIMIT 10"));
2937 EXPECT_FALSE(s.Step());
2938 }
2939
2919 } // namespace history 2940 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698