| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); | 827 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); |
| 829 ASSERT_TRUE(WaitForEvents()); | 828 ASSERT_TRUE(WaitForEvents()); |
| 830 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); | 829 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); |
| 831 DeleteDelegateOnFileThread(delegate.release()); | 830 DeleteDelegateOnFileThread(delegate.release()); |
| 832 } | 831 } |
| 833 | 832 |
| 834 #endif // OS_MACOSX | 833 #endif // OS_MACOSX |
| 835 } // namespace | 834 } // namespace |
| 836 | 835 |
| 837 } // namespace base | 836 } // namespace base |
| OLD | NEW |