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