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

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

Issue 283423003: Use FSEvents for recursive file watch on Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix dcheck 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.h ('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) 485 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX)
487 TEST_F(FilePathWatcherTest, RecursiveWatch) { 486 TEST_F(FilePathWatcherTest, RecursiveWatch) {
488 FilePathWatcher watcher; 487 FilePathWatcher watcher;
489 FilePath dir(temp_dir_.path().AppendASCII("dir")); 488 FilePath dir(temp_dir_.path().AppendASCII("dir"));
490 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); 489 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector()));
491 ASSERT_TRUE(SetupWatch(dir, &watcher, delegate.get(), true)); 490 ASSERT_TRUE(SetupWatch(dir, &watcher, delegate.get(), true));
492 491
493 // Main directory("dir") creation. 492 // Main directory("dir") creation.
494 ASSERT_TRUE(base::CreateDirectory(dir)); 493 ASSERT_TRUE(base::CreateDirectory(dir));
495 ASSERT_TRUE(WaitForEvents()); 494 ASSERT_TRUE(WaitForEvents());
496 495
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 FilePathWatcher watcher; 540 FilePathWatcher watcher;
542 FilePath dir(temp_dir_.path().AppendASCII("dir")); 541 FilePath dir(temp_dir_.path().AppendASCII("dir"));
543 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); 542 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector()));
544 // Only Windows/Linux support recursive watching. Other implementations 543 // Only Windows/Linux support recursive watching. Other implementations
545 // should simply fail. 544 // should simply fail.
546 ASSERT_FALSE(SetupWatch(dir, &watcher, delegate.get(), true)); 545 ASSERT_FALSE(SetupWatch(dir, &watcher, delegate.get(), true));
547 DeleteDelegateOnFileThread(delegate.release()); 546 DeleteDelegateOnFileThread(delegate.release());
548 } 547 }
549 #endif 548 #endif
550 549
550 #if defined(OS_LINUX) || defined(OS_MACOSX)
551 TEST_F(FilePathWatcherTest, RecursiveWithSymLink) {
552 FilePathWatcher watcher;
553 FilePath test_dir(temp_dir_.path().AppendASCII("test_dir"));
554 ASSERT_TRUE(base::CreateDirectory(test_dir));
555 FilePath symlink(test_dir.AppendASCII("symlink"));
556 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector()));
557 ASSERT_TRUE(SetupWatch(symlink, &watcher, delegate.get(), true));
558
559 // Link creation.
560 FilePath target1(temp_dir_.path().AppendASCII("target1"));
561 ASSERT_TRUE(base::CreateSymbolicLink(target1, symlink));
562 ASSERT_TRUE(WaitForEvents());
563
564 // Target1 creation.
565 ASSERT_TRUE(base::CreateDirectory(target1));
566 ASSERT_TRUE(WaitForEvents());
567
568 // Create a file in target1.
569 FilePath target1_file(target1.AppendASCII("file"));
570 ASSERT_TRUE(WriteFile(target1_file, "content"));
571 ASSERT_TRUE(WaitForEvents());
572
573 // Link change.
574 FilePath target2(temp_dir_.path().AppendASCII("target2"));
575 ASSERT_TRUE(base::CreateDirectory(target2));
576 ASSERT_TRUE(base::DeleteFile(symlink, false));
577 ASSERT_TRUE(base::CreateSymbolicLink(target2, symlink));
578 ASSERT_TRUE(WaitForEvents());
579
580 // Create a file in target2.
581 FilePath target2_file(target2.AppendASCII("file"));
582 ASSERT_TRUE(WriteFile(target2_file, "content"));
583 ASSERT_TRUE(WaitForEvents());
584
585 DeleteDelegateOnFileThread(delegate.release());
586 }
587 #endif
588
551 TEST_F(FilePathWatcherTest, MoveChild) { 589 TEST_F(FilePathWatcherTest, MoveChild) {
552 FilePathWatcher file_watcher; 590 FilePathWatcher file_watcher;
553 FilePathWatcher subdir_watcher; 591 FilePathWatcher subdir_watcher;
554 FilePath source_dir(temp_dir_.path().AppendASCII("source")); 592 FilePath source_dir(temp_dir_.path().AppendASCII("source"));
555 FilePath source_subdir(source_dir.AppendASCII("subdir")); 593 FilePath source_subdir(source_dir.AppendASCII("subdir"));
556 FilePath source_file(source_subdir.AppendASCII("file")); 594 FilePath source_file(source_subdir.AppendASCII("file"));
557 FilePath dest_dir(temp_dir_.path().AppendASCII("dest")); 595 FilePath dest_dir(temp_dir_.path().AppendASCII("dest"));
558 FilePath dest_subdir(dest_dir.AppendASCII("subdir")); 596 FilePath dest_subdir(dest_dir.AppendASCII("subdir"));
559 FilePath dest_file(dest_subdir.AppendASCII("file")); 597 FilePath dest_file(dest_subdir.AppendASCII("file"));
560 598
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); 866 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false));
829 ASSERT_TRUE(WaitForEvents()); 867 ASSERT_TRUE(WaitForEvents());
830 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); 868 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true));
831 DeleteDelegateOnFileThread(delegate.release()); 869 DeleteDelegateOnFileThread(delegate.release());
832 } 870 }
833 871
834 #endif // OS_MACOSX 872 #endif // OS_MACOSX
835 } // namespace 873 } // namespace
836 874
837 } // namespace base 875 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_path_watcher.h ('k') | base/files/file_path_watcher_fsevents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698