| 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 "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 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 // The first URL should still be bookmarked. | 678 // The first URL should still be bookmarked. |
| 679 EXPECT_TRUE(bookmark_model_->IsBookmarked(row1.url())); | 679 EXPECT_TRUE(bookmark_model_->IsBookmarked(row1.url())); |
| 680 | 680 |
| 681 // Check that we fire the notification about all history having been deleted. | 681 // Check that we fire the notification about all history having been deleted. |
| 682 ASSERT_EQ(1u, broadcasted_notifications().size()); | 682 ASSERT_EQ(1u, broadcasted_notifications().size()); |
| 683 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 683 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
| 684 broadcasted_notifications()[0].first); | 684 broadcasted_notifications()[0].first); |
| 685 const URLsDeletedDetails* details = static_cast<const URLsDeletedDetails*>( | 685 const URLsDeletedDetails* details = static_cast<const URLsDeletedDetails*>( |
| 686 broadcasted_notifications()[0].second); | 686 broadcasted_notifications()[0].second); |
| 687 EXPECT_TRUE(details->all_history); | 687 EXPECT_TRUE(details->all_history); |
| 688 EXPECT_FALSE(details->archived); | 688 EXPECT_FALSE(details->expired); |
| 689 } | 689 } |
| 690 | 690 |
| 691 // Checks that adding a visit, then calling DeleteAll, and then trying to add | 691 // Checks that adding a visit, then calling DeleteAll, and then trying to add |
| 692 // data for the visited page works. This can happen when clearing the history | 692 // data for the visited page works. This can happen when clearing the history |
| 693 // immediately after visiting a page. | 693 // immediately after visiting a page. |
| 694 TEST_F(HistoryBackendTest, DeleteAllThenAddData) { | 694 TEST_F(HistoryBackendTest, DeleteAllThenAddData) { |
| 695 ASSERT_TRUE(backend_.get()); | 695 ASSERT_TRUE(backend_.get()); |
| 696 | 696 |
| 697 Time visit_time = Time::Now(); | 697 Time visit_time = Time::Now(); |
| 698 GURL url("http://www.google.com/"); | 698 GURL url("http://www.google.com/"); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 row4.set_typed_count(1); | 930 row4.set_typed_count(1); |
| 931 row4.set_last_visit(Time::Now() - base::TimeDelta::FromDays(365 + 2)); | 931 row4.set_last_visit(Time::Now() - base::TimeDelta::FromDays(365 + 2)); |
| 932 | 932 |
| 933 URLRows rows; | 933 URLRows rows; |
| 934 rows.push_back(row1); | 934 rows.push_back(row1); |
| 935 rows.push_back(row2); | 935 rows.push_back(row2); |
| 936 rows.push_back(row3); | 936 rows.push_back(row3); |
| 937 rows.push_back(row4); | 937 rows.push_back(row4); |
| 938 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); | 938 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); |
| 939 | 939 |
| 940 // Verify that recent URLs have ended up in the main |db_|, while expired URLs | 940 // Verify that recent URLs have ended up in the main |db_|, while the already |
| 941 // have ended up in the |archived_db_|. | 941 // expired URL has been ignored. |
| 942 URLRow stored_row1, stored_row2, stored_row3, stored_row4; | 942 URLRow stored_row1, stored_row2, stored_row3, stored_row4; |
| 943 EXPECT_NE(0, backend_->db_->GetRowForURL(row1.url(), &stored_row1)); | 943 EXPECT_NE(0, backend_->db_->GetRowForURL(row1.url(), &stored_row1)); |
| 944 EXPECT_NE(0, backend_->db_->GetRowForURL(row2.url(), &stored_row2)); | 944 EXPECT_NE(0, backend_->db_->GetRowForURL(row2.url(), &stored_row2)); |
| 945 EXPECT_NE(0, backend_->db_->GetRowForURL(row3.url(), &stored_row3)); | 945 EXPECT_NE(0, backend_->db_->GetRowForURL(row3.url(), &stored_row3)); |
| 946 EXPECT_EQ(0, backend_->db_->GetRowForURL(row4.url(), &stored_row4)); | 946 EXPECT_EQ(0, backend_->db_->GetRowForURL(row4.url(), &stored_row4)); |
| 947 | 947 |
| 948 EXPECT_EQ(0, backend_->archived_db_->GetRowForURL(row1.url(), &stored_row1)); | |
| 949 EXPECT_EQ(0, backend_->archived_db_->GetRowForURL(row2.url(), &stored_row2)); | |
| 950 EXPECT_EQ(0, backend_->archived_db_->GetRowForURL(row3.url(), &stored_row3)); | |
| 951 EXPECT_NE(0, backend_->archived_db_->GetRowForURL(row4.url(), &stored_row4)); | |
| 952 | |
| 953 // Ensure that a notification was fired, and further verify that the IDs in | 948 // Ensure that a notification was fired, and further verify that the IDs in |
| 954 // the notification are set to those that are in effect in the main database. | 949 // the notification are set to those that are in effect in the main database. |
| 955 // The InMemoryHistoryBackend relies on this for caching. | 950 // The InMemoryHistoryBackend relies on this for caching. |
| 956 ASSERT_EQ(1u, broadcasted_notifications().size()); | 951 ASSERT_EQ(1u, broadcasted_notifications().size()); |
| 957 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, | 952 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, |
| 958 broadcasted_notifications()[0].first); | 953 broadcasted_notifications()[0].first); |
| 959 const URLsModifiedDetails* details = static_cast<const URLsModifiedDetails*>( | 954 const URLsModifiedDetails* details = static_cast<const URLsModifiedDetails*>( |
| 960 broadcasted_notifications()[0].second); | 955 broadcasted_notifications()[0].second); |
| 961 EXPECT_EQ(2u, details->changed_urls.size()); | 956 EXPECT_EQ(2u, details->changed_urls.size()); |
| 962 | 957 |
| (...skipping 1899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2862 // Remove the visit to cnn.com. | 2857 // Remove the visit to cnn.com. |
| 2863 ASSERT_TRUE(backend_->RemoveVisits(visits1)); | 2858 ASSERT_TRUE(backend_->RemoveVisits(visits1)); |
| 2864 } | 2859 } |
| 2865 | 2860 |
| 2866 // Test for migration of adding visit_duration column. | 2861 // Test for migration of adding visit_duration column. |
| 2867 TEST_F(HistoryBackendTest, MigrationVisitDuration) { | 2862 TEST_F(HistoryBackendTest, MigrationVisitDuration) { |
| 2868 ASSERT_TRUE(backend_.get()); | 2863 ASSERT_TRUE(backend_.get()); |
| 2869 backend_->Closing(); | 2864 backend_->Closing(); |
| 2870 backend_ = NULL; | 2865 backend_ = NULL; |
| 2871 | 2866 |
| 2872 base::FilePath old_history_path, old_history, old_archived; | 2867 base::FilePath old_history_path, old_history; |
| 2873 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &old_history_path)); | 2868 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &old_history_path)); |
| 2874 old_history_path = old_history_path.AppendASCII("History"); | 2869 old_history_path = old_history_path.AppendASCII("History"); |
| 2875 old_history = old_history_path.AppendASCII("HistoryNoDuration"); | 2870 old_history = old_history_path.AppendASCII("HistoryNoDuration"); |
| 2876 old_archived = old_history_path.AppendASCII("ArchivedNoDuration"); | |
| 2877 | 2871 |
| 2878 // Copy history database file to current directory so that it will be deleted | 2872 // Copy history database file to current directory so that it will be deleted |
| 2879 // in Teardown. | 2873 // in Teardown. |
| 2880 base::FilePath new_history_path(test_dir()); | 2874 base::FilePath new_history_path(test_dir()); |
| 2881 base::DeleteFile(new_history_path, true); | 2875 base::DeleteFile(new_history_path, true); |
| 2882 base::CreateDirectory(new_history_path); | 2876 base::CreateDirectory(new_history_path); |
| 2883 base::FilePath new_history_file = | 2877 base::FilePath new_history_file = |
| 2884 new_history_path.Append(chrome::kHistoryFilename); | 2878 new_history_path.Append(chrome::kHistoryFilename); |
| 2885 base::FilePath new_archived_file = | |
| 2886 new_history_path.Append(chrome::kArchivedHistoryFilename); | |
| 2887 ASSERT_TRUE(base::CopyFile(old_history, new_history_file)); | 2879 ASSERT_TRUE(base::CopyFile(old_history, new_history_file)); |
| 2888 ASSERT_TRUE(base::CopyFile(old_archived, new_archived_file)); | |
| 2889 | 2880 |
| 2890 backend_ = new HistoryBackend(new_history_path, | 2881 backend_ = new HistoryBackend(new_history_path, |
| 2891 new HistoryBackendTestDelegate(this), | 2882 new HistoryBackendTestDelegate(this), |
| 2892 bookmark_model_.get()); | 2883 bookmark_model_.get()); |
| 2893 backend_->Init(std::string(), false); | 2884 backend_->Init(std::string(), false); |
| 2894 backend_->Closing(); | 2885 backend_->Closing(); |
| 2895 backend_ = NULL; | 2886 backend_ = NULL; |
| 2896 | 2887 |
| 2897 // Now both history and archived_history databases should already be migrated. | 2888 // Now the history database should already be migrated. |
| 2898 | 2889 |
| 2899 // Check version in history database first. | 2890 // Check version in history database first. |
| 2900 int cur_version = HistoryDatabase::GetCurrentVersion(); | 2891 int cur_version = HistoryDatabase::GetCurrentVersion(); |
| 2901 sql::Connection db; | 2892 sql::Connection db; |
| 2902 ASSERT_TRUE(db.Open(new_history_file)); | 2893 ASSERT_TRUE(db.Open(new_history_file)); |
| 2903 sql::Statement s(db.GetUniqueStatement( | 2894 sql::Statement s(db.GetUniqueStatement( |
| 2904 "SELECT value FROM meta WHERE key = 'version'")); | 2895 "SELECT value FROM meta WHERE key = 'version'")); |
| 2905 ASSERT_TRUE(s.Step()); | 2896 ASSERT_TRUE(s.Step()); |
| 2906 int file_version = s.ColumnInt(0); | 2897 int file_version = s.ColumnInt(0); |
| 2907 EXPECT_EQ(cur_version, file_version); | 2898 EXPECT_EQ(cur_version, file_version); |
| 2908 | 2899 |
| 2909 // Check visit_duration column in visits table is created and set to 0. | 2900 // Check visit_duration column in visits table is created and set to 0. |
| 2910 s.Assign(db.GetUniqueStatement( | 2901 s.Assign(db.GetUniqueStatement( |
| 2911 "SELECT visit_duration FROM visits LIMIT 1")); | 2902 "SELECT visit_duration FROM visits LIMIT 1")); |
| 2912 ASSERT_TRUE(s.Step()); | 2903 ASSERT_TRUE(s.Step()); |
| 2913 EXPECT_EQ(0, s.ColumnInt(0)); | 2904 EXPECT_EQ(0, s.ColumnInt(0)); |
| 2914 | |
| 2915 // Repeat version and visit_duration checks in archived history database | |
| 2916 // also. | |
| 2917 cur_version = ArchivedDatabase::GetCurrentVersion(); | |
| 2918 sql::Connection archived_db; | |
| 2919 ASSERT_TRUE(archived_db.Open(new_archived_file)); | |
| 2920 sql::Statement s1(archived_db.GetUniqueStatement( | |
| 2921 "SELECT value FROM meta WHERE key = 'version'")); | |
| 2922 ASSERT_TRUE(s1.Step()); | |
| 2923 file_version = s1.ColumnInt(0); | |
| 2924 EXPECT_EQ(cur_version, file_version); | |
| 2925 | |
| 2926 // Check visit_duration column in visits table is created and set to 0. | |
| 2927 s1.Assign(archived_db.GetUniqueStatement( | |
| 2928 "SELECT visit_duration FROM visits LIMIT 1")); | |
| 2929 ASSERT_TRUE(s1.Step()); | |
| 2930 EXPECT_EQ(0, s1.ColumnInt(0)); | |
| 2931 } | 2905 } |
| 2932 | 2906 |
| 2933 TEST_F(HistoryBackendTest, AddPageNoVisitForBookmark) { | 2907 TEST_F(HistoryBackendTest, AddPageNoVisitForBookmark) { |
| 2934 ASSERT_TRUE(backend_.get()); | 2908 ASSERT_TRUE(backend_.get()); |
| 2935 | 2909 |
| 2936 GURL url("http://www.google.com"); | 2910 GURL url("http://www.google.com"); |
| 2937 base::string16 title(base::UTF8ToUTF16("Bookmark title")); | 2911 base::string16 title(base::UTF8ToUTF16("Bookmark title")); |
| 2938 backend_->AddPageNoVisitForBookmark(url, title); | 2912 backend_->AddPageNoVisitForBookmark(url, title); |
| 2939 | 2913 |
| 2940 URLRow row; | 2914 URLRow row; |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3384 // Verify that the second term is no longer returned as result, and also check | 3358 // Verify that the second term is no longer returned as result, and also check |
| 3385 // at the low level that it is gone for good. The term corresponding to the | 3359 // at the low level that it is gone for good. The term corresponding to the |
| 3386 // first URLRow should not be affected. | 3360 // first URLRow should not be affected. |
| 3387 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); | 3361 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); |
| 3388 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); | 3362 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); |
| 3389 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); | 3363 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); |
| 3390 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); | 3364 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); |
| 3391 } | 3365 } |
| 3392 | 3366 |
| 3393 } // namespace history | 3367 } // namespace history |
| OLD | NEW |