| Index: base/directory_watcher_unittest.cc
|
| ===================================================================
|
| --- base/directory_watcher_unittest.cc (revision 14201)
|
| +++ base/directory_watcher_unittest.cc (working copy)
|
| @@ -157,18 +157,18 @@
|
| TEST_F(DirectoryWatcherTest, SubDirRecursive) {
|
| FilePath subdir(FILE_PATH_LITERAL("SubDir"));
|
| ASSERT_TRUE(file_util::CreateDirectory(test_dir_.Append(subdir)));
|
| -
|
| -#if !defined(OS_WIN)
|
| - // TODO(port): Recursive watches are not implemented on Linux.
|
| - return;
|
| -#endif // !defined(OS_WIN)
|
| -
|
| // Verify that modifications to a subdirectory are noticed by recursive watch.
|
| DirectoryWatcher watcher;
|
| + // Write a file to the subdir.
|
| + FilePath test_path = subdir.AppendASCII("test_file");
|
| ASSERT_TRUE(watcher.Watch(test_dir_, this, true));
|
| - // Write a file to the subdir.
|
| SetExpectedNumberOfModifications(2);
|
| - FilePath test_path = subdir.AppendASCII("test_file");
|
| + // Sleep needs to go.
|
| + // Since watcher.Watch recursive will watch subdirectory on another thread,
|
| + // Sleep is needed to guarantee that we write content after we watch test_dir,
|
| + // otherwise we will not see any inotify event
|
| + // as the diretory is modified before watcher watch it.
|
| + sleep(1);
|
| WriteTestDirFile(test_path.value(), "some content");
|
| VerifyExpectedNumberOfModifications();
|
| }
|
| @@ -237,7 +237,7 @@
|
| TEST_F(DirectoryWatcherTest, MultipleWatchersSingleFile) {
|
| DirectoryWatcher watcher1, watcher2;
|
| ASSERT_TRUE(watcher1.Watch(test_dir_, this, false));
|
| - ASSERT_TRUE(watcher2.Watch(test_dir_, this, false));
|
| + ASSERT_TRUE(watcher2.Watch(test_dir_, this, true));
|
|
|
| SetExpectedNumberOfModifications(4); // Each watcher should fire twice.
|
| WriteTestDirFile(FILE_PATH_LITERAL("test_file"), "some content");
|
| @@ -248,11 +248,14 @@
|
| const int kNumberOfWatchers = 5;
|
| DirectoryWatcher watchers[kNumberOfWatchers];
|
| FilePath subdirs[kNumberOfWatchers];
|
| + bool recursive;
|
| for (int i = 0; i < kNumberOfWatchers; i++) {
|
| subdirs[i] = FilePath(FILE_PATH_LITERAL("Dir")).AppendASCII(IntToString(i));
|
| ASSERT_TRUE(file_util::CreateDirectory(test_dir_.Append(subdirs[i])));
|
|
|
| - ASSERT_TRUE(watchers[i].Watch(test_dir_.Append(subdirs[i]), this, false));
|
| + recursive = (i%2)?true:false;
|
| + ASSERT_TRUE(watchers[i].Watch(test_dir_.Append(subdirs[i]),
|
| + this, recursive));
|
| }
|
| for (int i = 0; i < kNumberOfWatchers; i++) {
|
| // Verify that we only get modifications from one watcher (each watcher has
|
| @@ -270,6 +273,39 @@
|
| }
|
| }
|
|
|
| +// testdir
|
| +// SubDir
|
| +// SubDir2
|
| +// Move Subdir2 to be a child of SubDir, while
|
| +// Both Subdir and SubDir2 are being watched recursively.
|
| +// testdir
|
| +// SubDir
|
| +// SubDir2
|
| +TEST_F(DirectoryWatcherTest, MoveDirectoryAcrossWatchRecursive) {
|
| + FilePath subdir(FILE_PATH_LITERAL("SubDir"));
|
| + ASSERT_TRUE(file_util::CreateDirectory(test_dir_.Append(subdir)));
|
| +
|
| + // Verify that modifications to a subdirectory are noticed by recursive watch.
|
| + DirectoryWatcher watcher;
|
| + ASSERT_TRUE(watcher.Watch(test_dir_.Append(subdir), this, true));
|
| +
|
| + FilePath subdir2(FILE_PATH_LITERAL("SubDir2"));
|
| + ASSERT_TRUE(file_util::CreateDirectory(test_dir_.Append(subdir2)));
|
| + DirectoryWatcher watcher2;
|
| + ASSERT_TRUE(watcher2.Watch(test_dir_.Append(subdir2), this, true));
|
| +
|
| + SetExpectedNumberOfModifications(7);
|
| +
|
| + // Write a file to the subdirectories.
|
| + FilePath test_path = subdir.AppendASCII("test_file");
|
| + WriteTestDirFile(test_path.value(), "some content");
|
| + FilePath test_path2 = subdir2.AppendASCII("test_file2");
|
| + WriteTestDirFile(test_path2.value(), "some content2");
|
| + ASSERT_TRUE((file_util::Move(test_dir_.Append(subdir2),
|
| + test_dir_.Append(subdir))));
|
| + VerifyExpectedNumberOfModifications();
|
| +}
|
| +
|
| // Verify that watching a directory that doesn't exist fails, but doesn't
|
| // asssert.
|
| // Basic test: add a file and verify we notice it.
|
|
|