diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-03 10:09:02 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-03 10:09:02 +0000 |
commit | a730335f3dfc06d91741790f79fc30463fb18dfe (patch) | |
tree | 3788460095d7fd8cd0e56e4dd4beb59b1111172e /base | |
parent | e15c8e011e4a6131e7e2745c5d75d0c3f1a5d685 (diff) | |
download | chromium_src-a730335f3dfc06d91741790f79fc30463fb18dfe.zip chromium_src-a730335f3dfc06d91741790f79fc30463fb18dfe.tar.gz chromium_src-a730335f3dfc06d91741790f79fc30463fb18dfe.tar.bz2 |
Re-enable DirectoryWatcherTest.SubDir on Vista
BUG=5072
Review URL: http://codereview.chromium.org/17046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7537 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/directory_watcher_unittest.cc | 37 | ||||
-rw-r--r-- | base/directory_watcher_win.cc | 1 |
2 files changed, 23 insertions, 15 deletions
diff --git a/base/directory_watcher_unittest.cc b/base/directory_watcher_unittest.cc index 39f64bb..27947ff 100644 --- a/base/directory_watcher_unittest.cc +++ b/base/directory_watcher_unittest.cc @@ -6,17 +6,13 @@ #include <fstream> -#include "build/build_config.h" - #include "base/file_path.h" #include "base/file_util.h" #include "base/logging.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" // For tests where we wait a bit to verify nothing happened @@ -43,6 +39,7 @@ class DirectoryWatcherTest : public testing::Test, } virtual void OnDirectoryChanged(const FilePath& path) { + EXPECT_EQ(path.value(), test_dir_.value()); ++directory_mods_; if (directory_mods_ == quit_mod_count_) MessageLoop::current()->Quit(); @@ -57,6 +54,7 @@ class DirectoryWatcherTest : public testing::Test, // Write |content| to a file under the test directory. void WriteTestDirFile(const FilePath::StringType& filename, const std::string& content) { + EXPECT_FALSE(FilePath(filename).IsAbsolute()); FilePath path = test_dir_.Append(filename); std::ofstream file; @@ -130,22 +128,31 @@ TEST_F(DirectoryWatcherTest, Unregister) { // Verify that modifications to a subdirectory isn't noticed. TEST_F(DirectoryWatcherTest, SubDir) { -#if defined(OS_WIN) - // Temporarily disabling test on Vista, see - // http://code.google.com/p/chromium/issues/detail?id=5072 - // TODO: Enable this test, quickly. - if (win_util::GetWinVersion() == win_util::WINVERSION_VISTA) - return; -#endif FilePath subdir(FILE_PATH_LITERAL("SubDir")); ASSERT_TRUE(file_util::CreateDirectory(test_dir_.Append(subdir))); - DirectoryWatcher watcher; - ASSERT_TRUE(watcher.Watch(test_dir_, this)); - // Write a file to the subdir. + // Create a file in the subdir. FilePath test_path = subdir.Append(FILE_PATH_LITERAL("test_file")); WriteTestDirFile(test_path.value(), "some content"); +#if defined(OS_WIN) + // We will flush the write buffer now to ensure it won't interfere + // with the notifications. + FilePath full_path(test_dir_.Append(test_path)); + HANDLE file_handle = CreateFile(full_path.value().c_str(), + GENERIC_READ | GENERIC_WRITE, + 0, NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, NULL); + ASSERT_TRUE(file_handle != INVALID_HANDLE_VALUE); + ASSERT_TRUE(FlushFileBuffers(file_handle)); + CloseHandle(file_handle); +#endif + + DirectoryWatcher watcher; + ASSERT_TRUE(watcher.Watch(test_dir_, this)); + + WriteTestDirFile(test_path.value(), "changed content"); + // We won't get a notification, so we just wait around a bit to verify // that notification doesn't come. loop_.PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, diff --git a/base/directory_watcher_win.cc b/base/directory_watcher_win.cc index cdaec39..68da1e50 100644 --- a/base/directory_watcher_win.cc +++ b/base/directory_watcher_win.cc @@ -42,6 +42,7 @@ DirectoryWatcher::Impl::~Impl() { bool DirectoryWatcher::Impl::Watch(const FilePath& path) { DCHECK(path_.value().empty()); // Can only watch one path. + DCHECK(path.IsAbsolute()); // FindFirstChangeNotification requires it. handle_ = FindFirstChangeNotification( path.value().c_str(), |