Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: base/files/file_path_watcher_browsertest.cc

Issue 313083007: Use FSEvents for recursive file watch on Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: include fix for iOS Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/files/file_path_watcher.cc ('k') | base/files/file_path_watcher_fsevents.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 }; 198 };
199 199
200 bool FilePathWatcherTest::SetupWatch(const FilePath& target, 200 bool FilePathWatcherTest::SetupWatch(const FilePath& target,
201 FilePathWatcher* watcher, 201 FilePathWatcher* watcher,
202 TestDelegateBase* delegate, 202 TestDelegateBase* delegate,
203 bool recursive_watch) { 203 bool recursive_watch) {
204 base::WaitableEvent completion(false, false); 204 base::WaitableEvent completion(false, false);
205 bool result; 205 bool result;
206 file_thread_.message_loop_proxy()->PostTask( 206 file_thread_.message_loop_proxy()->PostTask(
207 FROM_HERE, 207 FROM_HERE,
208 base::Bind(SetupWatchCallback, 208 base::Bind(SetupWatchCallback, target, watcher, delegate, recursive_watch,
209 target, watcher, delegate, recursive_watch, &result, 209 &result, &completion));
210 &completion));
211 completion.Wait(); 210 completion.Wait();
212 return result; 211 return result;
213 } 212 }
214 213
215 // Basic test: Create the file and verify that we notice. 214 // Basic test: Create the file and verify that we notice.
216 TEST_F(FilePathWatcherTest, NewFile) { 215 TEST_F(FilePathWatcherTest, NewFile) {
217 FilePathWatcher watcher; 216 FilePathWatcher watcher;
218 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); 217 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector()));
219 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); 218 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false));
220 219
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 ASSERT_TRUE(WaitForEvents()); 475 ASSERT_TRUE(WaitForEvents());
477 476
478 // Move the parent directory. 477 // Move the parent directory.
479 base::Move(dir, dest); 478 base::Move(dir, dest);
480 VLOG(1) << "Waiting for directory move"; 479 VLOG(1) << "Waiting for directory move";
481 ASSERT_TRUE(WaitForEvents()); 480 ASSERT_TRUE(WaitForEvents());
482 DeleteDelegateOnFileThread(file_delegate.release()); 481 DeleteDelegateOnFileThread(file_delegate.release());
483 DeleteDelegateOnFileThread(subdir_delegate.release()); 482 DeleteDelegateOnFileThread(subdir_delegate.release());
484 } 483 }
485 484
486 #if defined(OS_WIN) || defined(OS_LINUX)
487 TEST_F(FilePathWatcherTest, RecursiveWatch) { 485 TEST_F(FilePathWatcherTest, RecursiveWatch) {
488 FilePathWatcher watcher; 486 FilePathWatcher watcher;
489 FilePath dir(temp_dir_.path().AppendASCII("dir")); 487 FilePath dir(temp_dir_.path().AppendASCII("dir"));
490 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); 488 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector()));
491 ASSERT_TRUE(SetupWatch(dir, &watcher, delegate.get(), true)); 489 bool setup_result = SetupWatch(dir, &watcher, delegate.get(), true);
490 if (!FilePathWatcher::RecursiveWatchAvailable()) {
491 ASSERT_FALSE(setup_result);
492 DeleteDelegateOnFileThread(delegate.release());
493 return;
494 }
495 ASSERT_TRUE(setup_result);
492 496
493 // Main directory("dir") creation. 497 // Main directory("dir") creation.
494 ASSERT_TRUE(base::CreateDirectory(dir)); 498 ASSERT_TRUE(base::CreateDirectory(dir));
495 ASSERT_TRUE(WaitForEvents()); 499 ASSERT_TRUE(WaitForEvents());
496 500
497 // Create "$dir/file1". 501 // Create "$dir/file1".
498 FilePath file1(dir.AppendASCII("file1")); 502 FilePath file1(dir.AppendASCII("file1"));
499 ASSERT_TRUE(WriteFile(file1, "content")); 503 ASSERT_TRUE(WriteFile(file1, "content"));
500 ASSERT_TRUE(WaitForEvents()); 504 ASSERT_TRUE(WaitForEvents());
501 505
(...skipping 27 matching lines...) Expand all
529 533
530 // Delete "$dir/subdir/subdir_file1". 534 // Delete "$dir/subdir/subdir_file1".
531 ASSERT_TRUE(base::DeleteFile(subdir_file1, false)); 535 ASSERT_TRUE(base::DeleteFile(subdir_file1, false));
532 ASSERT_TRUE(WaitForEvents()); 536 ASSERT_TRUE(WaitForEvents());
533 537
534 // Delete "$dir/subdir/subdir_child_dir/child_dir_file1". 538 // Delete "$dir/subdir/subdir_child_dir/child_dir_file1".
535 ASSERT_TRUE(base::DeleteFile(child_dir_file1, false)); 539 ASSERT_TRUE(base::DeleteFile(child_dir_file1, false));
536 ASSERT_TRUE(WaitForEvents()); 540 ASSERT_TRUE(WaitForEvents());
537 DeleteDelegateOnFileThread(delegate.release()); 541 DeleteDelegateOnFileThread(delegate.release());
538 } 542 }
539 #else 543
540 TEST_F(FilePathWatcherTest, RecursiveWatch) { 544 #if defined(OS_POSIX)
545 TEST_F(FilePathWatcherTest, RecursiveWithSymLink) {
546 if (!FilePathWatcher::RecursiveWatchAvailable())
547 return;
548
541 FilePathWatcher watcher; 549 FilePathWatcher watcher;
542 FilePath dir(temp_dir_.path().AppendASCII("dir")); 550 FilePath test_dir(temp_dir_.path().AppendASCII("test_dir"));
551 ASSERT_TRUE(base::CreateDirectory(test_dir));
552 FilePath symlink(test_dir.AppendASCII("symlink"));
543 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); 553 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector()));
544 // Only Windows/Linux support recursive watching. Other implementations 554 ASSERT_TRUE(SetupWatch(symlink, &watcher, delegate.get(), true));
545 // should simply fail. 555
546 ASSERT_FALSE(SetupWatch(dir, &watcher, delegate.get(), true)); 556 // Link creation.
557 FilePath target1(temp_dir_.path().AppendASCII("target1"));
558 ASSERT_TRUE(base::CreateSymbolicLink(target1, symlink));
559 ASSERT_TRUE(WaitForEvents());
560
561 // Target1 creation.
562 ASSERT_TRUE(base::CreateDirectory(target1));
563 ASSERT_TRUE(WaitForEvents());
564
565 // Create a file in target1.
566 FilePath target1_file(target1.AppendASCII("file"));
567 ASSERT_TRUE(WriteFile(target1_file, "content"));
568 ASSERT_TRUE(WaitForEvents());
569
570 // Link change.
571 FilePath target2(temp_dir_.path().AppendASCII("target2"));
572 ASSERT_TRUE(base::CreateDirectory(target2));
573 ASSERT_TRUE(base::DeleteFile(symlink, false));
574 ASSERT_TRUE(base::CreateSymbolicLink(target2, symlink));
575 ASSERT_TRUE(WaitForEvents());
576
577 // Create a file in target2.
578 FilePath target2_file(target2.AppendASCII("file"));
579 ASSERT_TRUE(WriteFile(target2_file, "content"));
580 ASSERT_TRUE(WaitForEvents());
581
547 DeleteDelegateOnFileThread(delegate.release()); 582 DeleteDelegateOnFileThread(delegate.release());
548 } 583 }
549 #endif 584 #endif // OS_POSIX
550 585
551 TEST_F(FilePathWatcherTest, MoveChild) { 586 TEST_F(FilePathWatcherTest, MoveChild) {
552 FilePathWatcher file_watcher; 587 FilePathWatcher file_watcher;
553 FilePathWatcher subdir_watcher; 588 FilePathWatcher subdir_watcher;
554 FilePath source_dir(temp_dir_.path().AppendASCII("source")); 589 FilePath source_dir(temp_dir_.path().AppendASCII("source"));
555 FilePath source_subdir(source_dir.AppendASCII("subdir")); 590 FilePath source_subdir(source_dir.AppendASCII("subdir"));
556 FilePath source_file(source_subdir.AppendASCII("file")); 591 FilePath source_file(source_subdir.AppendASCII("file"));
557 FilePath dest_dir(temp_dir_.path().AppendASCII("dest")); 592 FilePath dest_dir(temp_dir_.path().AppendASCII("dest"));
558 FilePath dest_subdir(dest_dir.AppendASCII("subdir")); 593 FilePath dest_subdir(dest_dir.AppendASCII("subdir"));
559 FilePath dest_file(dest_subdir.AppendASCII("file")); 594 FilePath dest_file(dest_subdir.AppendASCII("file"));
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); 863 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false));
829 ASSERT_TRUE(WaitForEvents()); 864 ASSERT_TRUE(WaitForEvents());
830 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); 865 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true));
831 DeleteDelegateOnFileThread(delegate.release()); 866 DeleteDelegateOnFileThread(delegate.release());
832 } 867 }
833 868
834 #endif // OS_MACOSX 869 #endif // OS_MACOSX
835 } // namespace 870 } // namespace
836 871
837 } // namespace base 872 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_path_watcher.cc ('k') | base/files/file_path_watcher_fsevents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698