diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-24 15:26:09 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-24 15:26:09 +0000 |
commit | 5c31aa6e312dccfaccf92e237062273bfd995369 (patch) | |
tree | 475821ef3934b273bcf2b3a4094f0c431f572270 /base/directory_watcher_unittest.cc | |
parent | 0f43a8f1c138bd8d850a606ff028df8f6c30ba31 (diff) | |
download | chromium_src-5c31aa6e312dccfaccf92e237062273bfd995369.zip chromium_src-5c31aa6e312dccfaccf92e237062273bfd995369.tar.gz chromium_src-5c31aa6e312dccfaccf92e237062273bfd995369.tar.bz2 |
Enable non-recursive watches for Windows DirectoryWatcher.
- enable test for it on Windows
- clean up directory_watcher_unittest.cc
http://crbug.com/5072
Review URL: http://codereview.chromium.org/42388
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12358 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/directory_watcher_unittest.cc')
-rw-r--r-- | base/directory_watcher_unittest.cc | 87 |
1 files changed, 37 insertions, 50 deletions
diff --git a/base/directory_watcher_unittest.cc b/base/directory_watcher_unittest.cc index 3b6f645..20ec4897 100644 --- a/base/directory_watcher_unittest.cc +++ b/base/directory_watcher_unittest.cc @@ -4,37 +4,22 @@ #include "base/directory_watcher.h" -#include <fstream> - -#include "build/build_config.h" +#include <limits> +#include "base/basictypes.h" #include "base/file_path.h" #include "base/file_util.h" #include "base/message_loop.h" #include "base/path_service.h" #include "base/platform_thread.h" #include "base/string_util.h" -#if defined(OS_WIN) -#include "base/win_util.h" -#endif #include "testing/gtest/include/gtest/gtest.h" -// TODO(phajdan.jr): Clean up ifdefs in this file when Linux/Windows differences -// get sorted out. - namespace { // For tests where we wait a bit to verify nothing happened const int kWaitForEventTime = 500; -// Unfortunately Windows supports only recursive watches and Linux -// only non-recursive ones. -#if defined(OS_WIN) -const bool kDefaultRecursiveValue = true; -#elif defined(OS_LINUX) -const bool kDefaultRecursiveValue = false; -#endif - } // namespace class DirectoryWatcherTest : public testing::Test, @@ -126,7 +111,7 @@ class DirectoryWatcherTest : public testing::Test, // Basic test: add a file and verify we notice it. TEST_F(DirectoryWatcherTest, NewFile) { DirectoryWatcher watcher; - ASSERT_TRUE(watcher.Watch(test_dir_, this, kDefaultRecursiveValue)); + ASSERT_TRUE(watcher.Watch(test_dir_, this, false)); SetExpectedNumberOfModifications(2); WriteTestDirFile(FILE_PATH_LITERAL("test_file"), "some content"); @@ -136,7 +121,7 @@ TEST_F(DirectoryWatcherTest, NewFile) { // Verify that modifying a file is caught. TEST_F(DirectoryWatcherTest, ModifiedFile) { DirectoryWatcher watcher; - ASSERT_TRUE(watcher.Watch(test_dir_, this, kDefaultRecursiveValue)); + ASSERT_TRUE(watcher.Watch(test_dir_, this, false)); // Write a file to the test dir. SetExpectedNumberOfModifications(2); @@ -155,7 +140,7 @@ TEST_F(DirectoryWatcherTest, ModifiedFile) { TEST_F(DirectoryWatcherTest, Unregister) { { DirectoryWatcher watcher; - ASSERT_TRUE(watcher.Watch(test_dir_, this, kDefaultRecursiveValue)); + ASSERT_TRUE(watcher.Watch(test_dir_, this, false)); // And then let it fall out of scope, clearing its watch. } @@ -166,40 +151,43 @@ TEST_F(DirectoryWatcherTest, Unregister) { VerifyExpectedNumberOfModifications(); } -TEST_F(DirectoryWatcherTest, SubDir) { +TEST_F(DirectoryWatcherTest, SubDirRecursive) { FilePath subdir(FILE_PATH_LITERAL("SubDir")); ASSERT_TRUE(file_util::CreateDirectory(test_dir_.Append(subdir))); -#if defined(OS_WIN) +#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; - ASSERT_TRUE(watcher.Watch(test_dir_, this, true)); - // Write a file to the subdir. - SetExpectedNumberOfModifications(2); - FilePath test_path = subdir.AppendASCII("test_file"); - WriteTestDirFile(test_path.value(), "some content"); - VerifyExpectedNumberOfModifications(); - } -#endif // defined(OS_WIN) + DirectoryWatcher watcher; + ASSERT_TRUE(watcher.Watch(test_dir_, this, true)); + // Write a file to the subdir. + SetExpectedNumberOfModifications(2); + FilePath test_path = subdir.AppendASCII("test_file"); + WriteTestDirFile(test_path.value(), "some content"); + VerifyExpectedNumberOfModifications(); +} -#if !defined(OS_WIN) - // TODO: Enable when the root cause of http://crbug.com/5072 is fixed. +TEST_F(DirectoryWatcherTest, SubDirNonRecursive) { + FilePath subdir(FILE_PATH_LITERAL("SubDir")); + ASSERT_TRUE(file_util::CreateDirectory(test_dir_.Append(subdir))); + + // Create a test file before the test. On Windows we get a notification + // when creating a file in a subdir even with a non-recursive watch. + FilePath test_path = subdir.AppendASCII("test_file"); + WriteTestDirFile(test_path.value(), "some content"); // Verify that modifications to a subdirectory are not noticed // by a not-recursive watch. - { - DirectoryWatcher watcher; - ASSERT_TRUE(watcher.Watch(test_dir_, this, false)); - // Write a file to the subdir. - SetExpectedNumberOfModifications(0); - FilePath test_path = subdir.AppendASCII("test_file"); - WriteTestDirFile(test_path.value(), "some content"); - VerifyExpectedNumberOfModifications(); - } -#endif // !defined(OS_WIN) + DirectoryWatcher watcher; + ASSERT_TRUE(watcher.Watch(test_dir_, this, false)); + + // Modify the test file. There should be no notifications. + SetExpectedNumberOfModifications(0); + WriteTestDirFile(test_path.value(), "some other content"); + VerifyExpectedNumberOfModifications(); } namespace { @@ -226,7 +214,7 @@ class Deleter : public DirectoryWatcher::Delegate { TEST_F(DirectoryWatcherTest, DeleteDuringNotify) { DirectoryWatcher* watcher = new DirectoryWatcher; Deleter deleter(watcher, &loop_); // Takes ownership of watcher. - ASSERT_TRUE(watcher->Watch(test_dir_, &deleter, kDefaultRecursiveValue)); + ASSERT_TRUE(watcher->Watch(test_dir_, &deleter, false)); WriteTestDirFile(FILE_PATH_LITERAL("test_file"), "some content"); loop_.Run(); @@ -238,8 +226,8 @@ TEST_F(DirectoryWatcherTest, DeleteDuringNotify) { TEST_F(DirectoryWatcherTest, MultipleWatchersSingleFile) { DirectoryWatcher watcher1, watcher2; - ASSERT_TRUE(watcher1.Watch(test_dir_, this, kDefaultRecursiveValue)); - ASSERT_TRUE(watcher2.Watch(test_dir_, this, kDefaultRecursiveValue)); + ASSERT_TRUE(watcher1.Watch(test_dir_, this, false)); + ASSERT_TRUE(watcher2.Watch(test_dir_, this, false)); SetExpectedNumberOfModifications(4); // Each watcher should fire twice. WriteTestDirFile(FILE_PATH_LITERAL("test_file"), "some content"); @@ -254,8 +242,7 @@ TEST_F(DirectoryWatcherTest, MultipleWatchersDifferentFiles) { 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, - kDefaultRecursiveValue)); + ASSERT_TRUE(watchers[i].Watch(test_dir_.Append(subdirs[i]), this, false)); } for (int i = 0; i < kNumberOfWatchers; i++) { // Verify that we only get modifications from one watcher (each watcher has @@ -279,5 +266,5 @@ TEST_F(DirectoryWatcherTest, MultipleWatchersDifferentFiles) { TEST_F(DirectoryWatcherTest, NonExistentDirectory) { DirectoryWatcher watcher; ASSERT_FALSE(watcher.Watch(test_dir_.AppendASCII("does-not-exist"), this, - kDefaultRecursiveValue)); + false)); } |