diff options
author | gbillock@chromium.org <gbillock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-17 03:32:09 +0000 |
---|---|---|
committer | gbillock@chromium.org <gbillock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-17 03:32:09 +0000 |
commit | d6407d725fda466d5e6ed34670c7de446332a26a (patch) | |
tree | 86b1deb6779c20836ec5f9ba78184fe0e2088f8b /base/file_util_unittest.cc | |
parent | aba6323f8b8536a516f656673ceda805d1205a14 (diff) | |
download | chromium_src-d6407d725fda466d5e6ed34670c7de446332a26a.zip chromium_src-d6407d725fda466d5e6ed34670c7de446332a26a.tar.gz chromium_src-d6407d725fda466d5e6ed34670c7de446332a26a.tar.bz2 |
Fix the CountFilesCreatedAfter test.
R=evan@chromium.org
BUG=46246
TEST=FileUtilTest.CountFilesCreatedAfter
Review URL: http://codereview.chromium.org/9419029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122443 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_unittest.cc')
-rw-r--r-- | base/file_util_unittest.cc | 43 |
1 files changed, 16 insertions, 27 deletions
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc index bb9d814..9d438a6 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) { |