| 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 "base/files/file_path_watcher.h" | 5 #include "base/files/file_path_watcher.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <aclapi.h> | 9 #include <aclapi.h> |
| 10 #elif defined(OS_POSIX) | 10 #elif defined(OS_POSIX) |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 } | 267 } |
| 268 | 268 |
| 269 TEST_F(FilePathWatcherTest, DeletedFile) { | 269 TEST_F(FilePathWatcherTest, DeletedFile) { |
| 270 ASSERT_TRUE(WriteFile(test_file(), "content")); | 270 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 271 | 271 |
| 272 FilePathWatcher watcher; | 272 FilePathWatcher watcher; |
| 273 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 273 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 274 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); | 274 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); |
| 275 | 275 |
| 276 // Now make sure we get notified if the file is deleted. | 276 // Now make sure we get notified if the file is deleted. |
| 277 file_util::Delete(test_file(), false); | 277 base::Delete(test_file(), false); |
| 278 ASSERT_TRUE(WaitForEvents()); | 278 ASSERT_TRUE(WaitForEvents()); |
| 279 DeleteDelegateOnFileThread(delegate.release()); | 279 DeleteDelegateOnFileThread(delegate.release()); |
| 280 } | 280 } |
| 281 | 281 |
| 282 // Used by the DeleteDuringNotify test below. | 282 // Used by the DeleteDuringNotify test below. |
| 283 // Deletes the FilePathWatcher when it's notified. | 283 // Deletes the FilePathWatcher when it's notified. |
| 284 class Deleter : public TestDelegateBase { | 284 class Deleter : public TestDelegateBase { |
| 285 public: | 285 public: |
| 286 Deleter(FilePathWatcher* watcher, MessageLoop* loop) | 286 Deleter(FilePathWatcher* watcher, MessageLoop* loop) |
| 287 : watcher_(watcher), | 287 : watcher_(watcher), |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 | 362 |
| 363 ASSERT_TRUE(WriteFile(file, "content")); | 363 ASSERT_TRUE(WriteFile(file, "content")); |
| 364 | 364 |
| 365 VLOG(1) << "Waiting for file creation"; | 365 VLOG(1) << "Waiting for file creation"; |
| 366 ASSERT_TRUE(WaitForEvents()); | 366 ASSERT_TRUE(WaitForEvents()); |
| 367 | 367 |
| 368 ASSERT_TRUE(WriteFile(file, "content v2")); | 368 ASSERT_TRUE(WriteFile(file, "content v2")); |
| 369 VLOG(1) << "Waiting for file change"; | 369 VLOG(1) << "Waiting for file change"; |
| 370 ASSERT_TRUE(WaitForEvents()); | 370 ASSERT_TRUE(WaitForEvents()); |
| 371 | 371 |
| 372 ASSERT_TRUE(file_util::Delete(file, false)); | 372 ASSERT_TRUE(base::Delete(file, false)); |
| 373 VLOG(1) << "Waiting for file deletion"; | 373 VLOG(1) << "Waiting for file deletion"; |
| 374 ASSERT_TRUE(WaitForEvents()); | 374 ASSERT_TRUE(WaitForEvents()); |
| 375 DeleteDelegateOnFileThread(delegate.release()); | 375 DeleteDelegateOnFileThread(delegate.release()); |
| 376 } | 376 } |
| 377 | 377 |
| 378 // Exercises watch reconfiguration for the case that directories on the path | 378 // Exercises watch reconfiguration for the case that directories on the path |
| 379 // are rapidly created. | 379 // are rapidly created. |
| 380 TEST_F(FilePathWatcherTest, DirectoryChain) { | 380 TEST_F(FilePathWatcherTest, DirectoryChain) { |
| 381 FilePath path(temp_dir_.path()); | 381 FilePath path(temp_dir_.path()); |
| 382 std::vector<std::string> dir_names; | 382 std::vector<std::string> dir_names; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 #endif | 414 #endif |
| 415 TEST_F(FilePathWatcherTest, DisappearingDirectory) { | 415 TEST_F(FilePathWatcherTest, DisappearingDirectory) { |
| 416 FilePathWatcher watcher; | 416 FilePathWatcher watcher; |
| 417 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 417 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 418 FilePath file(dir.AppendASCII("file")); | 418 FilePath file(dir.AppendASCII("file")); |
| 419 ASSERT_TRUE(file_util::CreateDirectory(dir)); | 419 ASSERT_TRUE(file_util::CreateDirectory(dir)); |
| 420 ASSERT_TRUE(WriteFile(file, "content")); | 420 ASSERT_TRUE(WriteFile(file, "content")); |
| 421 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 421 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 422 ASSERT_TRUE(SetupWatch(file, &watcher, delegate.get(), false)); | 422 ASSERT_TRUE(SetupWatch(file, &watcher, delegate.get(), false)); |
| 423 | 423 |
| 424 ASSERT_TRUE(file_util::Delete(dir, true)); | 424 ASSERT_TRUE(base::Delete(dir, true)); |
| 425 ASSERT_TRUE(WaitForEvents()); | 425 ASSERT_TRUE(WaitForEvents()); |
| 426 DeleteDelegateOnFileThread(delegate.release()); | 426 DeleteDelegateOnFileThread(delegate.release()); |
| 427 } | 427 } |
| 428 | 428 |
| 429 // Tests that a file that is deleted and reappears is tracked correctly. | 429 // Tests that a file that is deleted and reappears is tracked correctly. |
| 430 TEST_F(FilePathWatcherTest, DeleteAndRecreate) { | 430 TEST_F(FilePathWatcherTest, DeleteAndRecreate) { |
| 431 ASSERT_TRUE(WriteFile(test_file(), "content")); | 431 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 432 FilePathWatcher watcher; | 432 FilePathWatcher watcher; |
| 433 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 433 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 434 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); | 434 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); |
| 435 | 435 |
| 436 ASSERT_TRUE(file_util::Delete(test_file(), false)); | 436 ASSERT_TRUE(base::Delete(test_file(), false)); |
| 437 VLOG(1) << "Waiting for file deletion"; | 437 VLOG(1) << "Waiting for file deletion"; |
| 438 ASSERT_TRUE(WaitForEvents()); | 438 ASSERT_TRUE(WaitForEvents()); |
| 439 | 439 |
| 440 ASSERT_TRUE(WriteFile(test_file(), "content")); | 440 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 441 VLOG(1) << "Waiting for file creation"; | 441 VLOG(1) << "Waiting for file creation"; |
| 442 ASSERT_TRUE(WaitForEvents()); | 442 ASSERT_TRUE(WaitForEvents()); |
| 443 DeleteDelegateOnFileThread(delegate.release()); | 443 DeleteDelegateOnFileThread(delegate.release()); |
| 444 } | 444 } |
| 445 | 445 |
| 446 TEST_F(FilePathWatcherTest, WatchDirectory) { | 446 TEST_F(FilePathWatcherTest, WatchDirectory) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 459 VLOG(1) << "Waiting for file1 creation"; | 459 VLOG(1) << "Waiting for file1 creation"; |
| 460 ASSERT_TRUE(WaitForEvents()); | 460 ASSERT_TRUE(WaitForEvents()); |
| 461 | 461 |
| 462 #if !defined(OS_MACOSX) | 462 #if !defined(OS_MACOSX) |
| 463 // Mac implementation does not detect files modified in a directory. | 463 // Mac implementation does not detect files modified in a directory. |
| 464 ASSERT_TRUE(WriteFile(file1, "content v2")); | 464 ASSERT_TRUE(WriteFile(file1, "content v2")); |
| 465 VLOG(1) << "Waiting for file1 modification"; | 465 VLOG(1) << "Waiting for file1 modification"; |
| 466 ASSERT_TRUE(WaitForEvents()); | 466 ASSERT_TRUE(WaitForEvents()); |
| 467 #endif // !OS_MACOSX | 467 #endif // !OS_MACOSX |
| 468 | 468 |
| 469 ASSERT_TRUE(file_util::Delete(file1, false)); | 469 ASSERT_TRUE(base::Delete(file1, false)); |
| 470 VLOG(1) << "Waiting for file1 deletion"; | 470 VLOG(1) << "Waiting for file1 deletion"; |
| 471 ASSERT_TRUE(WaitForEvents()); | 471 ASSERT_TRUE(WaitForEvents()); |
| 472 | 472 |
| 473 ASSERT_TRUE(WriteFile(file2, "content")); | 473 ASSERT_TRUE(WriteFile(file2, "content")); |
| 474 VLOG(1) << "Waiting for file2 creation"; | 474 VLOG(1) << "Waiting for file2 creation"; |
| 475 ASSERT_TRUE(WaitForEvents()); | 475 ASSERT_TRUE(WaitForEvents()); |
| 476 DeleteDelegateOnFileThread(delegate.release()); | 476 DeleteDelegateOnFileThread(delegate.release()); |
| 477 } | 477 } |
| 478 | 478 |
| 479 TEST_F(FilePathWatcherTest, MoveParent) { | 479 TEST_F(FilePathWatcherTest, MoveParent) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 | 541 |
| 542 // Write into "$dir/subdir/subdir_child_dir/child_dir_file1". | 542 // Write into "$dir/subdir/subdir_child_dir/child_dir_file1". |
| 543 ASSERT_TRUE(WriteFile(child_dir_file1, "content")); | 543 ASSERT_TRUE(WriteFile(child_dir_file1, "content")); |
| 544 ASSERT_TRUE(WaitForEvents()); | 544 ASSERT_TRUE(WaitForEvents()); |
| 545 | 545 |
| 546 // Modify "$dir/subdir/subdir_child_dir/child_dir_file1" attributes. | 546 // Modify "$dir/subdir/subdir_child_dir/child_dir_file1" attributes. |
| 547 ASSERT_TRUE(file_util::MakeFileUnreadable(child_dir_file1)); | 547 ASSERT_TRUE(file_util::MakeFileUnreadable(child_dir_file1)); |
| 548 ASSERT_TRUE(WaitForEvents()); | 548 ASSERT_TRUE(WaitForEvents()); |
| 549 | 549 |
| 550 // Delete "$dir/subdir/subdir_file1". | 550 // Delete "$dir/subdir/subdir_file1". |
| 551 ASSERT_TRUE(file_util::Delete(subdir_file1, false)); | 551 ASSERT_TRUE(base::Delete(subdir_file1, false)); |
| 552 ASSERT_TRUE(WaitForEvents()); | 552 ASSERT_TRUE(WaitForEvents()); |
| 553 | 553 |
| 554 // Delete "$dir/subdir/subdir_child_dir/child_dir_file1". | 554 // Delete "$dir/subdir/subdir_child_dir/child_dir_file1". |
| 555 ASSERT_TRUE(file_util::Delete(child_dir_file1, false)); | 555 ASSERT_TRUE(base::Delete(child_dir_file1, false)); |
| 556 ASSERT_TRUE(WaitForEvents()); | 556 ASSERT_TRUE(WaitForEvents()); |
| 557 DeleteDelegateOnFileThread(delegate.release()); | 557 DeleteDelegateOnFileThread(delegate.release()); |
| 558 } | 558 } |
| 559 #else | 559 #else |
| 560 TEST_F(FilePathWatcherTest, RecursiveWatch) { | 560 TEST_F(FilePathWatcherTest, RecursiveWatch) { |
| 561 FilePathWatcher watcher; | 561 FilePathWatcher watcher; |
| 562 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 562 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 563 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 563 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 564 // Non-Windows implementaion does not support recursive watching. | 564 // Non-Windows implementaion does not support recursive watching. |
| 565 ASSERT_FALSE(SetupWatch(dir, &watcher, delegate.get(), true)); | 565 ASSERT_FALSE(SetupWatch(dir, &watcher, delegate.get(), true)); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 TEST_F(FilePathWatcherTest, DeleteLink) { | 633 TEST_F(FilePathWatcherTest, DeleteLink) { |
| 634 // Unfortunately this test case only works if the link target exists. | 634 // Unfortunately this test case only works if the link target exists. |
| 635 // TODO(craig) fix this as part of crbug.com/91561. | 635 // TODO(craig) fix this as part of crbug.com/91561. |
| 636 ASSERT_TRUE(WriteFile(test_file(), "content")); | 636 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 637 ASSERT_TRUE(file_util::CreateSymbolicLink(test_file(), test_link())); | 637 ASSERT_TRUE(file_util::CreateSymbolicLink(test_file(), test_link())); |
| 638 FilePathWatcher watcher; | 638 FilePathWatcher watcher; |
| 639 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 639 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 640 ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false)); | 640 ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false)); |
| 641 | 641 |
| 642 // Now make sure we get notified if the link is deleted. | 642 // Now make sure we get notified if the link is deleted. |
| 643 ASSERT_TRUE(file_util::Delete(test_link(), false)); | 643 ASSERT_TRUE(base::Delete(test_link(), false)); |
| 644 ASSERT_TRUE(WaitForEvents()); | 644 ASSERT_TRUE(WaitForEvents()); |
| 645 DeleteDelegateOnFileThread(delegate.release()); | 645 DeleteDelegateOnFileThread(delegate.release()); |
| 646 } | 646 } |
| 647 | 647 |
| 648 // Verify that modifying a target file that a link is pointing to | 648 // Verify that modifying a target file that a link is pointing to |
| 649 // when we are watching the link is caught. | 649 // when we are watching the link is caught. |
| 650 TEST_F(FilePathWatcherTest, ModifiedLinkedFile) { | 650 TEST_F(FilePathWatcherTest, ModifiedLinkedFile) { |
| 651 ASSERT_TRUE(WriteFile(test_file(), "content")); | 651 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 652 ASSERT_TRUE(file_util::CreateSymbolicLink(test_file(), test_link())); | 652 ASSERT_TRUE(file_util::CreateSymbolicLink(test_file(), test_link())); |
| 653 FilePathWatcher watcher; | 653 FilePathWatcher watcher; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 680 // when we are watching the link is caught. | 680 // when we are watching the link is caught. |
| 681 TEST_F(FilePathWatcherTest, DeleteTargetLinkedFile) { | 681 TEST_F(FilePathWatcherTest, DeleteTargetLinkedFile) { |
| 682 ASSERT_TRUE(WriteFile(test_file(), "content")); | 682 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 683 ASSERT_TRUE(file_util::CreateSymbolicLink(test_file(), test_link())); | 683 ASSERT_TRUE(file_util::CreateSymbolicLink(test_file(), test_link())); |
| 684 FilePathWatcher watcher; | 684 FilePathWatcher watcher; |
| 685 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 685 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 686 // Note that we are watching the symlink. | 686 // Note that we are watching the symlink. |
| 687 ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false)); | 687 ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false)); |
| 688 | 688 |
| 689 // Now make sure we get notified if the target file is deleted. | 689 // Now make sure we get notified if the target file is deleted. |
| 690 ASSERT_TRUE(file_util::Delete(test_file(), false)); | 690 ASSERT_TRUE(base::Delete(test_file(), false)); |
| 691 ASSERT_TRUE(WaitForEvents()); | 691 ASSERT_TRUE(WaitForEvents()); |
| 692 DeleteDelegateOnFileThread(delegate.release()); | 692 DeleteDelegateOnFileThread(delegate.release()); |
| 693 } | 693 } |
| 694 | 694 |
| 695 // Verify that watching a file whose parent directory is a link that | 695 // Verify that watching a file whose parent directory is a link that |
| 696 // doesn't exist yet works if the symlink is created eventually. | 696 // doesn't exist yet works if the symlink is created eventually. |
| 697 TEST_F(FilePathWatcherTest, LinkedDirectoryPart1) { | 697 TEST_F(FilePathWatcherTest, LinkedDirectoryPart1) { |
| 698 FilePathWatcher watcher; | 698 FilePathWatcher watcher; |
| 699 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 699 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 700 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); | 700 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); |
| 701 FilePath file(dir.AppendASCII("file")); | 701 FilePath file(dir.AppendASCII("file")); |
| 702 FilePath linkfile(link_dir.AppendASCII("file")); | 702 FilePath linkfile(link_dir.AppendASCII("file")); |
| 703 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 703 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 704 // dir/file should exist. | 704 // dir/file should exist. |
| 705 ASSERT_TRUE(file_util::CreateDirectory(dir)); | 705 ASSERT_TRUE(file_util::CreateDirectory(dir)); |
| 706 ASSERT_TRUE(WriteFile(file, "content")); | 706 ASSERT_TRUE(WriteFile(file, "content")); |
| 707 // Note that we are watching dir.lnk/file which doesn't exist yet. | 707 // Note that we are watching dir.lnk/file which doesn't exist yet. |
| 708 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); | 708 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); |
| 709 | 709 |
| 710 ASSERT_TRUE(file_util::CreateSymbolicLink(dir, link_dir)); | 710 ASSERT_TRUE(file_util::CreateSymbolicLink(dir, link_dir)); |
| 711 VLOG(1) << "Waiting for link creation"; | 711 VLOG(1) << "Waiting for link creation"; |
| 712 ASSERT_TRUE(WaitForEvents()); | 712 ASSERT_TRUE(WaitForEvents()); |
| 713 | 713 |
| 714 ASSERT_TRUE(WriteFile(file, "content v2")); | 714 ASSERT_TRUE(WriteFile(file, "content v2")); |
| 715 VLOG(1) << "Waiting for file change"; | 715 VLOG(1) << "Waiting for file change"; |
| 716 ASSERT_TRUE(WaitForEvents()); | 716 ASSERT_TRUE(WaitForEvents()); |
| 717 | 717 |
| 718 ASSERT_TRUE(file_util::Delete(file, false)); | 718 ASSERT_TRUE(base::Delete(file, false)); |
| 719 VLOG(1) << "Waiting for file deletion"; | 719 VLOG(1) << "Waiting for file deletion"; |
| 720 ASSERT_TRUE(WaitForEvents()); | 720 ASSERT_TRUE(WaitForEvents()); |
| 721 DeleteDelegateOnFileThread(delegate.release()); | 721 DeleteDelegateOnFileThread(delegate.release()); |
| 722 } | 722 } |
| 723 | 723 |
| 724 // Verify that watching a file whose parent directory is a | 724 // Verify that watching a file whose parent directory is a |
| 725 // dangling symlink works if the directory is created eventually. | 725 // dangling symlink works if the directory is created eventually. |
| 726 TEST_F(FilePathWatcherTest, LinkedDirectoryPart2) { | 726 TEST_F(FilePathWatcherTest, LinkedDirectoryPart2) { |
| 727 FilePathWatcher watcher; | 727 FilePathWatcher watcher; |
| 728 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 728 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 729 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); | 729 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); |
| 730 FilePath file(dir.AppendASCII("file")); | 730 FilePath file(dir.AppendASCII("file")); |
| 731 FilePath linkfile(link_dir.AppendASCII("file")); | 731 FilePath linkfile(link_dir.AppendASCII("file")); |
| 732 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 732 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 733 // Now create the link from dir.lnk pointing to dir but | 733 // Now create the link from dir.lnk pointing to dir but |
| 734 // neither dir nor dir/file exist yet. | 734 // neither dir nor dir/file exist yet. |
| 735 ASSERT_TRUE(file_util::CreateSymbolicLink(dir, link_dir)); | 735 ASSERT_TRUE(file_util::CreateSymbolicLink(dir, link_dir)); |
| 736 // Note that we are watching dir.lnk/file. | 736 // Note that we are watching dir.lnk/file. |
| 737 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); | 737 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); |
| 738 | 738 |
| 739 ASSERT_TRUE(file_util::CreateDirectory(dir)); | 739 ASSERT_TRUE(file_util::CreateDirectory(dir)); |
| 740 ASSERT_TRUE(WriteFile(file, "content")); | 740 ASSERT_TRUE(WriteFile(file, "content")); |
| 741 VLOG(1) << "Waiting for dir/file creation"; | 741 VLOG(1) << "Waiting for dir/file creation"; |
| 742 ASSERT_TRUE(WaitForEvents()); | 742 ASSERT_TRUE(WaitForEvents()); |
| 743 | 743 |
| 744 ASSERT_TRUE(WriteFile(file, "content v2")); | 744 ASSERT_TRUE(WriteFile(file, "content v2")); |
| 745 VLOG(1) << "Waiting for file change"; | 745 VLOG(1) << "Waiting for file change"; |
| 746 ASSERT_TRUE(WaitForEvents()); | 746 ASSERT_TRUE(WaitForEvents()); |
| 747 | 747 |
| 748 ASSERT_TRUE(file_util::Delete(file, false)); | 748 ASSERT_TRUE(base::Delete(file, false)); |
| 749 VLOG(1) << "Waiting for file deletion"; | 749 VLOG(1) << "Waiting for file deletion"; |
| 750 ASSERT_TRUE(WaitForEvents()); | 750 ASSERT_TRUE(WaitForEvents()); |
| 751 DeleteDelegateOnFileThread(delegate.release()); | 751 DeleteDelegateOnFileThread(delegate.release()); |
| 752 } | 752 } |
| 753 | 753 |
| 754 // Verify that watching a file with a symlink on the path | 754 // Verify that watching a file with a symlink on the path |
| 755 // to the file works. | 755 // to the file works. |
| 756 TEST_F(FilePathWatcherTest, LinkedDirectoryPart3) { | 756 TEST_F(FilePathWatcherTest, LinkedDirectoryPart3) { |
| 757 FilePathWatcher watcher; | 757 FilePathWatcher watcher; |
| 758 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 758 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 759 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); | 759 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); |
| 760 FilePath file(dir.AppendASCII("file")); | 760 FilePath file(dir.AppendASCII("file")); |
| 761 FilePath linkfile(link_dir.AppendASCII("file")); | 761 FilePath linkfile(link_dir.AppendASCII("file")); |
| 762 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 762 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 763 ASSERT_TRUE(file_util::CreateDirectory(dir)); | 763 ASSERT_TRUE(file_util::CreateDirectory(dir)); |
| 764 ASSERT_TRUE(file_util::CreateSymbolicLink(dir, link_dir)); | 764 ASSERT_TRUE(file_util::CreateSymbolicLink(dir, link_dir)); |
| 765 // Note that we are watching dir.lnk/file but the file doesn't exist yet. | 765 // Note that we are watching dir.lnk/file but the file doesn't exist yet. |
| 766 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); | 766 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); |
| 767 | 767 |
| 768 ASSERT_TRUE(WriteFile(file, "content")); | 768 ASSERT_TRUE(WriteFile(file, "content")); |
| 769 VLOG(1) << "Waiting for file creation"; | 769 VLOG(1) << "Waiting for file creation"; |
| 770 ASSERT_TRUE(WaitForEvents()); | 770 ASSERT_TRUE(WaitForEvents()); |
| 771 | 771 |
| 772 ASSERT_TRUE(WriteFile(file, "content v2")); | 772 ASSERT_TRUE(WriteFile(file, "content v2")); |
| 773 VLOG(1) << "Waiting for file change"; | 773 VLOG(1) << "Waiting for file change"; |
| 774 ASSERT_TRUE(WaitForEvents()); | 774 ASSERT_TRUE(WaitForEvents()); |
| 775 | 775 |
| 776 ASSERT_TRUE(file_util::Delete(file, false)); | 776 ASSERT_TRUE(base::Delete(file, false)); |
| 777 VLOG(1) << "Waiting for file deletion"; | 777 VLOG(1) << "Waiting for file deletion"; |
| 778 ASSERT_TRUE(WaitForEvents()); | 778 ASSERT_TRUE(WaitForEvents()); |
| 779 DeleteDelegateOnFileThread(delegate.release()); | 779 DeleteDelegateOnFileThread(delegate.release()); |
| 780 } | 780 } |
| 781 | 781 |
| 782 #endif // OS_LINUX | 782 #endif // OS_LINUX |
| 783 | 783 |
| 784 enum Permission { | 784 enum Permission { |
| 785 Read, | 785 Read, |
| 786 Write, | 786 Write, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); | 906 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); |
| 907 ASSERT_TRUE(WaitForEvents()); | 907 ASSERT_TRUE(WaitForEvents()); |
| 908 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); | 908 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); |
| 909 DeleteDelegateOnFileThread(delegate.release()); | 909 DeleteDelegateOnFileThread(delegate.release()); |
| 910 } | 910 } |
| 911 | 911 |
| 912 #endif // OS_MACOSX | 912 #endif // OS_MACOSX |
| 913 } // namespace | 913 } // namespace |
| 914 | 914 |
| 915 } // namespace base | 915 } // namespace base |
| OLD | NEW |