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 <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "chrome/browser/bookmarks/bookmark_model.h" | 19 #include "chrome/browser/bookmarks/bookmark_model.h" |
20 #include "chrome/browser/bookmarks/bookmark_utils.h" | 20 #include "chrome/browser/bookmarks/bookmark_utils.h" |
21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
22 #include "chrome/browser/history/archived_database.h" | |
23 #include "chrome/browser/history/expire_history_backend.h" | 22 #include "chrome/browser/history/expire_history_backend.h" |
24 #include "chrome/browser/history/history_database.h" | 23 #include "chrome/browser/history/history_database.h" |
25 #include "chrome/browser/history/history_notifications.h" | 24 #include "chrome/browser/history/history_notifications.h" |
26 #include "chrome/browser/history/thumbnail_database.h" | 25 #include "chrome/browser/history/thumbnail_database.h" |
27 #include "chrome/browser/history/top_sites.h" | 26 #include "chrome/browser/history/top_sites.h" |
28 #include "chrome/common/thumbnail_score.h" | 27 #include "chrome/common/thumbnail_score.h" |
29 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" |
30 #include "chrome/tools/profiles/thumbnail-inl.h" | 29 #include "chrome/tools/profiles/thumbnail-inl.h" |
31 #include "content/public/test/test_browser_thread.h" | 30 #include "content/public/test/test_browser_thread.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
33 #include "third_party/skia/include/core/SkBitmap.h" | 32 #include "third_party/skia/include/core/SkBitmap.h" |
34 #include "ui/gfx/codec/jpeg_codec.h" | 33 #include "ui/gfx/codec/jpeg_codec.h" |
35 | 34 |
36 using base::Time; | 35 using base::Time; |
37 using base::TimeDelta; | 36 using base::TimeDelta; |
38 using base::TimeTicks; | 37 using base::TimeTicks; |
39 using content::BrowserThread; | 38 using content::BrowserThread; |
40 | 39 |
41 // Filename constants. | 40 // Filename constants. |
42 static const base::FilePath::CharType kHistoryFile[] = | 41 static const base::FilePath::CharType kHistoryFile[] = |
43 FILE_PATH_LITERAL("History"); | 42 FILE_PATH_LITERAL("History"); |
44 static const base::FilePath::CharType kArchivedHistoryFile[] = | |
45 FILE_PATH_LITERAL("Archived History"); | |
46 static const base::FilePath::CharType kThumbnailFile[] = | 43 static const base::FilePath::CharType kThumbnailFile[] = |
47 FILE_PATH_LITERAL("Thumbnails"); | 44 FILE_PATH_LITERAL("Thumbnails"); |
48 | 45 |
49 // The test must be in the history namespace for the gtest forward declarations | 46 // The test must be in the history namespace for the gtest forward declarations |
50 // to work. It also eliminates a bunch of ugly "history::". | 47 // to work. It also eliminates a bunch of ugly "history::". |
51 namespace history { | 48 namespace history { |
52 | 49 |
53 // ExpireHistoryTest ----------------------------------------------------------- | 50 // ExpireHistoryTest ----------------------------------------------------------- |
54 | 51 |
55 class ExpireHistoryTest : public testing::Test, | 52 class ExpireHistoryTest : public testing::Test, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 97 |
101 BookmarkModel bookmark_model_; | 98 BookmarkModel bookmark_model_; |
102 | 99 |
103 base::MessageLoopForUI message_loop_; | 100 base::MessageLoopForUI message_loop_; |
104 content::TestBrowserThread ui_thread_; | 101 content::TestBrowserThread ui_thread_; |
105 content::TestBrowserThread db_thread_; | 102 content::TestBrowserThread db_thread_; |
106 | 103 |
107 ExpireHistoryBackend expirer_; | 104 ExpireHistoryBackend expirer_; |
108 | 105 |
109 scoped_ptr<HistoryDatabase> main_db_; | 106 scoped_ptr<HistoryDatabase> main_db_; |
110 scoped_ptr<ArchivedDatabase> archived_db_; | |
111 scoped_ptr<ThumbnailDatabase> thumb_db_; | 107 scoped_ptr<ThumbnailDatabase> thumb_db_; |
112 TestingProfile profile_; | 108 TestingProfile profile_; |
113 scoped_refptr<TopSites> top_sites_; | 109 scoped_refptr<TopSites> top_sites_; |
114 | 110 |
115 // Time at the beginning of the test, so everybody agrees what "now" is. | 111 // Time at the beginning of the test, so everybody agrees what "now" is. |
116 const Time now_; | 112 const Time now_; |
117 | 113 |
118 // Notifications intended to be broadcast, we can check these values to make | 114 // Notifications intended to be broadcast, we can check these values to make |
119 // sure that the deletor is doing the correct broadcasts. We own the details | 115 // sure that the deletor is doing the correct broadcasts. We own the details |
120 // pointers. | 116 // pointers. |
121 typedef std::vector< std::pair<int, HistoryDetails*> > | 117 typedef std::vector< std::pair<int, HistoryDetails*> > |
122 NotificationList; | 118 NotificationList; |
123 NotificationList notifications_; | 119 NotificationList notifications_; |
124 | 120 |
125 private: | 121 private: |
126 virtual void SetUp() { | 122 virtual void SetUp() { |
127 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); | 123 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); |
128 | 124 |
129 base::FilePath history_name = path().Append(kHistoryFile); | 125 base::FilePath history_name = path().Append(kHistoryFile); |
130 main_db_.reset(new HistoryDatabase); | 126 main_db_.reset(new HistoryDatabase); |
131 if (main_db_->Init(history_name) != sql::INIT_OK) | 127 if (main_db_->Init(history_name) != sql::INIT_OK) |
132 main_db_.reset(); | 128 main_db_.reset(); |
133 | 129 |
134 base::FilePath archived_name = path().Append(kArchivedHistoryFile); | |
135 archived_db_.reset(new ArchivedDatabase); | |
136 if (!archived_db_->Init(archived_name)) | |
137 archived_db_.reset(); | |
138 | |
139 base::FilePath thumb_name = path().Append(kThumbnailFile); | 130 base::FilePath thumb_name = path().Append(kThumbnailFile); |
140 thumb_db_.reset(new ThumbnailDatabase); | 131 thumb_db_.reset(new ThumbnailDatabase); |
141 if (thumb_db_->Init(thumb_name) != sql::INIT_OK) | 132 if (thumb_db_->Init(thumb_name) != sql::INIT_OK) |
142 thumb_db_.reset(); | 133 thumb_db_.reset(); |
143 | 134 |
144 expirer_.SetDatabases(main_db_.get(), archived_db_.get(), thumb_db_.get()); | 135 expirer_.SetDatabases(main_db_.get(), thumb_db_.get()); |
145 profile_.CreateTopSites(); | 136 profile_.CreateTopSites(); |
146 profile_.BlockUntilTopSitesLoaded(); | 137 profile_.BlockUntilTopSitesLoaded(); |
147 top_sites_ = profile_.GetTopSites(); | 138 top_sites_ = profile_.GetTopSites(); |
148 } | 139 } |
149 | 140 |
150 virtual void TearDown() { | 141 virtual void TearDown() { |
151 top_sites_ = NULL; | 142 top_sites_ = NULL; |
152 | 143 |
153 ClearLastNotifications(); | 144 ClearLastNotifications(); |
154 | 145 |
155 expirer_.SetDatabases(NULL, NULL, NULL); | 146 expirer_.SetDatabases(NULL, NULL); |
156 | 147 |
157 main_db_.reset(); | 148 main_db_.reset(); |
158 archived_db_.reset(); | |
159 thumb_db_.reset(); | 149 thumb_db_.reset(); |
160 } | 150 } |
161 | 151 |
162 // BroadcastNotificationDelegate implementation. | 152 // BroadcastNotificationDelegate implementation. |
163 virtual void BroadcastNotifications( | 153 virtual void BroadcastNotifications( |
164 int type, | 154 int type, |
165 scoped_ptr<HistoryDetails> details) OVERRIDE { | 155 scoped_ptr<HistoryDetails> details) OVERRIDE { |
166 // This gets called when there are notifications to broadcast. Instead, we | 156 // This gets called when there are notifications to broadcast. Instead, we |
167 // store them so we can tell that the correct notifications were sent. | 157 // store them so we can tell that the correct notifications were sent. |
168 notifications_.push_back(std::make_pair(type, details.release())); | 158 notifications_.push_back(std::make_pair(type, details.release())); |
169 } | 159 } |
170 virtual void NotifySyncURLsDeleted( | 160 virtual void NotifySyncURLsDeleted( |
171 bool all_history, | 161 bool all_history, |
172 bool archived, | 162 bool expired, |
173 URLRows* rows) OVERRIDE {} | 163 URLRows* rows) OVERRIDE {} |
174 }; | 164 }; |
175 | 165 |
176 // The example data consists of 4 visits. The middle two visits are to the | 166 // The example data consists of 4 visits. The middle two visits are to the |
177 // same URL, while the first and last are for unique ones. This allows a test | 167 // same URL, while the first and last are for unique ones. This allows a test |
178 // for the oldest or newest to include both a URL that should get totally | 168 // for the oldest or newest to include both a URL that should get totally |
179 // deleted (the one on the end) with one that should only get a visit deleted | 169 // deleted (the one on the end) with one that should only get a visit deleted |
180 // (with the one in the middle) when it picks the proper threshold time. | 170 // (with the one in the middle) when it picks the proper threshold time. |
181 // | 171 // |
182 // Each visit has indexed data, each URL has thumbnail. The first two URLs will | 172 // Each visit has indexed data, each URL has thumbnail. The first two URLs will |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 | 316 |
327 // Thumbnail should be gone. | 317 // Thumbnail should be gone. |
328 // TODO(sky): fix this, see comment in HasThumbnail. | 318 // TODO(sky): fix this, see comment in HasThumbnail. |
329 // EXPECT_FALSE(HasThumbnail(row.id())); | 319 // EXPECT_FALSE(HasThumbnail(row.id())); |
330 | 320 |
331 bool found_delete_notification = false; | 321 bool found_delete_notification = false; |
332 for (size_t i = 0; i < notifications_.size(); i++) { | 322 for (size_t i = 0; i < notifications_.size(); i++) { |
333 if (notifications_[i].first == chrome::NOTIFICATION_HISTORY_URLS_DELETED) { | 323 if (notifications_[i].first == chrome::NOTIFICATION_HISTORY_URLS_DELETED) { |
334 URLsDeletedDetails* details = reinterpret_cast<URLsDeletedDetails*>( | 324 URLsDeletedDetails* details = reinterpret_cast<URLsDeletedDetails*>( |
335 notifications_[i].second); | 325 notifications_[i].second); |
336 EXPECT_FALSE(details->archived); | 326 EXPECT_FALSE(details->expired); |
337 const history::URLRows& rows(details->rows); | 327 const history::URLRows& rows(details->rows); |
338 if (std::find_if(rows.begin(), rows.end(), | 328 if (std::find_if(rows.begin(), rows.end(), |
339 history::URLRow::URLRowHasURL(row.url())) != rows.end()) { | 329 history::URLRow::URLRowHasURL(row.url())) != rows.end()) { |
340 found_delete_notification = true; | 330 found_delete_notification = true; |
341 } | 331 } |
342 } else { | 332 } else { |
343 EXPECT_NE(notifications_[i].first, | 333 EXPECT_NE(notifications_[i].first, |
344 chrome::NOTIFICATION_HISTORY_URL_VISITED); | 334 chrome::NOTIFICATION_HISTORY_URL_VISITED); |
345 EXPECT_NE(notifications_[i].first, | 335 EXPECT_NE(notifications_[i].first, |
346 chrome::NOTIFICATION_HISTORY_URLS_MODIFIED); | 336 chrome::NOTIFICATION_HISTORY_URLS_MODIFIED); |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 chrome::FaviconID favicon_id = GetFavicon(url_row1.url(), chrome::FAVICON); | 701 chrome::FaviconID favicon_id = GetFavicon(url_row1.url(), chrome::FAVICON); |
712 EXPECT_TRUE(HasFavicon(favicon_id)); | 702 EXPECT_TRUE(HasFavicon(favicon_id)); |
713 // TODO(sky): fix this, see comment in HasThumbnail. | 703 // TODO(sky): fix this, see comment in HasThumbnail. |
714 // EXPECT_TRUE(HasThumbnail(new_url_row1.id())); | 704 // EXPECT_TRUE(HasThumbnail(new_url_row1.id())); |
715 favicon_id = GetFavicon(url_row1.url(), chrome::FAVICON); | 705 favicon_id = GetFavicon(url_row1.url(), chrome::FAVICON); |
716 EXPECT_TRUE(HasFavicon(favicon_id)); | 706 EXPECT_TRUE(HasFavicon(favicon_id)); |
717 // TODO(sky): fix this, see comment in HasThumbnail. | 707 // TODO(sky): fix this, see comment in HasThumbnail. |
718 // EXPECT_TRUE(HasThumbnail(new_url_row2.id())); | 708 // EXPECT_TRUE(HasThumbnail(new_url_row2.id())); |
719 } | 709 } |
720 | 710 |
721 TEST_F(ExpireHistoryTest, ArchiveHistoryBeforeUnstarred) { | 711 TEST_F(ExpireHistoryTest, ExpireHistoryBeforeUnstarred) { |
722 URLID url_ids[3]; | 712 URLID url_ids[3]; |
723 Time visit_times[4]; | 713 Time visit_times[4]; |
724 AddExampleData(url_ids, visit_times); | 714 AddExampleData(url_ids, visit_times); |
725 | 715 |
726 URLRow url_row1, url_row2; | 716 URLRow url_row1, url_row2; |
727 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); | 717 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); |
728 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); | 718 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); |
729 | 719 |
730 // Archive the oldest two visits. This will actually result in deleting them | 720 // Expire the oldest two visits. |
731 // since their transition types are empty (not important). | 721 expirer_.ExpireHistoryBefore(visit_times[1]); |
732 expirer_.ArchiveHistoryBefore(visit_times[1]); | |
733 | 722 |
734 // The first URL should be deleted, the second should not be affected. | 723 // The first URL should be deleted along with its sole visit. The second URL |
| 724 // itself should not be affected, as there is still one more visit to it, but |
| 725 // its first visit should be deleted. |
735 URLRow temp_row; | 726 URLRow temp_row; |
736 EXPECT_FALSE(main_db_->GetURLRow(url_ids[0], &temp_row)); | 727 EXPECT_FALSE(main_db_->GetURLRow(url_ids[0], &temp_row)); |
737 EXPECT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); | 728 EXPECT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); |
| 729 VisitVector visits; |
| 730 main_db_->GetVisitsForURL(temp_row.id(), &visits); |
| 731 EXPECT_EQ(1U, visits.size()); |
| 732 EXPECT_EQ(visit_times[2], visits[0].visit_time); |
738 EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row)); | 733 EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row)); |
739 | 734 |
740 // Make sure the archived database has nothing in it. | 735 // Now expire one more visit so that the second URL should be removed. The |
741 EXPECT_FALSE(archived_db_->GetRowForURL(url_row1.url(), NULL)); | 736 // third URL and its visit should be intact. |
742 EXPECT_FALSE(archived_db_->GetRowForURL(url_row2.url(), NULL)); | 737 expirer_.ExpireHistoryBefore(visit_times[2]); |
743 | |
744 // Now archive one more visit so that the middle URL should be removed. This | |
745 // one will actually be archived instead of deleted. | |
746 expirer_.ArchiveHistoryBefore(visit_times[2]); | |
747 EXPECT_FALSE(main_db_->GetURLRow(url_ids[1], &temp_row)); | 738 EXPECT_FALSE(main_db_->GetURLRow(url_ids[1], &temp_row)); |
748 EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row)); | 739 EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row)); |
749 | 740 main_db_->GetVisitsForURL(temp_row.id(), &visits); |
750 // Make sure the archived database has an entry for the second URL. | 741 EXPECT_EQ(1U, visits.size()); |
751 URLRow archived_row; | |
752 // Note that the ID is different in the archived DB, so look up by URL. | |
753 EXPECT_TRUE(archived_db_->GetRowForURL(url_row1.url(), &archived_row)); | |
754 VisitVector archived_visits; | |
755 archived_db_->GetVisitsForURL(archived_row.id(), &archived_visits); | |
756 EXPECT_EQ(1U, archived_visits.size()); | |
757 } | 742 } |
758 | 743 |
759 TEST_F(ExpireHistoryTest, ArchiveHistoryBeforeStarred) { | 744 TEST_F(ExpireHistoryTest, ExpireHistoryBeforeStarred) { |
760 URLID url_ids[3]; | 745 URLID url_ids[3]; |
761 Time visit_times[4]; | 746 Time visit_times[4]; |
762 AddExampleData(url_ids, visit_times); | 747 AddExampleData(url_ids, visit_times); |
763 | 748 |
764 URLRow url_row0, url_row1; | 749 URLRow url_row0, url_row1; |
765 ASSERT_TRUE(main_db_->GetURLRow(url_ids[0], &url_row0)); | 750 ASSERT_TRUE(main_db_->GetURLRow(url_ids[0], &url_row0)); |
766 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); | 751 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); |
767 | 752 |
768 // Star the URLs. | 753 // Star the URLs. |
769 StarURL(url_row0.url()); | 754 StarURL(url_row0.url()); |
770 StarURL(url_row1.url()); | 755 StarURL(url_row1.url()); |
771 | 756 |
772 // Now archive the first three visits (first two URLs). The first two visits | 757 // Now expire the first three visits (first two URLs). The first three visits |
773 // should be, the third deleted, but the URL records should not. | 758 // should be deleted, but the URL records should not. |
774 expirer_.ArchiveHistoryBefore(visit_times[2]); | 759 expirer_.ExpireHistoryBefore(visit_times[2]); |
775 | 760 |
776 // The first URL should have its visit deleted, but it should still be present | 761 // The first URL should have its visit deleted, but it should still be present |
777 // in the main DB and not in the archived one since it is starred. | 762 // in the main DB since it is starred. |
778 URLRow temp_row; | 763 URLRow temp_row; |
779 ASSERT_TRUE(main_db_->GetURLRow(url_ids[0], &temp_row)); | 764 ASSERT_TRUE(main_db_->GetURLRow(url_ids[0], &temp_row)); |
780 // Note that the ID is different in the archived DB, so look up by URL. | |
781 EXPECT_FALSE(archived_db_->GetRowForURL(temp_row.url(), NULL)); | |
782 VisitVector visits; | 765 VisitVector visits; |
783 main_db_->GetVisitsForURL(temp_row.id(), &visits); | 766 main_db_->GetVisitsForURL(temp_row.id(), &visits); |
784 EXPECT_EQ(0U, visits.size()); | 767 EXPECT_EQ(0U, visits.size()); |
785 | 768 |
786 // The second URL should have its first visit deleted and its second visit | 769 // The second URL should have both its visits deleted, but it should still be |
787 // archived. It should be present in both the main DB (because it's starred) | 770 // present in the main DB because it is starred. |
788 // and the archived DB (for the archived visit). | |
789 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); | 771 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); |
790 main_db_->GetVisitsForURL(temp_row.id(), &visits); | 772 main_db_->GetVisitsForURL(temp_row.id(), &visits); |
791 EXPECT_EQ(0U, visits.size()); | 773 EXPECT_EQ(0U, visits.size()); |
792 | 774 |
793 // Note that the ID is different in the archived DB, so look up by URL. | |
794 ASSERT_TRUE(archived_db_->GetRowForURL(temp_row.url(), &temp_row)); | |
795 archived_db_->GetVisitsForURL(temp_row.id(), &visits); | |
796 ASSERT_EQ(1U, visits.size()); | |
797 EXPECT_TRUE(visit_times[2] == visits[0].visit_time); | |
798 | |
799 // The third URL should be unchanged. | 775 // The third URL should be unchanged. |
800 EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row)); | 776 EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row)); |
801 EXPECT_FALSE(archived_db_->GetRowForURL(temp_row.url(), NULL)); | 777 main_db_->GetVisitsForURL(temp_row.id(), &visits); |
| 778 EXPECT_EQ(1U, visits.size()); |
802 } | 779 } |
803 | 780 |
804 // Tests the return values from ArchiveSomeOldHistory. The rest of the | 781 // Tests the return values from ExpireSomeOldHistory. The rest of the |
805 // functionality of this function is tested by the ArchiveHistoryBefore* | 782 // functionality of this function is tested by the ExpireHistoryBefore* |
806 // tests which use this function internally. | 783 // tests which use this function internally. |
807 TEST_F(ExpireHistoryTest, ArchiveSomeOldHistory) { | 784 TEST_F(ExpireHistoryTest, ExpireSomeOldHistory) { |
808 URLID url_ids[3]; | 785 URLID url_ids[3]; |
809 Time visit_times[4]; | 786 Time visit_times[4]; |
810 AddExampleData(url_ids, visit_times); | 787 AddExampleData(url_ids, visit_times); |
811 const ExpiringVisitsReader* reader = expirer_.GetAllVisitsReader(); | 788 const ExpiringVisitsReader* reader = expirer_.GetAllVisitsReader(); |
812 | 789 |
813 // Deleting a time range with no URLs should return false (nothing found). | 790 // Deleting a time range with no URLs should return false (nothing found). |
814 EXPECT_FALSE(expirer_.ArchiveSomeOldHistory( | 791 EXPECT_FALSE(expirer_.ExpireSomeOldHistory( |
815 visit_times[0] - TimeDelta::FromDays(100), reader, 1)); | 792 visit_times[0] - TimeDelta::FromDays(100), reader, 1)); |
816 | 793 |
817 // Deleting a time range with not up the the max results should also return | 794 // Deleting a time range with not up the the max results should also return |
818 // false (there will only be one visit deleted in this range). | 795 // false (there will only be one visit deleted in this range). |
819 EXPECT_FALSE(expirer_.ArchiveSomeOldHistory(visit_times[0], reader, 2)); | 796 EXPECT_FALSE(expirer_.ExpireSomeOldHistory(visit_times[0], reader, 2)); |
820 | 797 |
821 // Deleting a time range with the max number of results should return true | 798 // Deleting a time range with the max number of results should return true |
822 // (max deleted). | 799 // (max deleted). |
823 EXPECT_TRUE(expirer_.ArchiveSomeOldHistory(visit_times[2], reader, 1)); | 800 EXPECT_TRUE(expirer_.ExpireSomeOldHistory(visit_times[2], reader, 1)); |
824 } | 801 } |
825 | 802 |
826 TEST_F(ExpireHistoryTest, ExpiringVisitsReader) { | 803 TEST_F(ExpireHistoryTest, ExpiringVisitsReader) { |
827 URLID url_ids[3]; | 804 URLID url_ids[3]; |
828 Time visit_times[4]; | 805 Time visit_times[4]; |
829 AddExampleData(url_ids, visit_times); | 806 AddExampleData(url_ids, visit_times); |
830 | 807 |
831 const ExpiringVisitsReader* all = expirer_.GetAllVisitsReader(); | 808 const ExpiringVisitsReader* all = expirer_.GetAllVisitsReader(); |
832 const ExpiringVisitsReader* auto_subframes = | 809 const ExpiringVisitsReader* auto_subframes = |
833 expirer_.GetAutoSubframeVisitsReader(); | 810 expirer_.GetAutoSubframeVisitsReader(); |
(...skipping 12 matching lines...) Expand all Loading... |
846 | 823 |
847 // Verify that the early expiration threshold was updated, since there are no | 824 // Verify that the early expiration threshold was updated, since there are no |
848 // AUTO_SUBFRAME visits in the given time range. | 825 // AUTO_SUBFRAME visits in the given time range. |
849 EXPECT_TRUE(now <= main_db_->GetEarlyExpirationThreshold()); | 826 EXPECT_TRUE(now <= main_db_->GetEarlyExpirationThreshold()); |
850 | 827 |
851 // Now, read all visits and verify that there's at least one. | 828 // Now, read all visits and verify that there's at least one. |
852 EXPECT_TRUE(all->Read(now, main_db_.get(), &visits, 1)); | 829 EXPECT_TRUE(all->Read(now, main_db_.get(), &visits, 1)); |
853 EXPECT_EQ(1U, visits.size()); | 830 EXPECT_EQ(1U, visits.size()); |
854 } | 831 } |
855 | 832 |
856 // Tests how ArchiveSomeOldHistory treats source information. | |
857 TEST_F(ExpireHistoryTest, ArchiveSomeOldHistoryWithSource) { | |
858 const GURL url("www.testsource.com"); | |
859 URLID url_id; | |
860 AddExampleSourceData(url, &url_id); | |
861 const ExpiringVisitsReader* reader = expirer_.GetAllVisitsReader(); | |
862 | |
863 // Archiving all the visits we added. | |
864 ASSERT_FALSE(expirer_.ArchiveSomeOldHistory(Time::Now(), reader, 10)); | |
865 | |
866 URLRow archived_row; | |
867 ASSERT_TRUE(archived_db_->GetRowForURL(url, &archived_row)); | |
868 VisitVector archived_visits; | |
869 archived_db_->GetVisitsForURL(archived_row.id(), &archived_visits); | |
870 ASSERT_EQ(4U, archived_visits.size()); | |
871 VisitSourceMap sources; | |
872 archived_db_->GetVisitsSource(archived_visits, &sources); | |
873 ASSERT_EQ(3U, sources.size()); | |
874 int result = 0; | |
875 VisitSourceMap::iterator iter; | |
876 for (int i = 0; i < 4; i++) { | |
877 iter = sources.find(archived_visits[i].visit_id); | |
878 if (iter == sources.end()) | |
879 continue; | |
880 switch (iter->second) { | |
881 case history::SOURCE_EXTENSION: | |
882 result |= 0x1; | |
883 break; | |
884 case history::SOURCE_FIREFOX_IMPORTED: | |
885 result |= 0x2; | |
886 break; | |
887 case history::SOURCE_SYNCED: | |
888 result |= 0x4; | |
889 default: | |
890 break; | |
891 } | |
892 } | |
893 EXPECT_EQ(0x7, result); | |
894 main_db_->GetVisitsSource(archived_visits, &sources); | |
895 EXPECT_EQ(0U, sources.size()); | |
896 main_db_->GetVisitsForURL(url_id, &archived_visits); | |
897 EXPECT_EQ(0U, archived_visits.size()); | |
898 } | |
899 | |
900 // TODO(brettw) add some visits with no URL to make sure everything is updated | 833 // TODO(brettw) add some visits with no URL to make sure everything is updated |
901 // properly. Have the visits also refer to nonexistent FTS rows. | 834 // properly. Have the visits also refer to nonexistent FTS rows. |
902 // | 835 // |
903 // Maybe also refer to invalid favicons. | 836 // Maybe also refer to invalid favicons. |
904 | 837 |
905 } // namespace history | 838 } // namespace history |
OLD | NEW |