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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 TEST_F(FileUtilTest, FileAndDirectorySize) { | 247 TEST_F(FileUtilTest, FileAndDirectorySize) { |
248 // Create three files of 20, 30 and 3 chars (utf8). ComputeDirectorySize | 248 // Create three files of 20, 30 and 3 chars (utf8). ComputeDirectorySize |
249 // should return 53 bytes. | 249 // should return 53 bytes. |
250 FilePath file_01 = temp_dir_.path().Append(FPL("The file 01.txt")); | 250 FilePath file_01 = temp_dir_.path().Append(FPL("The file 01.txt")); |
251 CreateTextFile(file_01, L"12345678901234567890"); | 251 CreateTextFile(file_01, L"12345678901234567890"); |
252 int64 size_f1 = 0; | 252 int64 size_f1 = 0; |
253 ASSERT_TRUE(GetFileSize(file_01, &size_f1)); | 253 ASSERT_TRUE(GetFileSize(file_01, &size_f1)); |
254 EXPECT_EQ(20ll, size_f1); | 254 EXPECT_EQ(20ll, size_f1); |
255 | 255 |
256 FilePath subdir_path = temp_dir_.path().Append(FPL("Level2")); | 256 FilePath subdir_path = temp_dir_.path().Append(FPL("Level2")); |
257 CreateDirectory(subdir_path); | 257 base::CreateDirectory(subdir_path); |
258 | 258 |
259 FilePath file_02 = subdir_path.Append(FPL("The file 02.txt")); | 259 FilePath file_02 = subdir_path.Append(FPL("The file 02.txt")); |
260 CreateTextFile(file_02, L"123456789012345678901234567890"); | 260 CreateTextFile(file_02, L"123456789012345678901234567890"); |
261 int64 size_f2 = 0; | 261 int64 size_f2 = 0; |
262 ASSERT_TRUE(GetFileSize(file_02, &size_f2)); | 262 ASSERT_TRUE(GetFileSize(file_02, &size_f2)); |
263 EXPECT_EQ(30ll, size_f2); | 263 EXPECT_EQ(30ll, size_f2); |
264 | 264 |
265 FilePath subsubdir_path = subdir_path.Append(FPL("Level3")); | 265 FilePath subsubdir_path = subdir_path.Append(FPL("Level3")); |
266 CreateDirectory(subsubdir_path); | 266 base::CreateDirectory(subsubdir_path); |
267 | 267 |
268 FilePath file_03 = subsubdir_path.Append(FPL("The file 03.txt")); | 268 FilePath file_03 = subsubdir_path.Append(FPL("The file 03.txt")); |
269 CreateTextFile(file_03, L"123"); | 269 CreateTextFile(file_03, L"123"); |
270 | 270 |
271 int64 computed_size = ComputeDirectorySize(temp_dir_.path()); | 271 int64 computed_size = ComputeDirectorySize(temp_dir_.path()); |
272 EXPECT_EQ(size_f1 + size_f2 + 3, computed_size); | 272 EXPECT_EQ(size_f1 + size_f2 + 3, computed_size); |
273 } | 273 } |
274 | 274 |
275 TEST_F(FileUtilTest, NormalizeFilePathBasic) { | 275 TEST_F(FileUtilTest, NormalizeFilePathBasic) { |
276 // Create a directory under the test dir. Because we create it, | 276 // Create a directory under the test dir. Because we create it, |
277 // we know it is not a link. | 277 // we know it is not a link. |
278 FilePath file_a_path = temp_dir_.path().Append(FPL("file_a")); | 278 FilePath file_a_path = temp_dir_.path().Append(FPL("file_a")); |
279 FilePath dir_path = temp_dir_.path().Append(FPL("dir")); | 279 FilePath dir_path = temp_dir_.path().Append(FPL("dir")); |
280 FilePath file_b_path = dir_path.Append(FPL("file_b")); | 280 FilePath file_b_path = dir_path.Append(FPL("file_b")); |
281 CreateDirectory(dir_path); | 281 base::CreateDirectory(dir_path); |
282 | 282 |
283 FilePath normalized_file_a_path, normalized_file_b_path; | 283 FilePath normalized_file_a_path, normalized_file_b_path; |
284 ASSERT_FALSE(PathExists(file_a_path)); | 284 ASSERT_FALSE(PathExists(file_a_path)); |
285 ASSERT_FALSE(NormalizeFilePath(file_a_path, &normalized_file_a_path)) | 285 ASSERT_FALSE(NormalizeFilePath(file_a_path, &normalized_file_a_path)) |
286 << "NormalizeFilePath() should fail on nonexistent paths."; | 286 << "NormalizeFilePath() should fail on nonexistent paths."; |
287 | 287 |
288 CreateTextFile(file_a_path, bogus_content); | 288 CreateTextFile(file_a_path, bogus_content); |
289 ASSERT_TRUE(PathExists(file_a_path)); | 289 ASSERT_TRUE(PathExists(file_a_path)); |
290 ASSERT_TRUE(NormalizeFilePath(file_a_path, &normalized_file_a_path)); | 290 ASSERT_TRUE(NormalizeFilePath(file_a_path, &normalized_file_a_path)); |
291 | 291 |
(...skipping 19 matching lines...) Expand all Loading... |
311 // | |-> file.txt | 311 // | |-> file.txt |
312 // | |-> long_name___... (Very long name.) | 312 // | |-> long_name___... (Very long name.) |
313 // | |-> sub_long | 313 // | |-> sub_long |
314 // | |-> deep.txt | 314 // | |-> deep.txt |
315 // |-> base_b | 315 // |-> base_b |
316 // |-> to_sub_a (reparse point to temp_dir\base_a\sub_a) | 316 // |-> to_sub_a (reparse point to temp_dir\base_a\sub_a) |
317 // |-> to_base_b (reparse point to temp_dir\base_b) | 317 // |-> to_base_b (reparse point to temp_dir\base_b) |
318 // |-> to_sub_long (reparse point to temp_dir\sub_a\long_name_\sub_long) | 318 // |-> to_sub_long (reparse point to temp_dir\sub_a\long_name_\sub_long) |
319 | 319 |
320 FilePath base_a = temp_dir_.path().Append(FPL("base_a")); | 320 FilePath base_a = temp_dir_.path().Append(FPL("base_a")); |
321 ASSERT_TRUE(CreateDirectory(base_a)); | 321 ASSERT_TRUE(base::CreateDirectory(base_a)); |
322 | 322 |
323 FilePath sub_a = base_a.Append(FPL("sub_a")); | 323 FilePath sub_a = base_a.Append(FPL("sub_a")); |
324 ASSERT_TRUE(CreateDirectory(sub_a)); | 324 ASSERT_TRUE(base::CreateDirectory(sub_a)); |
325 | 325 |
326 FilePath file_txt = sub_a.Append(FPL("file.txt")); | 326 FilePath file_txt = sub_a.Append(FPL("file.txt")); |
327 CreateTextFile(file_txt, bogus_content); | 327 CreateTextFile(file_txt, bogus_content); |
328 | 328 |
329 // Want a directory whose name is long enough to make the path to the file | 329 // Want a directory whose name is long enough to make the path to the file |
330 // inside just under MAX_PATH chars. This will be used to test that when | 330 // inside just under MAX_PATH chars. This will be used to test that when |
331 // a junction expands to a path over MAX_PATH chars in length, | 331 // a junction expands to a path over MAX_PATH chars in length, |
332 // NormalizeFilePath() fails without crashing. | 332 // NormalizeFilePath() fails without crashing. |
333 FilePath sub_long_rel(FPL("sub_long")); | 333 FilePath sub_long_rel(FPL("sub_long")); |
334 FilePath deep_txt(FPL("deep.txt")); | 334 FilePath deep_txt(FPL("deep.txt")); |
335 | 335 |
336 int target_length = MAX_PATH; | 336 int target_length = MAX_PATH; |
337 target_length -= (sub_a.value().length() + 1); // +1 for the sepperator '\'. | 337 target_length -= (sub_a.value().length() + 1); // +1 for the sepperator '\'. |
338 target_length -= (sub_long_rel.Append(deep_txt).value().length() + 1); | 338 target_length -= (sub_long_rel.Append(deep_txt).value().length() + 1); |
339 // Without making the path a bit shorter, CreateDirectory() fails. | 339 // Without making the path a bit shorter, CreateDirectory() fails. |
340 // the resulting path is still long enough to hit the failing case in | 340 // the resulting path is still long enough to hit the failing case in |
341 // NormalizePath(). | 341 // NormalizePath(). |
342 const int kCreateDirLimit = 4; | 342 const int kCreateDirLimit = 4; |
343 target_length -= kCreateDirLimit; | 343 target_length -= kCreateDirLimit; |
344 FilePath::StringType long_name_str = FPL("long_name_"); | 344 FilePath::StringType long_name_str = FPL("long_name_"); |
345 long_name_str.resize(target_length, '_'); | 345 long_name_str.resize(target_length, '_'); |
346 | 346 |
347 FilePath long_name = sub_a.Append(FilePath(long_name_str)); | 347 FilePath long_name = sub_a.Append(FilePath(long_name_str)); |
348 FilePath deep_file = long_name.Append(sub_long_rel).Append(deep_txt); | 348 FilePath deep_file = long_name.Append(sub_long_rel).Append(deep_txt); |
349 ASSERT_EQ(MAX_PATH - kCreateDirLimit, deep_file.value().length()); | 349 ASSERT_EQ(MAX_PATH - kCreateDirLimit, deep_file.value().length()); |
350 | 350 |
351 FilePath sub_long = deep_file.DirName(); | 351 FilePath sub_long = deep_file.DirName(); |
352 ASSERT_TRUE(CreateDirectory(sub_long)); | 352 ASSERT_TRUE(base::CreateDirectory(sub_long)); |
353 CreateTextFile(deep_file, bogus_content); | 353 CreateTextFile(deep_file, bogus_content); |
354 | 354 |
355 FilePath base_b = temp_dir_.path().Append(FPL("base_b")); | 355 FilePath base_b = temp_dir_.path().Append(FPL("base_b")); |
356 ASSERT_TRUE(CreateDirectory(base_b)); | 356 ASSERT_TRUE(base::CreateDirectory(base_b)); |
357 | 357 |
358 FilePath to_sub_a = base_b.Append(FPL("to_sub_a")); | 358 FilePath to_sub_a = base_b.Append(FPL("to_sub_a")); |
359 ASSERT_TRUE(CreateDirectory(to_sub_a)); | 359 ASSERT_TRUE(base::CreateDirectory(to_sub_a)); |
360 FilePath normalized_path; | 360 FilePath normalized_path; |
361 { | 361 { |
362 ReparsePoint reparse_to_sub_a(to_sub_a, sub_a); | 362 ReparsePoint reparse_to_sub_a(to_sub_a, sub_a); |
363 ASSERT_TRUE(reparse_to_sub_a.IsValid()); | 363 ASSERT_TRUE(reparse_to_sub_a.IsValid()); |
364 | 364 |
365 FilePath to_base_b = base_b.Append(FPL("to_base_b")); | 365 FilePath to_base_b = base_b.Append(FPL("to_base_b")); |
366 ASSERT_TRUE(CreateDirectory(to_base_b)); | 366 ASSERT_TRUE(base::CreateDirectory(to_base_b)); |
367 ReparsePoint reparse_to_base_b(to_base_b, base_b); | 367 ReparsePoint reparse_to_base_b(to_base_b, base_b); |
368 ASSERT_TRUE(reparse_to_base_b.IsValid()); | 368 ASSERT_TRUE(reparse_to_base_b.IsValid()); |
369 | 369 |
370 FilePath to_sub_long = base_b.Append(FPL("to_sub_long")); | 370 FilePath to_sub_long = base_b.Append(FPL("to_sub_long")); |
371 ASSERT_TRUE(CreateDirectory(to_sub_long)); | 371 ASSERT_TRUE(base::CreateDirectory(to_sub_long)); |
372 ReparsePoint reparse_to_sub_long(to_sub_long, sub_long); | 372 ReparsePoint reparse_to_sub_long(to_sub_long, sub_long); |
373 ASSERT_TRUE(reparse_to_sub_long.IsValid()); | 373 ASSERT_TRUE(reparse_to_sub_long.IsValid()); |
374 | 374 |
375 // Normalize a junction free path: base_a\sub_a\file.txt . | 375 // Normalize a junction free path: base_a\sub_a\file.txt . |
376 ASSERT_TRUE(NormalizeFilePath(file_txt, &normalized_path)); | 376 ASSERT_TRUE(NormalizeFilePath(file_txt, &normalized_path)); |
377 ASSERT_STREQ(file_txt.value().c_str(), normalized_path.value().c_str()); | 377 ASSERT_STREQ(file_txt.value().c_str(), normalized_path.value().c_str()); |
378 | 378 |
379 // Check that the path base_b\to_sub_a\file.txt can be normalized to exclude | 379 // Check that the path base_b\to_sub_a\file.txt can be normalized to exclude |
380 // the junction to_sub_a. | 380 // the junction to_sub_a. |
381 ASSERT_TRUE(NormalizeFilePath(to_sub_a.Append(FPL("file.txt")), | 381 ASSERT_TRUE(NormalizeFilePath(to_sub_a.Append(FPL("file.txt")), |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 real_device_path_plus_numbers, | 480 real_device_path_plus_numbers, |
481 &win32_path)); | 481 &win32_path)); |
482 | 482 |
483 ASSERT_FALSE(DevicePathToDriveLetterPath( | 483 ASSERT_FALSE(DevicePathToDriveLetterPath( |
484 real_device_path_plus_numbers.Append(kRelativePath), | 484 real_device_path_plus_numbers.Append(kRelativePath), |
485 &win32_path)); | 485 &win32_path)); |
486 } | 486 } |
487 | 487 |
488 TEST_F(FileUtilTest, GetPlatformFileInfoForDirectory) { | 488 TEST_F(FileUtilTest, GetPlatformFileInfoForDirectory) { |
489 FilePath empty_dir = temp_dir_.path().Append(FPL("gpfi_test")); | 489 FilePath empty_dir = temp_dir_.path().Append(FPL("gpfi_test")); |
490 ASSERT_TRUE(CreateDirectory(empty_dir)); | 490 ASSERT_TRUE(base::CreateDirectory(empty_dir)); |
491 win::ScopedHandle dir( | 491 win::ScopedHandle dir( |
492 ::CreateFile(empty_dir.value().c_str(), | 492 ::CreateFile(empty_dir.value().c_str(), |
493 FILE_ALL_ACCESS, | 493 FILE_ALL_ACCESS, |
494 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 494 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
495 NULL, | 495 NULL, |
496 OPEN_EXISTING, | 496 OPEN_EXISTING, |
497 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. | 497 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. |
498 NULL)); | 498 NULL)); |
499 ASSERT_TRUE(dir.IsValid()); | 499 ASSERT_TRUE(dir.IsValid()); |
500 PlatformFileInfo info; | 500 PlatformFileInfo info; |
501 EXPECT_TRUE(GetPlatformFileInfo(dir.Get(), &info)); | 501 EXPECT_TRUE(GetPlatformFileInfo(dir.Get(), &info)); |
502 EXPECT_TRUE(info.is_directory); | 502 EXPECT_TRUE(info.is_directory); |
503 EXPECT_FALSE(info.is_symbolic_link); | 503 EXPECT_FALSE(info.is_symbolic_link); |
504 EXPECT_EQ(0, info.size); | 504 EXPECT_EQ(0, info.size); |
505 } | 505 } |
506 | 506 |
507 TEST_F(FileUtilTest, CreateTemporaryFileInDirLongPathTest) { | 507 TEST_F(FileUtilTest, CreateTemporaryFileInDirLongPathTest) { |
508 // Test that CreateTemporaryFileInDir() creates a path and returns a long path | 508 // Test that CreateTemporaryFileInDir() creates a path and returns a long path |
509 // if it is available. This test requires that: | 509 // if it is available. This test requires that: |
510 // - the filesystem at |temp_dir_| supports long filenames. | 510 // - the filesystem at |temp_dir_| supports long filenames. |
511 // - the account has FILE_LIST_DIRECTORY permission for all ancestor | 511 // - the account has FILE_LIST_DIRECTORY permission for all ancestor |
512 // directories of |temp_dir_|. | 512 // directories of |temp_dir_|. |
513 const FilePath::CharType kLongDirName[] = FPL("A long path"); | 513 const FilePath::CharType kLongDirName[] = FPL("A long path"); |
514 const FilePath::CharType kTestSubDirName[] = FPL("test"); | 514 const FilePath::CharType kTestSubDirName[] = FPL("test"); |
515 FilePath long_test_dir = temp_dir_.path().Append(kLongDirName); | 515 FilePath long_test_dir = temp_dir_.path().Append(kLongDirName); |
516 ASSERT_TRUE(CreateDirectory(long_test_dir)); | 516 ASSERT_TRUE(base::CreateDirectory(long_test_dir)); |
517 | 517 |
518 // kLongDirName is not a 8.3 component. So GetShortName() should give us a | 518 // kLongDirName is not a 8.3 component. So GetShortName() should give us a |
519 // different short name. | 519 // different short name. |
520 WCHAR path_buffer[MAX_PATH]; | 520 WCHAR path_buffer[MAX_PATH]; |
521 DWORD path_buffer_length = GetShortPathName(long_test_dir.value().c_str(), | 521 DWORD path_buffer_length = GetShortPathName(long_test_dir.value().c_str(), |
522 path_buffer, MAX_PATH); | 522 path_buffer, MAX_PATH); |
523 ASSERT_LT(path_buffer_length, DWORD(MAX_PATH)); | 523 ASSERT_LT(path_buffer_length, DWORD(MAX_PATH)); |
524 ASSERT_NE(DWORD(0), path_buffer_length); | 524 ASSERT_NE(DWORD(0), path_buffer_length); |
525 FilePath short_test_dir(path_buffer); | 525 FilePath short_test_dir(path_buffer); |
526 ASSERT_STRNE(kLongDirName, short_test_dir.BaseName().value().c_str()); | 526 ASSERT_STRNE(kLongDirName, short_test_dir.BaseName().value().c_str()); |
527 | 527 |
528 FilePath temp_file; | 528 FilePath temp_file; |
529 ASSERT_TRUE(CreateTemporaryFileInDir(short_test_dir, &temp_file)); | 529 ASSERT_TRUE(base::CreateTemporaryFileInDir(short_test_dir, &temp_file)); |
530 EXPECT_STREQ(kLongDirName, temp_file.DirName().BaseName().value().c_str()); | 530 EXPECT_STREQ(kLongDirName, temp_file.DirName().BaseName().value().c_str()); |
531 EXPECT_TRUE(PathExists(temp_file)); | 531 EXPECT_TRUE(PathExists(temp_file)); |
532 | 532 |
533 // Create a subdirectory of |long_test_dir| and make |long_test_dir| | 533 // Create a subdirectory of |long_test_dir| and make |long_test_dir| |
534 // unreadable. We should still be able to create a temp file in the | 534 // unreadable. We should still be able to create a temp file in the |
535 // subdirectory, but we won't be able to determine the long path for it. This | 535 // subdirectory, but we won't be able to determine the long path for it. This |
536 // mimics the environment that some users run where their user profiles reside | 536 // mimics the environment that some users run where their user profiles reside |
537 // in a location where the don't have full access to the higher level | 537 // in a location where the don't have full access to the higher level |
538 // directories. (Note that this assumption is true for NTFS, but not for some | 538 // directories. (Note that this assumption is true for NTFS, but not for some |
539 // network file systems. E.g. AFS). | 539 // network file systems. E.g. AFS). |
540 FilePath access_test_dir = long_test_dir.Append(kTestSubDirName); | 540 FilePath access_test_dir = long_test_dir.Append(kTestSubDirName); |
541 ASSERT_TRUE(CreateDirectory(access_test_dir)); | 541 ASSERT_TRUE(base::CreateDirectory(access_test_dir)); |
542 file_util::PermissionRestorer long_test_dir_restorer(long_test_dir); | 542 file_util::PermissionRestorer long_test_dir_restorer(long_test_dir); |
543 ASSERT_TRUE(file_util::MakeFileUnreadable(long_test_dir)); | 543 ASSERT_TRUE(file_util::MakeFileUnreadable(long_test_dir)); |
544 | 544 |
545 // Use the short form of the directory to create a temporary filename. | 545 // Use the short form of the directory to create a temporary filename. |
546 ASSERT_TRUE(CreateTemporaryFileInDir( | 546 ASSERT_TRUE(base::CreateTemporaryFileInDir( |
547 short_test_dir.Append(kTestSubDirName), &temp_file)); | 547 short_test_dir.Append(kTestSubDirName), &temp_file)); |
548 EXPECT_TRUE(PathExists(temp_file)); | 548 EXPECT_TRUE(PathExists(temp_file)); |
549 EXPECT_TRUE(short_test_dir.IsParent(temp_file.DirName())); | 549 EXPECT_TRUE(short_test_dir.IsParent(temp_file.DirName())); |
550 | 550 |
551 // Check that the long path can't be determined for |temp_file|. | 551 // Check that the long path can't be determined for |temp_file|. |
552 path_buffer_length = GetLongPathName(temp_file.value().c_str(), | 552 path_buffer_length = GetLongPathName(temp_file.value().c_str(), |
553 path_buffer, MAX_PATH); | 553 path_buffer, MAX_PATH); |
554 EXPECT_EQ(DWORD(0), path_buffer_length); | 554 EXPECT_EQ(DWORD(0), path_buffer_length); |
555 } | 555 } |
556 | 556 |
(...skipping 14 matching lines...) Expand all Loading... |
571 std::wstring contents = ReadTextFile(link_from); | 571 std::wstring contents = ReadTextFile(link_from); |
572 EXPECT_EQ(bogus_content, contents); | 572 EXPECT_EQ(bogus_content, contents); |
573 | 573 |
574 FilePath result; | 574 FilePath result; |
575 ASSERT_TRUE(ReadSymbolicLink(link_from, &result)); | 575 ASSERT_TRUE(ReadSymbolicLink(link_from, &result)); |
576 EXPECT_EQ(link_to.value(), result.value()); | 576 EXPECT_EQ(link_to.value(), result.value()); |
577 | 577 |
578 // Link to a directory. | 578 // Link to a directory. |
579 link_from = temp_dir_.path().Append(FPL("from_dir")); | 579 link_from = temp_dir_.path().Append(FPL("from_dir")); |
580 link_to = temp_dir_.path().Append(FPL("to_dir")); | 580 link_to = temp_dir_.path().Append(FPL("to_dir")); |
581 ASSERT_TRUE(CreateDirectory(link_to)); | 581 ASSERT_TRUE(base::CreateDirectory(link_to)); |
582 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) | 582 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) |
583 << "Failed to create directory symlink."; | 583 << "Failed to create directory symlink."; |
584 | 584 |
585 // Test failures. | 585 // Test failures. |
586 EXPECT_FALSE(CreateSymbolicLink(link_to, link_to)); | 586 EXPECT_FALSE(CreateSymbolicLink(link_to, link_to)); |
587 EXPECT_FALSE(ReadSymbolicLink(link_to, &result)); | 587 EXPECT_FALSE(ReadSymbolicLink(link_to, &result)); |
588 FilePath missing = temp_dir_.path().Append(FPL("missing")); | 588 FilePath missing = temp_dir_.path().Append(FPL("missing")); |
589 EXPECT_FALSE(ReadSymbolicLink(missing, &result)); | 589 EXPECT_FALSE(ReadSymbolicLink(missing, &result)); |
590 } | 590 } |
591 | 591 |
(...skipping 14 matching lines...) Expand all Loading... |
606 // Check that NormalizeFilePath sees the link. | 606 // Check that NormalizeFilePath sees the link. |
607 FilePath normalized_path; | 607 FilePath normalized_path; |
608 ASSERT_TRUE(NormalizeFilePath(link_from, &normalized_path)); | 608 ASSERT_TRUE(NormalizeFilePath(link_from, &normalized_path)); |
609 EXPECT_NE(link_from, link_to); | 609 EXPECT_NE(link_from, link_to); |
610 EXPECT_EQ(link_to.BaseName().value(), normalized_path.BaseName().value()); | 610 EXPECT_EQ(link_to.BaseName().value(), normalized_path.BaseName().value()); |
611 EXPECT_EQ(link_to.BaseName().value(), normalized_path.BaseName().value()); | 611 EXPECT_EQ(link_to.BaseName().value(), normalized_path.BaseName().value()); |
612 | 612 |
613 // Link to a directory. | 613 // Link to a directory. |
614 link_from = temp_dir_.path().Append(FPL("from_dir")); | 614 link_from = temp_dir_.path().Append(FPL("from_dir")); |
615 link_to = temp_dir_.path().Append(FPL("to_dir")); | 615 link_to = temp_dir_.path().Append(FPL("to_dir")); |
616 ASSERT_TRUE(CreateDirectory(link_to)); | 616 ASSERT_TRUE(base::CreateDirectory(link_to)); |
617 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) | 617 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) |
618 << "Failed to create directory symlink."; | 618 << "Failed to create directory symlink."; |
619 | 619 |
620 EXPECT_FALSE(NormalizeFilePath(link_from, &normalized_path)) | 620 EXPECT_FALSE(NormalizeFilePath(link_from, &normalized_path)) |
621 << "Links to directories should return false."; | 621 << "Links to directories should return false."; |
622 | 622 |
623 // Test that a loop in the links causes NormalizeFilePath() to return false. | 623 // Test that a loop in the links causes NormalizeFilePath() to return false. |
624 link_from = temp_dir_.path().Append(FPL("link_a")); | 624 link_from = temp_dir_.path().Append(FPL("link_a")); |
625 link_to = temp_dir_.path().Append(FPL("link_b")); | 625 link_to = temp_dir_.path().Append(FPL("link_b")); |
626 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) | 626 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 // Make sure the file is readable. | 722 // Make sure the file is readable. |
723 int32 mode = 0; | 723 int32 mode = 0; |
724 EXPECT_TRUE(GetPosixFilePermissions(file_name, &mode)); | 724 EXPECT_TRUE(GetPosixFilePermissions(file_name, &mode)); |
725 EXPECT_TRUE(mode & FILE_PERMISSION_READ_BY_USER); | 725 EXPECT_TRUE(mode & FILE_PERMISSION_READ_BY_USER); |
726 | 726 |
727 // Get rid of the read permission. | 727 // Get rid of the read permission. |
728 EXPECT_TRUE(SetPosixFilePermissions(file_name, 0u)); | 728 EXPECT_TRUE(SetPosixFilePermissions(file_name, 0u)); |
729 EXPECT_TRUE(GetPosixFilePermissions(file_name, &mode)); | 729 EXPECT_TRUE(GetPosixFilePermissions(file_name, &mode)); |
730 EXPECT_FALSE(mode & FILE_PERMISSION_READ_BY_USER); | 730 EXPECT_FALSE(mode & FILE_PERMISSION_READ_BY_USER); |
731 // Make sure the file can't be read. | 731 // Make sure the file can't be read. |
732 EXPECT_EQ(-1, ReadFile(file_name, buffer, buffer_size)); | 732 EXPECT_EQ(-1, file_util::ReadFile(file_name, buffer, buffer_size)); |
733 | 733 |
734 // Give the read permission. | 734 // Give the read permission. |
735 EXPECT_TRUE(SetPosixFilePermissions(file_name, FILE_PERMISSION_READ_BY_USER)); | 735 EXPECT_TRUE(SetPosixFilePermissions(file_name, FILE_PERMISSION_READ_BY_USER)); |
736 EXPECT_TRUE(GetPosixFilePermissions(file_name, &mode)); | 736 EXPECT_TRUE(GetPosixFilePermissions(file_name, &mode)); |
737 EXPECT_TRUE(mode & FILE_PERMISSION_READ_BY_USER); | 737 EXPECT_TRUE(mode & FILE_PERMISSION_READ_BY_USER); |
738 // Make sure the file can be read. | 738 // Make sure the file can be read. |
739 EXPECT_EQ(static_cast<int>(kData.length()), | 739 EXPECT_EQ(static_cast<int>(kData.length()), |
740 ReadFile(file_name, buffer, buffer_size)); | 740 file_util::ReadFile(file_name, buffer, buffer_size)); |
741 | 741 |
742 // Delete the file. | 742 // Delete the file. |
743 EXPECT_TRUE(DeleteFile(file_name, false)); | 743 EXPECT_TRUE(DeleteFile(file_name, false)); |
744 EXPECT_FALSE(PathExists(file_name)); | 744 EXPECT_FALSE(PathExists(file_name)); |
745 | 745 |
746 delete[] buffer; | 746 delete[] buffer; |
747 } | 747 } |
748 | 748 |
749 TEST_F(FileUtilTest, ChangeFilePermissionsAndWrite) { | 749 TEST_F(FileUtilTest, ChangeFilePermissionsAndWrite) { |
750 // Create a file path. | 750 // Create a file path. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 | 785 |
786 // Delete the file. | 786 // Delete the file. |
787 EXPECT_TRUE(DeleteFile(file_name, false)); | 787 EXPECT_TRUE(DeleteFile(file_name, false)); |
788 EXPECT_FALSE(PathExists(file_name)); | 788 EXPECT_FALSE(PathExists(file_name)); |
789 } | 789 } |
790 | 790 |
791 TEST_F(FileUtilTest, ChangeDirectoryPermissionsAndEnumerate) { | 791 TEST_F(FileUtilTest, ChangeDirectoryPermissionsAndEnumerate) { |
792 // Create a directory path. | 792 // Create a directory path. |
793 FilePath subdir_path = | 793 FilePath subdir_path = |
794 temp_dir_.path().Append(FPL("PermissionTest1")); | 794 temp_dir_.path().Append(FPL("PermissionTest1")); |
795 CreateDirectory(subdir_path); | 795 base::CreateDirectory(subdir_path); |
796 ASSERT_TRUE(PathExists(subdir_path)); | 796 ASSERT_TRUE(PathExists(subdir_path)); |
797 | 797 |
798 // Create a dummy file to enumerate. | 798 // Create a dummy file to enumerate. |
799 FilePath file_name = subdir_path.Append(FPL("Test Readable File.txt")); | 799 FilePath file_name = subdir_path.Append(FPL("Test Readable File.txt")); |
800 EXPECT_FALSE(PathExists(file_name)); | 800 EXPECT_FALSE(PathExists(file_name)); |
801 const std::string kData("hello"); | 801 const std::string kData("hello"); |
802 EXPECT_EQ(static_cast<int>(kData.length()), | 802 EXPECT_EQ(static_cast<int>(kData.length()), |
803 file_util::WriteFile(file_name, kData.data(), kData.length())); | 803 file_util::WriteFile(file_name, kData.data(), kData.length())); |
804 EXPECT_TRUE(PathExists(file_name)); | 804 EXPECT_TRUE(PathExists(file_name)); |
805 | 805 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 // Tests that the Delete function works for wild cards, especially | 842 // Tests that the Delete function works for wild cards, especially |
843 // with the recursion flag. Also coincidentally tests PathExists. | 843 // with the recursion flag. Also coincidentally tests PathExists. |
844 // TODO(erikkay): see if anyone's actually using this feature of the API | 844 // TODO(erikkay): see if anyone's actually using this feature of the API |
845 TEST_F(FileUtilTest, DeleteWildCard) { | 845 TEST_F(FileUtilTest, DeleteWildCard) { |
846 // Create a file and a directory | 846 // Create a file and a directory |
847 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteWildCard.txt")); | 847 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteWildCard.txt")); |
848 CreateTextFile(file_name, bogus_content); | 848 CreateTextFile(file_name, bogus_content); |
849 ASSERT_TRUE(PathExists(file_name)); | 849 ASSERT_TRUE(PathExists(file_name)); |
850 | 850 |
851 FilePath subdir_path = temp_dir_.path().Append(FPL("DeleteWildCardDir")); | 851 FilePath subdir_path = temp_dir_.path().Append(FPL("DeleteWildCardDir")); |
852 CreateDirectory(subdir_path); | 852 base::CreateDirectory(subdir_path); |
853 ASSERT_TRUE(PathExists(subdir_path)); | 853 ASSERT_TRUE(PathExists(subdir_path)); |
854 | 854 |
855 // Create the wildcard path | 855 // Create the wildcard path |
856 FilePath directory_contents = temp_dir_.path(); | 856 FilePath directory_contents = temp_dir_.path(); |
857 directory_contents = directory_contents.Append(FPL("*")); | 857 directory_contents = directory_contents.Append(FPL("*")); |
858 | 858 |
859 // Delete non-recursively and check that only the file is deleted | 859 // Delete non-recursively and check that only the file is deleted |
860 EXPECT_TRUE(DeleteFile(directory_contents, false)); | 860 EXPECT_TRUE(DeleteFile(directory_contents, false)); |
861 EXPECT_FALSE(PathExists(file_name)); | 861 EXPECT_FALSE(PathExists(file_name)); |
862 EXPECT_TRUE(PathExists(subdir_path)); | 862 EXPECT_TRUE(PathExists(subdir_path)); |
863 | 863 |
864 // Delete recursively and make sure all contents are deleted | 864 // Delete recursively and make sure all contents are deleted |
865 EXPECT_TRUE(DeleteFile(directory_contents, true)); | 865 EXPECT_TRUE(DeleteFile(directory_contents, true)); |
866 EXPECT_FALSE(PathExists(file_name)); | 866 EXPECT_FALSE(PathExists(file_name)); |
867 EXPECT_FALSE(PathExists(subdir_path)); | 867 EXPECT_FALSE(PathExists(subdir_path)); |
868 } | 868 } |
869 | 869 |
870 // TODO(erikkay): see if anyone's actually using this feature of the API | 870 // TODO(erikkay): see if anyone's actually using this feature of the API |
871 TEST_F(FileUtilTest, DeleteNonExistantWildCard) { | 871 TEST_F(FileUtilTest, DeleteNonExistantWildCard) { |
872 // Create a file and a directory | 872 // Create a file and a directory |
873 FilePath subdir_path = | 873 FilePath subdir_path = |
874 temp_dir_.path().Append(FPL("DeleteNonExistantWildCard")); | 874 temp_dir_.path().Append(FPL("DeleteNonExistantWildCard")); |
875 CreateDirectory(subdir_path); | 875 base::CreateDirectory(subdir_path); |
876 ASSERT_TRUE(PathExists(subdir_path)); | 876 ASSERT_TRUE(PathExists(subdir_path)); |
877 | 877 |
878 // Create the wildcard path | 878 // Create the wildcard path |
879 FilePath directory_contents = subdir_path; | 879 FilePath directory_contents = subdir_path; |
880 directory_contents = directory_contents.Append(FPL("*")); | 880 directory_contents = directory_contents.Append(FPL("*")); |
881 | 881 |
882 // Delete non-recursively and check nothing got deleted | 882 // Delete non-recursively and check nothing got deleted |
883 EXPECT_TRUE(DeleteFile(directory_contents, false)); | 883 EXPECT_TRUE(DeleteFile(directory_contents, false)); |
884 EXPECT_TRUE(PathExists(subdir_path)); | 884 EXPECT_TRUE(PathExists(subdir_path)); |
885 | 885 |
886 // Delete recursively and check nothing got deleted | 886 // Delete recursively and check nothing got deleted |
887 EXPECT_TRUE(DeleteFile(directory_contents, true)); | 887 EXPECT_TRUE(DeleteFile(directory_contents, true)); |
888 EXPECT_TRUE(PathExists(subdir_path)); | 888 EXPECT_TRUE(PathExists(subdir_path)); |
889 } | 889 } |
890 #endif | 890 #endif |
891 | 891 |
892 // Tests non-recursive Delete() for a directory. | 892 // Tests non-recursive Delete() for a directory. |
893 TEST_F(FileUtilTest, DeleteDirNonRecursive) { | 893 TEST_F(FileUtilTest, DeleteDirNonRecursive) { |
894 // Create a subdirectory and put a file and two directories inside. | 894 // Create a subdirectory and put a file and two directories inside. |
895 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirNonRecursive")); | 895 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirNonRecursive")); |
896 CreateDirectory(test_subdir); | 896 base::CreateDirectory(test_subdir); |
897 ASSERT_TRUE(PathExists(test_subdir)); | 897 ASSERT_TRUE(PathExists(test_subdir)); |
898 | 898 |
899 FilePath file_name = test_subdir.Append(FPL("Test DeleteDir.txt")); | 899 FilePath file_name = test_subdir.Append(FPL("Test DeleteDir.txt")); |
900 CreateTextFile(file_name, bogus_content); | 900 CreateTextFile(file_name, bogus_content); |
901 ASSERT_TRUE(PathExists(file_name)); | 901 ASSERT_TRUE(PathExists(file_name)); |
902 | 902 |
903 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); | 903 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); |
904 CreateDirectory(subdir_path1); | 904 base::CreateDirectory(subdir_path1); |
905 ASSERT_TRUE(PathExists(subdir_path1)); | 905 ASSERT_TRUE(PathExists(subdir_path1)); |
906 | 906 |
907 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); | 907 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); |
908 CreateDirectory(subdir_path2); | 908 base::CreateDirectory(subdir_path2); |
909 ASSERT_TRUE(PathExists(subdir_path2)); | 909 ASSERT_TRUE(PathExists(subdir_path2)); |
910 | 910 |
911 // Delete non-recursively and check that the empty dir got deleted | 911 // Delete non-recursively and check that the empty dir got deleted |
912 EXPECT_TRUE(DeleteFile(subdir_path2, false)); | 912 EXPECT_TRUE(DeleteFile(subdir_path2, false)); |
913 EXPECT_FALSE(PathExists(subdir_path2)); | 913 EXPECT_FALSE(PathExists(subdir_path2)); |
914 | 914 |
915 // Delete non-recursively and check that nothing got deleted | 915 // Delete non-recursively and check that nothing got deleted |
916 EXPECT_FALSE(DeleteFile(test_subdir, false)); | 916 EXPECT_FALSE(DeleteFile(test_subdir, false)); |
917 EXPECT_TRUE(PathExists(test_subdir)); | 917 EXPECT_TRUE(PathExists(test_subdir)); |
918 EXPECT_TRUE(PathExists(file_name)); | 918 EXPECT_TRUE(PathExists(file_name)); |
919 EXPECT_TRUE(PathExists(subdir_path1)); | 919 EXPECT_TRUE(PathExists(subdir_path1)); |
920 } | 920 } |
921 | 921 |
922 // Tests recursive Delete() for a directory. | 922 // Tests recursive Delete() for a directory. |
923 TEST_F(FileUtilTest, DeleteDirRecursive) { | 923 TEST_F(FileUtilTest, DeleteDirRecursive) { |
924 // Create a subdirectory and put a file and two directories inside. | 924 // Create a subdirectory and put a file and two directories inside. |
925 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirRecursive")); | 925 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirRecursive")); |
926 CreateDirectory(test_subdir); | 926 base::CreateDirectory(test_subdir); |
927 ASSERT_TRUE(PathExists(test_subdir)); | 927 ASSERT_TRUE(PathExists(test_subdir)); |
928 | 928 |
929 FilePath file_name = test_subdir.Append(FPL("Test DeleteDirRecursive.txt")); | 929 FilePath file_name = test_subdir.Append(FPL("Test DeleteDirRecursive.txt")); |
930 CreateTextFile(file_name, bogus_content); | 930 CreateTextFile(file_name, bogus_content); |
931 ASSERT_TRUE(PathExists(file_name)); | 931 ASSERT_TRUE(PathExists(file_name)); |
932 | 932 |
933 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); | 933 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); |
934 CreateDirectory(subdir_path1); | 934 base::CreateDirectory(subdir_path1); |
935 ASSERT_TRUE(PathExists(subdir_path1)); | 935 ASSERT_TRUE(PathExists(subdir_path1)); |
936 | 936 |
937 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); | 937 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); |
938 CreateDirectory(subdir_path2); | 938 base::CreateDirectory(subdir_path2); |
939 ASSERT_TRUE(PathExists(subdir_path2)); | 939 ASSERT_TRUE(PathExists(subdir_path2)); |
940 | 940 |
941 // Delete recursively and check that the empty dir got deleted | 941 // Delete recursively and check that the empty dir got deleted |
942 EXPECT_TRUE(DeleteFile(subdir_path2, true)); | 942 EXPECT_TRUE(DeleteFile(subdir_path2, true)); |
943 EXPECT_FALSE(PathExists(subdir_path2)); | 943 EXPECT_FALSE(PathExists(subdir_path2)); |
944 | 944 |
945 // Delete recursively and check that everything got deleted | 945 // Delete recursively and check that everything got deleted |
946 EXPECT_TRUE(DeleteFile(test_subdir, true)); | 946 EXPECT_TRUE(DeleteFile(test_subdir, true)); |
947 EXPECT_FALSE(PathExists(file_name)); | 947 EXPECT_FALSE(PathExists(file_name)); |
948 EXPECT_FALSE(PathExists(subdir_path1)); | 948 EXPECT_FALSE(PathExists(subdir_path1)); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 TEST_F(FileUtilTest, MoveFileDirExists) { | 992 TEST_F(FileUtilTest, MoveFileDirExists) { |
993 // Create a file | 993 // Create a file |
994 FilePath file_name_from = | 994 FilePath file_name_from = |
995 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 995 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
996 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 996 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
997 ASSERT_TRUE(PathExists(file_name_from)); | 997 ASSERT_TRUE(PathExists(file_name_from)); |
998 | 998 |
999 // The destination directory | 999 // The destination directory |
1000 FilePath dir_name_to = | 1000 FilePath dir_name_to = |
1001 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); | 1001 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); |
1002 CreateDirectory(dir_name_to); | 1002 base::CreateDirectory(dir_name_to); |
1003 ASSERT_TRUE(PathExists(dir_name_to)); | 1003 ASSERT_TRUE(PathExists(dir_name_to)); |
1004 | 1004 |
1005 EXPECT_FALSE(Move(file_name_from, dir_name_to)); | 1005 EXPECT_FALSE(Move(file_name_from, dir_name_to)); |
1006 } | 1006 } |
1007 | 1007 |
1008 | 1008 |
1009 TEST_F(FileUtilTest, MoveNew) { | 1009 TEST_F(FileUtilTest, MoveNew) { |
1010 // Create a directory | 1010 // Create a directory |
1011 FilePath dir_name_from = | 1011 FilePath dir_name_from = |
1012 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); | 1012 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); |
1013 CreateDirectory(dir_name_from); | 1013 base::CreateDirectory(dir_name_from); |
1014 ASSERT_TRUE(PathExists(dir_name_from)); | 1014 ASSERT_TRUE(PathExists(dir_name_from)); |
1015 | 1015 |
1016 // Create a file under the directory | 1016 // Create a file under the directory |
1017 FilePath txt_file_name(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1017 FilePath txt_file_name(FILE_PATH_LITERAL("Move_Test_File.txt")); |
1018 FilePath file_name_from = dir_name_from.Append(txt_file_name); | 1018 FilePath file_name_from = dir_name_from.Append(txt_file_name); |
1019 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1019 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1020 ASSERT_TRUE(PathExists(file_name_from)); | 1020 ASSERT_TRUE(PathExists(file_name_from)); |
1021 | 1021 |
1022 // Move the directory. | 1022 // Move the directory. |
1023 FilePath dir_name_to = | 1023 FilePath dir_name_to = |
(...skipping 20 matching lines...) Expand all Loading... |
1044 EXPECT_FALSE(PathExists(file_name_to)); | 1044 EXPECT_FALSE(PathExists(file_name_to)); |
1045 EXPECT_TRUE(internal::MoveUnsafe(file_name_from, file_name_to)); | 1045 EXPECT_TRUE(internal::MoveUnsafe(file_name_from, file_name_to)); |
1046 EXPECT_FALSE(PathExists(file_name_from)); | 1046 EXPECT_FALSE(PathExists(file_name_from)); |
1047 EXPECT_TRUE(PathExists(file_name_to)); | 1047 EXPECT_TRUE(PathExists(file_name_to)); |
1048 } | 1048 } |
1049 | 1049 |
1050 TEST_F(FileUtilTest, MoveExist) { | 1050 TEST_F(FileUtilTest, MoveExist) { |
1051 // Create a directory | 1051 // Create a directory |
1052 FilePath dir_name_from = | 1052 FilePath dir_name_from = |
1053 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); | 1053 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); |
1054 CreateDirectory(dir_name_from); | 1054 base::CreateDirectory(dir_name_from); |
1055 ASSERT_TRUE(PathExists(dir_name_from)); | 1055 ASSERT_TRUE(PathExists(dir_name_from)); |
1056 | 1056 |
1057 // Create a file under the directory | 1057 // Create a file under the directory |
1058 FilePath file_name_from = | 1058 FilePath file_name_from = |
1059 dir_name_from.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1059 dir_name_from.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
1060 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1060 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1061 ASSERT_TRUE(PathExists(file_name_from)); | 1061 ASSERT_TRUE(PathExists(file_name_from)); |
1062 | 1062 |
1063 // Move the directory | 1063 // Move the directory |
1064 FilePath dir_name_exists = | 1064 FilePath dir_name_exists = |
1065 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); | 1065 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); |
1066 | 1066 |
1067 FilePath dir_name_to = | 1067 FilePath dir_name_to = |
1068 dir_name_exists.Append(FILE_PATH_LITERAL("Move_To_Subdir")); | 1068 dir_name_exists.Append(FILE_PATH_LITERAL("Move_To_Subdir")); |
1069 FilePath file_name_to = | 1069 FilePath file_name_to = |
1070 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1070 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
1071 | 1071 |
1072 // Create the destination directory. | 1072 // Create the destination directory. |
1073 CreateDirectory(dir_name_exists); | 1073 base::CreateDirectory(dir_name_exists); |
1074 ASSERT_TRUE(PathExists(dir_name_exists)); | 1074 ASSERT_TRUE(PathExists(dir_name_exists)); |
1075 | 1075 |
1076 EXPECT_TRUE(Move(dir_name_from, dir_name_to)); | 1076 EXPECT_TRUE(Move(dir_name_from, dir_name_to)); |
1077 | 1077 |
1078 // Check everything has been moved. | 1078 // Check everything has been moved. |
1079 EXPECT_FALSE(PathExists(dir_name_from)); | 1079 EXPECT_FALSE(PathExists(dir_name_from)); |
1080 EXPECT_FALSE(PathExists(file_name_from)); | 1080 EXPECT_FALSE(PathExists(file_name_from)); |
1081 EXPECT_TRUE(PathExists(dir_name_to)); | 1081 EXPECT_TRUE(PathExists(dir_name_to)); |
1082 EXPECT_TRUE(PathExists(file_name_to)); | 1082 EXPECT_TRUE(PathExists(file_name_to)); |
1083 } | 1083 } |
1084 | 1084 |
1085 TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) { | 1085 TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) { |
1086 // Create a directory. | 1086 // Create a directory. |
1087 FilePath dir_name_from = | 1087 FilePath dir_name_from = |
1088 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1088 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
1089 CreateDirectory(dir_name_from); | 1089 base::CreateDirectory(dir_name_from); |
1090 ASSERT_TRUE(PathExists(dir_name_from)); | 1090 ASSERT_TRUE(PathExists(dir_name_from)); |
1091 | 1091 |
1092 // Create a file under the directory. | 1092 // Create a file under the directory. |
1093 FilePath file_name_from = | 1093 FilePath file_name_from = |
1094 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1094 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1095 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1095 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1096 ASSERT_TRUE(PathExists(file_name_from)); | 1096 ASSERT_TRUE(PathExists(file_name_from)); |
1097 | 1097 |
1098 // Create a subdirectory. | 1098 // Create a subdirectory. |
1099 FilePath subdir_name_from = | 1099 FilePath subdir_name_from = |
1100 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1100 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
1101 CreateDirectory(subdir_name_from); | 1101 base::CreateDirectory(subdir_name_from); |
1102 ASSERT_TRUE(PathExists(subdir_name_from)); | 1102 ASSERT_TRUE(PathExists(subdir_name_from)); |
1103 | 1103 |
1104 // Create a file under the subdirectory. | 1104 // Create a file under the subdirectory. |
1105 FilePath file_name2_from = | 1105 FilePath file_name2_from = |
1106 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1106 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1107 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1107 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
1108 ASSERT_TRUE(PathExists(file_name2_from)); | 1108 ASSERT_TRUE(PathExists(file_name2_from)); |
1109 | 1109 |
1110 // Copy the directory recursively. | 1110 // Copy the directory recursively. |
1111 FilePath dir_name_to = | 1111 FilePath dir_name_to = |
(...skipping 17 matching lines...) Expand all Loading... |
1129 EXPECT_TRUE(PathExists(dir_name_to)); | 1129 EXPECT_TRUE(PathExists(dir_name_to)); |
1130 EXPECT_TRUE(PathExists(file_name_to)); | 1130 EXPECT_TRUE(PathExists(file_name_to)); |
1131 EXPECT_TRUE(PathExists(subdir_name_to)); | 1131 EXPECT_TRUE(PathExists(subdir_name_to)); |
1132 EXPECT_TRUE(PathExists(file_name2_to)); | 1132 EXPECT_TRUE(PathExists(file_name2_to)); |
1133 } | 1133 } |
1134 | 1134 |
1135 TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) { | 1135 TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) { |
1136 // Create a directory. | 1136 // Create a directory. |
1137 FilePath dir_name_from = | 1137 FilePath dir_name_from = |
1138 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1138 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
1139 CreateDirectory(dir_name_from); | 1139 base::CreateDirectory(dir_name_from); |
1140 ASSERT_TRUE(PathExists(dir_name_from)); | 1140 ASSERT_TRUE(PathExists(dir_name_from)); |
1141 | 1141 |
1142 // Create a file under the directory. | 1142 // Create a file under the directory. |
1143 FilePath file_name_from = | 1143 FilePath file_name_from = |
1144 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1144 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1145 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1145 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1146 ASSERT_TRUE(PathExists(file_name_from)); | 1146 ASSERT_TRUE(PathExists(file_name_from)); |
1147 | 1147 |
1148 // Create a subdirectory. | 1148 // Create a subdirectory. |
1149 FilePath subdir_name_from = | 1149 FilePath subdir_name_from = |
1150 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1150 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
1151 CreateDirectory(subdir_name_from); | 1151 base::CreateDirectory(subdir_name_from); |
1152 ASSERT_TRUE(PathExists(subdir_name_from)); | 1152 ASSERT_TRUE(PathExists(subdir_name_from)); |
1153 | 1153 |
1154 // Create a file under the subdirectory. | 1154 // Create a file under the subdirectory. |
1155 FilePath file_name2_from = | 1155 FilePath file_name2_from = |
1156 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1156 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1157 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1157 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
1158 ASSERT_TRUE(PathExists(file_name2_from)); | 1158 ASSERT_TRUE(PathExists(file_name2_from)); |
1159 | 1159 |
1160 // Copy the directory recursively. | 1160 // Copy the directory recursively. |
1161 FilePath dir_name_exists = | 1161 FilePath dir_name_exists = |
1162 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); | 1162 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); |
1163 | 1163 |
1164 FilePath dir_name_to = | 1164 FilePath dir_name_to = |
1165 dir_name_exists.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1165 dir_name_exists.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
1166 FilePath file_name_to = | 1166 FilePath file_name_to = |
1167 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1167 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1168 FilePath subdir_name_to = | 1168 FilePath subdir_name_to = |
1169 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1169 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
1170 FilePath file_name2_to = | 1170 FilePath file_name2_to = |
1171 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1171 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1172 | 1172 |
1173 // Create the destination directory. | 1173 // Create the destination directory. |
1174 CreateDirectory(dir_name_exists); | 1174 base::CreateDirectory(dir_name_exists); |
1175 ASSERT_TRUE(PathExists(dir_name_exists)); | 1175 ASSERT_TRUE(PathExists(dir_name_exists)); |
1176 | 1176 |
1177 EXPECT_TRUE(CopyDirectory(dir_name_from, dir_name_exists, true)); | 1177 EXPECT_TRUE(CopyDirectory(dir_name_from, dir_name_exists, true)); |
1178 | 1178 |
1179 // Check everything has been copied. | 1179 // Check everything has been copied. |
1180 EXPECT_TRUE(PathExists(dir_name_from)); | 1180 EXPECT_TRUE(PathExists(dir_name_from)); |
1181 EXPECT_TRUE(PathExists(file_name_from)); | 1181 EXPECT_TRUE(PathExists(file_name_from)); |
1182 EXPECT_TRUE(PathExists(subdir_name_from)); | 1182 EXPECT_TRUE(PathExists(subdir_name_from)); |
1183 EXPECT_TRUE(PathExists(file_name2_from)); | 1183 EXPECT_TRUE(PathExists(file_name2_from)); |
1184 EXPECT_TRUE(PathExists(dir_name_to)); | 1184 EXPECT_TRUE(PathExists(dir_name_to)); |
1185 EXPECT_TRUE(PathExists(file_name_to)); | 1185 EXPECT_TRUE(PathExists(file_name_to)); |
1186 EXPECT_TRUE(PathExists(subdir_name_to)); | 1186 EXPECT_TRUE(PathExists(subdir_name_to)); |
1187 EXPECT_TRUE(PathExists(file_name2_to)); | 1187 EXPECT_TRUE(PathExists(file_name2_to)); |
1188 } | 1188 } |
1189 | 1189 |
1190 TEST_F(FileUtilTest, CopyDirectoryNew) { | 1190 TEST_F(FileUtilTest, CopyDirectoryNew) { |
1191 // Create a directory. | 1191 // Create a directory. |
1192 FilePath dir_name_from = | 1192 FilePath dir_name_from = |
1193 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1193 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
1194 CreateDirectory(dir_name_from); | 1194 base::CreateDirectory(dir_name_from); |
1195 ASSERT_TRUE(PathExists(dir_name_from)); | 1195 ASSERT_TRUE(PathExists(dir_name_from)); |
1196 | 1196 |
1197 // Create a file under the directory. | 1197 // Create a file under the directory. |
1198 FilePath file_name_from = | 1198 FilePath file_name_from = |
1199 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1199 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1200 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1200 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1201 ASSERT_TRUE(PathExists(file_name_from)); | 1201 ASSERT_TRUE(PathExists(file_name_from)); |
1202 | 1202 |
1203 // Create a subdirectory. | 1203 // Create a subdirectory. |
1204 FilePath subdir_name_from = | 1204 FilePath subdir_name_from = |
1205 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1205 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
1206 CreateDirectory(subdir_name_from); | 1206 base::CreateDirectory(subdir_name_from); |
1207 ASSERT_TRUE(PathExists(subdir_name_from)); | 1207 ASSERT_TRUE(PathExists(subdir_name_from)); |
1208 | 1208 |
1209 // Create a file under the subdirectory. | 1209 // Create a file under the subdirectory. |
1210 FilePath file_name2_from = | 1210 FilePath file_name2_from = |
1211 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1211 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1212 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1212 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
1213 ASSERT_TRUE(PathExists(file_name2_from)); | 1213 ASSERT_TRUE(PathExists(file_name2_from)); |
1214 | 1214 |
1215 // Copy the directory not recursively. | 1215 // Copy the directory not recursively. |
1216 FilePath dir_name_to = | 1216 FilePath dir_name_to = |
(...skipping 14 matching lines...) Expand all Loading... |
1231 EXPECT_TRUE(PathExists(file_name2_from)); | 1231 EXPECT_TRUE(PathExists(file_name2_from)); |
1232 EXPECT_TRUE(PathExists(dir_name_to)); | 1232 EXPECT_TRUE(PathExists(dir_name_to)); |
1233 EXPECT_TRUE(PathExists(file_name_to)); | 1233 EXPECT_TRUE(PathExists(file_name_to)); |
1234 EXPECT_FALSE(PathExists(subdir_name_to)); | 1234 EXPECT_FALSE(PathExists(subdir_name_to)); |
1235 } | 1235 } |
1236 | 1236 |
1237 TEST_F(FileUtilTest, CopyDirectoryExists) { | 1237 TEST_F(FileUtilTest, CopyDirectoryExists) { |
1238 // Create a directory. | 1238 // Create a directory. |
1239 FilePath dir_name_from = | 1239 FilePath dir_name_from = |
1240 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1240 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
1241 CreateDirectory(dir_name_from); | 1241 base::CreateDirectory(dir_name_from); |
1242 ASSERT_TRUE(PathExists(dir_name_from)); | 1242 ASSERT_TRUE(PathExists(dir_name_from)); |
1243 | 1243 |
1244 // Create a file under the directory. | 1244 // Create a file under the directory. |
1245 FilePath file_name_from = | 1245 FilePath file_name_from = |
1246 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1246 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1247 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1247 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1248 ASSERT_TRUE(PathExists(file_name_from)); | 1248 ASSERT_TRUE(PathExists(file_name_from)); |
1249 | 1249 |
1250 // Create a subdirectory. | 1250 // Create a subdirectory. |
1251 FilePath subdir_name_from = | 1251 FilePath subdir_name_from = |
1252 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1252 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
1253 CreateDirectory(subdir_name_from); | 1253 base::CreateDirectory(subdir_name_from); |
1254 ASSERT_TRUE(PathExists(subdir_name_from)); | 1254 ASSERT_TRUE(PathExists(subdir_name_from)); |
1255 | 1255 |
1256 // Create a file under the subdirectory. | 1256 // Create a file under the subdirectory. |
1257 FilePath file_name2_from = | 1257 FilePath file_name2_from = |
1258 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1258 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1259 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1259 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
1260 ASSERT_TRUE(PathExists(file_name2_from)); | 1260 ASSERT_TRUE(PathExists(file_name2_from)); |
1261 | 1261 |
1262 // Copy the directory not recursively. | 1262 // Copy the directory not recursively. |
1263 FilePath dir_name_to = | 1263 FilePath dir_name_to = |
1264 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1264 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
1265 FilePath file_name_to = | 1265 FilePath file_name_to = |
1266 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1266 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1267 FilePath subdir_name_to = | 1267 FilePath subdir_name_to = |
1268 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1268 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
1269 | 1269 |
1270 // Create the destination directory. | 1270 // Create the destination directory. |
1271 CreateDirectory(dir_name_to); | 1271 base::CreateDirectory(dir_name_to); |
1272 ASSERT_TRUE(PathExists(dir_name_to)); | 1272 ASSERT_TRUE(PathExists(dir_name_to)); |
1273 | 1273 |
1274 EXPECT_TRUE(CopyDirectory(dir_name_from, dir_name_to, false)); | 1274 EXPECT_TRUE(CopyDirectory(dir_name_from, dir_name_to, false)); |
1275 | 1275 |
1276 // Check everything has been copied. | 1276 // Check everything has been copied. |
1277 EXPECT_TRUE(PathExists(dir_name_from)); | 1277 EXPECT_TRUE(PathExists(dir_name_from)); |
1278 EXPECT_TRUE(PathExists(file_name_from)); | 1278 EXPECT_TRUE(PathExists(file_name_from)); |
1279 EXPECT_TRUE(PathExists(subdir_name_from)); | 1279 EXPECT_TRUE(PathExists(subdir_name_from)); |
1280 EXPECT_TRUE(PathExists(file_name2_from)); | 1280 EXPECT_TRUE(PathExists(file_name2_from)); |
1281 EXPECT_TRUE(PathExists(dir_name_to)); | 1281 EXPECT_TRUE(PathExists(dir_name_to)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1324 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExistingDirectory) { | 1324 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExistingDirectory) { |
1325 // Create a file | 1325 // Create a file |
1326 FilePath file_name_from = | 1326 FilePath file_name_from = |
1327 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1327 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1328 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1328 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1329 ASSERT_TRUE(PathExists(file_name_from)); | 1329 ASSERT_TRUE(PathExists(file_name_from)); |
1330 | 1330 |
1331 // The destination | 1331 // The destination |
1332 FilePath dir_name_to = | 1332 FilePath dir_name_to = |
1333 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); | 1333 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); |
1334 CreateDirectory(dir_name_to); | 1334 base::CreateDirectory(dir_name_to); |
1335 ASSERT_TRUE(PathExists(dir_name_to)); | 1335 ASSERT_TRUE(PathExists(dir_name_to)); |
1336 FilePath file_name_to = | 1336 FilePath file_name_to = |
1337 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1337 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1338 | 1338 |
1339 EXPECT_TRUE(CopyDirectory(file_name_from, dir_name_to, true)); | 1339 EXPECT_TRUE(CopyDirectory(file_name_from, dir_name_to, true)); |
1340 | 1340 |
1341 // Check the has been copied | 1341 // Check the has been copied |
1342 EXPECT_TRUE(PathExists(file_name_to)); | 1342 EXPECT_TRUE(PathExists(file_name_to)); |
1343 } | 1343 } |
1344 | 1344 |
1345 TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) { | 1345 TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) { |
1346 // Create a directory. | 1346 // Create a directory. |
1347 FilePath dir_name_from = | 1347 FilePath dir_name_from = |
1348 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1348 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
1349 CreateDirectory(dir_name_from); | 1349 base::CreateDirectory(dir_name_from); |
1350 ASSERT_TRUE(PathExists(dir_name_from)); | 1350 ASSERT_TRUE(PathExists(dir_name_from)); |
1351 | 1351 |
1352 // Create a file under the directory. | 1352 // Create a file under the directory. |
1353 FilePath file_name_from = | 1353 FilePath file_name_from = |
1354 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1354 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1355 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1355 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1356 ASSERT_TRUE(PathExists(file_name_from)); | 1356 ASSERT_TRUE(PathExists(file_name_from)); |
1357 | 1357 |
1358 // Copy the directory recursively. | 1358 // Copy the directory recursively. |
1359 FilePath dir_name_to = | 1359 FilePath dir_name_to = |
(...skipping 16 matching lines...) Expand all Loading... |
1376 EXPECT_TRUE(PathExists(dir_name_from)); | 1376 EXPECT_TRUE(PathExists(dir_name_from)); |
1377 EXPECT_TRUE(PathExists(file_name_from)); | 1377 EXPECT_TRUE(PathExists(file_name_from)); |
1378 EXPECT_TRUE(PathExists(dir_name_to)); | 1378 EXPECT_TRUE(PathExists(dir_name_to)); |
1379 EXPECT_TRUE(PathExists(file_name_to)); | 1379 EXPECT_TRUE(PathExists(file_name_to)); |
1380 } | 1380 } |
1381 | 1381 |
1382 TEST_F(FileUtilTest, CopyFile) { | 1382 TEST_F(FileUtilTest, CopyFile) { |
1383 // Create a directory | 1383 // Create a directory |
1384 FilePath dir_name_from = | 1384 FilePath dir_name_from = |
1385 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1385 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
1386 CreateDirectory(dir_name_from); | 1386 base::CreateDirectory(dir_name_from); |
1387 ASSERT_TRUE(PathExists(dir_name_from)); | 1387 ASSERT_TRUE(PathExists(dir_name_from)); |
1388 | 1388 |
1389 // Create a file under the directory | 1389 // Create a file under the directory |
1390 FilePath file_name_from = | 1390 FilePath file_name_from = |
1391 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1391 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
1392 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); | 1392 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); |
1393 CreateTextFile(file_name_from, file_contents); | 1393 CreateTextFile(file_name_from, file_contents); |
1394 ASSERT_TRUE(PathExists(file_name_from)); | 1394 ASSERT_TRUE(PathExists(file_name_from)); |
1395 | 1395 |
1396 // Copy the file. | 1396 // Copy the file. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1511 EXPECT_FALSE(TextContentsEqual(original_file, empty1_file)); | 1511 EXPECT_FALSE(TextContentsEqual(original_file, empty1_file)); |
1512 EXPECT_TRUE(TextContentsEqual(blank_line_file, blank_line_crlf_file)); | 1512 EXPECT_TRUE(TextContentsEqual(blank_line_file, blank_line_crlf_file)); |
1513 } | 1513 } |
1514 | 1514 |
1515 // We don't need equivalent functionality outside of Windows. | 1515 // We don't need equivalent functionality outside of Windows. |
1516 #if defined(OS_WIN) | 1516 #if defined(OS_WIN) |
1517 TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) { | 1517 TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) { |
1518 // Create a directory | 1518 // Create a directory |
1519 FilePath dir_name_from = | 1519 FilePath dir_name_from = |
1520 temp_dir_.path().Append(FILE_PATH_LITERAL("CopyAndDelete_From_Subdir")); | 1520 temp_dir_.path().Append(FILE_PATH_LITERAL("CopyAndDelete_From_Subdir")); |
1521 CreateDirectory(dir_name_from); | 1521 base::CreateDirectory(dir_name_from); |
1522 ASSERT_TRUE(PathExists(dir_name_from)); | 1522 ASSERT_TRUE(PathExists(dir_name_from)); |
1523 | 1523 |
1524 // Create a file under the directory | 1524 // Create a file under the directory |
1525 FilePath file_name_from = | 1525 FilePath file_name_from = |
1526 dir_name_from.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); | 1526 dir_name_from.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); |
1527 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1527 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
1528 ASSERT_TRUE(PathExists(file_name_from)); | 1528 ASSERT_TRUE(PathExists(file_name_from)); |
1529 | 1529 |
1530 // Move the directory by using CopyAndDeleteDirectory | 1530 // Move the directory by using CopyAndDeleteDirectory |
1531 FilePath dir_name_to = temp_dir_.path().Append( | 1531 FilePath dir_name_to = temp_dir_.path().Append( |
(...skipping 20 matching lines...) Expand all Loading... |
1552 }; | 1552 }; |
1553 // Save the original $TMP. | 1553 // Save the original $TMP. |
1554 size_t original_tmp_size; | 1554 size_t original_tmp_size; |
1555 TCHAR* original_tmp; | 1555 TCHAR* original_tmp; |
1556 ASSERT_EQ(0, ::_tdupenv_s(&original_tmp, &original_tmp_size, kTmpKey)); | 1556 ASSERT_EQ(0, ::_tdupenv_s(&original_tmp, &original_tmp_size, kTmpKey)); |
1557 // original_tmp may be NULL. | 1557 // original_tmp may be NULL. |
1558 | 1558 |
1559 for (unsigned int i = 0; i < arraysize(kTmpValues); ++i) { | 1559 for (unsigned int i = 0; i < arraysize(kTmpValues); ++i) { |
1560 FilePath path; | 1560 FilePath path; |
1561 ::_tputenv_s(kTmpKey, kTmpValues[i]); | 1561 ::_tputenv_s(kTmpKey, kTmpValues[i]); |
1562 GetTempDir(&path); | 1562 base::GetTempDir(&path); |
1563 EXPECT_TRUE(path.IsAbsolute()) << "$TMP=" << kTmpValues[i] << | 1563 EXPECT_TRUE(path.IsAbsolute()) << "$TMP=" << kTmpValues[i] << |
1564 " result=" << path.value(); | 1564 " result=" << path.value(); |
1565 } | 1565 } |
1566 | 1566 |
1567 // Restore the original $TMP. | 1567 // Restore the original $TMP. |
1568 if (original_tmp) { | 1568 if (original_tmp) { |
1569 ::_tputenv_s(kTmpKey, original_tmp); | 1569 ::_tputenv_s(kTmpKey, original_tmp); |
1570 free(original_tmp); | 1570 free(original_tmp); |
1571 } else { | 1571 } else { |
1572 ::_tputenv_s(kTmpKey, _T("")); | 1572 ::_tputenv_s(kTmpKey, _T("")); |
1573 } | 1573 } |
1574 } | 1574 } |
1575 #endif // OS_WIN | 1575 #endif // OS_WIN |
1576 | 1576 |
1577 TEST_F(FileUtilTest, CreateTemporaryFileTest) { | 1577 TEST_F(FileUtilTest, CreateTemporaryFileTest) { |
1578 FilePath temp_files[3]; | 1578 FilePath temp_files[3]; |
1579 for (int i = 0; i < 3; i++) { | 1579 for (int i = 0; i < 3; i++) { |
1580 ASSERT_TRUE(CreateTemporaryFile(&(temp_files[i]))); | 1580 ASSERT_TRUE(base::CreateTemporaryFile(&(temp_files[i]))); |
1581 EXPECT_TRUE(PathExists(temp_files[i])); | 1581 EXPECT_TRUE(PathExists(temp_files[i])); |
1582 EXPECT_FALSE(DirectoryExists(temp_files[i])); | 1582 EXPECT_FALSE(DirectoryExists(temp_files[i])); |
1583 } | 1583 } |
1584 for (int i = 0; i < 3; i++) | 1584 for (int i = 0; i < 3; i++) |
1585 EXPECT_FALSE(temp_files[i] == temp_files[(i+1)%3]); | 1585 EXPECT_FALSE(temp_files[i] == temp_files[(i+1)%3]); |
1586 for (int i = 0; i < 3; i++) | 1586 for (int i = 0; i < 3; i++) |
1587 EXPECT_TRUE(DeleteFile(temp_files[i], false)); | 1587 EXPECT_TRUE(DeleteFile(temp_files[i], false)); |
1588 } | 1588 } |
1589 | 1589 |
1590 TEST_F(FileUtilTest, CreateAndOpenTemporaryFileTest) { | 1590 TEST_F(FileUtilTest, CreateAndOpenTemporaryFileTest) { |
1591 FilePath names[3]; | 1591 FilePath names[3]; |
1592 FILE* fps[3]; | 1592 FILE* fps[3]; |
1593 int i; | 1593 int i; |
1594 | 1594 |
1595 // Create; make sure they are open and exist. | 1595 // Create; make sure they are open and exist. |
1596 for (i = 0; i < 3; ++i) { | 1596 for (i = 0; i < 3; ++i) { |
1597 fps[i] = CreateAndOpenTemporaryFile(&(names[i])); | 1597 fps[i] = base::CreateAndOpenTemporaryFile(&(names[i])); |
1598 ASSERT_TRUE(fps[i]); | 1598 ASSERT_TRUE(fps[i]); |
1599 EXPECT_TRUE(PathExists(names[i])); | 1599 EXPECT_TRUE(PathExists(names[i])); |
1600 } | 1600 } |
1601 | 1601 |
1602 // Make sure all names are unique. | 1602 // Make sure all names are unique. |
1603 for (i = 0; i < 3; ++i) { | 1603 for (i = 0; i < 3; ++i) { |
1604 EXPECT_FALSE(names[i] == names[(i+1)%3]); | 1604 EXPECT_FALSE(names[i] == names[(i+1)%3]); |
1605 } | 1605 } |
1606 | 1606 |
1607 // Close and delete. | 1607 // Close and delete. |
1608 for (i = 0; i < 3; ++i) { | 1608 for (i = 0; i < 3; ++i) { |
1609 EXPECT_TRUE(CloseFile(fps[i])); | 1609 EXPECT_TRUE(file_util::CloseFile(fps[i])); |
1610 EXPECT_TRUE(DeleteFile(names[i], false)); | 1610 EXPECT_TRUE(DeleteFile(names[i], false)); |
1611 } | 1611 } |
1612 } | 1612 } |
1613 | 1613 |
1614 TEST_F(FileUtilTest, CreateNewTempDirectoryTest) { | 1614 TEST_F(FileUtilTest, CreateNewTempDirectoryTest) { |
1615 FilePath temp_dir; | 1615 FilePath temp_dir; |
1616 ASSERT_TRUE(CreateNewTempDirectory(FilePath::StringType(), &temp_dir)); | 1616 ASSERT_TRUE(base::CreateNewTempDirectory(FilePath::StringType(), &temp_dir)); |
1617 EXPECT_TRUE(PathExists(temp_dir)); | 1617 EXPECT_TRUE(PathExists(temp_dir)); |
1618 EXPECT_TRUE(DeleteFile(temp_dir, false)); | 1618 EXPECT_TRUE(DeleteFile(temp_dir, false)); |
1619 } | 1619 } |
1620 | 1620 |
1621 TEST_F(FileUtilTest, CreateNewTemporaryDirInDirTest) { | 1621 TEST_F(FileUtilTest, CreateNewTemporaryDirInDirTest) { |
1622 FilePath new_dir; | 1622 FilePath new_dir; |
1623 ASSERT_TRUE(CreateTemporaryDirInDir( | 1623 ASSERT_TRUE(base::CreateTemporaryDirInDir( |
1624 temp_dir_.path(), | 1624 temp_dir_.path(), |
1625 FILE_PATH_LITERAL("CreateNewTemporaryDirInDirTest"), | 1625 FILE_PATH_LITERAL("CreateNewTemporaryDirInDirTest"), |
1626 &new_dir)); | 1626 &new_dir)); |
1627 EXPECT_TRUE(PathExists(new_dir)); | 1627 EXPECT_TRUE(PathExists(new_dir)); |
1628 EXPECT_TRUE(temp_dir_.path().IsParent(new_dir)); | 1628 EXPECT_TRUE(temp_dir_.path().IsParent(new_dir)); |
1629 EXPECT_TRUE(DeleteFile(new_dir, false)); | 1629 EXPECT_TRUE(DeleteFile(new_dir, false)); |
1630 } | 1630 } |
1631 | 1631 |
1632 TEST_F(FileUtilTest, GetShmemTempDirTest) { | 1632 TEST_F(FileUtilTest, GetShmemTempDirTest) { |
1633 FilePath dir; | 1633 FilePath dir; |
1634 EXPECT_TRUE(GetShmemTempDir(false, &dir)); | 1634 EXPECT_TRUE(GetShmemTempDir(false, &dir)); |
1635 EXPECT_TRUE(DirectoryExists(dir)); | 1635 EXPECT_TRUE(DirectoryExists(dir)); |
1636 } | 1636 } |
1637 | 1637 |
1638 TEST_F(FileUtilTest, CreateDirectoryTest) { | 1638 TEST_F(FileUtilTest, CreateDirectoryTest) { |
1639 FilePath test_root = | 1639 FilePath test_root = |
1640 temp_dir_.path().Append(FILE_PATH_LITERAL("create_directory_test")); | 1640 temp_dir_.path().Append(FILE_PATH_LITERAL("create_directory_test")); |
1641 #if defined(OS_WIN) | 1641 #if defined(OS_WIN) |
1642 FilePath test_path = | 1642 FilePath test_path = |
1643 test_root.Append(FILE_PATH_LITERAL("dir\\tree\\likely\\doesnt\\exist\\")); | 1643 test_root.Append(FILE_PATH_LITERAL("dir\\tree\\likely\\doesnt\\exist\\")); |
1644 #elif defined(OS_POSIX) | 1644 #elif defined(OS_POSIX) |
1645 FilePath test_path = | 1645 FilePath test_path = |
1646 test_root.Append(FILE_PATH_LITERAL("dir/tree/likely/doesnt/exist/")); | 1646 test_root.Append(FILE_PATH_LITERAL("dir/tree/likely/doesnt/exist/")); |
1647 #endif | 1647 #endif |
1648 | 1648 |
1649 EXPECT_FALSE(PathExists(test_path)); | 1649 EXPECT_FALSE(PathExists(test_path)); |
1650 EXPECT_TRUE(CreateDirectory(test_path)); | 1650 EXPECT_TRUE(base::CreateDirectory(test_path)); |
1651 EXPECT_TRUE(PathExists(test_path)); | 1651 EXPECT_TRUE(PathExists(test_path)); |
1652 // CreateDirectory returns true if the DirectoryExists returns true. | 1652 // CreateDirectory returns true if the DirectoryExists returns true. |
1653 EXPECT_TRUE(CreateDirectory(test_path)); | 1653 EXPECT_TRUE(base::CreateDirectory(test_path)); |
1654 | 1654 |
1655 // Doesn't work to create it on top of a non-dir | 1655 // Doesn't work to create it on top of a non-dir |
1656 test_path = test_path.Append(FILE_PATH_LITERAL("foobar.txt")); | 1656 test_path = test_path.Append(FILE_PATH_LITERAL("foobar.txt")); |
1657 EXPECT_FALSE(PathExists(test_path)); | 1657 EXPECT_FALSE(PathExists(test_path)); |
1658 CreateTextFile(test_path, L"test file"); | 1658 CreateTextFile(test_path, L"test file"); |
1659 EXPECT_TRUE(PathExists(test_path)); | 1659 EXPECT_TRUE(PathExists(test_path)); |
1660 EXPECT_FALSE(CreateDirectory(test_path)); | 1660 EXPECT_FALSE(base::CreateDirectory(test_path)); |
1661 | 1661 |
1662 EXPECT_TRUE(DeleteFile(test_root, true)); | 1662 EXPECT_TRUE(DeleteFile(test_root, true)); |
1663 EXPECT_FALSE(PathExists(test_root)); | 1663 EXPECT_FALSE(PathExists(test_root)); |
1664 EXPECT_FALSE(PathExists(test_path)); | 1664 EXPECT_FALSE(PathExists(test_path)); |
1665 | 1665 |
1666 // Verify assumptions made by the Windows implementation: | 1666 // Verify assumptions made by the Windows implementation: |
1667 // 1. The current directory always exists. | 1667 // 1. The current directory always exists. |
1668 // 2. The root directory always exists. | 1668 // 2. The root directory always exists. |
1669 ASSERT_TRUE(DirectoryExists(FilePath(FilePath::kCurrentDirectory))); | 1669 ASSERT_TRUE(DirectoryExists(FilePath(FilePath::kCurrentDirectory))); |
1670 FilePath top_level = test_root; | 1670 FilePath top_level = test_root; |
1671 while (top_level != top_level.DirName()) { | 1671 while (top_level != top_level.DirName()) { |
1672 top_level = top_level.DirName(); | 1672 top_level = top_level.DirName(); |
1673 } | 1673 } |
1674 ASSERT_TRUE(DirectoryExists(top_level)); | 1674 ASSERT_TRUE(DirectoryExists(top_level)); |
1675 | 1675 |
1676 // Given these assumptions hold, it should be safe to | 1676 // Given these assumptions hold, it should be safe to |
1677 // test that "creating" these directories succeeds. | 1677 // test that "creating" these directories succeeds. |
1678 EXPECT_TRUE(CreateDirectory( | 1678 EXPECT_TRUE(base::CreateDirectory( |
1679 FilePath(FilePath::kCurrentDirectory))); | 1679 FilePath(FilePath::kCurrentDirectory))); |
1680 EXPECT_TRUE(CreateDirectory(top_level)); | 1680 EXPECT_TRUE(base::CreateDirectory(top_level)); |
1681 | 1681 |
1682 #if defined(OS_WIN) | 1682 #if defined(OS_WIN) |
1683 FilePath invalid_drive(FILE_PATH_LITERAL("o:\\")); | 1683 FilePath invalid_drive(FILE_PATH_LITERAL("o:\\")); |
1684 FilePath invalid_path = | 1684 FilePath invalid_path = |
1685 invalid_drive.Append(FILE_PATH_LITERAL("some\\inaccessible\\dir")); | 1685 invalid_drive.Append(FILE_PATH_LITERAL("some\\inaccessible\\dir")); |
1686 if (!PathExists(invalid_drive)) { | 1686 if (!PathExists(invalid_drive)) { |
1687 EXPECT_FALSE(CreateDirectory(invalid_path)); | 1687 EXPECT_FALSE(base::CreateDirectory(invalid_path)); |
1688 } | 1688 } |
1689 #endif | 1689 #endif |
1690 } | 1690 } |
1691 | 1691 |
1692 TEST_F(FileUtilTest, DetectDirectoryTest) { | 1692 TEST_F(FileUtilTest, DetectDirectoryTest) { |
1693 // Check a directory | 1693 // Check a directory |
1694 FilePath test_root = | 1694 FilePath test_root = |
1695 temp_dir_.path().Append(FILE_PATH_LITERAL("detect_directory_test")); | 1695 temp_dir_.path().Append(FILE_PATH_LITERAL("detect_directory_test")); |
1696 EXPECT_FALSE(PathExists(test_root)); | 1696 EXPECT_FALSE(PathExists(test_root)); |
1697 EXPECT_TRUE(CreateDirectory(test_root)); | 1697 EXPECT_TRUE(base::CreateDirectory(test_root)); |
1698 EXPECT_TRUE(PathExists(test_root)); | 1698 EXPECT_TRUE(PathExists(test_root)); |
1699 EXPECT_TRUE(DirectoryExists(test_root)); | 1699 EXPECT_TRUE(DirectoryExists(test_root)); |
1700 // Check a file | 1700 // Check a file |
1701 FilePath test_path = | 1701 FilePath test_path = |
1702 test_root.Append(FILE_PATH_LITERAL("foobar.txt")); | 1702 test_root.Append(FILE_PATH_LITERAL("foobar.txt")); |
1703 EXPECT_FALSE(PathExists(test_path)); | 1703 EXPECT_FALSE(PathExists(test_path)); |
1704 CreateTextFile(test_path, L"test file"); | 1704 CreateTextFile(test_path, L"test file"); |
1705 EXPECT_TRUE(PathExists(test_path)); | 1705 EXPECT_TRUE(PathExists(test_path)); |
1706 EXPECT_FALSE(DirectoryExists(test_path)); | 1706 EXPECT_FALSE(DirectoryExists(test_path)); |
1707 EXPECT_TRUE(DeleteFile(test_path, false)); | 1707 EXPECT_TRUE(DeleteFile(test_path, false)); |
1708 | 1708 |
1709 EXPECT_TRUE(DeleteFile(test_root, true)); | 1709 EXPECT_TRUE(DeleteFile(test_root, true)); |
1710 } | 1710 } |
1711 | 1711 |
1712 TEST_F(FileUtilTest, FileEnumeratorTest) { | 1712 TEST_F(FileUtilTest, FileEnumeratorTest) { |
1713 // Test an empty directory. | 1713 // Test an empty directory. |
1714 FileEnumerator f0(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 1714 FileEnumerator f0(temp_dir_.path(), true, FILES_AND_DIRECTORIES); |
1715 EXPECT_EQ(f0.Next().value(), FPL("")); | 1715 EXPECT_EQ(f0.Next().value(), FPL("")); |
1716 EXPECT_EQ(f0.Next().value(), FPL("")); | 1716 EXPECT_EQ(f0.Next().value(), FPL("")); |
1717 | 1717 |
1718 // Test an empty directory, non-recursively, including "..". | 1718 // Test an empty directory, non-recursively, including "..". |
1719 FileEnumerator f0_dotdot(temp_dir_.path(), false, | 1719 FileEnumerator f0_dotdot(temp_dir_.path(), false, |
1720 FILES_AND_DIRECTORIES | FileEnumerator::INCLUDE_DOT_DOT); | 1720 FILES_AND_DIRECTORIES | FileEnumerator::INCLUDE_DOT_DOT); |
1721 EXPECT_EQ(temp_dir_.path().Append(FPL("..")).value(), | 1721 EXPECT_EQ(temp_dir_.path().Append(FPL("..")).value(), |
1722 f0_dotdot.Next().value()); | 1722 f0_dotdot.Next().value()); |
1723 EXPECT_EQ(FPL(""), f0_dotdot.Next().value()); | 1723 EXPECT_EQ(FPL(""), f0_dotdot.Next().value()); |
1724 | 1724 |
1725 // create the directories | 1725 // create the directories |
1726 FilePath dir1 = temp_dir_.path().Append(FPL("dir1")); | 1726 FilePath dir1 = temp_dir_.path().Append(FPL("dir1")); |
1727 EXPECT_TRUE(CreateDirectory(dir1)); | 1727 EXPECT_TRUE(base::CreateDirectory(dir1)); |
1728 FilePath dir2 = temp_dir_.path().Append(FPL("dir2")); | 1728 FilePath dir2 = temp_dir_.path().Append(FPL("dir2")); |
1729 EXPECT_TRUE(CreateDirectory(dir2)); | 1729 EXPECT_TRUE(base::CreateDirectory(dir2)); |
1730 FilePath dir2inner = dir2.Append(FPL("inner")); | 1730 FilePath dir2inner = dir2.Append(FPL("inner")); |
1731 EXPECT_TRUE(CreateDirectory(dir2inner)); | 1731 EXPECT_TRUE(base::CreateDirectory(dir2inner)); |
1732 | 1732 |
1733 // create the files | 1733 // create the files |
1734 FilePath dir2file = dir2.Append(FPL("dir2file.txt")); | 1734 FilePath dir2file = dir2.Append(FPL("dir2file.txt")); |
1735 CreateTextFile(dir2file, std::wstring()); | 1735 CreateTextFile(dir2file, std::wstring()); |
1736 FilePath dir2innerfile = dir2inner.Append(FPL("innerfile.txt")); | 1736 FilePath dir2innerfile = dir2inner.Append(FPL("innerfile.txt")); |
1737 CreateTextFile(dir2innerfile, std::wstring()); | 1737 CreateTextFile(dir2innerfile, std::wstring()); |
1738 FilePath file1 = temp_dir_.path().Append(FPL("file1.txt")); | 1738 FilePath file1 = temp_dir_.path().Append(FPL("file1.txt")); |
1739 CreateTextFile(file1, std::wstring()); | 1739 CreateTextFile(file1, std::wstring()); |
1740 FilePath file2_rel = dir2.Append(FilePath::kParentDirectory) | 1740 FilePath file2_rel = dir2.Append(FilePath::kParentDirectory) |
1741 .Append(FPL("file2.txt")); | 1741 .Append(FPL("file2.txt")); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1807 EXPECT_TRUE(c5.HasFile(dir2inner)); | 1807 EXPECT_TRUE(c5.HasFile(dir2inner)); |
1808 EXPECT_TRUE(c5.HasFile(dir2innerfile)); | 1808 EXPECT_TRUE(c5.HasFile(dir2innerfile)); |
1809 EXPECT_EQ(c5.size(), 5); | 1809 EXPECT_EQ(c5.size(), 5); |
1810 | 1810 |
1811 #if defined(OS_WIN) | 1811 #if defined(OS_WIN) |
1812 { | 1812 { |
1813 // Make dir1 point to dir2. | 1813 // Make dir1 point to dir2. |
1814 ReparsePoint reparse_point(dir1, dir2); | 1814 ReparsePoint reparse_point(dir1, dir2); |
1815 EXPECT_TRUE(reparse_point.IsValid()); | 1815 EXPECT_TRUE(reparse_point.IsValid()); |
1816 | 1816 |
1817 if ((win::GetVersion() >= win::VERSION_VISTA)) { | 1817 if ((win::GetVersion() >= base::win::VERSION_VISTA)) { |
1818 // There can be a delay for the enumeration code to see the change on | 1818 // There can be a delay for the enumeration code to see the change on |
1819 // the file system so skip this test for XP. | 1819 // the file system so skip this test for XP. |
1820 // Enumerate the reparse point. | 1820 // Enumerate the reparse point. |
1821 FileEnumerator f6(dir1, true, FILES_AND_DIRECTORIES); | 1821 FileEnumerator f6(dir1, true, FILES_AND_DIRECTORIES); |
1822 FindResultCollector c6(f6); | 1822 FindResultCollector c6(f6); |
1823 FilePath inner2 = dir1.Append(FPL("inner")); | 1823 FilePath inner2 = dir1.Append(FPL("inner")); |
1824 EXPECT_TRUE(c6.HasFile(inner2)); | 1824 EXPECT_TRUE(c6.HasFile(inner2)); |
1825 EXPECT_TRUE(c6.HasFile(inner2.Append(FPL("innerfile.txt")))); | 1825 EXPECT_TRUE(c6.HasFile(inner2.Append(FPL("innerfile.txt")))); |
1826 EXPECT_TRUE(c6.HasFile(dir1.Append(FPL("dir2file.txt")))); | 1826 EXPECT_TRUE(c6.HasFile(dir1.Append(FPL("dir2file.txt")))); |
1827 EXPECT_EQ(c6.size(), 3); | 1827 EXPECT_EQ(c6.size(), 3); |
(...skipping 30 matching lines...) Expand all Loading... |
1858 } | 1858 } |
1859 | 1859 |
1860 TEST_F(FileUtilTest, AppendToFile) { | 1860 TEST_F(FileUtilTest, AppendToFile) { |
1861 FilePath data_dir = | 1861 FilePath data_dir = |
1862 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); | 1862 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); |
1863 | 1863 |
1864 // Create a fresh, empty copy of this directory. | 1864 // Create a fresh, empty copy of this directory. |
1865 if (PathExists(data_dir)) { | 1865 if (PathExists(data_dir)) { |
1866 ASSERT_TRUE(DeleteFile(data_dir, true)); | 1866 ASSERT_TRUE(DeleteFile(data_dir, true)); |
1867 } | 1867 } |
1868 ASSERT_TRUE(CreateDirectory(data_dir)); | 1868 ASSERT_TRUE(base::CreateDirectory(data_dir)); |
1869 | 1869 |
1870 // Create a fresh, empty copy of this directory. | 1870 // Create a fresh, empty copy of this directory. |
1871 if (PathExists(data_dir)) { | 1871 if (PathExists(data_dir)) { |
1872 ASSERT_TRUE(DeleteFile(data_dir, true)); | 1872 ASSERT_TRUE(DeleteFile(data_dir, true)); |
1873 } | 1873 } |
1874 ASSERT_TRUE(CreateDirectory(data_dir)); | 1874 ASSERT_TRUE(base::CreateDirectory(data_dir)); |
1875 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); | 1875 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); |
1876 | 1876 |
1877 std::string data("hello"); | 1877 std::string data("hello"); |
1878 EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length())); | 1878 EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length())); |
1879 EXPECT_EQ(static_cast<int>(data.length()), | 1879 EXPECT_EQ(static_cast<int>(data.length()), |
1880 file_util::WriteFile(foobar, data.c_str(), data.length())); | 1880 file_util::WriteFile(foobar, data.c_str(), data.length())); |
1881 EXPECT_EQ(static_cast<int>(data.length()), | 1881 EXPECT_EQ(static_cast<int>(data.length()), |
1882 file_util::AppendToFile(foobar, data.c_str(), data.length())); | 1882 file_util::AppendToFile(foobar, data.c_str(), data.length())); |
1883 | 1883 |
1884 const std::wstring read_content = ReadTextFile(foobar); | 1884 const std::wstring read_content = ReadTextFile(foobar); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1918 access_time.ToInternalValue()); | 1918 access_time.ToInternalValue()); |
1919 EXPECT_EQ(file_info.last_modified.ToInternalValue(), | 1919 EXPECT_EQ(file_info.last_modified.ToInternalValue(), |
1920 modification_time.ToInternalValue()); | 1920 modification_time.ToInternalValue()); |
1921 } | 1921 } |
1922 | 1922 |
1923 TEST_F(FileUtilTest, IsDirectoryEmpty) { | 1923 TEST_F(FileUtilTest, IsDirectoryEmpty) { |
1924 FilePath empty_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("EmptyDir")); | 1924 FilePath empty_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("EmptyDir")); |
1925 | 1925 |
1926 ASSERT_FALSE(PathExists(empty_dir)); | 1926 ASSERT_FALSE(PathExists(empty_dir)); |
1927 | 1927 |
1928 ASSERT_TRUE(CreateDirectory(empty_dir)); | 1928 ASSERT_TRUE(base::CreateDirectory(empty_dir)); |
1929 | 1929 |
1930 EXPECT_TRUE(IsDirectoryEmpty(empty_dir)); | 1930 EXPECT_TRUE(base::IsDirectoryEmpty(empty_dir)); |
1931 | 1931 |
1932 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); | 1932 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); |
1933 std::string bar("baz"); | 1933 std::string bar("baz"); |
1934 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); | 1934 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); |
1935 | 1935 |
1936 EXPECT_FALSE(IsDirectoryEmpty(empty_dir)); | 1936 EXPECT_FALSE(base::IsDirectoryEmpty(empty_dir)); |
1937 } | 1937 } |
1938 | 1938 |
1939 #if defined(OS_POSIX) | 1939 #if defined(OS_POSIX) |
1940 | 1940 |
1941 // Testing VerifyPathControlledByAdmin() is hard, because there is no | 1941 // Testing VerifyPathControlledByAdmin() is hard, because there is no |
1942 // way a test can make a file owned by root, or change file paths | 1942 // way a test can make a file owned by root, or change file paths |
1943 // at the root of the file system. VerifyPathControlledByAdmin() | 1943 // at the root of the file system. VerifyPathControlledByAdmin() |
1944 // is implemented as a call to VerifyPathControlledByUser, which gives | 1944 // is implemented as a call to VerifyPathControlledByUser, which gives |
1945 // us the ability to test with paths under the test's temp directory, | 1945 // us the ability to test with paths under the test's temp directory, |
1946 // using a user id we control. | 1946 // using a user id we control. |
1947 // Pull tests of VerifyPathControlledByUserTest() into a separate test class | 1947 // Pull tests of VerifyPathControlledByUserTest() into a separate test class |
1948 // with a common SetUp() method. | 1948 // with a common SetUp() method. |
1949 class VerifyPathControlledByUserTest : public FileUtilTest { | 1949 class VerifyPathControlledByUserTest : public FileUtilTest { |
1950 protected: | 1950 protected: |
1951 virtual void SetUp() OVERRIDE { | 1951 virtual void SetUp() OVERRIDE { |
1952 FileUtilTest::SetUp(); | 1952 FileUtilTest::SetUp(); |
1953 | 1953 |
1954 // Create a basic structure used by each test. | 1954 // Create a basic structure used by each test. |
1955 // base_dir_ | 1955 // base_dir_ |
1956 // |-> sub_dir_ | 1956 // |-> sub_dir_ |
1957 // |-> text_file_ | 1957 // |-> text_file_ |
1958 | 1958 |
1959 base_dir_ = temp_dir_.path().AppendASCII("base_dir"); | 1959 base_dir_ = temp_dir_.path().AppendASCII("base_dir"); |
1960 ASSERT_TRUE(CreateDirectory(base_dir_)); | 1960 ASSERT_TRUE(base::CreateDirectory(base_dir_)); |
1961 | 1961 |
1962 sub_dir_ = base_dir_.AppendASCII("sub_dir"); | 1962 sub_dir_ = base_dir_.AppendASCII("sub_dir"); |
1963 ASSERT_TRUE(CreateDirectory(sub_dir_)); | 1963 ASSERT_TRUE(base::CreateDirectory(sub_dir_)); |
1964 | 1964 |
1965 text_file_ = sub_dir_.AppendASCII("file.txt"); | 1965 text_file_ = sub_dir_.AppendASCII("file.txt"); |
1966 CreateTextFile(text_file_, L"This text file has some text in it."); | 1966 CreateTextFile(text_file_, L"This text file has some text in it."); |
1967 | 1967 |
1968 // Get the user and group files are created with from |base_dir_|. | 1968 // Get the user and group files are created with from |base_dir_|. |
1969 struct stat stat_buf; | 1969 struct stat stat_buf; |
1970 ASSERT_EQ(0, stat(base_dir_.value().c_str(), &stat_buf)); | 1970 ASSERT_EQ(0, stat(base_dir_.value().c_str(), &stat_buf)); |
1971 uid_ = stat_buf.st_uid; | 1971 uid_ = stat_buf.st_uid; |
1972 ok_gids_.insert(stat_buf.st_gid); | 1972 ok_gids_.insert(stat_buf.st_gid); |
1973 bad_gids_.insert(stat_buf.st_gid + 1); | 1973 bad_gids_.insert(stat_buf.st_gid + 1); |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2347 int fd = OpenContentUriForRead(path); | 2347 int fd = OpenContentUriForRead(path); |
2348 EXPECT_EQ(-1, fd); | 2348 EXPECT_EQ(-1, fd); |
2349 } | 2349 } |
2350 #endif | 2350 #endif |
2351 | 2351 |
2352 #endif // defined(OS_POSIX) | 2352 #endif // defined(OS_POSIX) |
2353 | 2353 |
2354 } // namespace | 2354 } // namespace |
2355 | 2355 |
2356 } // namespace base | 2356 } // namespace base |
OLD | NEW |