| 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 7886df8de218f00b04b1e3d8401f850d6b4da3ac..5eea88c5fd7e0ce58fd3aea876098ca3173426b8 100644
|
| --- a/base/files/file_path_watcher_browsertest.cc
|
| +++ b/base/files/file_path_watcher_browsertest.cc
|
| @@ -119,7 +119,7 @@ class TestDelegate : public FilePathWatcher::Delegate {
|
| DISALLOW_COPY_AND_ASSIGN(TestDelegate);
|
| };
|
|
|
| -void SetupWatchCallback(const FilePath& target,
|
| +void SetupWatchDelegate(const FilePath& target,
|
| FilePathWatcher* watcher,
|
| FilePathWatcher::Delegate* delegate,
|
| bool* result,
|
| @@ -128,6 +128,25 @@ void SetupWatchCallback(const FilePath& target,
|
| completion->Signal();
|
| }
|
|
|
| +void SetupWatchCallback(const FilePath& target,
|
| + FilePathWatcher* watcher,
|
| + const FilePathWatcher::Callback& callback) {
|
| + ASSERT_TRUE(watcher->Watch(target, callback));
|
| +}
|
| +
|
| +void QuitLoopWatchCallback(MessageLoop* loop,
|
| + const FilePath& expected_path,
|
| + bool expected_error,
|
| + bool* flag,
|
| + const FilePath& path,
|
| + bool error) {
|
| + ASSERT_TRUE(flag);
|
| + *flag = true;
|
| + EXPECT_EQ(expected_path, path);
|
| + EXPECT_EQ(expected_error, error);
|
| + loop->PostTask(FROM_HERE, loop->QuitClosure());
|
| +}
|
| +
|
| class FilePathWatcherTest : public testing::Test {
|
| public:
|
| FilePathWatcherTest()
|
| @@ -170,7 +189,7 @@ class FilePathWatcherTest : public testing::Test {
|
| bool result;
|
| file_thread_.message_loop_proxy()->PostTask(
|
| FROM_HERE,
|
| - base::Bind(SetupWatchCallback, target, watcher,
|
| + base::Bind(SetupWatchDelegate, target, watcher,
|
| make_scoped_refptr(delegate), &result, &completion));
|
| completion.Wait();
|
| return result;
|
| @@ -239,6 +258,32 @@ TEST_F(FilePathWatcherTest, DeletedFile) {
|
| ASSERT_TRUE(WaitForEvents());
|
| }
|
|
|
| +TEST_F(FilePathWatcherTest, Callback) {
|
| + FilePathWatcher watcher;
|
| + bool called_back = false;
|
| +
|
| + MessageLoop* file_loop = file_thread_.message_loop();
|
| + ASSERT_TRUE(file_loop);
|
| + // The callback makes |loop_| quit on file events, and flips |called_back|
|
| + // to true.
|
| + FilePathWatcher::Callback callback = base::Bind(
|
| + QuitLoopWatchCallback, &loop_, test_file(), false, &called_back);
|
| +
|
| + // Start watching on the file thread, and unblock the loop once the callback
|
| + // has been installed.
|
| + file_thread_.message_loop_proxy()->PostTaskAndReply(
|
| + FROM_HERE,
|
| + base::Bind(SetupWatchCallback, test_file(), &watcher, callback),
|
| + base::Bind(&MessageLoop::Quit, base::Unretained(&loop_)));
|
| + loop_.Run();
|
| +
|
| + // The watch has been installed. Trigger a file event now, which will unblock
|
| + // the loop again.
|
| + ASSERT_TRUE(WriteFile(test_file(), "content"));
|
| + loop_.Run();
|
| + EXPECT_TRUE(called_back);
|
| +}
|
| +
|
| // Used by the DeleteDuringNotify test below.
|
| // Deletes the FilePathWatcher when it's notified.
|
| class Deleter : public FilePathWatcher::Delegate {
|
|
|