| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 EXPECT_FALSE(file_util::PathExists(file_name)); | 373 EXPECT_FALSE(file_util::PathExists(file_name)); |
| 374 EXPECT_TRUE(file_util::PathExists(subdir_path)); | 374 EXPECT_TRUE(file_util::PathExists(subdir_path)); |
| 375 #endif | 375 #endif |
| 376 | 376 |
| 377 // Delete recursively and make sure all contents are deleted | 377 // Delete recursively and make sure all contents are deleted |
| 378 ASSERT_TRUE(file_util::Delete(directory_contents, true)); | 378 ASSERT_TRUE(file_util::Delete(directory_contents, true)); |
| 379 EXPECT_FALSE(file_util::PathExists(file_name)); | 379 EXPECT_FALSE(file_util::PathExists(file_name)); |
| 380 EXPECT_FALSE(file_util::PathExists(subdir_path)); | 380 EXPECT_FALSE(file_util::PathExists(subdir_path)); |
| 381 } | 381 } |
| 382 | 382 |
| 383 TEST_F(FileUtilTest, Move) { | 383 TEST_F(FileUtilTest, MoveNew) { |
| 384 // Create a directory | 384 // Create a directory |
| 385 FilePath dir_name_from = | 385 FilePath dir_name_from = |
| 386 test_dir_.Append(FILE_PATH_LITERAL("Move_From_Subdir")); | 386 test_dir_.Append(FILE_PATH_LITERAL("Move_From_Subdir")); |
| 387 file_util::CreateDirectory(dir_name_from); | 387 file_util::CreateDirectory(dir_name_from); |
| 388 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 388 ASSERT_TRUE(file_util::PathExists(dir_name_from)); |
| 389 | 389 |
| 390 // Create a file under the directory | 390 // Create a file under the directory |
| 391 FilePath file_name_from = | 391 FilePath file_name_from = |
| 392 dir_name_from.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 392 dir_name_from.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 393 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 393 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 394 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 394 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
| 395 | 395 |
| 396 // Move the directory | 396 // Move the directory |
| 397 FilePath dir_name_to = test_dir_.Append(FILE_PATH_LITERAL("Move_To_Subdir")); | 397 FilePath dir_name_to = test_dir_.Append(FILE_PATH_LITERAL("Move_To_Subdir")); |
| 398 FilePath file_name_to = | 398 FilePath file_name_to = |
| 399 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 399 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 400 | 400 |
| 401 ASSERT_FALSE(file_util::PathExists(dir_name_to)); | 401 ASSERT_FALSE(file_util::PathExists(dir_name_to)); |
| 402 | 402 |
| 403 EXPECT_TRUE(file_util::Move(dir_name_from, dir_name_to)); | 403 EXPECT_TRUE(file_util::Move(dir_name_from, dir_name_to)); |
| 404 | 404 |
| 405 // Check everything has been moved. | 405 // Check everything has been moved. |
| 406 EXPECT_FALSE(file_util::PathExists(dir_name_from)); | 406 EXPECT_FALSE(file_util::PathExists(dir_name_from)); |
| 407 EXPECT_FALSE(file_util::PathExists(file_name_from)); | 407 EXPECT_FALSE(file_util::PathExists(file_name_from)); |
| 408 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 408 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
| 409 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 409 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
| 410 } | 410 } |
| 411 | 411 |
| 412 TEST_F(FileUtilTest, CopyDirectoryRecursively) { | 412 TEST_F(FileUtilTest, MoveExist) { |
| 413 // Create a directory |
| 414 FilePath dir_name_from = |
| 415 test_dir_.Append(FILE_PATH_LITERAL("Move_From_Subdir")); |
| 416 file_util::CreateDirectory(dir_name_from); |
| 417 ASSERT_TRUE(file_util::PathExists(dir_name_from)); |
| 418 |
| 419 // Create a file under the directory |
| 420 FilePath file_name_from = |
| 421 dir_name_from.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 422 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 423 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
| 424 |
| 425 // Move the directory |
| 426 FilePath dir_name_exists = |
| 427 test_dir_.Append(FILE_PATH_LITERAL("Destination")); |
| 428 |
| 429 FilePath dir_name_to = |
| 430 dir_name_exists.Append(FILE_PATH_LITERAL("Move_To_Subdir")); |
| 431 FilePath file_name_to = |
| 432 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 433 |
| 434 // Create the destination directory. |
| 435 file_util::CreateDirectory(dir_name_exists); |
| 436 ASSERT_TRUE(file_util::PathExists(dir_name_exists)); |
| 437 |
| 438 EXPECT_TRUE(file_util::Move(dir_name_from, dir_name_to)); |
| 439 |
| 440 // Check everything has been moved. |
| 441 EXPECT_FALSE(file_util::PathExists(dir_name_from)); |
| 442 EXPECT_FALSE(file_util::PathExists(file_name_from)); |
| 443 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
| 444 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
| 445 } |
| 446 |
| 447 TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) { |
| 413 // Create a directory. | 448 // Create a directory. |
| 414 FilePath dir_name_from = | 449 FilePath dir_name_from = |
| 415 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 450 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 416 file_util::CreateDirectory(dir_name_from); | 451 file_util::CreateDirectory(dir_name_from); |
| 417 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 452 ASSERT_TRUE(file_util::PathExists(dir_name_from)); |
| 418 | 453 |
| 419 // Create a file under the directory. | 454 // Create a file under the directory. |
| 420 FilePath file_name_from = | 455 FilePath file_name_from = |
| 421 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 456 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 422 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 457 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 452 EXPECT_TRUE(file_util::PathExists(dir_name_from)); | 487 EXPECT_TRUE(file_util::PathExists(dir_name_from)); |
| 453 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 488 EXPECT_TRUE(file_util::PathExists(file_name_from)); |
| 454 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); | 489 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); |
| 455 EXPECT_TRUE(file_util::PathExists(file_name2_from)); | 490 EXPECT_TRUE(file_util::PathExists(file_name2_from)); |
| 456 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 491 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
| 457 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 492 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
| 458 EXPECT_TRUE(file_util::PathExists(subdir_name_to)); | 493 EXPECT_TRUE(file_util::PathExists(subdir_name_to)); |
| 459 EXPECT_TRUE(file_util::PathExists(file_name2_to)); | 494 EXPECT_TRUE(file_util::PathExists(file_name2_to)); |
| 460 } | 495 } |
| 461 | 496 |
| 462 TEST_F(FileUtilTest, CopyDirectory) { | 497 TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) { |
| 463 // Create a directory. | 498 // Create a directory. |
| 464 FilePath dir_name_from = | 499 FilePath dir_name_from = |
| 465 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 500 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 466 file_util::CreateDirectory(dir_name_from); | 501 file_util::CreateDirectory(dir_name_from); |
| 467 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 502 ASSERT_TRUE(file_util::PathExists(dir_name_from)); |
| 468 | 503 |
| 469 // Create a file under the directory. | 504 // Create a file under the directory. |
| 470 FilePath file_name_from = | 505 FilePath file_name_from = |
| 471 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 506 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 472 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 507 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 473 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 508 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
| 474 | 509 |
| 475 // Create a subdirectory. | 510 // Create a subdirectory. |
| 476 FilePath subdir_name_from = | 511 FilePath subdir_name_from = |
| 477 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 512 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 478 file_util::CreateDirectory(subdir_name_from); | 513 file_util::CreateDirectory(subdir_name_from); |
| 479 ASSERT_TRUE(file_util::PathExists(subdir_name_from)); | 514 ASSERT_TRUE(file_util::PathExists(subdir_name_from)); |
| 480 | 515 |
| 481 // Create a file under the subdirectory. | 516 // Create a file under the subdirectory. |
| 482 FilePath file_name2_from = | 517 FilePath file_name2_from = |
| 483 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 518 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 484 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 519 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
| 485 ASSERT_TRUE(file_util::PathExists(file_name2_from)); | 520 ASSERT_TRUE(file_util::PathExists(file_name2_from)); |
| 486 | 521 |
| 522 // Copy the directory recursively. |
| 523 FilePath dir_name_exists = |
| 524 test_dir_.Append(FILE_PATH_LITERAL("Destination")); |
| 525 |
| 526 FilePath dir_name_to = |
| 527 dir_name_exists.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 528 FilePath file_name_to = |
| 529 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 530 FilePath subdir_name_to = |
| 531 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
| 532 FilePath file_name2_to = |
| 533 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 534 |
| 535 // Create the destination directory. |
| 536 file_util::CreateDirectory(dir_name_exists); |
| 537 ASSERT_TRUE(file_util::PathExists(dir_name_exists)); |
| 538 |
| 539 EXPECT_TRUE(file_util::CopyDirectory(dir_name_from, dir_name_exists, true)); |
| 540 |
| 541 // Check everything has been copied. |
| 542 EXPECT_TRUE(file_util::PathExists(dir_name_from)); |
| 543 EXPECT_TRUE(file_util::PathExists(file_name_from)); |
| 544 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); |
| 545 EXPECT_TRUE(file_util::PathExists(file_name2_from)); |
| 546 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
| 547 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
| 548 EXPECT_TRUE(file_util::PathExists(subdir_name_to)); |
| 549 EXPECT_TRUE(file_util::PathExists(file_name2_to)); |
| 550 } |
| 551 |
| 552 TEST_F(FileUtilTest, CopyDirectoryNew) { |
| 553 // Create a directory. |
| 554 FilePath dir_name_from = |
| 555 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 556 file_util::CreateDirectory(dir_name_from); |
| 557 ASSERT_TRUE(file_util::PathExists(dir_name_from)); |
| 558 |
| 559 // Create a file under the directory. |
| 560 FilePath file_name_from = |
| 561 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 562 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 563 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
| 564 |
| 565 // Create a subdirectory. |
| 566 FilePath subdir_name_from = |
| 567 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 568 file_util::CreateDirectory(subdir_name_from); |
| 569 ASSERT_TRUE(file_util::PathExists(subdir_name_from)); |
| 570 |
| 571 // Create a file under the subdirectory. |
| 572 FilePath file_name2_from = |
| 573 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 574 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
| 575 ASSERT_TRUE(file_util::PathExists(file_name2_from)); |
| 576 |
| 487 // Copy the directory not recursively. | 577 // Copy the directory not recursively. |
| 488 FilePath dir_name_to = | 578 FilePath dir_name_to = |
| 489 test_dir_.Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 579 test_dir_.Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
| 490 FilePath file_name_to = | 580 FilePath file_name_to = |
| 491 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 581 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 492 FilePath subdir_name_to = | 582 FilePath subdir_name_to = |
| 493 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 583 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
| 494 | 584 |
| 495 ASSERT_FALSE(file_util::PathExists(dir_name_to)); | 585 ASSERT_FALSE(file_util::PathExists(dir_name_to)); |
| 496 | 586 |
| 497 EXPECT_TRUE(file_util::CopyDirectory(dir_name_from, dir_name_to, false)); | 587 EXPECT_TRUE(file_util::CopyDirectory(dir_name_from, dir_name_to, false)); |
| 498 | 588 |
| 499 // Check everything has been copied. | 589 // Check everything has been copied. |
| 500 EXPECT_TRUE(file_util::PathExists(dir_name_from)); | 590 EXPECT_TRUE(file_util::PathExists(dir_name_from)); |
| 501 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 591 EXPECT_TRUE(file_util::PathExists(file_name_from)); |
| 502 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); | 592 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); |
| 503 EXPECT_TRUE(file_util::PathExists(file_name2_from)); | 593 EXPECT_TRUE(file_util::PathExists(file_name2_from)); |
| 504 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 594 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
| 505 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 595 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
| 506 EXPECT_FALSE(file_util::PathExists(subdir_name_to)); | 596 EXPECT_FALSE(file_util::PathExists(subdir_name_to)); |
| 507 } | 597 } |
| 508 | 598 |
| 599 TEST_F(FileUtilTest, CopyDirectoryExists) { |
| 600 // Create a directory. |
| 601 FilePath dir_name_from = |
| 602 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 603 file_util::CreateDirectory(dir_name_from); |
| 604 ASSERT_TRUE(file_util::PathExists(dir_name_from)); |
| 605 |
| 606 // Create a file under the directory. |
| 607 FilePath file_name_from = |
| 608 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 609 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 610 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
| 611 |
| 612 // Create a subdirectory. |
| 613 FilePath subdir_name_from = |
| 614 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 615 file_util::CreateDirectory(subdir_name_from); |
| 616 ASSERT_TRUE(file_util::PathExists(subdir_name_from)); |
| 617 |
| 618 // Create a file under the subdirectory. |
| 619 FilePath file_name2_from = |
| 620 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 621 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
| 622 ASSERT_TRUE(file_util::PathExists(file_name2_from)); |
| 623 |
| 624 // Copy the directory not recursively. |
| 625 FilePath dir_name_to = |
| 626 test_dir_.Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
| 627 FilePath file_name_to = |
| 628 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 629 FilePath subdir_name_to = |
| 630 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
| 631 |
| 632 // Create the destination directory. |
| 633 file_util::CreateDirectory(dir_name_to); |
| 634 ASSERT_TRUE(file_util::PathExists(dir_name_to)); |
| 635 |
| 636 EXPECT_TRUE(file_util::CopyDirectory(dir_name_from, dir_name_to, false)); |
| 637 |
| 638 // Check everything has been copied. |
| 639 EXPECT_TRUE(file_util::PathExists(dir_name_from)); |
| 640 EXPECT_TRUE(file_util::PathExists(file_name_from)); |
| 641 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); |
| 642 EXPECT_TRUE(file_util::PathExists(file_name2_from)); |
| 643 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
| 644 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
| 645 EXPECT_FALSE(file_util::PathExists(subdir_name_to)); |
| 646 } |
| 647 |
| 509 TEST_F(FileUtilTest, CopyFile) { | 648 TEST_F(FileUtilTest, CopyFile) { |
| 510 // Create a directory | 649 // Create a directory |
| 511 FilePath dir_name_from = | 650 FilePath dir_name_from = |
| 512 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 651 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 513 file_util::CreateDirectory(dir_name_from); | 652 file_util::CreateDirectory(dir_name_from); |
| 514 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 653 ASSERT_TRUE(file_util::PathExists(dir_name_from)); |
| 515 | 654 |
| 516 // Create a file under the directory | 655 // Create a file under the directory |
| 517 FilePath file_name_from = | 656 FilePath file_name_from = |
| 518 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 657 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 #elif defined(OS_LINUX) | 1239 #elif defined(OS_LINUX) |
| 1101 EXPECT_FALSE(file_util::ContainsPath(foo, | 1240 EXPECT_FALSE(file_util::ContainsPath(foo, |
| 1102 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); | 1241 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); |
| 1103 #else | 1242 #else |
| 1104 // We can't really do this test on osx since the case-sensitivity of the | 1243 // We can't really do this test on osx since the case-sensitivity of the |
| 1105 // filesystem is configurable. | 1244 // filesystem is configurable. |
| 1106 #endif | 1245 #endif |
| 1107 } | 1246 } |
| 1108 | 1247 |
| 1109 } // namespace | 1248 } // namespace |
| OLD | NEW |