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 <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/platform_thread.h" | 14 #include "base/platform_thread.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/thread.h" |
16 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
17 #include "base/win_util.h" | 18 #include "base/win_util.h" |
18 #endif // defined(OS_WIN) | 19 #endif // defined(OS_WIN) |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // For tests where we wait a bit to verify nothing happened | 24 // For tests where we wait a bit to verify nothing happened |
24 const int kWaitForEventTime = 1000; | 25 const int kWaitForEventTime = 1000; |
25 | 26 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 145 |
145 // Keep track of original thread id to verify that callbacks are called | 146 // Keep track of original thread id to verify that callbacks are called |
146 // on the same thread. | 147 // on the same thread. |
147 PlatformThreadId original_thread_id_; | 148 PlatformThreadId original_thread_id_; |
148 }; | 149 }; |
149 | 150 |
150 // Basic test: add a file and verify we notice it. | 151 // Basic test: add a file and verify we notice it. |
151 TEST_F(DirectoryWatcherTest, NewFile) { | 152 TEST_F(DirectoryWatcherTest, NewFile) { |
152 DirectoryWatcher watcher; | 153 DirectoryWatcher watcher; |
153 TestDelegate delegate(this); | 154 TestDelegate delegate(this); |
154 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, false)); | 155 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, false)); |
155 | 156 |
156 SetExpectedNumberOfNotifiedDelegates(1); | 157 SetExpectedNumberOfNotifiedDelegates(1); |
157 ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); | 158 ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); |
158 VerifyExpectedNumberOfNotifiedDelegates(); | 159 VerifyExpectedNumberOfNotifiedDelegates(); |
159 } | 160 } |
160 | 161 |
161 // Verify that modifying a file is caught. | 162 // Verify that modifying a file is caught. |
162 TEST_F(DirectoryWatcherTest, ModifiedFile) { | 163 TEST_F(DirectoryWatcherTest, ModifiedFile) { |
163 // Write a file to the test dir. | 164 // Write a file to the test dir. |
164 ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); | 165 ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); |
165 SyncIfPOSIX(); | 166 SyncIfPOSIX(); |
166 | 167 |
167 DirectoryWatcher watcher; | 168 DirectoryWatcher watcher; |
168 TestDelegate delegate(this); | 169 TestDelegate delegate(this); |
169 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, false)); | 170 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, false)); |
170 | 171 |
171 // Now make sure we get notified if the file is modified. | 172 // Now make sure we get notified if the file is modified. |
172 SetExpectedNumberOfNotifiedDelegates(1); | 173 SetExpectedNumberOfNotifiedDelegates(1); |
173 ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "new content")); | 174 ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "new content")); |
174 VerifyExpectedNumberOfNotifiedDelegates(); | 175 VerifyExpectedNumberOfNotifiedDelegates(); |
175 } | 176 } |
176 | 177 |
177 TEST_F(DirectoryWatcherTest, DeletedFile) { | 178 TEST_F(DirectoryWatcherTest, DeletedFile) { |
178 // Write a file to the test dir. | 179 // Write a file to the test dir. |
179 ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); | 180 ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); |
180 SyncIfPOSIX(); | 181 SyncIfPOSIX(); |
181 | 182 |
182 DirectoryWatcher watcher; | 183 DirectoryWatcher watcher; |
183 TestDelegate delegate(this); | 184 TestDelegate delegate(this); |
184 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, false)); | 185 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, false)); |
185 | 186 |
186 // Now make sure we get notified if the file is deleted. | 187 // Now make sure we get notified if the file is deleted. |
187 SetExpectedNumberOfNotifiedDelegates(1); | 188 SetExpectedNumberOfNotifiedDelegates(1); |
188 ASSERT_TRUE(file_util::Delete(test_dir_.AppendASCII("test_file"), false)); | 189 ASSERT_TRUE(file_util::Delete(test_dir_.AppendASCII("test_file"), false)); |
189 VerifyExpectedNumberOfNotifiedDelegates(); | 190 VerifyExpectedNumberOfNotifiedDelegates(); |
190 } | 191 } |
191 | 192 |
192 // Verify that letting the watcher go out of scope stops notifications. | 193 // Verify that letting the watcher go out of scope stops notifications. |
193 TEST_F(DirectoryWatcherTest, Unregister) { | 194 TEST_F(DirectoryWatcherTest, Unregister) { |
194 TestDelegate delegate(this); | 195 TestDelegate delegate(this); |
195 | 196 |
196 { | 197 { |
197 DirectoryWatcher watcher; | 198 DirectoryWatcher watcher; |
198 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, false)); | 199 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, false)); |
199 | 200 |
200 // And then let it fall out of scope, clearing its watch. | 201 // And then let it fall out of scope, clearing its watch. |
201 } | 202 } |
202 | 203 |
203 // Write a file to the test dir. | 204 // Write a file to the test dir. |
204 SetExpectedNumberOfNotifiedDelegates(0); | 205 SetExpectedNumberOfNotifiedDelegates(0); |
205 ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); | 206 ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); |
206 VerifyExpectedNumberOfNotifiedDelegates(); | 207 VerifyExpectedNumberOfNotifiedDelegates(); |
207 } | 208 } |
208 | 209 |
209 TEST_F(DirectoryWatcherTest, SubDirRecursive) { | 210 TEST_F(DirectoryWatcherTest, SubDirRecursive) { |
210 FilePath subdir(CreateTestDirDirectoryASCII("SubDir", true)); | 211 FilePath subdir(CreateTestDirDirectoryASCII("SubDir", true)); |
211 | 212 |
212 #if defined(OS_LINUX) | |
213 // TODO(port): Recursive watches are not implemented on Linux. | |
214 return; | |
215 #endif // !defined(OS_WIN) | |
216 | |
217 // Verify that modifications to a subdirectory are noticed by recursive watch. | 213 // Verify that modifications to a subdirectory are noticed by recursive watch. |
218 TestDelegate delegate(this); | 214 TestDelegate delegate(this); |
219 DirectoryWatcher watcher; | 215 DirectoryWatcher watcher; |
220 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, true)); | 216 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, true)); |
221 // Write a file to the subdir. | 217 // Write a file to the subdir. |
222 SetExpectedNumberOfNotifiedDelegates(1); | 218 SetExpectedNumberOfNotifiedDelegates(1); |
223 ASSERT_TRUE(WriteTestFile(subdir.AppendASCII("test_file"), "some content")); | 219 ASSERT_TRUE(WriteTestFile(subdir.AppendASCII("test_file"), "some content")); |
224 VerifyExpectedNumberOfNotifiedDelegates(); | 220 VerifyExpectedNumberOfNotifiedDelegates(); |
225 } | 221 } |
226 | 222 |
227 TEST_F(DirectoryWatcherTest, SubDirNonRecursive) { | 223 TEST_F(DirectoryWatcherTest, SubDirNonRecursive) { |
228 #if defined(OS_WIN) | 224 #if defined(OS_WIN) |
229 // Disable this test for earlier version of Windows. It turned out to be | 225 // Disable this test for earlier version of Windows. It turned out to be |
230 // very difficult to create a reliable test for them. | 226 // very difficult to create a reliable test for them. |
231 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) | 227 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) |
232 return; | 228 return; |
233 #endif // defined(OS_WIN) | 229 #endif // defined(OS_WIN) |
234 | 230 |
235 FilePath subdir(CreateTestDirDirectoryASCII("SubDir", false)); | 231 FilePath subdir(CreateTestDirDirectoryASCII("SubDir", false)); |
236 | 232 |
237 // Create a test file before the test. On Windows we get a notification | 233 // Create a test file before the test. On Windows we get a notification |
238 // when creating a file in a subdir even with a non-recursive watch. | 234 // when creating a file in a subdir even with a non-recursive watch. |
239 ASSERT_TRUE(WriteTestFile(subdir.AppendASCII("test_file"), "some content")); | 235 ASSERT_TRUE(WriteTestFile(subdir.AppendASCII("test_file"), "some content")); |
240 | 236 |
241 SyncIfPOSIX(); | 237 SyncIfPOSIX(); |
242 | 238 |
243 // Verify that modifications to a subdirectory are not noticed | 239 // Verify that modifications to a subdirectory are not noticed |
244 // by a not-recursive watch. | 240 // by a not-recursive watch. |
245 DirectoryWatcher watcher; | 241 DirectoryWatcher watcher; |
246 TestDelegate delegate(this); | 242 TestDelegate delegate(this); |
247 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, false)); | 243 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, false)); |
248 | 244 |
249 // Modify the test file. There should be no notifications. | 245 // Modify the test file. There should be no notifications. |
250 SetExpectedNumberOfNotifiedDelegates(0); | 246 SetExpectedNumberOfNotifiedDelegates(0); |
251 ASSERT_TRUE(WriteTestFile(subdir.AppendASCII("test_file"), "other content")); | 247 ASSERT_TRUE(WriteTestFile(subdir.AppendASCII("test_file"), "other content")); |
252 VerifyExpectedNumberOfNotifiedDelegates(); | 248 VerifyExpectedNumberOfNotifiedDelegates(); |
253 } | 249 } |
254 | 250 |
255 namespace { | 251 namespace { |
256 // Used by the DeleteDuringNotify test below. | 252 // Used by the DeleteDuringNotify test below. |
257 // Deletes the DirectoryWatcher when it's notified. | 253 // Deletes the DirectoryWatcher when it's notified. |
(...skipping 11 matching lines...) Expand all Loading... |
269 | 265 |
270 scoped_ptr<DirectoryWatcher> watcher_; | 266 scoped_ptr<DirectoryWatcher> watcher_; |
271 MessageLoop* loop_; | 267 MessageLoop* loop_; |
272 }; | 268 }; |
273 } // anonymous namespace | 269 } // anonymous namespace |
274 | 270 |
275 // Verify that deleting a watcher during the callback | 271 // Verify that deleting a watcher during the callback |
276 TEST_F(DirectoryWatcherTest, DeleteDuringNotify) { | 272 TEST_F(DirectoryWatcherTest, DeleteDuringNotify) { |
277 DirectoryWatcher* watcher = new DirectoryWatcher; | 273 DirectoryWatcher* watcher = new DirectoryWatcher; |
278 Deleter deleter(watcher, &loop_); // Takes ownership of watcher. | 274 Deleter deleter(watcher, &loop_); // Takes ownership of watcher. |
279 ASSERT_TRUE(watcher->Watch(test_dir_, &deleter, false)); | 275 ASSERT_TRUE(watcher->Watch(test_dir_, &deleter, NULL, false)); |
280 | 276 |
281 ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); | 277 ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); |
282 loop_.Run(); | 278 loop_.Run(); |
283 | 279 |
284 // We win if we haven't crashed yet. | 280 // We win if we haven't crashed yet. |
285 // Might as well double-check it got deleted, too. | 281 // Might as well double-check it got deleted, too. |
286 ASSERT_TRUE(deleter.watcher_.get() == NULL); | 282 ASSERT_TRUE(deleter.watcher_.get() == NULL); |
287 } | 283 } |
288 | 284 |
| 285 TEST_F(DirectoryWatcherTest, BackendLoop) { |
| 286 base::Thread thread("test"); |
| 287 ASSERT_TRUE(thread.Start()); |
| 288 |
| 289 DirectoryWatcher watcher; |
| 290 TestDelegate delegate(this); |
| 291 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, thread.message_loop(), |
| 292 true)); |
| 293 } |
| 294 |
289 TEST_F(DirectoryWatcherTest, MultipleWatchersSingleFile) { | 295 TEST_F(DirectoryWatcherTest, MultipleWatchersSingleFile) { |
290 DirectoryWatcher watcher1, watcher2; | 296 DirectoryWatcher watcher1, watcher2; |
291 TestDelegate delegate1(this), delegate2(this); | 297 TestDelegate delegate1(this), delegate2(this); |
292 ASSERT_TRUE(watcher1.Watch(test_dir_, &delegate1, false)); | 298 ASSERT_TRUE(watcher1.Watch(test_dir_, &delegate1, NULL, false)); |
293 ASSERT_TRUE(watcher2.Watch(test_dir_, &delegate2, false)); | 299 ASSERT_TRUE(watcher2.Watch(test_dir_, &delegate2, NULL, false)); |
294 | 300 |
295 SetExpectedNumberOfNotifiedDelegates(2); | 301 SetExpectedNumberOfNotifiedDelegates(2); |
296 ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); | 302 ASSERT_TRUE(WriteTestFile(test_dir_.AppendASCII("test_file"), "content")); |
297 VerifyExpectedNumberOfNotifiedDelegates(); | 303 VerifyExpectedNumberOfNotifiedDelegates(); |
298 } | 304 } |
299 | 305 |
300 TEST_F(DirectoryWatcherTest, MultipleWatchersDifferentFiles) { | 306 TEST_F(DirectoryWatcherTest, MultipleWatchersDifferentFiles) { |
301 const int kNumberOfWatchers = 5; | 307 const int kNumberOfWatchers = 5; |
302 DirectoryWatcher watchers[kNumberOfWatchers]; | 308 DirectoryWatcher watchers[kNumberOfWatchers]; |
303 TestDelegate delegates[kNumberOfWatchers] = {this, this, this, this, this}; | 309 TestDelegate delegates[kNumberOfWatchers] = {this, this, this, this, this}; |
304 FilePath subdirs[kNumberOfWatchers]; | 310 FilePath subdirs[kNumberOfWatchers]; |
305 for (int i = 0; i < kNumberOfWatchers; i++) { | 311 for (int i = 0; i < kNumberOfWatchers; i++) { |
306 subdirs[i] = CreateTestDirDirectoryASCII("Dir" + IntToString(i), false); | 312 subdirs[i] = CreateTestDirDirectoryASCII("Dir" + IntToString(i), false); |
307 ASSERT_TRUE(watchers[i].Watch(subdirs[i], &delegates[i], false)); | 313 ASSERT_TRUE(watchers[i].Watch(subdirs[i], &delegates[i], |
| 314 NULL, ((i % 2) == 0))); |
308 } | 315 } |
309 for (int i = 0; i < kNumberOfWatchers; i++) { | 316 for (int i = 0; i < kNumberOfWatchers; i++) { |
310 // Verify that we only get modifications from one watcher (each watcher has | 317 // Verify that we only get modifications from one watcher (each watcher has |
311 // different directory). | 318 // different directory). |
312 | 319 |
313 for (int j = 0; j < kNumberOfWatchers; j++) | 320 for (int j = 0; j < kNumberOfWatchers; j++) |
314 delegates[j].reset(); | 321 delegates[j].reset(); |
315 | 322 |
316 // Write a file to the subdir. | 323 // Write a file to the subdir. |
317 SetExpectedNumberOfNotifiedDelegates(1); | 324 SetExpectedNumberOfNotifiedDelegates(1); |
318 ASSERT_TRUE(WriteTestFile(subdirs[i].AppendASCII("test_file"), "content")); | 325 ASSERT_TRUE(WriteTestFile(subdirs[i].AppendASCII("test_file"), "content")); |
319 VerifyExpectedNumberOfNotifiedDelegates(); | 326 VerifyExpectedNumberOfNotifiedDelegates(); |
320 | 327 |
321 loop_.RunAllPending(); | 328 loop_.RunAllPending(); |
322 } | 329 } |
323 } | 330 } |
324 | 331 |
325 #if defined(OS_WIN) || defined(OS_MACOSX) | 332 #if defined(OS_WIN) || defined(OS_MACOSX) |
326 // TODO(phajdan.jr): Enable when support for Linux recursive watches is added. | 333 // TODO(phajdan.jr): Enable when support for Linux recursive watches is added. |
327 | 334 |
328 TEST_F(DirectoryWatcherTest, WatchCreatedDirectory) { | 335 TEST_F(DirectoryWatcherTest, WatchCreatedDirectory) { |
329 TestDelegate delegate(this); | 336 TestDelegate delegate(this); |
330 DirectoryWatcher watcher; | 337 DirectoryWatcher watcher; |
331 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, true)); | 338 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, true)); |
332 | 339 |
333 SetExpectedNumberOfNotifiedDelegates(1); | 340 SetExpectedNumberOfNotifiedDelegates(1); |
334 FilePath subdir(CreateTestDirDirectoryASCII("SubDir", true)); | 341 FilePath subdir(CreateTestDirDirectoryASCII("SubDir", true)); |
335 VerifyExpectedNumberOfNotifiedDelegates(); | 342 VerifyExpectedNumberOfNotifiedDelegates(); |
336 | 343 |
337 delegate.reset(); | 344 delegate.reset(); |
338 | 345 |
339 // Verify that changes inside the subdir are noticed. | 346 // Verify that changes inside the subdir are noticed. |
340 SetExpectedNumberOfNotifiedDelegates(1); | 347 SetExpectedNumberOfNotifiedDelegates(1); |
341 ASSERT_TRUE(WriteTestFile(subdir.AppendASCII("test_file"), "some content")); | 348 ASSERT_TRUE(WriteTestFile(subdir.AppendASCII("test_file"), "some content")); |
342 VerifyExpectedNumberOfNotifiedDelegates(); | 349 VerifyExpectedNumberOfNotifiedDelegates(); |
343 } | 350 } |
344 | 351 |
345 TEST_F(DirectoryWatcherTest, RecursiveWatchDeletedSubdirectory) { | 352 TEST_F(DirectoryWatcherTest, RecursiveWatchDeletedSubdirectory) { |
346 FilePath subdir(CreateTestDirDirectoryASCII("SubDir", true)); | 353 FilePath subdir(CreateTestDirDirectoryASCII("SubDir", true)); |
347 | 354 |
348 TestDelegate delegate(this); | 355 TestDelegate delegate(this); |
349 DirectoryWatcher watcher; | 356 DirectoryWatcher watcher; |
350 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, true)); | 357 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, true)); |
351 | 358 |
352 // Write a file to the subdir. | 359 // Write a file to the subdir. |
353 SetExpectedNumberOfNotifiedDelegates(1); | 360 SetExpectedNumberOfNotifiedDelegates(1); |
354 ASSERT_TRUE(WriteTestFile(subdir.AppendASCII("test_file"), "some content")); | 361 ASSERT_TRUE(WriteTestFile(subdir.AppendASCII("test_file"), "some content")); |
355 VerifyExpectedNumberOfNotifiedDelegates(); | 362 VerifyExpectedNumberOfNotifiedDelegates(); |
356 | 363 |
357 delegate.reset(); | 364 delegate.reset(); |
358 | 365 |
359 SetExpectedNumberOfNotifiedDelegates(1); | 366 SetExpectedNumberOfNotifiedDelegates(1); |
360 ASSERT_TRUE(file_util::Delete(subdir, true)); | 367 ASSERT_TRUE(file_util::Delete(subdir, true)); |
361 VerifyExpectedNumberOfNotifiedDelegates(); | 368 VerifyExpectedNumberOfNotifiedDelegates(); |
362 } | 369 } |
363 | 370 |
364 TEST_F(DirectoryWatcherTest, MoveFileAcrossWatches) { | 371 TEST_F(DirectoryWatcherTest, MoveFileAcrossWatches) { |
365 FilePath subdir1(CreateTestDirDirectoryASCII("SubDir1", true)); | 372 FilePath subdir1(CreateTestDirDirectoryASCII("SubDir1", true)); |
366 FilePath subdir2(CreateTestDirDirectoryASCII("SubDir2", true)); | 373 FilePath subdir2(CreateTestDirDirectoryASCII("SubDir2", true)); |
367 | 374 |
368 TestDelegate delegate1(this), delegate2(this); | 375 TestDelegate delegate1(this), delegate2(this); |
369 DirectoryWatcher watcher1, watcher2; | 376 DirectoryWatcher watcher1, watcher2; |
370 ASSERT_TRUE(watcher1.Watch(subdir1, &delegate1, true)); | 377 ASSERT_TRUE(watcher1.Watch(subdir1, &delegate1, NULL, true)); |
371 ASSERT_TRUE(watcher2.Watch(subdir2, &delegate2, true)); | 378 ASSERT_TRUE(watcher2.Watch(subdir2, &delegate2, NULL, true)); |
372 | 379 |
373 SetExpectedNumberOfNotifiedDelegates(1); | 380 SetExpectedNumberOfNotifiedDelegates(1); |
374 ASSERT_TRUE(WriteTestFile(subdir1.AppendASCII("file"), "some content")); | 381 ASSERT_TRUE(WriteTestFile(subdir1.AppendASCII("file"), "some content")); |
375 SyncIfPOSIX(); | 382 SyncIfPOSIX(); |
376 VerifyExpectedNumberOfNotifiedDelegates(); | 383 VerifyExpectedNumberOfNotifiedDelegates(); |
377 | 384 |
378 delegate1.reset(); | 385 delegate1.reset(); |
379 delegate2.reset(); | 386 delegate2.reset(); |
380 | 387 |
381 SetExpectedNumberOfNotifiedDelegates(2); | 388 SetExpectedNumberOfNotifiedDelegates(2); |
382 ASSERT_TRUE(file_util::Move(subdir1.AppendASCII("file"), | 389 ASSERT_TRUE(file_util::Move(subdir1.AppendASCII("file"), |
383 subdir2.AppendASCII("file"))); | 390 subdir2.AppendASCII("file"))); |
384 VerifyExpectedNumberOfNotifiedDelegates(); | 391 VerifyExpectedNumberOfNotifiedDelegates(); |
385 | 392 |
386 delegate1.reset(); | 393 delegate1.reset(); |
387 delegate2.reset(); | 394 delegate2.reset(); |
388 | 395 |
389 SetExpectedNumberOfNotifiedDelegates(1); | 396 SetExpectedNumberOfNotifiedDelegates(1); |
390 ASSERT_TRUE(WriteTestFile(subdir2.AppendASCII("file"), "other content")); | 397 ASSERT_TRUE(WriteTestFile(subdir2.AppendASCII("file"), "other content")); |
391 VerifyExpectedNumberOfNotifiedDelegates(); | 398 VerifyExpectedNumberOfNotifiedDelegates(); |
392 } | 399 } |
393 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 400 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
394 | 401 |
395 // Verify that watching a directory that doesn't exist fails, but doesn't | 402 // Verify that watching a directory that doesn't exist fails, but doesn't |
396 // asssert. | 403 // asssert. |
397 // Basic test: add a file and verify we notice it. | 404 // Basic test: add a file and verify we notice it. |
398 TEST_F(DirectoryWatcherTest, NonExistentDirectory) { | 405 TEST_F(DirectoryWatcherTest, NonExistentDirectory) { |
399 DirectoryWatcher watcher; | 406 DirectoryWatcher watcher; |
400 ASSERT_FALSE(watcher.Watch(test_dir_.AppendASCII("does-not-exist"), NULL, | 407 ASSERT_FALSE(watcher.Watch(test_dir_.AppendASCII("does-not-exist"), |
401 false)); | 408 NULL, NULL, false)); |
402 } | 409 } |
403 | 410 |
404 } // namespace | 411 } // namespace |
OLD | NEW |