| 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 "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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 {L"/foo/bar/", L"/foo/bar"}, | 332 {L"/foo/bar/", L"/foo/bar"}, |
| 333 {L"/foo/bar//", L"/foo/bar"}, | 333 {L"/foo/bar//", L"/foo/bar"}, |
| 334 {L"/foo/bar", L"/foo"}, | 334 {L"/foo/bar", L"/foo"}, |
| 335 {L"/foo/bar./", L"/foo/bar."}, | 335 {L"/foo/bar./", L"/foo/bar."}, |
| 336 {L"/", L"/"}, | 336 {L"/", L"/"}, |
| 337 {L".", L"."}, | 337 {L".", L"."}, |
| 338 {L"..", L"."}, // yes, ".." technically lives in "." | 338 {L"..", L"."}, // yes, ".." technically lives in "." |
| 339 #endif | 339 #endif |
| 340 }; | 340 }; |
| 341 | 341 |
| 342 // Flaky, http://crbug.com/46246 | 342 TEST_F(FileUtilTest, CountFilesCreatedAfter) { |
| 343 TEST_F(FileUtilTest, DISABLED_CountFilesCreatedAfter) { | 343 FilePath file_name = |
| 344 // Create old file (that we don't want to count) | 344 temp_dir_.path().Append(FILE_PATH_LITERAL("f.txt")); |
| 345 FilePath old_file_name = | 345 CreateTextFile(file_name, L"test"); |
| 346 temp_dir_.path().Append(FILE_PATH_LITERAL("Old File.txt")); | |
| 347 CreateTextFile(old_file_name, L"Just call me Mr. Creakybits"); | |
| 348 | 346 |
| 349 // Age to perfection | 347 base::PlatformFileInfo info; |
| 350 #if defined(OS_WIN) | 348 file_util::GetFileInfo(file_name, &info); |
| 351 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); | 349 base::Time file_time = info.creation_time; |
| 352 #elif defined(OS_POSIX) | |
| 353 // We need to wait at least one second here because the precision of | |
| 354 // file creation time is one second. | |
| 355 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1500)); | |
| 356 #endif | |
| 357 | 350 |
| 358 // Establish our cutoff time | 351 base::TimeDelta two_secs = base::TimeDelta::FromSeconds(2); |
| 359 base::Time now(base::Time::NowFromSystemTime()); | 352 base::Time after = file_time + two_secs; |
| 360 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(temp_dir_.path(), now)); | 353 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(temp_dir_.path(), after)); |
| 361 | 354 |
| 362 // Create a new file (that we do want to count) | 355 base::Time before = file_time - two_secs; |
| 363 FilePath new_file_name = | 356 EXPECT_EQ(1, file_util::CountFilesCreatedAfter(temp_dir_.path(), before)); |
| 364 temp_dir_.path().Append(FILE_PATH_LITERAL("New File.txt")); | |
| 365 CreateTextFile(new_file_name, L"Waaaaaaaaaaaaaah."); | |
| 366 | 357 |
| 367 // We should see only the new file. | 358 // After deleting the file, shouldn't find it any more. |
| 368 EXPECT_EQ(1, file_util::CountFilesCreatedAfter(temp_dir_.path(), now)); | 359 EXPECT_TRUE(file_util::Delete(file_name, false)); |
| 369 | 360 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(temp_dir_.path(), before)); |
| 370 // Delete new file, we should see no files after cutoff now | 361 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(temp_dir_.path(), after)); |
| 371 EXPECT_TRUE(file_util::Delete(new_file_name, false)); | |
| 372 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(temp_dir_.path(), now)); | |
| 373 } | 362 } |
| 374 | 363 |
| 375 TEST_F(FileUtilTest, FileAndDirectorySize) { | 364 TEST_F(FileUtilTest, FileAndDirectorySize) { |
| 376 // Create three files of 20, 30 and 3 chars (utf8). ComputeDirectorySize | 365 // Create three files of 20, 30 and 3 chars (utf8). ComputeDirectorySize |
| 377 // should return 53 bytes. | 366 // should return 53 bytes. |
| 378 FilePath file_01 = temp_dir_.path().Append(FPL("The file 01.txt")); | 367 FilePath file_01 = temp_dir_.path().Append(FPL("The file 01.txt")); |
| 379 CreateTextFile(file_01, L"12345678901234567890"); | 368 CreateTextFile(file_01, L"12345678901234567890"); |
| 380 int64 size_f1 = 0; | 369 int64 size_f1 = 0; |
| 381 ASSERT_TRUE(file_util::GetFileSize(file_01, &size_f1)); | 370 ASSERT_TRUE(file_util::GetFileSize(file_01, &size_f1)); |
| 382 EXPECT_EQ(20ll, size_f1); | 371 EXPECT_EQ(20ll, size_f1); |
| (...skipping 1903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2286 file_util::VerifyPathControlledByUser( | 2275 file_util::VerifyPathControlledByUser( |
| 2287 base_dir_, text_file_, uid_, ok_gids_)); | 2276 base_dir_, text_file_, uid_, ok_gids_)); |
| 2288 EXPECT_TRUE( | 2277 EXPECT_TRUE( |
| 2289 file_util::VerifyPathControlledByUser( | 2278 file_util::VerifyPathControlledByUser( |
| 2290 sub_dir_, text_file_, uid_, ok_gids_)); | 2279 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2291 } | 2280 } |
| 2292 | 2281 |
| 2293 #endif // defined(OS_POSIX) | 2282 #endif // defined(OS_POSIX) |
| 2294 | 2283 |
| 2295 } // namespace | 2284 } // namespace |
| OLD | NEW |