| Index: base/files/file_path_watcher_browsertest.cc
|
| diff --git a/base/files/file_path_watcher_browsertest.cc b/base/files/file_path_watcher_browsertest.cc
|
| index 2bdcf13827c88216eb1db428780d0227a61cb5a8..e9be97d2390335ac0947198a6ed48ebcabfc5081 100644
|
| --- a/base/files/file_path_watcher_browsertest.cc
|
| +++ b/base/files/file_path_watcher_browsertest.cc
|
| @@ -31,12 +31,29 @@
|
| #include "base/threading/thread.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| +#if defined(OS_MACOSX)
|
| +#include "base/mac/mac_util.h"
|
| +#endif
|
| +
|
| namespace base {
|
|
|
| namespace {
|
|
|
| class TestDelegate;
|
|
|
| +
|
| +bool RecursiveWatchAvaiable() {
|
| +#if defined(OS_MACOSX) && !defined(OS_IOS)
|
| + // FSEvents isn't available on iOS and is broken on OSX 10.6 and earlier.
|
| + // See http://crbug.com/54822#c31
|
| + return mac::IsOSLionOrLater();
|
| +#elif defined(OS_WIN) || defined(OS_LINUX)
|
| + return true;
|
| +#else
|
| + return false;
|
| +#endif
|
| +}
|
| +
|
| // Aggregates notifications from the test delegates and breaks the message loop
|
| // the test thread is waiting on once they all came in.
|
| class NotificationCollector
|
| @@ -205,9 +222,8 @@ bool FilePathWatcherTest::SetupWatch(const FilePath& target,
|
| bool result;
|
| file_thread_.message_loop_proxy()->PostTask(
|
| FROM_HERE,
|
| - base::Bind(SetupWatchCallback,
|
| - target, watcher, delegate, recursive_watch, &result,
|
| - &completion));
|
| + base::Bind(SetupWatchCallback, target, watcher, delegate, recursive_watch,
|
| + &result, &completion));
|
| completion.Wait();
|
| return result;
|
| }
|
| @@ -483,12 +499,17 @@ TEST_F(FilePathWatcherTest, MoveParent) {
|
| DeleteDelegateOnFileThread(subdir_delegate.release());
|
| }
|
|
|
| -#if defined(OS_WIN) || defined(OS_LINUX)
|
| TEST_F(FilePathWatcherTest, RecursiveWatch) {
|
| FilePathWatcher watcher;
|
| FilePath dir(temp_dir_.path().AppendASCII("dir"));
|
| scoped_ptr<TestDelegate> delegate(new TestDelegate(collector()));
|
| - ASSERT_TRUE(SetupWatch(dir, &watcher, delegate.get(), true));
|
| + bool setup_result = SetupWatch(dir, &watcher, delegate.get(), true);
|
| + if (!RecursiveWatchAvaiable()) {
|
| + ASSERT_FALSE(setup_result);
|
| + DeleteDelegateOnFileThread(delegate.release());
|
| + return;
|
| + }
|
| + ASSERT_TRUE(setup_result);
|
|
|
| // Main directory("dir") creation.
|
| ASSERT_TRUE(base::CreateDirectory(dir));
|
| @@ -536,17 +557,48 @@ TEST_F(FilePathWatcherTest, RecursiveWatch) {
|
| ASSERT_TRUE(WaitForEvents());
|
| DeleteDelegateOnFileThread(delegate.release());
|
| }
|
| -#else
|
| -TEST_F(FilePathWatcherTest, RecursiveWatch) {
|
| +
|
| +#if defined(OS_POSIX)
|
| +TEST_F(FilePathWatcherTest, RecursiveWithSymLink) {
|
| + if (!RecursiveWatchAvaiable())
|
| + return;
|
| +
|
| FilePathWatcher watcher;
|
| - FilePath dir(temp_dir_.path().AppendASCII("dir"));
|
| + FilePath test_dir(temp_dir_.path().AppendASCII("test_dir"));
|
| + ASSERT_TRUE(base::CreateDirectory(test_dir));
|
| + FilePath symlink(test_dir.AppendASCII("symlink"));
|
| scoped_ptr<TestDelegate> delegate(new TestDelegate(collector()));
|
| - // Only Windows/Linux support recursive watching. Other implementations
|
| - // should simply fail.
|
| - ASSERT_FALSE(SetupWatch(dir, &watcher, delegate.get(), true));
|
| + ASSERT_TRUE(SetupWatch(symlink, &watcher, delegate.get(), true));
|
| +
|
| + // Link creation.
|
| + FilePath target1(temp_dir_.path().AppendASCII("target1"));
|
| + ASSERT_TRUE(base::CreateSymbolicLink(target1, symlink));
|
| + ASSERT_TRUE(WaitForEvents());
|
| +
|
| + // Target1 creation.
|
| + ASSERT_TRUE(base::CreateDirectory(target1));
|
| + ASSERT_TRUE(WaitForEvents());
|
| +
|
| + // Create a file in target1.
|
| + FilePath target1_file(target1.AppendASCII("file"));
|
| + ASSERT_TRUE(WriteFile(target1_file, "content"));
|
| + ASSERT_TRUE(WaitForEvents());
|
| +
|
| + // Link change.
|
| + FilePath target2(temp_dir_.path().AppendASCII("target2"));
|
| + ASSERT_TRUE(base::CreateDirectory(target2));
|
| + ASSERT_TRUE(base::DeleteFile(symlink, false));
|
| + ASSERT_TRUE(base::CreateSymbolicLink(target2, symlink));
|
| + ASSERT_TRUE(WaitForEvents());
|
| +
|
| + // Create a file in target2.
|
| + FilePath target2_file(target2.AppendASCII("file"));
|
| + ASSERT_TRUE(WriteFile(target2_file, "content"));
|
| + ASSERT_TRUE(WaitForEvents());
|
| +
|
| DeleteDelegateOnFileThread(delegate.release());
|
| }
|
| -#endif
|
| +#endif // OS_POSIX
|
|
|
| TEST_F(FilePathWatcherTest, MoveChild) {
|
| FilePathWatcher file_watcher;
|
|
|