| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 // TODO: Enable this test, quickly. | 136 // TODO: Enable this test, quickly. |
| 137 if (win_util::GetWinVersion() == win_util::WINVERSION_VISTA) | 137 if (win_util::GetWinVersion() == win_util::WINVERSION_VISTA) |
| 138 return; | 138 return; |
| 139 #endif | 139 #endif |
| 140 FilePath subdir(FILE_PATH_LITERAL("SubDir")); | 140 FilePath subdir(FILE_PATH_LITERAL("SubDir")); |
| 141 ASSERT_TRUE(file_util::CreateDirectory(test_dir_.Append(subdir))); | 141 ASSERT_TRUE(file_util::CreateDirectory(test_dir_.Append(subdir))); |
| 142 | 142 |
| 143 DirectoryWatcher watcher; | 143 DirectoryWatcher watcher; |
| 144 ASSERT_TRUE(watcher.Watch(test_dir_, this)); | 144 ASSERT_TRUE(watcher.Watch(test_dir_, this)); |
| 145 // Write a file to the subdir. | 145 // Write a file to the subdir. |
| 146 FilePath test_path = subdir.Append(FILE_PATH_LITERAL("test_file")); | 146 FilePath test_path = subdir.AppendASCII("test_file"); |
| 147 WriteTestDirFile(test_path.value(), "some content"); | 147 WriteTestDirFile(test_path.value(), "some content"); |
| 148 | 148 |
| 149 // We won't get a notification, so we just wait around a bit to verify | 149 // We won't get a notification, so we just wait around a bit to verify |
| 150 // that notification doesn't come. | 150 // that notification doesn't come. |
| 151 loop_.PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, | 151 loop_.PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, |
| 152 kWaitForEventTime); | 152 kWaitForEventTime); |
| 153 loop_.Run(); | 153 loop_.Run(); |
| 154 | 154 |
| 155 // We shouldn't have been notified and shouldn't have crashed. | 155 // We shouldn't have been notified and shouldn't have crashed. |
| 156 ASSERT_EQ(0, directory_mods_); | 156 ASSERT_EQ(0, directory_mods_); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 183 // We win if we haven't crashed yet. | 183 // We win if we haven't crashed yet. |
| 184 // Might as well double-check it got deleted, too. | 184 // Might as well double-check it got deleted, too. |
| 185 ASSERT_TRUE(deleter.watcher_.get() == NULL); | 185 ASSERT_TRUE(deleter.watcher_.get() == NULL); |
| 186 } | 186 } |
| 187 | 187 |
| 188 // Verify that watching a directory that doesn't exist fails, but doesn't | 188 // Verify that watching a directory that doesn't exist fails, but doesn't |
| 189 // asssert. | 189 // asssert. |
| 190 // Basic test: add a file and verify we notice it. | 190 // Basic test: add a file and verify we notice it. |
| 191 TEST_F(DirectoryWatcherTest, NonExistentDirectory) { | 191 TEST_F(DirectoryWatcherTest, NonExistentDirectory) { |
| 192 DirectoryWatcher watcher; | 192 DirectoryWatcher watcher; |
| 193 ASSERT_FALSE(watcher.Watch( | 193 ASSERT_FALSE(watcher.Watch(test_dir_.AppendASCII("does-not-exist"), this)); |
| 194 test_dir_.Append(FILE_PATH_LITERAL("does-not-exist")), this)); | |
| 195 } | 194 } |
| OLD | NEW |