Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <shlobj.h> | 10 #include <shlobj.h> |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 | 306 |
| 307 TEST_F(FileUtilTest, GetDirectoryFromPath) { | 307 TEST_F(FileUtilTest, GetDirectoryFromPath) { |
| 308 for (unsigned int i = 0; i < arraysize(dir_cases); ++i) { | 308 for (unsigned int i = 0; i < arraysize(dir_cases); ++i) { |
| 309 const dir_case& dir = dir_cases[i]; | 309 const dir_case& dir = dir_cases[i]; |
| 310 const std::wstring parent = | 310 const std::wstring parent = |
| 311 file_util::GetDirectoryFromPath(dir.full_path); | 311 file_util::GetDirectoryFromPath(dir.full_path); |
| 312 EXPECT_EQ(dir.directory, parent); | 312 EXPECT_EQ(dir.directory, parent); |
| 313 } | 313 } |
| 314 } | 314 } |
| 315 | 315 |
| 316 // TODO(erikkay): implement | |
| 317 #if defined OS_WIN | |
| 318 TEST_F(FileUtilTest, CountFilesCreatedAfter) { | 316 TEST_F(FileUtilTest, CountFilesCreatedAfter) { |
| 319 // Create old file (that we don't want to count) | 317 // Create old file (that we don't want to count) |
| 320 FilePath old_file_name = test_dir_.Append(FILE_PATH_LITERAL("Old File.txt")); | 318 FilePath old_file_name = test_dir_.Append(FILE_PATH_LITERAL("Old File.txt")); |
| 321 CreateTextFile(old_file_name, L"Just call me Mr. Creakybits"); | 319 CreateTextFile(old_file_name, L"Just call me Mr. Creakybits"); |
| 322 | 320 |
| 323 // Age to perfection | 321 // Age to perfection |
| 322 #if defined(OS_WIN) | |
| 324 Sleep(100); | 323 Sleep(100); |
| 324 #elif defined(OS_POSIX) | |
| 325 // We need to wait at least one second here because the precision of | |
| 326 // file creation time is one second. | |
| 327 sleep(1); | |
|
Erik does not do reviews
2009/04/21 16:10:21
nit: for new code, it's probably better to use Pla
| |
| 328 #endif | |
| 325 | 329 |
| 326 // Establish our cutoff time | 330 // Establish our cutoff time |
| 327 base::Time now(base::Time::NowFromSystemTime()); | 331 base::Time now(base::Time::NowFromSystemTime()); |
| 328 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_, now)); | 332 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_, now)); |
| 329 | 333 |
| 330 // Create a new file (that we do want to count) | 334 // Create a new file (that we do want to count) |
| 331 FilePath new_file_name = test_dir_.Append(FILE_PATH_LITERAL("New File.txt")); | 335 FilePath new_file_name = test_dir_.Append(FILE_PATH_LITERAL("New File.txt")); |
| 332 CreateTextFile(new_file_name, L"Waaaaaaaaaaaaaah."); | 336 CreateTextFile(new_file_name, L"Waaaaaaaaaaaaaah."); |
| 333 | 337 |
| 334 // We should see only the new file. | 338 // We should see only the new file. |
| 335 EXPECT_EQ(1, file_util::CountFilesCreatedAfter(test_dir_, now)); | 339 EXPECT_EQ(1, file_util::CountFilesCreatedAfter(test_dir_, now)); |
| 336 | 340 |
| 337 // Delete new file, we should see no files after cutoff now | 341 // Delete new file, we should see no files after cutoff now |
| 338 EXPECT_TRUE(file_util::Delete(new_file_name, false)); | 342 EXPECT_TRUE(file_util::Delete(new_file_name, false)); |
| 339 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_, now)); | 343 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_, now)); |
| 340 } | 344 } |
| 341 #endif | |
| 342 | 345 |
| 343 // Tests that the Delete function works as expected, especially | 346 // Tests that the Delete function works as expected, especially |
| 344 // the recursion flag. Also coincidentally tests PathExists. | 347 // the recursion flag. Also coincidentally tests PathExists. |
| 345 TEST_F(FileUtilTest, Delete) { | 348 TEST_F(FileUtilTest, Delete) { |
| 346 // Create a file | 349 // Create a file |
| 347 FilePath file_name = test_dir_.Append(FILE_PATH_LITERAL("Test File.txt")); | 350 FilePath file_name = test_dir_.Append(FILE_PATH_LITERAL("Test File.txt")); |
| 348 CreateTextFile(file_name, L"I'm cannon fodder."); | 351 CreateTextFile(file_name, L"I'm cannon fodder."); |
| 349 | 352 |
| 350 ASSERT_TRUE(file_util::PathExists(file_name)); | 353 ASSERT_TRUE(file_util::PathExists(file_name)); |
| 351 | 354 |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1083 #elif defined(OS_LINUX) | 1086 #elif defined(OS_LINUX) |
| 1084 EXPECT_FALSE(file_util::ContainsPath(foo, | 1087 EXPECT_FALSE(file_util::ContainsPath(foo, |
| 1085 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); | 1088 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); |
| 1086 #else | 1089 #else |
| 1087 // We can't really do this test on osx since the case-sensitivity of the | 1090 // We can't really do this test on osx since the case-sensitivity of the |
| 1088 // filesystem is configurable. | 1091 // filesystem is configurable. |
| 1089 #endif | 1092 #endif |
| 1090 } | 1093 } |
| 1091 | 1094 |
| 1092 } // namespace | 1095 } // namespace |
| OLD | NEW |