| 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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 | 332 |
| 333 // Verify that watching a file whose parent directory doesn't exist yet works if | 333 // Verify that watching a file whose parent directory doesn't exist yet works if |
| 334 // the directory and file are created eventually. | 334 // the directory and file are created eventually. |
| 335 TEST_F(FilePathWatcherTest, NonExistentDirectory) { | 335 TEST_F(FilePathWatcherTest, NonExistentDirectory) { |
| 336 FilePathWatcher watcher; | 336 FilePathWatcher watcher; |
| 337 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 337 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 338 FilePath file(dir.AppendASCII("file")); | 338 FilePath file(dir.AppendASCII("file")); |
| 339 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 339 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 340 ASSERT_TRUE(SetupWatch(file, &watcher, delegate.get(), false)); | 340 ASSERT_TRUE(SetupWatch(file, &watcher, delegate.get(), false)); |
| 341 | 341 |
| 342 ASSERT_TRUE(file_util::CreateDirectory(dir)); | 342 ASSERT_TRUE(base::CreateDirectory(dir)); |
| 343 | 343 |
| 344 ASSERT_TRUE(WriteFile(file, "content")); | 344 ASSERT_TRUE(WriteFile(file, "content")); |
| 345 | 345 |
| 346 VLOG(1) << "Waiting for file creation"; | 346 VLOG(1) << "Waiting for file creation"; |
| 347 ASSERT_TRUE(WaitForEvents()); | 347 ASSERT_TRUE(WaitForEvents()); |
| 348 | 348 |
| 349 ASSERT_TRUE(WriteFile(file, "content v2")); | 349 ASSERT_TRUE(WriteFile(file, "content v2")); |
| 350 VLOG(1) << "Waiting for file change"; | 350 VLOG(1) << "Waiting for file change"; |
| 351 ASSERT_TRUE(WaitForEvents()); | 351 ASSERT_TRUE(WaitForEvents()); |
| 352 | 352 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 369 | 369 |
| 370 FilePathWatcher watcher; | 370 FilePathWatcher watcher; |
| 371 FilePath file(path.AppendASCII("file")); | 371 FilePath file(path.AppendASCII("file")); |
| 372 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 372 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 373 ASSERT_TRUE(SetupWatch(file, &watcher, delegate.get(), false)); | 373 ASSERT_TRUE(SetupWatch(file, &watcher, delegate.get(), false)); |
| 374 | 374 |
| 375 FilePath sub_path(temp_dir_.path()); | 375 FilePath sub_path(temp_dir_.path()); |
| 376 for (std::vector<std::string>::const_iterator d(dir_names.begin()); | 376 for (std::vector<std::string>::const_iterator d(dir_names.begin()); |
| 377 d != dir_names.end(); ++d) { | 377 d != dir_names.end(); ++d) { |
| 378 sub_path = sub_path.AppendASCII(*d); | 378 sub_path = sub_path.AppendASCII(*d); |
| 379 ASSERT_TRUE(file_util::CreateDirectory(sub_path)); | 379 ASSERT_TRUE(base::CreateDirectory(sub_path)); |
| 380 } | 380 } |
| 381 VLOG(1) << "Create File"; | 381 VLOG(1) << "Create File"; |
| 382 ASSERT_TRUE(WriteFile(file, "content")); | 382 ASSERT_TRUE(WriteFile(file, "content")); |
| 383 VLOG(1) << "Waiting for file creation"; | 383 VLOG(1) << "Waiting for file creation"; |
| 384 ASSERT_TRUE(WaitForEvents()); | 384 ASSERT_TRUE(WaitForEvents()); |
| 385 | 385 |
| 386 ASSERT_TRUE(WriteFile(file, "content v2")); | 386 ASSERT_TRUE(WriteFile(file, "content v2")); |
| 387 VLOG(1) << "Waiting for file modification"; | 387 VLOG(1) << "Waiting for file modification"; |
| 388 ASSERT_TRUE(WaitForEvents()); | 388 ASSERT_TRUE(WaitForEvents()); |
| 389 DeleteDelegateOnFileThread(delegate.release()); | 389 DeleteDelegateOnFileThread(delegate.release()); |
| 390 } | 390 } |
| 391 | 391 |
| 392 #if defined(OS_MACOSX) | 392 #if defined(OS_MACOSX) |
| 393 // http://crbug.com/85930 | 393 // http://crbug.com/85930 |
| 394 #define DisappearingDirectory DISABLED_DisappearingDirectory | 394 #define DisappearingDirectory DISABLED_DisappearingDirectory |
| 395 #endif | 395 #endif |
| 396 TEST_F(FilePathWatcherTest, DisappearingDirectory) { | 396 TEST_F(FilePathWatcherTest, DisappearingDirectory) { |
| 397 FilePathWatcher watcher; | 397 FilePathWatcher watcher; |
| 398 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 398 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 399 FilePath file(dir.AppendASCII("file")); | 399 FilePath file(dir.AppendASCII("file")); |
| 400 ASSERT_TRUE(file_util::CreateDirectory(dir)); | 400 ASSERT_TRUE(base::CreateDirectory(dir)); |
| 401 ASSERT_TRUE(WriteFile(file, "content")); | 401 ASSERT_TRUE(WriteFile(file, "content")); |
| 402 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 402 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 403 ASSERT_TRUE(SetupWatch(file, &watcher, delegate.get(), false)); | 403 ASSERT_TRUE(SetupWatch(file, &watcher, delegate.get(), false)); |
| 404 | 404 |
| 405 ASSERT_TRUE(base::DeleteFile(dir, true)); | 405 ASSERT_TRUE(base::DeleteFile(dir, true)); |
| 406 ASSERT_TRUE(WaitForEvents()); | 406 ASSERT_TRUE(WaitForEvents()); |
| 407 DeleteDelegateOnFileThread(delegate.release()); | 407 DeleteDelegateOnFileThread(delegate.release()); |
| 408 } | 408 } |
| 409 | 409 |
| 410 // Tests that a file that is deleted and reappears is tracked correctly. | 410 // Tests that a file that is deleted and reappears is tracked correctly. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 425 } | 425 } |
| 426 | 426 |
| 427 TEST_F(FilePathWatcherTest, WatchDirectory) { | 427 TEST_F(FilePathWatcherTest, WatchDirectory) { |
| 428 FilePathWatcher watcher; | 428 FilePathWatcher watcher; |
| 429 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 429 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 430 FilePath file1(dir.AppendASCII("file1")); | 430 FilePath file1(dir.AppendASCII("file1")); |
| 431 FilePath file2(dir.AppendASCII("file2")); | 431 FilePath file2(dir.AppendASCII("file2")); |
| 432 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 432 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 433 ASSERT_TRUE(SetupWatch(dir, &watcher, delegate.get(), false)); | 433 ASSERT_TRUE(SetupWatch(dir, &watcher, delegate.get(), false)); |
| 434 | 434 |
| 435 ASSERT_TRUE(file_util::CreateDirectory(dir)); | 435 ASSERT_TRUE(base::CreateDirectory(dir)); |
| 436 VLOG(1) << "Waiting for directory creation"; | 436 VLOG(1) << "Waiting for directory creation"; |
| 437 ASSERT_TRUE(WaitForEvents()); | 437 ASSERT_TRUE(WaitForEvents()); |
| 438 | 438 |
| 439 ASSERT_TRUE(WriteFile(file1, "content")); | 439 ASSERT_TRUE(WriteFile(file1, "content")); |
| 440 VLOG(1) << "Waiting for file1 creation"; | 440 VLOG(1) << "Waiting for file1 creation"; |
| 441 ASSERT_TRUE(WaitForEvents()); | 441 ASSERT_TRUE(WaitForEvents()); |
| 442 | 442 |
| 443 #if !defined(OS_MACOSX) | 443 #if !defined(OS_MACOSX) |
| 444 // Mac implementation does not detect files modified in a directory. | 444 // Mac implementation does not detect files modified in a directory. |
| 445 ASSERT_TRUE(WriteFile(file1, "content v2")); | 445 ASSERT_TRUE(WriteFile(file1, "content v2")); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 464 FilePath dest(temp_dir_.path().AppendASCII("dest")); | 464 FilePath dest(temp_dir_.path().AppendASCII("dest")); |
| 465 FilePath subdir(dir.AppendASCII("subdir")); | 465 FilePath subdir(dir.AppendASCII("subdir")); |
| 466 FilePath file(subdir.AppendASCII("file")); | 466 FilePath file(subdir.AppendASCII("file")); |
| 467 scoped_ptr<TestDelegate> file_delegate(new TestDelegate(collector())); | 467 scoped_ptr<TestDelegate> file_delegate(new TestDelegate(collector())); |
| 468 ASSERT_TRUE(SetupWatch(file, &file_watcher, file_delegate.get(), false)); | 468 ASSERT_TRUE(SetupWatch(file, &file_watcher, file_delegate.get(), false)); |
| 469 scoped_ptr<TestDelegate> subdir_delegate(new TestDelegate(collector())); | 469 scoped_ptr<TestDelegate> subdir_delegate(new TestDelegate(collector())); |
| 470 ASSERT_TRUE(SetupWatch(subdir, &subdir_watcher, subdir_delegate.get(), | 470 ASSERT_TRUE(SetupWatch(subdir, &subdir_watcher, subdir_delegate.get(), |
| 471 false)); | 471 false)); |
| 472 | 472 |
| 473 // Setup a directory hierarchy. | 473 // Setup a directory hierarchy. |
| 474 ASSERT_TRUE(file_util::CreateDirectory(subdir)); | 474 ASSERT_TRUE(base::CreateDirectory(subdir)); |
| 475 ASSERT_TRUE(WriteFile(file, "content")); | 475 ASSERT_TRUE(WriteFile(file, "content")); |
| 476 VLOG(1) << "Waiting for file creation"; | 476 VLOG(1) << "Waiting for file creation"; |
| 477 ASSERT_TRUE(WaitForEvents()); | 477 ASSERT_TRUE(WaitForEvents()); |
| 478 | 478 |
| 479 // Move the parent directory. | 479 // Move the parent directory. |
| 480 base::Move(dir, dest); | 480 base::Move(dir, dest); |
| 481 VLOG(1) << "Waiting for directory move"; | 481 VLOG(1) << "Waiting for directory move"; |
| 482 ASSERT_TRUE(WaitForEvents()); | 482 ASSERT_TRUE(WaitForEvents()); |
| 483 DeleteDelegateOnFileThread(file_delegate.release()); | 483 DeleteDelegateOnFileThread(file_delegate.release()); |
| 484 DeleteDelegateOnFileThread(subdir_delegate.release()); | 484 DeleteDelegateOnFileThread(subdir_delegate.release()); |
| 485 } | 485 } |
| 486 | 486 |
| 487 #if defined(OS_WIN) | 487 #if defined(OS_WIN) |
| 488 TEST_F(FilePathWatcherTest, RecursiveWatch) { | 488 TEST_F(FilePathWatcherTest, RecursiveWatch) { |
| 489 FilePathWatcher watcher; | 489 FilePathWatcher watcher; |
| 490 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 490 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 491 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 491 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 492 ASSERT_TRUE(SetupWatch(dir, &watcher, delegate.get(), true)); | 492 ASSERT_TRUE(SetupWatch(dir, &watcher, delegate.get(), true)); |
| 493 | 493 |
| 494 // Main directory("dir") creation. | 494 // Main directory("dir") creation. |
| 495 ASSERT_TRUE(file_util::CreateDirectory(dir)); | 495 ASSERT_TRUE(base::CreateDirectory(dir)); |
| 496 ASSERT_TRUE(WaitForEvents()); | 496 ASSERT_TRUE(WaitForEvents()); |
| 497 | 497 |
| 498 // Create "$dir/file1". | 498 // Create "$dir/file1". |
| 499 FilePath file1(dir.AppendASCII("file1")); | 499 FilePath file1(dir.AppendASCII("file1")); |
| 500 ASSERT_TRUE(WriteFile(file1, "content")); | 500 ASSERT_TRUE(WriteFile(file1, "content")); |
| 501 ASSERT_TRUE(WaitForEvents()); | 501 ASSERT_TRUE(WaitForEvents()); |
| 502 | 502 |
| 503 // Create "$dir/subdir". | 503 // Create "$dir/subdir". |
| 504 FilePath subdir(dir.AppendASCII("subdir")); | 504 FilePath subdir(dir.AppendASCII("subdir")); |
| 505 ASSERT_TRUE(file_util::CreateDirectory(subdir)); | 505 ASSERT_TRUE(base::CreateDirectory(subdir)); |
| 506 ASSERT_TRUE(WaitForEvents()); | 506 ASSERT_TRUE(WaitForEvents()); |
| 507 | 507 |
| 508 // Create "$dir/subdir/subdir_file1". | 508 // Create "$dir/subdir/subdir_file1". |
| 509 FilePath subdir_file1(subdir.AppendASCII("subdir_file1")); | 509 FilePath subdir_file1(subdir.AppendASCII("subdir_file1")); |
| 510 ASSERT_TRUE(WriteFile(subdir_file1, "content")); | 510 ASSERT_TRUE(WriteFile(subdir_file1, "content")); |
| 511 ASSERT_TRUE(WaitForEvents()); | 511 ASSERT_TRUE(WaitForEvents()); |
| 512 | 512 |
| 513 // Create "$dir/subdir/subdir_child_dir". | 513 // Create "$dir/subdir/subdir_child_dir". |
| 514 FilePath subdir_child_dir(subdir.AppendASCII("subdir_child_dir")); | 514 FilePath subdir_child_dir(subdir.AppendASCII("subdir_child_dir")); |
| 515 ASSERT_TRUE(file_util::CreateDirectory(subdir_child_dir)); | 515 ASSERT_TRUE(base::CreateDirectory(subdir_child_dir)); |
| 516 ASSERT_TRUE(WaitForEvents()); | 516 ASSERT_TRUE(WaitForEvents()); |
| 517 | 517 |
| 518 // Create "$dir/subdir/subdir_child_dir/child_dir_file1". | 518 // Create "$dir/subdir/subdir_child_dir/child_dir_file1". |
| 519 FilePath child_dir_file1(subdir_child_dir.AppendASCII("child_dir_file1")); | 519 FilePath child_dir_file1(subdir_child_dir.AppendASCII("child_dir_file1")); |
| 520 ASSERT_TRUE(WriteFile(child_dir_file1, "content v2")); | 520 ASSERT_TRUE(WriteFile(child_dir_file1, "content v2")); |
| 521 ASSERT_TRUE(WaitForEvents()); | 521 ASSERT_TRUE(WaitForEvents()); |
| 522 | 522 |
| 523 // Write into "$dir/subdir/subdir_child_dir/child_dir_file1". | 523 // Write into "$dir/subdir/subdir_child_dir/child_dir_file1". |
| 524 ASSERT_TRUE(WriteFile(child_dir_file1, "content")); | 524 ASSERT_TRUE(WriteFile(child_dir_file1, "content")); |
| 525 ASSERT_TRUE(WaitForEvents()); | 525 ASSERT_TRUE(WaitForEvents()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 552 FilePathWatcher file_watcher; | 552 FilePathWatcher file_watcher; |
| 553 FilePathWatcher subdir_watcher; | 553 FilePathWatcher subdir_watcher; |
| 554 FilePath source_dir(temp_dir_.path().AppendASCII("source")); | 554 FilePath source_dir(temp_dir_.path().AppendASCII("source")); |
| 555 FilePath source_subdir(source_dir.AppendASCII("subdir")); | 555 FilePath source_subdir(source_dir.AppendASCII("subdir")); |
| 556 FilePath source_file(source_subdir.AppendASCII("file")); | 556 FilePath source_file(source_subdir.AppendASCII("file")); |
| 557 FilePath dest_dir(temp_dir_.path().AppendASCII("dest")); | 557 FilePath dest_dir(temp_dir_.path().AppendASCII("dest")); |
| 558 FilePath dest_subdir(dest_dir.AppendASCII("subdir")); | 558 FilePath dest_subdir(dest_dir.AppendASCII("subdir")); |
| 559 FilePath dest_file(dest_subdir.AppendASCII("file")); | 559 FilePath dest_file(dest_subdir.AppendASCII("file")); |
| 560 | 560 |
| 561 // Setup a directory hierarchy. | 561 // Setup a directory hierarchy. |
| 562 ASSERT_TRUE(file_util::CreateDirectory(source_subdir)); | 562 ASSERT_TRUE(base::CreateDirectory(source_subdir)); |
| 563 ASSERT_TRUE(WriteFile(source_file, "content")); | 563 ASSERT_TRUE(WriteFile(source_file, "content")); |
| 564 | 564 |
| 565 scoped_ptr<TestDelegate> file_delegate(new TestDelegate(collector())); | 565 scoped_ptr<TestDelegate> file_delegate(new TestDelegate(collector())); |
| 566 ASSERT_TRUE(SetupWatch(dest_file, &file_watcher, file_delegate.get(), false)); | 566 ASSERT_TRUE(SetupWatch(dest_file, &file_watcher, file_delegate.get(), false)); |
| 567 scoped_ptr<TestDelegate> subdir_delegate(new TestDelegate(collector())); | 567 scoped_ptr<TestDelegate> subdir_delegate(new TestDelegate(collector())); |
| 568 ASSERT_TRUE(SetupWatch(dest_subdir, &subdir_watcher, subdir_delegate.get(), | 568 ASSERT_TRUE(SetupWatch(dest_subdir, &subdir_watcher, subdir_delegate.get(), |
| 569 false)); | 569 false)); |
| 570 | 570 |
| 571 // Move the directory into place, s.t. the watched file appears. | 571 // Move the directory into place, s.t. the watched file appears. |
| 572 ASSERT_TRUE(base::Move(source_dir, dest_dir)); | 572 ASSERT_TRUE(base::Move(source_dir, dest_dir)); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 // Verify that watching a file whose parent directory is a link that | 676 // Verify that watching a file whose parent directory is a link that |
| 677 // doesn't exist yet works if the symlink is created eventually. | 677 // doesn't exist yet works if the symlink is created eventually. |
| 678 TEST_F(FilePathWatcherTest, LinkedDirectoryPart1) { | 678 TEST_F(FilePathWatcherTest, LinkedDirectoryPart1) { |
| 679 FilePathWatcher watcher; | 679 FilePathWatcher watcher; |
| 680 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 680 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 681 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); | 681 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); |
| 682 FilePath file(dir.AppendASCII("file")); | 682 FilePath file(dir.AppendASCII("file")); |
| 683 FilePath linkfile(link_dir.AppendASCII("file")); | 683 FilePath linkfile(link_dir.AppendASCII("file")); |
| 684 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 684 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 685 // dir/file should exist. | 685 // dir/file should exist. |
| 686 ASSERT_TRUE(file_util::CreateDirectory(dir)); | 686 ASSERT_TRUE(base::CreateDirectory(dir)); |
| 687 ASSERT_TRUE(WriteFile(file, "content")); | 687 ASSERT_TRUE(WriteFile(file, "content")); |
| 688 // Note that we are watching dir.lnk/file which doesn't exist yet. | 688 // Note that we are watching dir.lnk/file which doesn't exist yet. |
| 689 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); | 689 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); |
| 690 | 690 |
| 691 ASSERT_TRUE(CreateSymbolicLink(dir, link_dir)); | 691 ASSERT_TRUE(CreateSymbolicLink(dir, link_dir)); |
| 692 VLOG(1) << "Waiting for link creation"; | 692 VLOG(1) << "Waiting for link creation"; |
| 693 ASSERT_TRUE(WaitForEvents()); | 693 ASSERT_TRUE(WaitForEvents()); |
| 694 | 694 |
| 695 ASSERT_TRUE(WriteFile(file, "content v2")); | 695 ASSERT_TRUE(WriteFile(file, "content v2")); |
| 696 VLOG(1) << "Waiting for file change"; | 696 VLOG(1) << "Waiting for file change"; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 710 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); | 710 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); |
| 711 FilePath file(dir.AppendASCII("file")); | 711 FilePath file(dir.AppendASCII("file")); |
| 712 FilePath linkfile(link_dir.AppendASCII("file")); | 712 FilePath linkfile(link_dir.AppendASCII("file")); |
| 713 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 713 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 714 // Now create the link from dir.lnk pointing to dir but | 714 // Now create the link from dir.lnk pointing to dir but |
| 715 // neither dir nor dir/file exist yet. | 715 // neither dir nor dir/file exist yet. |
| 716 ASSERT_TRUE(CreateSymbolicLink(dir, link_dir)); | 716 ASSERT_TRUE(CreateSymbolicLink(dir, link_dir)); |
| 717 // Note that we are watching dir.lnk/file. | 717 // Note that we are watching dir.lnk/file. |
| 718 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); | 718 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); |
| 719 | 719 |
| 720 ASSERT_TRUE(file_util::CreateDirectory(dir)); | 720 ASSERT_TRUE(base::CreateDirectory(dir)); |
| 721 ASSERT_TRUE(WriteFile(file, "content")); | 721 ASSERT_TRUE(WriteFile(file, "content")); |
| 722 VLOG(1) << "Waiting for dir/file creation"; | 722 VLOG(1) << "Waiting for dir/file creation"; |
| 723 ASSERT_TRUE(WaitForEvents()); | 723 ASSERT_TRUE(WaitForEvents()); |
| 724 | 724 |
| 725 ASSERT_TRUE(WriteFile(file, "content v2")); | 725 ASSERT_TRUE(WriteFile(file, "content v2")); |
| 726 VLOG(1) << "Waiting for file change"; | 726 VLOG(1) << "Waiting for file change"; |
| 727 ASSERT_TRUE(WaitForEvents()); | 727 ASSERT_TRUE(WaitForEvents()); |
| 728 | 728 |
| 729 ASSERT_TRUE(base::DeleteFile(file, false)); | 729 ASSERT_TRUE(base::DeleteFile(file, false)); |
| 730 VLOG(1) << "Waiting for file deletion"; | 730 VLOG(1) << "Waiting for file deletion"; |
| 731 ASSERT_TRUE(WaitForEvents()); | 731 ASSERT_TRUE(WaitForEvents()); |
| 732 DeleteDelegateOnFileThread(delegate.release()); | 732 DeleteDelegateOnFileThread(delegate.release()); |
| 733 } | 733 } |
| 734 | 734 |
| 735 // Verify that watching a file with a symlink on the path | 735 // Verify that watching a file with a symlink on the path |
| 736 // to the file works. | 736 // to the file works. |
| 737 TEST_F(FilePathWatcherTest, LinkedDirectoryPart3) { | 737 TEST_F(FilePathWatcherTest, LinkedDirectoryPart3) { |
| 738 FilePathWatcher watcher; | 738 FilePathWatcher watcher; |
| 739 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 739 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 740 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); | 740 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); |
| 741 FilePath file(dir.AppendASCII("file")); | 741 FilePath file(dir.AppendASCII("file")); |
| 742 FilePath linkfile(link_dir.AppendASCII("file")); | 742 FilePath linkfile(link_dir.AppendASCII("file")); |
| 743 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 743 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 744 ASSERT_TRUE(file_util::CreateDirectory(dir)); | 744 ASSERT_TRUE(base::CreateDirectory(dir)); |
| 745 ASSERT_TRUE(CreateSymbolicLink(dir, link_dir)); | 745 ASSERT_TRUE(CreateSymbolicLink(dir, link_dir)); |
| 746 // Note that we are watching dir.lnk/file but the file doesn't exist yet. | 746 // Note that we are watching dir.lnk/file but the file doesn't exist yet. |
| 747 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); | 747 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); |
| 748 | 748 |
| 749 ASSERT_TRUE(WriteFile(file, "content")); | 749 ASSERT_TRUE(WriteFile(file, "content")); |
| 750 VLOG(1) << "Waiting for file creation"; | 750 VLOG(1) << "Waiting for file creation"; |
| 751 ASSERT_TRUE(WaitForEvents()); | 751 ASSERT_TRUE(WaitForEvents()); |
| 752 | 752 |
| 753 ASSERT_TRUE(WriteFile(file, "content v2")); | 753 ASSERT_TRUE(WriteFile(file, "content v2")); |
| 754 VLOG(1) << "Waiting for file change"; | 754 VLOG(1) << "Waiting for file change"; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 // Windows implementation of FilePathWatcher catches attribute changes that | 805 // Windows implementation of FilePathWatcher catches attribute changes that |
| 806 // don't affect the path being watched. | 806 // don't affect the path being watched. |
| 807 // http://crbug.com/78045 | 807 // http://crbug.com/78045 |
| 808 | 808 |
| 809 // Verify that changing attributes on a directory works. | 809 // Verify that changing attributes on a directory works. |
| 810 TEST_F(FilePathWatcherTest, DirAttributesChanged) { | 810 TEST_F(FilePathWatcherTest, DirAttributesChanged) { |
| 811 FilePath test_dir1(temp_dir_.path().AppendASCII("DirAttributesChangedDir1")); | 811 FilePath test_dir1(temp_dir_.path().AppendASCII("DirAttributesChangedDir1")); |
| 812 FilePath test_dir2(test_dir1.AppendASCII("DirAttributesChangedDir2")); | 812 FilePath test_dir2(test_dir1.AppendASCII("DirAttributesChangedDir2")); |
| 813 FilePath test_file(test_dir2.AppendASCII("DirAttributesChangedFile")); | 813 FilePath test_file(test_dir2.AppendASCII("DirAttributesChangedFile")); |
| 814 // Setup a directory hierarchy. | 814 // Setup a directory hierarchy. |
| 815 ASSERT_TRUE(file_util::CreateDirectory(test_dir1)); | 815 ASSERT_TRUE(base::CreateDirectory(test_dir1)); |
| 816 ASSERT_TRUE(file_util::CreateDirectory(test_dir2)); | 816 ASSERT_TRUE(base::CreateDirectory(test_dir2)); |
| 817 ASSERT_TRUE(WriteFile(test_file, "content")); | 817 ASSERT_TRUE(WriteFile(test_file, "content")); |
| 818 | 818 |
| 819 FilePathWatcher watcher; | 819 FilePathWatcher watcher; |
| 820 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 820 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 821 ASSERT_TRUE(SetupWatch(test_file, &watcher, delegate.get(), false)); | 821 ASSERT_TRUE(SetupWatch(test_file, &watcher, delegate.get(), false)); |
| 822 | 822 |
| 823 // We should not get notified in this case as it hasn't affected our ability | 823 // We should not get notified in this case as it hasn't affected our ability |
| 824 // to access the file. | 824 // to access the file. |
| 825 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Read, false)); | 825 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Read, false)); |
| 826 loop_.PostDelayedTask(FROM_HERE, | 826 loop_.PostDelayedTask(FROM_HERE, |
| 827 MessageLoop::QuitWhenIdleClosure(), | 827 MessageLoop::QuitWhenIdleClosure(), |
| 828 TestTimeouts::tiny_timeout()); | 828 TestTimeouts::tiny_timeout()); |
| 829 ASSERT_FALSE(WaitForEvents()); | 829 ASSERT_FALSE(WaitForEvents()); |
| 830 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Read, true)); | 830 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Read, true)); |
| 831 | 831 |
| 832 // We should get notified in this case because filepathwatcher can no | 832 // We should get notified in this case because filepathwatcher can no |
| 833 // longer access the file | 833 // longer access the file |
| 834 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); | 834 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); |
| 835 ASSERT_TRUE(WaitForEvents()); | 835 ASSERT_TRUE(WaitForEvents()); |
| 836 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); | 836 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); |
| 837 DeleteDelegateOnFileThread(delegate.release()); | 837 DeleteDelegateOnFileThread(delegate.release()); |
| 838 } | 838 } |
| 839 | 839 |
| 840 #endif // OS_MACOSX | 840 #endif // OS_MACOSX |
| 841 } // namespace | 841 } // namespace |
| 842 | 842 |
| 843 } // namespace base | 843 } // namespace base |
| OLD | NEW |