Index: base/files/file_path_watcher_browsertest.cc |
diff --git a/base/files/file_path_watcher_browsertest.cc b/base/files/file_path_watcher_browsertest.cc |
index 49b652f5d463b0c7711c084114258c38212f008b..aaae1b3cf6a6eab7692f1fe8466b44162cdd2031 100644 |
--- a/base/files/file_path_watcher_browsertest.cc |
+++ b/base/files/file_path_watcher_browsertest.cc |
@@ -165,6 +165,10 @@ class FilePathWatcherTest : public testing::Test { |
return temp_dir_.path().AppendASCII("FilePathWatcherTest"); |
} |
+ FilePath test_link() { |
+ return temp_dir_.path().AppendASCII("FilePathWatcherTest.lnk"); |
+ } |
+ |
// Write |content| to |file|. Returns true on success. |
bool WriteFile(const FilePath& file, const std::string& content) { |
int write_size = file_util::WriteFile(file, content.c_str(), |
@@ -494,6 +498,65 @@ TEST_F(FilePathWatcherTest, FileAttributesChanged) { |
#endif // !OS_LINUX |
+#if defined(OS_LINUX) |
+ |
+// Verify that creating a symlink is caught. |
+TEST_F(FilePathWatcherTest, CreateLink) { |
+ FilePathWatcher watcher; |
+ scoped_refptr<TestDelegate> delegate(new TestDelegate(collector())); |
+ // Note that we are watching the symlink |
+ ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get())); |
+ |
+ // Now make sure we get notified if the link is created. |
+ // Note that test_file() doesn't have to exist. |
+ ASSERT_TRUE(file_util::CreateSymbolicLink(test_file(), test_link())); |
+ ASSERT_TRUE(WaitForEvents()); |
+} |
+ |
+// Verify that deleting a symlink is caught. |
+TEST_F(FilePathWatcherTest, DeleteLink) { |
+ ASSERT_TRUE(WriteFile(test_file(), "content")); |
+ ASSERT_TRUE(file_util::CreateSymbolicLink(test_file(), test_link())); |
+ FilePathWatcher watcher; |
+ scoped_refptr<TestDelegate> delegate(new TestDelegate(collector())); |
+ ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get())); |
+ |
+ // Now make sure we get notified if the link is deleted. |
+ ASSERT_TRUE(file_util::Delete(test_link(), false)); |
+ ASSERT_TRUE(WaitForEvents()); |
+} |
+ |
+// Verify that modifying a target file that a link is pointing to |
+// when we are watching the link is caught. |
+TEST_F(FilePathWatcherTest, ModifiedLinkedFile) { |
+ ASSERT_TRUE(WriteFile(test_file(), "content")); |
+ ASSERT_TRUE(file_util::CreateSymbolicLink(test_file(), test_link())); |
+ FilePathWatcher watcher; |
+ scoped_refptr<TestDelegate> delegate(new TestDelegate(collector())); |
+ // Note that we are watching the symlink. |
+ ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get())); |
+ |
+ // Now make sure we get notified if the file is modified. |
+ ASSERT_TRUE(WriteFile(test_file(), "new content")); |
+ ASSERT_TRUE(WaitForEvents()); |
+} |
+ |
+// Verify that creating a target file that a link is pointing to |
+// when we are watching the link is caught. |
+TEST_F(FilePathWatcherTest, CreateTargetLinkedFile) { |
+ ASSERT_TRUE(file_util::CreateSymbolicLink(test_file(), test_link())); |
+ FilePathWatcher watcher; |
+ scoped_refptr<TestDelegate> delegate(new TestDelegate(collector())); |
+ // Note that we are watching the symlink. |
+ ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get())); |
+ |
+ // Now make sure we get notified if the target file is created. |
+ ASSERT_TRUE(WriteFile(test_file(), "content")); |
+ ASSERT_TRUE(WaitForEvents()); |
+} |
Mattias Nissler (ping if slow)
2011/08/30 09:53:06
You may want to add another test that deletes the
Craig
2011/08/30 16:00:16
Will do.
|
+ |
+#endif // OS_LINUX |
+ |
enum Permission { |
Read, |
Write, |