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

Side by Side Diff: chrome/browser/history/expire_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: Rebased, improved comments, fixed minor formatting nits. Created 6 years, 6 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 <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/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/history/archived_database.h"
21 #include "chrome/browser/history/expire_history_backend.h" 20 #include "chrome/browser/history/expire_history_backend.h"
22 #include "chrome/browser/history/history_database.h" 21 #include "chrome/browser/history/history_database.h"
23 #include "chrome/browser/history/history_notifications.h" 22 #include "chrome/browser/history/history_notifications.h"
24 #include "chrome/browser/history/thumbnail_database.h" 23 #include "chrome/browser/history/thumbnail_database.h"
25 #include "chrome/browser/history/top_sites.h" 24 #include "chrome/browser/history/top_sites.h"
26 #include "chrome/common/thumbnail_score.h" 25 #include "chrome/common/thumbnail_score.h"
27 #include "chrome/test/base/testing_profile.h" 26 #include "chrome/test/base/testing_profile.h"
28 #include "chrome/tools/profiles/thumbnail-inl.h" 27 #include "chrome/tools/profiles/thumbnail-inl.h"
29 #include "components/bookmarks/browser/bookmark_model.h" 28 #include "components/bookmarks/browser/bookmark_model.h"
30 #include "components/bookmarks/browser/bookmark_utils.h" 29 #include "components/bookmarks/browser/bookmark_utils.h"
31 #include "components/bookmarks/test/test_bookmark_client.h" 30 #include "components/bookmarks/test/test_bookmark_client.h"
32 #include "content/public/test/test_browser_thread.h" 31 #include "content/public/test/test_browser_thread.h"
33 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
34 #include "third_party/skia/include/core/SkBitmap.h" 33 #include "third_party/skia/include/core/SkBitmap.h"
35 #include "ui/gfx/codec/jpeg_codec.h" 34 #include "ui/gfx/codec/jpeg_codec.h"
36 35
37 using base::Time; 36 using base::Time;
38 using base::TimeDelta; 37 using base::TimeDelta;
39 using base::TimeTicks; 38 using base::TimeTicks;
40 using content::BrowserThread; 39 using content::BrowserThread;
41 40
42 // Filename constants. 41 // Filename constants.
43 static const base::FilePath::CharType kHistoryFile[] = 42 static const base::FilePath::CharType kHistoryFile[] =
44 FILE_PATH_LITERAL("History"); 43 FILE_PATH_LITERAL("History");
45 static const base::FilePath::CharType kArchivedHistoryFile[] =
46 FILE_PATH_LITERAL("Archived History");
47 static const base::FilePath::CharType kThumbnailFile[] = 44 static const base::FilePath::CharType kThumbnailFile[] =
48 FILE_PATH_LITERAL("Thumbnails"); 45 FILE_PATH_LITERAL("Thumbnails");
49 46
50 // The test must be in the history namespace for the gtest forward declarations 47 // The test must be in the history namespace for the gtest forward declarations
51 // to work. It also eliminates a bunch of ugly "history::". 48 // to work. It also eliminates a bunch of ugly "history::".
52 namespace history { 49 namespace history {
53 50
54 // ExpireHistoryTest ----------------------------------------------------------- 51 // ExpireHistoryTest -----------------------------------------------------------
55 52
56 class ExpireHistoryTest : public testing::Test, 53 class ExpireHistoryTest : public testing::Test,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 test::TestBookmarkClient bookmark_client_; 102 test::TestBookmarkClient bookmark_client_;
106 scoped_ptr<BookmarkModel> bookmark_model_; 103 scoped_ptr<BookmarkModel> bookmark_model_;
107 104
108 base::MessageLoopForUI message_loop_; 105 base::MessageLoopForUI message_loop_;
109 content::TestBrowserThread ui_thread_; 106 content::TestBrowserThread ui_thread_;
110 content::TestBrowserThread db_thread_; 107 content::TestBrowserThread db_thread_;
111 108
112 ExpireHistoryBackend expirer_; 109 ExpireHistoryBackend expirer_;
113 110
114 scoped_ptr<HistoryDatabase> main_db_; 111 scoped_ptr<HistoryDatabase> main_db_;
115 scoped_ptr<ArchivedDatabase> archived_db_;
116 scoped_ptr<ThumbnailDatabase> thumb_db_; 112 scoped_ptr<ThumbnailDatabase> thumb_db_;
117 TestingProfile profile_; 113 TestingProfile profile_;
118 scoped_refptr<TopSites> top_sites_; 114 scoped_refptr<TopSites> top_sites_;
119 115
120 // Time at the beginning of the test, so everybody agrees what "now" is. 116 // Time at the beginning of the test, so everybody agrees what "now" is.
121 const Time now_; 117 const Time now_;
122 118
123 // Notifications intended to be broadcast, we can check these values to make 119 // Notifications intended to be broadcast, we can check these values to make
124 // sure that the deletor is doing the correct broadcasts. We own the details 120 // sure that the deletor is doing the correct broadcasts. We own the details
125 // pointers. 121 // pointers.
126 typedef std::vector< std::pair<int, HistoryDetails*> > 122 typedef std::vector< std::pair<int, HistoryDetails*> >
127 NotificationList; 123 NotificationList;
128 NotificationList notifications_; 124 NotificationList notifications_;
129 125
130 private: 126 private:
131 virtual void SetUp() { 127 virtual void SetUp() {
132 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); 128 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir());
133 129
134 base::FilePath history_name = path().Append(kHistoryFile); 130 base::FilePath history_name = path().Append(kHistoryFile);
135 main_db_.reset(new HistoryDatabase); 131 main_db_.reset(new HistoryDatabase);
136 if (main_db_->Init(history_name) != sql::INIT_OK) 132 if (main_db_->Init(history_name) != sql::INIT_OK)
137 main_db_.reset(); 133 main_db_.reset();
138 134
139 base::FilePath archived_name = path().Append(kArchivedHistoryFile);
140 archived_db_.reset(new ArchivedDatabase);
141 if (!archived_db_->Init(archived_name))
142 archived_db_.reset();
143
144 base::FilePath thumb_name = path().Append(kThumbnailFile); 135 base::FilePath thumb_name = path().Append(kThumbnailFile);
145 thumb_db_.reset(new ThumbnailDatabase); 136 thumb_db_.reset(new ThumbnailDatabase);
146 if (thumb_db_->Init(thumb_name) != sql::INIT_OK) 137 if (thumb_db_->Init(thumb_name) != sql::INIT_OK)
147 thumb_db_.reset(); 138 thumb_db_.reset();
148 139
149 expirer_.SetDatabases(main_db_.get(), archived_db_.get(), thumb_db_.get()); 140 expirer_.SetDatabases(main_db_.get(), thumb_db_.get());
150 profile_.CreateTopSites(); 141 profile_.CreateTopSites();
151 profile_.BlockUntilTopSitesLoaded(); 142 profile_.BlockUntilTopSitesLoaded();
152 top_sites_ = profile_.GetTopSites(); 143 top_sites_ = profile_.GetTopSites();
153 } 144 }
154 145
155 virtual void TearDown() { 146 virtual void TearDown() {
156 top_sites_ = NULL; 147 top_sites_ = NULL;
157 148
158 ClearLastNotifications(); 149 ClearLastNotifications();
159 150
160 expirer_.SetDatabases(NULL, NULL, NULL); 151 expirer_.SetDatabases(NULL, NULL);
161 152
162 main_db_.reset(); 153 main_db_.reset();
163 archived_db_.reset();
164 thumb_db_.reset(); 154 thumb_db_.reset();
165 } 155 }
166 156
167 // BroadcastNotificationDelegate: 157 // BroadcastNotificationDelegate:
168 virtual void BroadcastNotifications( 158 virtual void BroadcastNotifications(
169 int type, 159 int type,
170 scoped_ptr<HistoryDetails> details) OVERRIDE { 160 scoped_ptr<HistoryDetails> details) OVERRIDE {
171 // This gets called when there are notifications to broadcast. Instead, we 161 // This gets called when there are notifications to broadcast. Instead, we
172 // store them so we can tell that the correct notifications were sent. 162 // store them so we can tell that the correct notifications were sent.
173 notifications_.push_back(std::make_pair(type, details.release())); 163 notifications_.push_back(std::make_pair(type, details.release()));
174 } 164 }
175 virtual void NotifySyncURLsModified(URLRows* rows) OVERRIDE {} 165 virtual void NotifySyncURLsModified(URLRows* rows) OVERRIDE {}
176 virtual void NotifySyncURLsDeleted(bool all_history, 166 virtual void NotifySyncURLsDeleted(bool all_history,
177 bool archived, 167 bool expired,
178 URLRows* rows) OVERRIDE {} 168 URLRows* rows) OVERRIDE {}
179 }; 169 };
180 170
181 // The example data consists of 4 visits. The middle two visits are to the 171 // The example data consists of 4 visits. The middle two visits are to the
182 // same URL, while the first and last are for unique ones. This allows a test 172 // same URL, while the first and last are for unique ones. This allows a test
183 // for the oldest or newest to include both a URL that should get totally 173 // for the oldest or newest to include both a URL that should get totally
184 // deleted (the one on the end) with one that should only get a visit deleted 174 // deleted (the one on the end) with one that should only get a visit deleted
185 // (with the one in the middle) when it picks the proper threshold time. 175 // (with the one in the middle) when it picks the proper threshold time.
186 // 176 //
187 // Each visit has indexed data, each URL has thumbnail. The first two URLs will 177 // Each visit has indexed data, each URL has thumbnail. The first two URLs will
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // TODO(sky): fix this. This test isn't really valid for TopSites. For 303 // TODO(sky): fix this. This test isn't really valid for TopSites. For
314 // TopSites we should be checking URL always, not the id. 304 // TopSites we should be checking URL always, not the id.
315 URLRow info; 305 URLRow info;
316 if (!main_db_->GetURLRow(url_id, &info)) 306 if (!main_db_->GetURLRow(url_id, &info))
317 return false; 307 return false;
318 GURL url = info.url(); 308 GURL url = info.url();
319 scoped_refptr<base::RefCountedMemory> data; 309 scoped_refptr<base::RefCountedMemory> data;
320 return top_sites_->GetPageThumbnail(url, false, &data); 310 return top_sites_->GetPageThumbnail(url, false, &data);
321 } 311 }
322 312
323 void ExpireHistoryTest::EnsureURLInfoGone(const URLRow& row, bool archived) { 313 void ExpireHistoryTest::EnsureURLInfoGone(const URLRow& row, bool expired) {
324 // The passed in |row| must originate from |main_db_| so that its ID will be 314 // The passed in |row| must originate from |main_db_| so that its ID will be
325 // set to what had been in effect in |main_db_| before the deletion. 315 // set to what had been in effect in |main_db_| before the deletion.
326 ASSERT_NE(0, row.id()); 316 ASSERT_NE(0, row.id());
327 317
328 // Verify the URL no longer exists. 318 // Verify the URL no longer exists.
329 URLRow temp_row; 319 URLRow temp_row;
330 EXPECT_FALSE(main_db_->GetURLRow(row.id(), &temp_row)); 320 EXPECT_FALSE(main_db_->GetURLRow(row.id(), &temp_row));
331 321
332 // There should be no visits. 322 // There should be no visits.
333 VisitVector visits; 323 VisitVector visits;
334 main_db_->GetVisitsForURL(row.id(), &visits); 324 main_db_->GetVisitsForURL(row.id(), &visits);
335 EXPECT_EQ(0U, visits.size()); 325 EXPECT_EQ(0U, visits.size());
336 326
337 // Thumbnail should be gone. 327 // Thumbnail should be gone.
338 // TODO(sky): fix this, see comment in HasThumbnail. 328 // TODO(sky): fix this, see comment in HasThumbnail.
339 // EXPECT_FALSE(HasThumbnail(row.id())); 329 // EXPECT_FALSE(HasThumbnail(row.id()));
340 330
341 bool found_delete_notification = false; 331 bool found_delete_notification = false;
342 for (size_t i = 0; i < notifications_.size(); i++) { 332 for (size_t i = 0; i < notifications_.size(); i++) {
343 if (notifications_[i].first == chrome::NOTIFICATION_HISTORY_URLS_DELETED) { 333 if (notifications_[i].first == chrome::NOTIFICATION_HISTORY_URLS_DELETED) {
344 URLsDeletedDetails* details = reinterpret_cast<URLsDeletedDetails*>( 334 URLsDeletedDetails* details = reinterpret_cast<URLsDeletedDetails*>(
345 notifications_[i].second); 335 notifications_[i].second);
346 EXPECT_EQ(archived, details->archived); 336 EXPECT_EQ(expired, details->expired);
347 const history::URLRows& rows(details->rows); 337 const history::URLRows& rows(details->rows);
348 history::URLRows::const_iterator it_row = std::find_if( 338 history::URLRows::const_iterator it_row = std::find_if(
349 rows.begin(), rows.end(), history::URLRow::URLRowHasURL(row.url())); 339 rows.begin(), rows.end(), history::URLRow::URLRowHasURL(row.url()));
350 if (it_row != rows.end()) { 340 if (it_row != rows.end()) {
351 // Further verify that the ID is set to what had been in effect in the 341 // Further verify that the ID is set to what had been in effect in the
352 // main database before the deletion. The InMemoryHistoryBackend relies 342 // main database before the deletion. The InMemoryHistoryBackend relies
353 // on this to delete its cached copy of the row. 343 // on this to delete its cached copy of the row.
354 EXPECT_EQ(row.id(), it_row->id()); 344 EXPECT_EQ(row.id(), it_row->id());
355 found_delete_notification = true; 345 found_delete_notification = true;
356 } 346 }
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 GetFavicon(url_row1.url(), favicon_base::FAVICON); 750 GetFavicon(url_row1.url(), favicon_base::FAVICON);
761 EXPECT_TRUE(HasFavicon(favicon_id)); 751 EXPECT_TRUE(HasFavicon(favicon_id));
762 // TODO(sky): fix this, see comment in HasThumbnail. 752 // TODO(sky): fix this, see comment in HasThumbnail.
763 // EXPECT_TRUE(HasThumbnail(new_url_row1.id())); 753 // EXPECT_TRUE(HasThumbnail(new_url_row1.id()));
764 favicon_id = GetFavicon(url_row1.url(), favicon_base::FAVICON); 754 favicon_id = GetFavicon(url_row1.url(), favicon_base::FAVICON);
765 EXPECT_TRUE(HasFavicon(favicon_id)); 755 EXPECT_TRUE(HasFavicon(favicon_id));
766 // TODO(sky): fix this, see comment in HasThumbnail. 756 // TODO(sky): fix this, see comment in HasThumbnail.
767 // EXPECT_TRUE(HasThumbnail(new_url_row2.id())); 757 // EXPECT_TRUE(HasThumbnail(new_url_row2.id()));
768 } 758 }
769 759
770 TEST_F(ExpireHistoryTest, ArchiveHistoryBeforeUnstarred) { 760 TEST_F(ExpireHistoryTest, ExpireHistoryBeforeUnstarred) {
771 URLID url_ids[3]; 761 URLID url_ids[3];
772 Time visit_times[4]; 762 Time visit_times[4];
773 AddExampleData(url_ids, visit_times); 763 AddExampleData(url_ids, visit_times);
774 764
775 URLRow url_row0, url_row1, url_row2; 765 URLRow url_row0, url_row1, url_row2;
776 ASSERT_TRUE(main_db_->GetURLRow(url_ids[0], &url_row0)); 766 ASSERT_TRUE(main_db_->GetURLRow(url_ids[0], &url_row0));
777 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); 767 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1));
778 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2)); 768 ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &url_row2));
779 769
780 // Archive the oldest two visits. This will actually result in deleting them 770 // Expire the oldest two visits.
781 // since their transition types are empty. 771 expirer_.ExpireHistoryBefore(visit_times[1]);
782 expirer_.ArchiveHistoryBefore(visit_times[1]);
783 772
784 // The first URL should be deleted, the second should not. 773 // The first URL should be deleted along with its sole visit. The second URL
774 // itself should not be affected, as there is still one more visit to it, but
775 // its first visit should be deleted.
785 URLRow temp_row; 776 URLRow temp_row;
786 EnsureURLInfoGone(url_row0, true); 777 EnsureURLInfoGone(url_row0, true);
787 EXPECT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); 778 EXPECT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row));
788 EXPECT_TRUE(ModifiedNotificationSent(url_row1.url())); 779 EXPECT_TRUE(ModifiedNotificationSent(url_row1.url()));
780 VisitVector visits;
781 main_db_->GetVisitsForURL(temp_row.id(), &visits);
782 EXPECT_EQ(1U, visits.size());
783 EXPECT_EQ(visit_times[2], visits[0].visit_time);
789 EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row)); 784 EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row));
790 785
791 // Make sure the archived database has nothing in it. 786 // Now expire one more visit so that the second URL should be removed. The
792 EXPECT_FALSE(archived_db_->GetRowForURL(url_row1.url(), NULL)); 787 // third URL and its visit should be intact.
793 EXPECT_FALSE(archived_db_->GetRowForURL(url_row2.url(), NULL));
794
795 // Now archive one more visit so that the middle URL should be removed. This
796 // one will actually be archived instead of deleted.
797 ClearLastNotifications(); 788 ClearLastNotifications();
798 expirer_.ArchiveHistoryBefore(visit_times[2]); 789 expirer_.ExpireHistoryBefore(visit_times[2]);
799 EnsureURLInfoGone(url_row1, true); 790 EnsureURLInfoGone(url_row1, true);
800 EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row)); 791 EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row));
801 792 main_db_->GetVisitsForURL(temp_row.id(), &visits);
802 // Make sure the archived database has an entry for the second URL. 793 EXPECT_EQ(1U, visits.size());
803 URLRow archived_row;
804 // Note that the ID is different in the archived DB, so look up by URL.
805 EXPECT_TRUE(archived_db_->GetRowForURL(url_row1.url(), &archived_row));
806 VisitVector archived_visits;
807 archived_db_->GetVisitsForURL(archived_row.id(), &archived_visits);
808 EXPECT_EQ(1U, archived_visits.size());
809 } 794 }
810 795
811 TEST_F(ExpireHistoryTest, ArchiveHistoryBeforeStarred) { 796 TEST_F(ExpireHistoryTest, ExpireHistoryBeforeStarred) {
812 URLID url_ids[3]; 797 URLID url_ids[3];
813 Time visit_times[4]; 798 Time visit_times[4];
814 AddExampleData(url_ids, visit_times); 799 AddExampleData(url_ids, visit_times);
815 800
816 URLRow url_row0, url_row1; 801 URLRow url_row0, url_row1;
817 ASSERT_TRUE(main_db_->GetURLRow(url_ids[0], &url_row0)); 802 ASSERT_TRUE(main_db_->GetURLRow(url_ids[0], &url_row0));
818 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1)); 803 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &url_row1));
819 804
820 // Star the URLs. 805 // Star the URLs.
821 StarURL(url_row0.url()); 806 StarURL(url_row0.url());
822 StarURL(url_row1.url()); 807 StarURL(url_row1.url());
823 808
824 // Now archive the first three visits (first two URLs). The first two visits 809 // Now expire the first three visits (first two URLs). The first three visits
825 // should be deleted, the third archived. 810 // should be deleted, but the URL records themselves should not, as they are
826 expirer_.ArchiveHistoryBefore(visit_times[2]); 811 // starred.
812 expirer_.ExpireHistoryBefore(visit_times[2]);
827 813
828 // The first URL should have its visit deleted, but it should still be present
829 // in the main DB and not in the archived one since it is starred.
830 URLRow temp_row; 814 URLRow temp_row;
831 ASSERT_TRUE(main_db_->GetURLRow(url_ids[0], &temp_row)); 815 ASSERT_TRUE(main_db_->GetURLRow(url_ids[0], &temp_row));
832 // Note that the ID is different in the archived DB, so look up by URL.
833 EXPECT_FALSE(archived_db_->GetRowForURL(temp_row.url(), NULL));
834 EXPECT_TRUE(ModifiedNotificationSent(url_row0.url())); 816 EXPECT_TRUE(ModifiedNotificationSent(url_row0.url()));
835 VisitVector visits; 817 VisitVector visits;
836 main_db_->GetVisitsForURL(temp_row.id(), &visits); 818 main_db_->GetVisitsForURL(temp_row.id(), &visits);
837 EXPECT_EQ(0U, visits.size()); 819 EXPECT_EQ(0U, visits.size());
838 820
839 // The second URL should have its first visit deleted and its second visit
840 // archived. It should be present in both the main DB (because it's starred)
841 // and the archived DB (for the archived visit).
842 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row)); 821 ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &temp_row));
843 EXPECT_TRUE(ModifiedNotificationSent(url_row1.url())); 822 EXPECT_TRUE(ModifiedNotificationSent(url_row1.url()));
844 main_db_->GetVisitsForURL(temp_row.id(), &visits); 823 main_db_->GetVisitsForURL(temp_row.id(), &visits);
845 EXPECT_EQ(0U, visits.size()); 824 EXPECT_EQ(0U, visits.size());
846 825
847 // Note that the ID is different in the archived DB, so look up by URL.
848 ASSERT_TRUE(archived_db_->GetRowForURL(temp_row.url(), &temp_row));
849 archived_db_->GetVisitsForURL(temp_row.id(), &visits);
850 ASSERT_EQ(1U, visits.size());
851 EXPECT_TRUE(visit_times[2] == visits[0].visit_time);
852
853 // The third URL should be unchanged. 826 // The third URL should be unchanged.
854 EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row)); 827 EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row));
855 EXPECT_FALSE(archived_db_->GetRowForURL(temp_row.url(), NULL));
856 EXPECT_FALSE(ModifiedNotificationSent(temp_row.url())); 828 EXPECT_FALSE(ModifiedNotificationSent(temp_row.url()));
829 main_db_->GetVisitsForURL(temp_row.id(), &visits);
830 EXPECT_EQ(1U, visits.size());
857 } 831 }
858 832
859 // Tests the return values from ArchiveSomeOldHistory. The rest of the 833 // Tests the return values from ExpireSomeOldHistory. The rest of the
860 // functionality of this function is tested by the ArchiveHistoryBefore* 834 // functionality of this function is tested by the ExpireHistoryBefore*
861 // tests which use this function internally. 835 // tests which use this function internally.
862 TEST_F(ExpireHistoryTest, ArchiveSomeOldHistory) { 836 TEST_F(ExpireHistoryTest, ExpireSomeOldHistory) {
863 URLID url_ids[3]; 837 URLID url_ids[3];
864 Time visit_times[4]; 838 Time visit_times[4];
865 AddExampleData(url_ids, visit_times); 839 AddExampleData(url_ids, visit_times);
866 const ExpiringVisitsReader* reader = expirer_.GetAllVisitsReader(); 840 const ExpiringVisitsReader* reader = expirer_.GetAllVisitsReader();
867 841
868 // Deleting a time range with no URLs should return false (nothing found). 842 // Deleting a time range with no URLs should return false (nothing found).
869 EXPECT_FALSE(expirer_.ArchiveSomeOldHistory( 843 EXPECT_FALSE(expirer_.ExpireSomeOldHistory(
870 visit_times[0] - TimeDelta::FromDays(100), reader, 1)); 844 visit_times[0] - TimeDelta::FromDays(100), reader, 1));
871 845
872 // Deleting a time range with not up the the max results should also return 846 // Deleting a time range with not up the the max results should also return
873 // false (there will only be one visit deleted in this range). 847 // false (there will only be one visit deleted in this range).
874 EXPECT_FALSE(expirer_.ArchiveSomeOldHistory(visit_times[0], reader, 2)); 848 EXPECT_FALSE(expirer_.ExpireSomeOldHistory(visit_times[0], reader, 2));
875 849
876 // Deleting a time range with the max number of results should return true 850 // Deleting a time range with the max number of results should return true
877 // (max deleted). 851 // (max deleted).
878 EXPECT_TRUE(expirer_.ArchiveSomeOldHistory(visit_times[2], reader, 1)); 852 EXPECT_TRUE(expirer_.ExpireSomeOldHistory(visit_times[2], reader, 1));
879 } 853 }
880 854
881 TEST_F(ExpireHistoryTest, ExpiringVisitsReader) { 855 TEST_F(ExpireHistoryTest, ExpiringVisitsReader) {
882 URLID url_ids[3]; 856 URLID url_ids[3];
883 Time visit_times[4]; 857 Time visit_times[4];
884 AddExampleData(url_ids, visit_times); 858 AddExampleData(url_ids, visit_times);
885 859
886 const ExpiringVisitsReader* all = expirer_.GetAllVisitsReader(); 860 const ExpiringVisitsReader* all = expirer_.GetAllVisitsReader();
887 const ExpiringVisitsReader* auto_subframes = 861 const ExpiringVisitsReader* auto_subframes =
888 expirer_.GetAutoSubframeVisitsReader(); 862 expirer_.GetAutoSubframeVisitsReader();
(...skipping 12 matching lines...) Expand all
901 875
902 // Verify that the early expiration threshold was updated, since there are no 876 // Verify that the early expiration threshold was updated, since there are no
903 // AUTO_SUBFRAME visits in the given time range. 877 // AUTO_SUBFRAME visits in the given time range.
904 EXPECT_TRUE(now <= main_db_->GetEarlyExpirationThreshold()); 878 EXPECT_TRUE(now <= main_db_->GetEarlyExpirationThreshold());
905 879
906 // Now, read all visits and verify that there's at least one. 880 // Now, read all visits and verify that there's at least one.
907 EXPECT_TRUE(all->Read(now, main_db_.get(), &visits, 1)); 881 EXPECT_TRUE(all->Read(now, main_db_.get(), &visits, 1));
908 EXPECT_EQ(1U, visits.size()); 882 EXPECT_EQ(1U, visits.size());
909 } 883 }
910 884
911 // Tests how ArchiveSomeOldHistory treats source information.
912 TEST_F(ExpireHistoryTest, ArchiveSomeOldHistoryWithSource) {
913 const GURL url("www.testsource.com");
914 URLID url_id;
915 AddExampleSourceData(url, &url_id);
916 const ExpiringVisitsReader* reader = expirer_.GetAllVisitsReader();
917
918 // Archiving all the visits we added.
919 ASSERT_FALSE(expirer_.ArchiveSomeOldHistory(Time::Now(), reader, 10));
920
921 URLRow archived_row;
922 ASSERT_TRUE(archived_db_->GetRowForURL(url, &archived_row));
923 VisitVector archived_visits;
924 archived_db_->GetVisitsForURL(archived_row.id(), &archived_visits);
925 ASSERT_EQ(4U, archived_visits.size());
926 VisitSourceMap sources;
927 archived_db_->GetVisitsSource(archived_visits, &sources);
928 ASSERT_EQ(3U, sources.size());
929 int result = 0;
930 VisitSourceMap::iterator iter;
931 for (int i = 0; i < 4; i++) {
932 iter = sources.find(archived_visits[i].visit_id);
933 if (iter == sources.end())
934 continue;
935 switch (iter->second) {
936 case history::SOURCE_EXTENSION:
937 result |= 0x1;
938 break;
939 case history::SOURCE_FIREFOX_IMPORTED:
940 result |= 0x2;
941 break;
942 case history::SOURCE_SYNCED:
943 result |= 0x4;
944 default:
945 break;
946 }
947 }
948 EXPECT_EQ(0x7, result);
949 main_db_->GetVisitsSource(archived_visits, &sources);
950 EXPECT_EQ(0U, sources.size());
951 main_db_->GetVisitsForURL(url_id, &archived_visits);
952 EXPECT_EQ(0U, archived_visits.size());
953 }
954
955 // TODO(brettw) add some visits with no URL to make sure everything is updated 885 // TODO(brettw) add some visits with no URL to make sure everything is updated
956 // properly. Have the visits also refer to nonexistent FTS rows. 886 // properly. Have the visits also refer to nonexistent FTS rows.
957 // 887 //
958 // Maybe also refer to invalid favicons. 888 // Maybe also refer to invalid favicons.
959 889
960 } // namespace history 890 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698