Chromium Code Reviews| Index: base/directory_watcher_unittest.cc |
| =================================================================== |
| --- base/directory_watcher_unittest.cc (revision 7533) |
| +++ base/directory_watcher_unittest.cc (working copy) |
| @@ -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 @@ |
| } |
| 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 @@ |
| // 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 @@ |
| // 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) |
|
M-A Ruel
2009/01/02 20:47:21
If the flush was done in WriteTestDirFile(), you c
|
| + // 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, |