diff options
Diffstat (limited to 'chrome/browser/history/expire_history_backend_unittest.cc')
-rw-r--r-- | chrome/browser/history/expire_history_backend_unittest.cc | 74 |
1 files changed, 45 insertions, 29 deletions
diff --git a/chrome/browser/history/expire_history_backend_unittest.cc b/chrome/browser/history/expire_history_backend_unittest.cc index 91129ed..3177dde 100644 --- a/chrome/browser/history/expire_history_backend_unittest.cc +++ b/chrome/browser/history/expire_history_backend_unittest.cc @@ -8,6 +8,7 @@ #include "base/file_util.h" #include "base/path_service.h" #include "base/scoped_ptr.h" +#include "base/scoped_temp_dir.h" #include "base/string16.h" #include "base/utf_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_model.h" @@ -31,7 +32,6 @@ using base::TimeDelta; using base::TimeTicks; // Filename constants. -static const FilePath::CharType kTestDir[] = FILE_PATH_LITERAL("ExpireTest"); static const FilePath::CharType kHistoryFile[] = FILE_PATH_LITERAL("History"); static const FilePath::CharType kArchivedHistoryFile[] = FILE_PATH_LITERAL("Archived History"); @@ -49,6 +49,8 @@ class ExpireHistoryTest : public testing::Test, public: ExpireHistoryTest() : bookmark_model_(NULL), + ui_thread_(BrowserThread::UI, &message_loop_), + db_thread_(BrowserThread::DB, &message_loop_), ALLOW_THIS_IN_INITIALIZER_LIST(expirer_(this, &bookmark_model_)), now_(Time::Now()) { } @@ -85,9 +87,17 @@ class ExpireHistoryTest : public testing::Test, static bool IsStringInFile(const FilePath& filename, const char* str); + // Returns the path the db files are created in. + const FilePath& path() const { return tmp_dir_.path(); } + + // This must be destroyed last. + ScopedTempDir tmp_dir_; + BookmarkModel bookmark_model_; - MessageLoop message_loop_; + MessageLoopForUI message_loop_; + BrowserThread ui_thread_; + BrowserThread db_thread_; ExpireHistoryBackend expirer_; @@ -108,43 +118,40 @@ class ExpireHistoryTest : public testing::Test, NotificationList; NotificationList notifications_; - // Directory for the history files. - FilePath dir_; - private: void SetUp() { - FilePath temp_dir; - PathService::Get(base::DIR_TEMP, &temp_dir); - dir_ = temp_dir.Append(kTestDir); - file_util::Delete(dir_, true); - file_util::CreateDirectory(dir_); + ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); - FilePath history_name = dir_.Append(kHistoryFile); + FilePath history_name = path().Append(kHistoryFile); main_db_.reset(new HistoryDatabase); if (main_db_->Init(history_name, FilePath()) != sql::INIT_OK) main_db_.reset(); - FilePath archived_name = dir_.Append(kArchivedHistoryFile); + FilePath archived_name = path().Append(kArchivedHistoryFile); archived_db_.reset(new ArchivedDatabase); if (!archived_db_->Init(archived_name)) archived_db_.reset(); - FilePath thumb_name = dir_.Append(kThumbnailFile); + FilePath thumb_name = path().Append(kThumbnailFile); thumb_db_.reset(new ThumbnailDatabase); if (thumb_db_->Init(thumb_name, NULL) != sql::INIT_OK) thumb_db_.reset(); - text_db_.reset(new TextDatabaseManager(dir_, + text_db_.reset(new TextDatabaseManager(path(), main_db_.get(), main_db_.get())); if (!text_db_->Init(NULL)) text_db_.reset(); expirer_.SetDatabases(main_db_.get(), archived_db_.get(), thumb_db_.get(), text_db_.get()); + profile_.CreateTopSites(); + profile_.BlockUntilTopSitesLoaded(); top_sites_ = profile_.GetTopSites(); } void TearDown() { + top_sites_ = NULL; + ClearLastNotifications(); expirer_.SetDatabases(NULL, NULL, NULL, NULL); @@ -153,8 +160,6 @@ class ExpireHistoryTest : public testing::Test, archived_db_.reset(); thumb_db_.reset(); text_db_.reset(); - TopSites::DeleteTopSites(top_sites_); - file_util::Delete(dir_, true); } // BroadcastNotificationDelegate implementation. @@ -309,11 +314,13 @@ bool ExpireHistoryTest::HasFavIcon(FavIconID favicon_id) { } bool ExpireHistoryTest::HasThumbnail(URLID url_id) { + // TODO(sky): fix this. This test isn't really valid for TopSites. For + // TopSites we should be checking URL always, not the id. URLRow info; if (!main_db_->GetURLRow(url_id, &info)) return false; GURL url = info.url(); - RefCountedBytes *data; + scoped_refptr<RefCountedBytes> data; return top_sites_->GetPageThumbnail(url, &data); } @@ -350,7 +357,8 @@ void ExpireHistoryTest::EnsureURLInfoGone(const URLRow& row) { EXPECT_EQ(0U, visits.size()); // Thumbnail should be gone. - EXPECT_FALSE(HasThumbnail(row.id())); + // TODO(sky): fix this, see comment in HasThumbnail. + // EXPECT_FALSE(HasThumbnail(row.id())); // Check the notifications. There should be a delete notification with this // URL in it. There should also be a "typed URL changed" notification if the @@ -439,7 +447,8 @@ TEST_F(ExpireHistoryTest, FLAKY_DeleteURLAndFavicon) { URLRow last_row; ASSERT_TRUE(main_db_->GetURLRow(url_ids[2], &last_row)); EXPECT_TRUE(HasFavIcon(last_row.favicon_id())); - EXPECT_TRUE(HasThumbnail(url_ids[2])); + // TODO(sky): fix this, see comment in HasThumbnail. + // EXPECT_TRUE(HasThumbnail(url_ids[2])); VisitVector visits; main_db_->GetVisitsForURL(url_ids[2], &visits); @@ -452,14 +461,14 @@ TEST_F(ExpireHistoryTest, FLAKY_DeleteURLAndFavicon) { visits[0].visit_time); // Compute the text DB filename. - FilePath fts_filename = dir_.Append( + FilePath fts_filename = path().Append( TextDatabase::IDToFileName(text_db_->TimeToID(visit_times[3]))); // When checking the file, the database must be closed. We then re-initialize // it just like the test set-up did. text_db_.reset(); EXPECT_TRUE(IsStringInFile(fts_filename, "goats")); - text_db_.reset(new TextDatabaseManager(dir_, + text_db_.reset(new TextDatabaseManager(path(), main_db_.get(), main_db_.get())); ASSERT_TRUE(text_db_->Init(NULL)); expirer_.SetDatabases(main_db_.get(), archived_db_.get(), thumb_db_.get(), @@ -472,7 +481,7 @@ TEST_F(ExpireHistoryTest, FLAKY_DeleteURLAndFavicon) { // doesn't remove it from the file, we want to be sure we're doing the latter. text_db_.reset(); EXPECT_FALSE(IsStringInFile(fts_filename, "goats")); - text_db_.reset(new TextDatabaseManager(dir_, + text_db_.reset(new TextDatabaseManager(path(), main_db_.get(), main_db_.get())); ASSERT_TRUE(text_db_->Init(NULL)); expirer_.SetDatabases(main_db_.get(), archived_db_.get(), thumb_db_.get(), @@ -500,7 +509,8 @@ TEST_F(ExpireHistoryTest, DeleteURLWithoutFavicon) { URLRow last_row; ASSERT_TRUE(main_db_->GetURLRow(url_ids[1], &last_row)); EXPECT_TRUE(HasFavIcon(last_row.favicon_id())); - EXPECT_TRUE(HasThumbnail(url_ids[1])); + // TODO(sky): fix this, see comment in HasThumbnail. + // EXPECT_TRUE(HasThumbnail(url_ids[1])); VisitVector visits; main_db_->GetVisitsForURL(url_ids[1], &visits); @@ -546,7 +556,8 @@ TEST_F(ExpireHistoryTest, DontDeleteStarredURL) { ASSERT_EQ(0U, visits.size()); // Should still have the thumbnail. - ASSERT_TRUE(HasThumbnail(url_row.id())); + // TODO(sky): fix this, see comment in HasThumbnail. + // ASSERT_TRUE(HasThumbnail(url_row.id())); // Unstar the URL and delete again. bookmark_model_.SetURLStarred(url, string16(), false); @@ -604,7 +615,8 @@ TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarred) { // Verify that the middle URL's favicon and thumbnail is still there. EXPECT_TRUE(HasFavIcon(url_row1.favicon_id())); - EXPECT_TRUE(HasThumbnail(url_row1.id())); + // TODO(sky): fix this, see comment in HasThumbnail. + // EXPECT_TRUE(HasThumbnail(url_row1.id())); // Verify that the last URL was deleted. EnsureURLInfoGone(url_row2); @@ -660,12 +672,14 @@ TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarredRestricted) { // Verify that the middle URL's favicon and thumbnail is still there. EXPECT_TRUE(HasFavIcon(url_row1.favicon_id())); - EXPECT_TRUE(HasThumbnail(url_row1.id())); + // TODO(sky): fix this, see comment in HasThumbnail. + // EXPECT_TRUE(HasThumbnail(url_row1.id())); // Verify that the last URL was not touched. EXPECT_TRUE(main_db_->GetURLRow(url_ids[2], &temp_row)); EXPECT_TRUE(HasFavIcon(url_row2.favicon_id())); - EXPECT_TRUE(HasThumbnail(url_row2.id())); + // TODO(sky): fix this, see comment in HasThumbnail. + // EXPECT_TRUE(HasThumbnail(url_row2.id())); } // Expire a starred URL, it shouldn't get deleted @@ -706,9 +720,11 @@ TEST_F(ExpireHistoryTest, FlushRecentURLsStarred) { // exists in history, this should not be a privacy problem, we only update // the visit counts in this case for consistency anyway. EXPECT_TRUE(HasFavIcon(new_url_row1.favicon_id())); - EXPECT_TRUE(HasThumbnail(new_url_row1.id())); + // TODO(sky): fix this, see comment in HasThumbnail. + // EXPECT_TRUE(HasThumbnail(new_url_row1.id())); EXPECT_TRUE(HasFavIcon(new_url_row2.favicon_id())); - EXPECT_TRUE(HasThumbnail(new_url_row2.id())); + // TODO(sky): fix this, see comment in HasThumbnail. + // EXPECT_TRUE(HasThumbnail(new_url_row2.id())); } TEST_F(ExpireHistoryTest, ArchiveHistoryBeforeUnstarred) { |