Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: base/directory_watcher_unittest.cc

Issue 52005: Implement recursive DirectoryWatcher watches on Linux (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/directory_watcher_inotify.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 322
323 // Write a file to the subdir. 323 // Write a file to the subdir.
324 SetExpectedNumberOfNotifiedDelegates(1); 324 SetExpectedNumberOfNotifiedDelegates(1);
325 ASSERT_TRUE(WriteTestFile(subdirs[i].AppendASCII("test_file"), "content")); 325 ASSERT_TRUE(WriteTestFile(subdirs[i].AppendASCII("test_file"), "content"));
326 VerifyExpectedNumberOfNotifiedDelegates(); 326 VerifyExpectedNumberOfNotifiedDelegates();
327 327
328 loop_.RunAllPending(); 328 loop_.RunAllPending();
329 } 329 }
330 } 330 }
331 331
332 #if defined(OS_WIN) || defined(OS_MACOSX)
333 // TODO(phajdan.jr): Enable when support for Linux recursive watches is added.
334
335 TEST_F(DirectoryWatcherTest, WatchCreatedDirectory) { 332 TEST_F(DirectoryWatcherTest, WatchCreatedDirectory) {
336 TestDelegate delegate(this); 333 TestDelegate delegate(this);
337 DirectoryWatcher watcher; 334 DirectoryWatcher watcher;
338 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, true)); 335 ASSERT_TRUE(watcher.Watch(test_dir_, &delegate, NULL, true));
339 336
340 SetExpectedNumberOfNotifiedDelegates(1); 337 SetExpectedNumberOfNotifiedDelegates(1);
341 FilePath subdir(CreateTestDirDirectoryASCII("SubDir", true)); 338 FilePath subdir(CreateTestDirDirectoryASCII("SubDir", true));
342 VerifyExpectedNumberOfNotifiedDelegates(); 339 VerifyExpectedNumberOfNotifiedDelegates();
343 340
344 delegate.reset(); 341 delegate.reset();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 subdir2.AppendASCII("file"))); 387 subdir2.AppendASCII("file")));
391 VerifyExpectedNumberOfNotifiedDelegates(); 388 VerifyExpectedNumberOfNotifiedDelegates();
392 389
393 delegate1.reset(); 390 delegate1.reset();
394 delegate2.reset(); 391 delegate2.reset();
395 392
396 SetExpectedNumberOfNotifiedDelegates(1); 393 SetExpectedNumberOfNotifiedDelegates(1);
397 ASSERT_TRUE(WriteTestFile(subdir2.AppendASCII("file"), "other content")); 394 ASSERT_TRUE(WriteTestFile(subdir2.AppendASCII("file"), "other content"));
398 VerifyExpectedNumberOfNotifiedDelegates(); 395 VerifyExpectedNumberOfNotifiedDelegates();
399 } 396 }
400 #endif // defined(OS_WIN) || defined(OS_MACOSX) 397
398 TEST_F(DirectoryWatcherTest, MoveFileOutofWatcher) {
399 FilePath subdir(CreateTestDirDirectoryASCII("SubDir", true));
400 FilePath subdir2(subdir.AppendASCII("SubDir2"));
401 EXPECT_TRUE(file_util::CreateDirectory(subdir2));
402
403 TestDelegate delegate(this);
404 DirectoryWatcher watcher;
405 ASSERT_TRUE(watcher.Watch(subdir2, &delegate, NULL, true));
406
407 // Write a file to the subdir.
408 SetExpectedNumberOfNotifiedDelegates(1);
409 ASSERT_TRUE(WriteTestFile(subdir2.AppendASCII("test_file"), "some content"));
410 VerifyExpectedNumberOfNotifiedDelegates();
411
412 delegate.reset();
413
414 SetExpectedNumberOfNotifiedDelegates(1);
415 ASSERT_TRUE(file_util::Move(subdir, test_dir_));
416 VerifyExpectedNumberOfNotifiedDelegates();
417
418 SetExpectedNumberOfNotifiedDelegates(0);
419 FilePath test_file(test_dir_.AppendASCII("SubDir2"));
420 ASSERT_TRUE(WriteTestFile(test_file.AppendASCII("test_file"),
421 "some content2"));
422 VerifyExpectedNumberOfNotifiedDelegates();
423 }
424
425 TEST_F(DirectoryWatcherTest, ParentDeleted) {
426 FilePath subdir(CreateTestDirDirectoryASCII("SubDir", true));
427 FilePath subdir2(subdir.AppendASCII("SubDir2"));
428 EXPECT_TRUE(file_util::CreateDirectory(subdir2));
429
430 TestDelegate delegate(this);
431 DirectoryWatcher watcher;
432 ASSERT_TRUE(watcher.Watch(subdir, &delegate, NULL, true));
433
434 #if defined(OS_LINUX)
435 SetExpectedNumberOfNotifiedDelegates(1);
436 #else
437 SetExpectedNumberOfNotifiedDelegates(2);
438 #endif
439 ASSERT_TRUE(file_util::Delete(subdir, true));
440 VerifyExpectedNumberOfNotifiedDelegates();
441 }
401 442
402 // Verify that watching a directory that doesn't exist fails, but doesn't 443 // Verify that watching a directory that doesn't exist fails, but doesn't
403 // asssert. 444 // asssert.
404 // Basic test: add a file and verify we notice it. 445 // Basic test: add a file and verify we notice it.
405 TEST_F(DirectoryWatcherTest, NonExistentDirectory) { 446 TEST_F(DirectoryWatcherTest, NonExistentDirectory) {
406 DirectoryWatcher watcher; 447 DirectoryWatcher watcher;
407 ASSERT_FALSE(watcher.Watch(test_dir_.AppendASCII("does-not-exist"), 448 ASSERT_FALSE(watcher.Watch(test_dir_.AppendASCII("does-not-exist"),
408 NULL, NULL, false)); 449 NULL, NULL, false));
409 } 450 }
410 451
411 } // namespace 452 } // namespace
OLDNEW
« no previous file with comments | « base/directory_watcher_inotify.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698