OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/directory_watcher.h" | 5 #include "base/directory_watcher.h" |
6 | 6 |
7 #include <fstream> | 7 #include <fstream> |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 // We won't get a notification, so we just wait around a bit to verify | 122 // We won't get a notification, so we just wait around a bit to verify |
123 // that notification doesn't come. | 123 // that notification doesn't come. |
124 loop_.PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, | 124 loop_.PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, |
125 kWaitForEventTime); | 125 kWaitForEventTime); |
126 loop_.Run(); | 126 loop_.Run(); |
127 | 127 |
128 ASSERT_EQ(directory_mods_, 0); | 128 ASSERT_EQ(directory_mods_, 0); |
129 } | 129 } |
130 | 130 |
131 // Verify that modifications to a subdirectory isn't noticed. | 131 // Verify that modifications to a subdirectory are noticed. |
132 TEST_F(DirectoryWatcherTest, SubDir) { | 132 TEST_F(DirectoryWatcherTest, SubDir) { |
133 #if defined(OS_WIN) | |
134 // Temporarily disabling test on Vista, see | |
135 // http://code.google.com/p/chromium/issues/detail?id=5072 | |
136 // TODO: Enable this test, quickly. | |
137 if (win_util::GetWinVersion() == win_util::WINVERSION_VISTA) | |
138 return; | |
139 #endif | |
140 FilePath subdir(FILE_PATH_LITERAL("SubDir")); | 133 FilePath subdir(FILE_PATH_LITERAL("SubDir")); |
141 ASSERT_TRUE(file_util::CreateDirectory(test_dir_.Append(subdir))); | 134 ASSERT_TRUE(file_util::CreateDirectory(test_dir_.Append(subdir))); |
142 | 135 |
143 DirectoryWatcher watcher; | 136 DirectoryWatcher watcher; |
144 ASSERT_TRUE(watcher.Watch(test_dir_, this)); | 137 ASSERT_TRUE(watcher.Watch(test_dir_, this)); |
145 // Write a file to the subdir. | 138 // Write a file to the subdir. |
146 FilePath test_path = subdir.AppendASCII("test_file"); | 139 FilePath test_path = subdir.AppendASCII("test_file"); |
147 WriteTestDirFile(test_path.value(), "some content"); | 140 WriteTestDirFile(test_path.value(), "some content"); |
148 | 141 LoopUntilModsEqual(2); |
149 // We won't get a notification, so we just wait around a bit to verify | |
150 // that notification doesn't come. | |
151 loop_.PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, | |
152 kWaitForEventTime); | |
153 loop_.Run(); | |
154 | |
155 // We shouldn't have been notified and shouldn't have crashed. | |
156 ASSERT_EQ(0, directory_mods_); | |
157 } | 142 } |
158 | 143 |
159 namespace { | 144 namespace { |
160 // Used by the DeleteDuringNotify test below. | 145 // Used by the DeleteDuringNotify test below. |
161 // Deletes the DirectoryWatcher when it's notified. | 146 // Deletes the DirectoryWatcher when it's notified. |
162 class Deleter : public DirectoryWatcher::Delegate { | 147 class Deleter : public DirectoryWatcher::Delegate { |
163 public: | 148 public: |
164 Deleter(DirectoryWatcher* watcher) : watcher_(watcher) {} | 149 Deleter(DirectoryWatcher* watcher) : watcher_(watcher) {} |
165 virtual void OnDirectoryChanged(const FilePath& path) { | 150 virtual void OnDirectoryChanged(const FilePath& path) { |
166 watcher_.reset(NULL); | 151 watcher_.reset(NULL); |
(...skipping 18 matching lines...) Expand all Loading... |
185 ASSERT_TRUE(deleter.watcher_.get() == NULL); | 170 ASSERT_TRUE(deleter.watcher_.get() == NULL); |
186 } | 171 } |
187 | 172 |
188 // Verify that watching a directory that doesn't exist fails, but doesn't | 173 // Verify that watching a directory that doesn't exist fails, but doesn't |
189 // asssert. | 174 // asssert. |
190 // Basic test: add a file and verify we notice it. | 175 // Basic test: add a file and verify we notice it. |
191 TEST_F(DirectoryWatcherTest, NonExistentDirectory) { | 176 TEST_F(DirectoryWatcherTest, NonExistentDirectory) { |
192 DirectoryWatcher watcher; | 177 DirectoryWatcher watcher; |
193 ASSERT_FALSE(watcher.Watch(test_dir_.AppendASCII("does-not-exist"), this)); | 178 ASSERT_FALSE(watcher.Watch(test_dir_.AppendASCII("does-not-exist"), this)); |
194 } | 179 } |
OLD | NEW |