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(history_client_.IsBookmarked(row1.url())); | 679 EXPECT_TRUE(history_client_.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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 GURL url_c("http://google.com/c"); | 906 GURL url_c("http://google.com/c"); |
907 AddClientRedirect(url_b, url_c, true, base::Time(), | 907 AddClientRedirect(url_b, url_c, true, base::Time(), |
908 &transition1, &transition2); | 908 &transition1, &transition2); |
909 EXPECT_FALSE(transition1 & content::PAGE_TRANSITION_CHAIN_END); | 909 EXPECT_FALSE(transition1 & content::PAGE_TRANSITION_CHAIN_END); |
910 EXPECT_TRUE(transition2 & content::PAGE_TRANSITION_CHAIN_END); | 910 EXPECT_TRUE(transition2 & content::PAGE_TRANSITION_CHAIN_END); |
911 } | 911 } |
912 | 912 |
913 TEST_F(HistoryBackendTest, AddPagesWithDetails) { | 913 TEST_F(HistoryBackendTest, AddPagesWithDetails) { |
914 ASSERT_TRUE(backend_.get()); | 914 ASSERT_TRUE(backend_.get()); |
915 | 915 |
916 // Import one non-typed URL, two non-archived and one archived typed URLs. | 916 // Import one non-typed URL, and two recent and one expired typed URLs. |
917 URLRow row1(GURL("https://news.google.com/")); | 917 URLRow row1(GURL("https://news.google.com/")); |
918 row1.set_visit_count(1); | 918 row1.set_visit_count(1); |
919 row1.set_last_visit(Time::Now()); | 919 row1.set_last_visit(Time::Now()); |
920 URLRow row2(GURL("https://www.google.com/")); | 920 URLRow row2(GURL("https://www.google.com/")); |
921 row2.set_typed_count(1); | 921 row2.set_typed_count(1); |
922 row2.set_last_visit(Time::Now()); | 922 row2.set_last_visit(Time::Now()); |
923 URLRow row3(GURL("https://mail.google.com/")); | 923 URLRow row3(GURL("https://mail.google.com/")); |
924 row3.set_visit_count(1); | 924 row3.set_visit_count(1); |
925 row3.set_typed_count(1); | 925 row3.set_typed_count(1); |
926 row3.set_last_visit(Time::Now() - base::TimeDelta::FromDays(7 - 1)); | 926 row3.set_last_visit(Time::Now() - base::TimeDelta::FromDays(7 - 1)); |
927 URLRow row4(GURL("https://maps.google.com/")); | 927 URLRow row4(GURL("https://maps.google.com/")); |
928 row4.set_visit_count(1); | 928 row4.set_visit_count(1); |
929 row4.set_typed_count(1); | 929 row4.set_typed_count(1); |
930 row4.set_last_visit(Time::Now() - base::TimeDelta::FromDays(365 + 2)); | 930 row4.set_last_visit(Time::Now() - base::TimeDelta::FromDays(365 + 2)); |
931 | 931 |
932 URLRows rows; | 932 URLRows rows; |
933 rows.push_back(row1); | 933 rows.push_back(row1); |
934 rows.push_back(row2); | 934 rows.push_back(row2); |
935 rows.push_back(row3); | 935 rows.push_back(row3); |
936 rows.push_back(row4); | 936 rows.push_back(row4); |
937 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); | 937 backend_->AddPagesWithDetails(rows, history::SOURCE_BROWSED); |
938 | 938 |
939 // Verify that recent URLs have ended up in the main |db_|, while expired URLs | 939 // Verify that recent URLs have ended up in the main |db_|, while the already |
940 // have ended up in the |archived_db_|. | 940 // expired URL has been ignored. |
941 URLRow stored_row1, stored_row2, stored_row3, stored_row4; | 941 URLRow stored_row1, stored_row2, stored_row3, stored_row4; |
942 EXPECT_NE(0, backend_->db_->GetRowForURL(row1.url(), &stored_row1)); | 942 EXPECT_NE(0, backend_->db_->GetRowForURL(row1.url(), &stored_row1)); |
943 EXPECT_NE(0, backend_->db_->GetRowForURL(row2.url(), &stored_row2)); | 943 EXPECT_NE(0, backend_->db_->GetRowForURL(row2.url(), &stored_row2)); |
944 EXPECT_NE(0, backend_->db_->GetRowForURL(row3.url(), &stored_row3)); | 944 EXPECT_NE(0, backend_->db_->GetRowForURL(row3.url(), &stored_row3)); |
945 EXPECT_EQ(0, backend_->db_->GetRowForURL(row4.url(), &stored_row4)); | 945 EXPECT_EQ(0, backend_->db_->GetRowForURL(row4.url(), &stored_row4)); |
946 | 946 |
947 EXPECT_EQ(0, backend_->archived_db_->GetRowForURL(row1.url(), &stored_row1)); | |
948 EXPECT_EQ(0, backend_->archived_db_->GetRowForURL(row2.url(), &stored_row2)); | |
949 EXPECT_EQ(0, backend_->archived_db_->GetRowForURL(row3.url(), &stored_row3)); | |
950 EXPECT_NE(0, backend_->archived_db_->GetRowForURL(row4.url(), &stored_row4)); | |
951 | |
952 // Ensure that a notification was fired, and further verify that the IDs in | 947 // Ensure that a notification was fired, and further verify that the IDs in |
953 // the notification are set to those that are in effect in the main database. | 948 // the notification are set to those that are in effect in the main database. |
954 // The InMemoryHistoryBackend relies on this for caching. | 949 // The InMemoryHistoryBackend relies on this for caching. |
955 ASSERT_EQ(1u, broadcasted_notifications().size()); | 950 ASSERT_EQ(1u, broadcasted_notifications().size()); |
956 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, | 951 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, |
957 broadcasted_notifications()[0].first); | 952 broadcasted_notifications()[0].first); |
958 const URLsModifiedDetails* details = static_cast<const URLsModifiedDetails*>( | 953 const URLsModifiedDetails* details = static_cast<const URLsModifiedDetails*>( |
959 broadcasted_notifications()[0].second); | 954 broadcasted_notifications()[0].second); |
960 EXPECT_EQ(2u, details->changed_urls.size()); | 955 EXPECT_EQ(2u, details->changed_urls.size()); |
961 | 956 |
(...skipping 1897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2859 // Remove the visit to cnn.com. | 2854 // Remove the visit to cnn.com. |
2860 ASSERT_TRUE(backend_->RemoveVisits(visits1)); | 2855 ASSERT_TRUE(backend_->RemoveVisits(visits1)); |
2861 } | 2856 } |
2862 | 2857 |
2863 // Test for migration of adding visit_duration column. | 2858 // Test for migration of adding visit_duration column. |
2864 TEST_F(HistoryBackendTest, MigrationVisitDuration) { | 2859 TEST_F(HistoryBackendTest, MigrationVisitDuration) { |
2865 ASSERT_TRUE(backend_.get()); | 2860 ASSERT_TRUE(backend_.get()); |
2866 backend_->Closing(); | 2861 backend_->Closing(); |
2867 backend_ = NULL; | 2862 backend_ = NULL; |
2868 | 2863 |
2869 base::FilePath old_history_path, old_history, old_archived; | 2864 base::FilePath old_history_path, old_history; |
2870 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &old_history_path)); | 2865 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &old_history_path)); |
2871 old_history_path = old_history_path.AppendASCII("History"); | 2866 old_history_path = old_history_path.AppendASCII("History"); |
2872 old_history = old_history_path.AppendASCII("HistoryNoDuration"); | 2867 old_history = old_history_path.AppendASCII("HistoryNoDuration"); |
2873 old_archived = old_history_path.AppendASCII("ArchivedNoDuration"); | |
2874 | 2868 |
2875 // Copy history database file to current directory so that it will be deleted | 2869 // Copy history database file to current directory so that it will be deleted |
2876 // in Teardown. | 2870 // in Teardown. |
2877 base::FilePath new_history_path(test_dir()); | 2871 base::FilePath new_history_path(test_dir()); |
2878 base::DeleteFile(new_history_path, true); | 2872 base::DeleteFile(new_history_path, true); |
2879 base::CreateDirectory(new_history_path); | 2873 base::CreateDirectory(new_history_path); |
2880 base::FilePath new_history_file = | 2874 base::FilePath new_history_file = |
2881 new_history_path.Append(chrome::kHistoryFilename); | 2875 new_history_path.Append(chrome::kHistoryFilename); |
2882 base::FilePath new_archived_file = | |
2883 new_history_path.Append(chrome::kArchivedHistoryFilename); | |
2884 ASSERT_TRUE(base::CopyFile(old_history, new_history_file)); | 2876 ASSERT_TRUE(base::CopyFile(old_history, new_history_file)); |
2885 ASSERT_TRUE(base::CopyFile(old_archived, new_archived_file)); | |
2886 | 2877 |
2887 backend_ = new HistoryBackend( | 2878 backend_ = new HistoryBackend( |
2888 new_history_path, new HistoryBackendTestDelegate(this), &history_client_); | 2879 new_history_path, new HistoryBackendTestDelegate(this), &history_client_); |
2889 backend_->Init(std::string(), false); | 2880 backend_->Init(std::string(), false); |
2890 backend_->Closing(); | 2881 backend_->Closing(); |
2891 backend_ = NULL; | 2882 backend_ = NULL; |
2892 | 2883 |
2893 // Now both history and archived_history databases should already be migrated. | 2884 // Now the history database should already be migrated. |
2894 | 2885 |
2895 // Check version in history database first. | 2886 // Check version in history database first. |
2896 int cur_version = HistoryDatabase::GetCurrentVersion(); | 2887 int cur_version = HistoryDatabase::GetCurrentVersion(); |
2897 sql::Connection db; | 2888 sql::Connection db; |
2898 ASSERT_TRUE(db.Open(new_history_file)); | 2889 ASSERT_TRUE(db.Open(new_history_file)); |
2899 sql::Statement s(db.GetUniqueStatement( | 2890 sql::Statement s(db.GetUniqueStatement( |
2900 "SELECT value FROM meta WHERE key = 'version'")); | 2891 "SELECT value FROM meta WHERE key = 'version'")); |
2901 ASSERT_TRUE(s.Step()); | 2892 ASSERT_TRUE(s.Step()); |
2902 int file_version = s.ColumnInt(0); | 2893 int file_version = s.ColumnInt(0); |
2903 EXPECT_EQ(cur_version, file_version); | 2894 EXPECT_EQ(cur_version, file_version); |
2904 | 2895 |
2905 // Check visit_duration column in visits table is created and set to 0. | 2896 // Check visit_duration column in visits table is created and set to 0. |
2906 s.Assign(db.GetUniqueStatement( | 2897 s.Assign(db.GetUniqueStatement( |
2907 "SELECT visit_duration FROM visits LIMIT 1")); | 2898 "SELECT visit_duration FROM visits LIMIT 1")); |
2908 ASSERT_TRUE(s.Step()); | 2899 ASSERT_TRUE(s.Step()); |
2909 EXPECT_EQ(0, s.ColumnInt(0)); | 2900 EXPECT_EQ(0, s.ColumnInt(0)); |
2910 | |
2911 // Repeat version and visit_duration checks in archived history database | |
2912 // also. | |
2913 cur_version = ArchivedDatabase::GetCurrentVersion(); | |
2914 sql::Connection archived_db; | |
2915 ASSERT_TRUE(archived_db.Open(new_archived_file)); | |
2916 sql::Statement s1(archived_db.GetUniqueStatement( | |
2917 "SELECT value FROM meta WHERE key = 'version'")); | |
2918 ASSERT_TRUE(s1.Step()); | |
2919 file_version = s1.ColumnInt(0); | |
2920 EXPECT_EQ(cur_version, file_version); | |
2921 | |
2922 // Check visit_duration column in visits table is created and set to 0. | |
2923 s1.Assign(archived_db.GetUniqueStatement( | |
2924 "SELECT visit_duration FROM visits LIMIT 1")); | |
2925 ASSERT_TRUE(s1.Step()); | |
2926 EXPECT_EQ(0, s1.ColumnInt(0)); | |
2927 } | 2901 } |
2928 | 2902 |
2929 TEST_F(HistoryBackendTest, AddPageNoVisitForBookmark) { | 2903 TEST_F(HistoryBackendTest, AddPageNoVisitForBookmark) { |
2930 ASSERT_TRUE(backend_.get()); | 2904 ASSERT_TRUE(backend_.get()); |
2931 | 2905 |
2932 GURL url("http://www.google.com"); | 2906 GURL url("http://www.google.com"); |
2933 base::string16 title(base::UTF8ToUTF16("Bookmark title")); | 2907 base::string16 title(base::UTF8ToUTF16("Bookmark title")); |
2934 backend_->AddPageNoVisitForBookmark(url, title); | 2908 backend_->AddPageNoVisitForBookmark(url, title); |
2935 | 2909 |
2936 URLRow row; | 2910 URLRow row; |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3377 // Verify that the second term is no longer returned as result, and also check | 3351 // Verify that the second term is no longer returned as result, and also check |
3378 // at the low level that it is gone for good. The term corresponding to the | 3352 // at the low level that it is gone for good. The term corresponding to the |
3379 // first URLRow should not be affected. | 3353 // first URLRow should not be affected. |
3380 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); | 3354 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); |
3381 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); | 3355 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); |
3382 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); | 3356 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); |
3383 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); | 3357 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); |
3384 } | 3358 } |
3385 | 3359 |
3386 } // namespace history | 3360 } // namespace history |
OLD | NEW |