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

Unified Diff: base/file_util_unittest.cc

Issue 9419029: Fix the CountFilesCreatedAfter test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Switch to new test impl. Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_unittest.cc
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index bb9d8148412848f1cf249a964f8001147e77f612..9d438a6b100f23dd9f5a692f0b4132eed076a5f0 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -339,37 +339,26 @@ static const struct dir_case {
#endif
};
-// Flaky, http://crbug.com/46246
-TEST_F(FileUtilTest, DISABLED_CountFilesCreatedAfter) {
- // Create old file (that we don't want to count)
- FilePath old_file_name =
- temp_dir_.path().Append(FILE_PATH_LITERAL("Old File.txt"));
- CreateTextFile(old_file_name, L"Just call me Mr. Creakybits");
-
- // Age to perfection
-#if defined(OS_WIN)
- base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
-#elif defined(OS_POSIX)
- // We need to wait at least one second here because the precision of
- // file creation time is one second.
- base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1500));
-#endif
+TEST_F(FileUtilTest, CountFilesCreatedAfter) {
+ FilePath file_name =
+ temp_dir_.path().Append(FILE_PATH_LITERAL("f.txt"));
+ CreateTextFile(file_name, L"test");
- // Establish our cutoff time
- base::Time now(base::Time::NowFromSystemTime());
- EXPECT_EQ(0, file_util::CountFilesCreatedAfter(temp_dir_.path(), now));
+ base::PlatformFileInfo info;
+ file_util::GetFileInfo(file_name, &info);
+ base::Time file_time = info.creation_time;
- // Create a new file (that we do want to count)
- FilePath new_file_name =
- temp_dir_.path().Append(FILE_PATH_LITERAL("New File.txt"));
- CreateTextFile(new_file_name, L"Waaaaaaaaaaaaaah.");
+ base::TimeDelta two_secs = base::TimeDelta::FromSeconds(2);
+ base::Time after = file_time + two_secs;
+ EXPECT_EQ(0, file_util::CountFilesCreatedAfter(temp_dir_.path(), after));
- // We should see only the new file.
- EXPECT_EQ(1, file_util::CountFilesCreatedAfter(temp_dir_.path(), now));
+ base::Time before = file_time - two_secs;
+ EXPECT_EQ(1, file_util::CountFilesCreatedAfter(temp_dir_.path(), before));
- // Delete new file, we should see no files after cutoff now
- EXPECT_TRUE(file_util::Delete(new_file_name, false));
- EXPECT_EQ(0, file_util::CountFilesCreatedAfter(temp_dir_.path(), now));
+ // After deleting the file, shouldn't find it any more.
+ EXPECT_TRUE(file_util::Delete(file_name, false));
+ EXPECT_EQ(0, file_util::CountFilesCreatedAfter(temp_dir_.path(), before));
+ EXPECT_EQ(0, file_util::CountFilesCreatedAfter(temp_dir_.path(), after));
}
TEST_F(FileUtilTest, FileAndDirectorySize) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698