| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/files/file_path_watcher.h" | 5 #include "base/files/file_path_watcher.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <aclapi.h> | 9 #include <aclapi.h> |
| 10 #elif defined(OS_POSIX) | 10 #elif defined(OS_POSIX) |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 file_thread_.task_runner()->PostTask( | 220 file_thread_.task_runner()->PostTask( |
| 221 FROM_HERE, base::Bind(SetupWatchCallback, target, watcher, delegate, | 221 FROM_HERE, base::Bind(SetupWatchCallback, target, watcher, delegate, |
| 222 recursive_watch, &result, &completion)); | 222 recursive_watch, &result, &completion)); |
| 223 completion.Wait(); | 223 completion.Wait(); |
| 224 return result; | 224 return result; |
| 225 } | 225 } |
| 226 | 226 |
| 227 // Basic test: Create the file and verify that we notice. | 227 // Basic test: Create the file and verify that we notice. |
| 228 TEST_F(FilePathWatcherTest, NewFile) { | 228 TEST_F(FilePathWatcherTest, NewFile) { |
| 229 FilePathWatcher watcher; | 229 FilePathWatcher watcher; |
| 230 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 230 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 231 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); | 231 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); |
| 232 | 232 |
| 233 ASSERT_TRUE(WriteFile(test_file(), "content")); | 233 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 234 ASSERT_TRUE(WaitForEvents()); | 234 ASSERT_TRUE(WaitForEvents()); |
| 235 DeleteDelegateOnFileThread(delegate.release()); | 235 DeleteDelegateOnFileThread(delegate.release()); |
| 236 } | 236 } |
| 237 | 237 |
| 238 // Verify that modifying the file is caught. | 238 // Verify that modifying the file is caught. |
| 239 TEST_F(FilePathWatcherTest, ModifiedFile) { | 239 TEST_F(FilePathWatcherTest, ModifiedFile) { |
| 240 ASSERT_TRUE(WriteFile(test_file(), "content")); | 240 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 241 | 241 |
| 242 FilePathWatcher watcher; | 242 FilePathWatcher watcher; |
| 243 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 243 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 244 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); | 244 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); |
| 245 | 245 |
| 246 // Now make sure we get notified if the file is modified. | 246 // Now make sure we get notified if the file is modified. |
| 247 ASSERT_TRUE(WriteFile(test_file(), "new content")); | 247 ASSERT_TRUE(WriteFile(test_file(), "new content")); |
| 248 ASSERT_TRUE(WaitForEvents()); | 248 ASSERT_TRUE(WaitForEvents()); |
| 249 DeleteDelegateOnFileThread(delegate.release()); | 249 DeleteDelegateOnFileThread(delegate.release()); |
| 250 } | 250 } |
| 251 | 251 |
| 252 // Verify that moving the file into place is caught. | 252 // Verify that moving the file into place is caught. |
| 253 TEST_F(FilePathWatcherTest, MovedFile) { | 253 TEST_F(FilePathWatcherTest, MovedFile) { |
| 254 FilePath source_file(temp_dir_.path().AppendASCII("source")); | 254 FilePath source_file(temp_dir_.path().AppendASCII("source")); |
| 255 ASSERT_TRUE(WriteFile(source_file, "content")); | 255 ASSERT_TRUE(WriteFile(source_file, "content")); |
| 256 | 256 |
| 257 FilePathWatcher watcher; | 257 FilePathWatcher watcher; |
| 258 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 258 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 259 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); | 259 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); |
| 260 | 260 |
| 261 // Now make sure we get notified if the file is modified. | 261 // Now make sure we get notified if the file is modified. |
| 262 ASSERT_TRUE(base::Move(source_file, test_file())); | 262 ASSERT_TRUE(base::Move(source_file, test_file())); |
| 263 ASSERT_TRUE(WaitForEvents()); | 263 ASSERT_TRUE(WaitForEvents()); |
| 264 DeleteDelegateOnFileThread(delegate.release()); | 264 DeleteDelegateOnFileThread(delegate.release()); |
| 265 } | 265 } |
| 266 | 266 |
| 267 TEST_F(FilePathWatcherTest, DeletedFile) { | 267 TEST_F(FilePathWatcherTest, DeletedFile) { |
| 268 ASSERT_TRUE(WriteFile(test_file(), "content")); | 268 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 269 | 269 |
| 270 FilePathWatcher watcher; | 270 FilePathWatcher watcher; |
| 271 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 271 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 272 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); | 272 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); |
| 273 | 273 |
| 274 // Now make sure we get notified if the file is deleted. | 274 // Now make sure we get notified if the file is deleted. |
| 275 base::DeleteFile(test_file(), false); | 275 base::DeleteFile(test_file(), false); |
| 276 ASSERT_TRUE(WaitForEvents()); | 276 ASSERT_TRUE(WaitForEvents()); |
| 277 DeleteDelegateOnFileThread(delegate.release()); | 277 DeleteDelegateOnFileThread(delegate.release()); |
| 278 } | 278 } |
| 279 | 279 |
| 280 // Used by the DeleteDuringNotify test below. | 280 // Used by the DeleteDuringNotify test below. |
| 281 // Deletes the FilePathWatcher when it's notified. | 281 // Deletes the FilePathWatcher when it's notified. |
| 282 class Deleter : public TestDelegateBase { | 282 class Deleter : public TestDelegateBase { |
| 283 public: | 283 public: |
| 284 Deleter(FilePathWatcher* watcher, MessageLoop* loop) | 284 Deleter(FilePathWatcher* watcher, MessageLoop* loop) |
| 285 : watcher_(watcher), | 285 : watcher_(watcher), |
| 286 loop_(loop) { | 286 loop_(loop) { |
| 287 } | 287 } |
| 288 ~Deleter() override {} | 288 ~Deleter() override {} |
| 289 | 289 |
| 290 void OnFileChanged(const FilePath&, bool) override { | 290 void OnFileChanged(const FilePath&, bool) override { |
| 291 watcher_.reset(); | 291 watcher_.reset(); |
| 292 loop_->task_runner()->PostTask(FROM_HERE, | 292 loop_->task_runner()->PostTask(FROM_HERE, |
| 293 MessageLoop::QuitWhenIdleClosure()); | 293 MessageLoop::QuitWhenIdleClosure()); |
| 294 } | 294 } |
| 295 | 295 |
| 296 FilePathWatcher* watcher() const { return watcher_.get(); } | 296 FilePathWatcher* watcher() const { return watcher_.get(); } |
| 297 | 297 |
| 298 private: | 298 private: |
| 299 scoped_ptr<FilePathWatcher> watcher_; | 299 std::unique_ptr<FilePathWatcher> watcher_; |
| 300 MessageLoop* loop_; | 300 MessageLoop* loop_; |
| 301 | 301 |
| 302 DISALLOW_COPY_AND_ASSIGN(Deleter); | 302 DISALLOW_COPY_AND_ASSIGN(Deleter); |
| 303 }; | 303 }; |
| 304 | 304 |
| 305 // Verify that deleting a watcher during the callback doesn't crash. | 305 // Verify that deleting a watcher during the callback doesn't crash. |
| 306 TEST_F(FilePathWatcherTest, DeleteDuringNotify) { | 306 TEST_F(FilePathWatcherTest, DeleteDuringNotify) { |
| 307 FilePathWatcher* watcher = new FilePathWatcher; | 307 FilePathWatcher* watcher = new FilePathWatcher; |
| 308 // Takes ownership of watcher. | 308 // Takes ownership of watcher. |
| 309 scoped_ptr<Deleter> deleter(new Deleter(watcher, &loop_)); | 309 std::unique_ptr<Deleter> deleter(new Deleter(watcher, &loop_)); |
| 310 ASSERT_TRUE(SetupWatch(test_file(), watcher, deleter.get(), false)); | 310 ASSERT_TRUE(SetupWatch(test_file(), watcher, deleter.get(), false)); |
| 311 | 311 |
| 312 ASSERT_TRUE(WriteFile(test_file(), "content")); | 312 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 313 ASSERT_TRUE(WaitForEvents()); | 313 ASSERT_TRUE(WaitForEvents()); |
| 314 | 314 |
| 315 // We win if we haven't crashed yet. | 315 // We win if we haven't crashed yet. |
| 316 // Might as well double-check it got deleted, too. | 316 // Might as well double-check it got deleted, too. |
| 317 ASSERT_TRUE(deleter->watcher() == NULL); | 317 ASSERT_TRUE(deleter->watcher() == NULL); |
| 318 } | 318 } |
| 319 | 319 |
| 320 // Verify that deleting the watcher works even if there is a pending | 320 // Verify that deleting the watcher works even if there is a pending |
| 321 // notification. | 321 // notification. |
| 322 // Flaky on MacOS (and ARM linux): http://crbug.com/85930 | 322 // Flaky on MacOS (and ARM linux): http://crbug.com/85930 |
| 323 TEST_F(FilePathWatcherTest, DISABLED_DestroyWithPendingNotification) { | 323 TEST_F(FilePathWatcherTest, DISABLED_DestroyWithPendingNotification) { |
| 324 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 324 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 325 FilePathWatcher* watcher = new FilePathWatcher; | 325 FilePathWatcher* watcher = new FilePathWatcher; |
| 326 ASSERT_TRUE(SetupWatch(test_file(), watcher, delegate.get(), false)); | 326 ASSERT_TRUE(SetupWatch(test_file(), watcher, delegate.get(), false)); |
| 327 ASSERT_TRUE(WriteFile(test_file(), "content")); | 327 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 328 file_thread_.task_runner()->DeleteSoon(FROM_HERE, watcher); | 328 file_thread_.task_runner()->DeleteSoon(FROM_HERE, watcher); |
| 329 DeleteDelegateOnFileThread(delegate.release()); | 329 DeleteDelegateOnFileThread(delegate.release()); |
| 330 } | 330 } |
| 331 | 331 |
| 332 TEST_F(FilePathWatcherTest, MultipleWatchersSingleFile) { | 332 TEST_F(FilePathWatcherTest, MultipleWatchersSingleFile) { |
| 333 FilePathWatcher watcher1, watcher2; | 333 FilePathWatcher watcher1, watcher2; |
| 334 scoped_ptr<TestDelegate> delegate1(new TestDelegate(collector())); | 334 std::unique_ptr<TestDelegate> delegate1(new TestDelegate(collector())); |
| 335 scoped_ptr<TestDelegate> delegate2(new TestDelegate(collector())); | 335 std::unique_ptr<TestDelegate> delegate2(new TestDelegate(collector())); |
| 336 ASSERT_TRUE(SetupWatch(test_file(), &watcher1, delegate1.get(), false)); | 336 ASSERT_TRUE(SetupWatch(test_file(), &watcher1, delegate1.get(), false)); |
| 337 ASSERT_TRUE(SetupWatch(test_file(), &watcher2, delegate2.get(), false)); | 337 ASSERT_TRUE(SetupWatch(test_file(), &watcher2, delegate2.get(), false)); |
| 338 | 338 |
| 339 ASSERT_TRUE(WriteFile(test_file(), "content")); | 339 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 340 ASSERT_TRUE(WaitForEvents()); | 340 ASSERT_TRUE(WaitForEvents()); |
| 341 DeleteDelegateOnFileThread(delegate1.release()); | 341 DeleteDelegateOnFileThread(delegate1.release()); |
| 342 DeleteDelegateOnFileThread(delegate2.release()); | 342 DeleteDelegateOnFileThread(delegate2.release()); |
| 343 } | 343 } |
| 344 | 344 |
| 345 // Verify that watching a file whose parent directory doesn't exist yet works if | 345 // Verify that watching a file whose parent directory doesn't exist yet works if |
| 346 // the directory and file are created eventually. | 346 // the directory and file are created eventually. |
| 347 TEST_F(FilePathWatcherTest, NonExistentDirectory) { | 347 TEST_F(FilePathWatcherTest, NonExistentDirectory) { |
| 348 FilePathWatcher watcher; | 348 FilePathWatcher watcher; |
| 349 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 349 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 350 FilePath file(dir.AppendASCII("file")); | 350 FilePath file(dir.AppendASCII("file")); |
| 351 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 351 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 352 ASSERT_TRUE(SetupWatch(file, &watcher, delegate.get(), false)); | 352 ASSERT_TRUE(SetupWatch(file, &watcher, delegate.get(), false)); |
| 353 | 353 |
| 354 ASSERT_TRUE(base::CreateDirectory(dir)); | 354 ASSERT_TRUE(base::CreateDirectory(dir)); |
| 355 | 355 |
| 356 ASSERT_TRUE(WriteFile(file, "content")); | 356 ASSERT_TRUE(WriteFile(file, "content")); |
| 357 | 357 |
| 358 VLOG(1) << "Waiting for file creation"; | 358 VLOG(1) << "Waiting for file creation"; |
| 359 ASSERT_TRUE(WaitForEvents()); | 359 ASSERT_TRUE(WaitForEvents()); |
| 360 | 360 |
| 361 ASSERT_TRUE(WriteFile(file, "content v2")); | 361 ASSERT_TRUE(WriteFile(file, "content v2")); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 374 FilePath path(temp_dir_.path()); | 374 FilePath path(temp_dir_.path()); |
| 375 std::vector<std::string> dir_names; | 375 std::vector<std::string> dir_names; |
| 376 for (int i = 0; i < 20; i++) { | 376 for (int i = 0; i < 20; i++) { |
| 377 std::string dir(base::StringPrintf("d%d", i)); | 377 std::string dir(base::StringPrintf("d%d", i)); |
| 378 dir_names.push_back(dir); | 378 dir_names.push_back(dir); |
| 379 path = path.AppendASCII(dir); | 379 path = path.AppendASCII(dir); |
| 380 } | 380 } |
| 381 | 381 |
| 382 FilePathWatcher watcher; | 382 FilePathWatcher watcher; |
| 383 FilePath file(path.AppendASCII("file")); | 383 FilePath file(path.AppendASCII("file")); |
| 384 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 384 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 385 ASSERT_TRUE(SetupWatch(file, &watcher, delegate.get(), false)); | 385 ASSERT_TRUE(SetupWatch(file, &watcher, delegate.get(), false)); |
| 386 | 386 |
| 387 FilePath sub_path(temp_dir_.path()); | 387 FilePath sub_path(temp_dir_.path()); |
| 388 for (std::vector<std::string>::const_iterator d(dir_names.begin()); | 388 for (std::vector<std::string>::const_iterator d(dir_names.begin()); |
| 389 d != dir_names.end(); ++d) { | 389 d != dir_names.end(); ++d) { |
| 390 sub_path = sub_path.AppendASCII(*d); | 390 sub_path = sub_path.AppendASCII(*d); |
| 391 ASSERT_TRUE(base::CreateDirectory(sub_path)); | 391 ASSERT_TRUE(base::CreateDirectory(sub_path)); |
| 392 } | 392 } |
| 393 VLOG(1) << "Create File"; | 393 VLOG(1) << "Create File"; |
| 394 ASSERT_TRUE(WriteFile(file, "content")); | 394 ASSERT_TRUE(WriteFile(file, "content")); |
| 395 VLOG(1) << "Waiting for file creation"; | 395 VLOG(1) << "Waiting for file creation"; |
| 396 ASSERT_TRUE(WaitForEvents()); | 396 ASSERT_TRUE(WaitForEvents()); |
| 397 | 397 |
| 398 ASSERT_TRUE(WriteFile(file, "content v2")); | 398 ASSERT_TRUE(WriteFile(file, "content v2")); |
| 399 VLOG(1) << "Waiting for file modification"; | 399 VLOG(1) << "Waiting for file modification"; |
| 400 ASSERT_TRUE(WaitForEvents()); | 400 ASSERT_TRUE(WaitForEvents()); |
| 401 DeleteDelegateOnFileThread(delegate.release()); | 401 DeleteDelegateOnFileThread(delegate.release()); |
| 402 } | 402 } |
| 403 | 403 |
| 404 #if defined(OS_MACOSX) | 404 #if defined(OS_MACOSX) |
| 405 // http://crbug.com/85930 | 405 // http://crbug.com/85930 |
| 406 #define DisappearingDirectory DISABLED_DisappearingDirectory | 406 #define DisappearingDirectory DISABLED_DisappearingDirectory |
| 407 #endif | 407 #endif |
| 408 TEST_F(FilePathWatcherTest, DisappearingDirectory) { | 408 TEST_F(FilePathWatcherTest, DisappearingDirectory) { |
| 409 FilePathWatcher watcher; | 409 FilePathWatcher watcher; |
| 410 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 410 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 411 FilePath file(dir.AppendASCII("file")); | 411 FilePath file(dir.AppendASCII("file")); |
| 412 ASSERT_TRUE(base::CreateDirectory(dir)); | 412 ASSERT_TRUE(base::CreateDirectory(dir)); |
| 413 ASSERT_TRUE(WriteFile(file, "content")); | 413 ASSERT_TRUE(WriteFile(file, "content")); |
| 414 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 414 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 415 ASSERT_TRUE(SetupWatch(file, &watcher, delegate.get(), false)); | 415 ASSERT_TRUE(SetupWatch(file, &watcher, delegate.get(), false)); |
| 416 | 416 |
| 417 ASSERT_TRUE(base::DeleteFile(dir, true)); | 417 ASSERT_TRUE(base::DeleteFile(dir, true)); |
| 418 ASSERT_TRUE(WaitForEvents()); | 418 ASSERT_TRUE(WaitForEvents()); |
| 419 DeleteDelegateOnFileThread(delegate.release()); | 419 DeleteDelegateOnFileThread(delegate.release()); |
| 420 } | 420 } |
| 421 | 421 |
| 422 // Tests that a file that is deleted and reappears is tracked correctly. | 422 // Tests that a file that is deleted and reappears is tracked correctly. |
| 423 TEST_F(FilePathWatcherTest, DeleteAndRecreate) { | 423 TEST_F(FilePathWatcherTest, DeleteAndRecreate) { |
| 424 ASSERT_TRUE(WriteFile(test_file(), "content")); | 424 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 425 FilePathWatcher watcher; | 425 FilePathWatcher watcher; |
| 426 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 426 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 427 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); | 427 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); |
| 428 | 428 |
| 429 ASSERT_TRUE(base::DeleteFile(test_file(), false)); | 429 ASSERT_TRUE(base::DeleteFile(test_file(), false)); |
| 430 VLOG(1) << "Waiting for file deletion"; | 430 VLOG(1) << "Waiting for file deletion"; |
| 431 ASSERT_TRUE(WaitForEvents()); | 431 ASSERT_TRUE(WaitForEvents()); |
| 432 | 432 |
| 433 ASSERT_TRUE(WriteFile(test_file(), "content")); | 433 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 434 VLOG(1) << "Waiting for file creation"; | 434 VLOG(1) << "Waiting for file creation"; |
| 435 ASSERT_TRUE(WaitForEvents()); | 435 ASSERT_TRUE(WaitForEvents()); |
| 436 DeleteDelegateOnFileThread(delegate.release()); | 436 DeleteDelegateOnFileThread(delegate.release()); |
| 437 } | 437 } |
| 438 | 438 |
| 439 TEST_F(FilePathWatcherTest, WatchDirectory) { | 439 TEST_F(FilePathWatcherTest, WatchDirectory) { |
| 440 FilePathWatcher watcher; | 440 FilePathWatcher watcher; |
| 441 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 441 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 442 FilePath file1(dir.AppendASCII("file1")); | 442 FilePath file1(dir.AppendASCII("file1")); |
| 443 FilePath file2(dir.AppendASCII("file2")); | 443 FilePath file2(dir.AppendASCII("file2")); |
| 444 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 444 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 445 ASSERT_TRUE(SetupWatch(dir, &watcher, delegate.get(), false)); | 445 ASSERT_TRUE(SetupWatch(dir, &watcher, delegate.get(), false)); |
| 446 | 446 |
| 447 ASSERT_TRUE(base::CreateDirectory(dir)); | 447 ASSERT_TRUE(base::CreateDirectory(dir)); |
| 448 VLOG(1) << "Waiting for directory creation"; | 448 VLOG(1) << "Waiting for directory creation"; |
| 449 ASSERT_TRUE(WaitForEvents()); | 449 ASSERT_TRUE(WaitForEvents()); |
| 450 | 450 |
| 451 ASSERT_TRUE(WriteFile(file1, "content")); | 451 ASSERT_TRUE(WriteFile(file1, "content")); |
| 452 VLOG(1) << "Waiting for file1 creation"; | 452 VLOG(1) << "Waiting for file1 creation"; |
| 453 ASSERT_TRUE(WaitForEvents()); | 453 ASSERT_TRUE(WaitForEvents()); |
| 454 | 454 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 469 DeleteDelegateOnFileThread(delegate.release()); | 469 DeleteDelegateOnFileThread(delegate.release()); |
| 470 } | 470 } |
| 471 | 471 |
| 472 TEST_F(FilePathWatcherTest, MoveParent) { | 472 TEST_F(FilePathWatcherTest, MoveParent) { |
| 473 FilePathWatcher file_watcher; | 473 FilePathWatcher file_watcher; |
| 474 FilePathWatcher subdir_watcher; | 474 FilePathWatcher subdir_watcher; |
| 475 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 475 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 476 FilePath dest(temp_dir_.path().AppendASCII("dest")); | 476 FilePath dest(temp_dir_.path().AppendASCII("dest")); |
| 477 FilePath subdir(dir.AppendASCII("subdir")); | 477 FilePath subdir(dir.AppendASCII("subdir")); |
| 478 FilePath file(subdir.AppendASCII("file")); | 478 FilePath file(subdir.AppendASCII("file")); |
| 479 scoped_ptr<TestDelegate> file_delegate(new TestDelegate(collector())); | 479 std::unique_ptr<TestDelegate> file_delegate(new TestDelegate(collector())); |
| 480 ASSERT_TRUE(SetupWatch(file, &file_watcher, file_delegate.get(), false)); | 480 ASSERT_TRUE(SetupWatch(file, &file_watcher, file_delegate.get(), false)); |
| 481 scoped_ptr<TestDelegate> subdir_delegate(new TestDelegate(collector())); | 481 std::unique_ptr<TestDelegate> subdir_delegate(new TestDelegate(collector())); |
| 482 ASSERT_TRUE(SetupWatch(subdir, &subdir_watcher, subdir_delegate.get(), | 482 ASSERT_TRUE(SetupWatch(subdir, &subdir_watcher, subdir_delegate.get(), |
| 483 false)); | 483 false)); |
| 484 | 484 |
| 485 // Setup a directory hierarchy. | 485 // Setup a directory hierarchy. |
| 486 ASSERT_TRUE(base::CreateDirectory(subdir)); | 486 ASSERT_TRUE(base::CreateDirectory(subdir)); |
| 487 ASSERT_TRUE(WriteFile(file, "content")); | 487 ASSERT_TRUE(WriteFile(file, "content")); |
| 488 VLOG(1) << "Waiting for file creation"; | 488 VLOG(1) << "Waiting for file creation"; |
| 489 ASSERT_TRUE(WaitForEvents()); | 489 ASSERT_TRUE(WaitForEvents()); |
| 490 | 490 |
| 491 // Move the parent directory. | 491 // Move the parent directory. |
| 492 base::Move(dir, dest); | 492 base::Move(dir, dest); |
| 493 VLOG(1) << "Waiting for directory move"; | 493 VLOG(1) << "Waiting for directory move"; |
| 494 ASSERT_TRUE(WaitForEvents()); | 494 ASSERT_TRUE(WaitForEvents()); |
| 495 DeleteDelegateOnFileThread(file_delegate.release()); | 495 DeleteDelegateOnFileThread(file_delegate.release()); |
| 496 DeleteDelegateOnFileThread(subdir_delegate.release()); | 496 DeleteDelegateOnFileThread(subdir_delegate.release()); |
| 497 } | 497 } |
| 498 | 498 |
| 499 TEST_F(FilePathWatcherTest, RecursiveWatch) { | 499 TEST_F(FilePathWatcherTest, RecursiveWatch) { |
| 500 FilePathWatcher watcher; | 500 FilePathWatcher watcher; |
| 501 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 501 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 502 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 502 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 503 bool setup_result = SetupWatch(dir, &watcher, delegate.get(), true); | 503 bool setup_result = SetupWatch(dir, &watcher, delegate.get(), true); |
| 504 if (!FilePathWatcher::RecursiveWatchAvailable()) { | 504 if (!FilePathWatcher::RecursiveWatchAvailable()) { |
| 505 ASSERT_FALSE(setup_result); | 505 ASSERT_FALSE(setup_result); |
| 506 DeleteDelegateOnFileThread(delegate.release()); | 506 DeleteDelegateOnFileThread(delegate.release()); |
| 507 return; | 507 return; |
| 508 } | 508 } |
| 509 ASSERT_TRUE(setup_result); | 509 ASSERT_TRUE(setup_result); |
| 510 | 510 |
| 511 // Main directory("dir") creation. | 511 // Main directory("dir") creation. |
| 512 ASSERT_TRUE(base::CreateDirectory(dir)); | 512 ASSERT_TRUE(base::CreateDirectory(dir)); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 #define RecursiveWithSymLink DISABLED_RecursiveWithSymLink | 572 #define RecursiveWithSymLink DISABLED_RecursiveWithSymLink |
| 573 #endif // defined(OS_ANDROID) | 573 #endif // defined(OS_ANDROID) |
| 574 TEST_F(FilePathWatcherTest, RecursiveWithSymLink) { | 574 TEST_F(FilePathWatcherTest, RecursiveWithSymLink) { |
| 575 if (!FilePathWatcher::RecursiveWatchAvailable()) | 575 if (!FilePathWatcher::RecursiveWatchAvailable()) |
| 576 return; | 576 return; |
| 577 | 577 |
| 578 FilePathWatcher watcher; | 578 FilePathWatcher watcher; |
| 579 FilePath test_dir(temp_dir_.path().AppendASCII("test_dir")); | 579 FilePath test_dir(temp_dir_.path().AppendASCII("test_dir")); |
| 580 ASSERT_TRUE(base::CreateDirectory(test_dir)); | 580 ASSERT_TRUE(base::CreateDirectory(test_dir)); |
| 581 FilePath symlink(test_dir.AppendASCII("symlink")); | 581 FilePath symlink(test_dir.AppendASCII("symlink")); |
| 582 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 582 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 583 ASSERT_TRUE(SetupWatch(symlink, &watcher, delegate.get(), true)); | 583 ASSERT_TRUE(SetupWatch(symlink, &watcher, delegate.get(), true)); |
| 584 | 584 |
| 585 // Link creation. | 585 // Link creation. |
| 586 FilePath target1(temp_dir_.path().AppendASCII("target1")); | 586 FilePath target1(temp_dir_.path().AppendASCII("target1")); |
| 587 ASSERT_TRUE(base::CreateSymbolicLink(target1, symlink)); | 587 ASSERT_TRUE(base::CreateSymbolicLink(target1, symlink)); |
| 588 ASSERT_TRUE(WaitForEvents()); | 588 ASSERT_TRUE(WaitForEvents()); |
| 589 | 589 |
| 590 // Target1 creation. | 590 // Target1 creation. |
| 591 ASSERT_TRUE(base::CreateDirectory(target1)); | 591 ASSERT_TRUE(base::CreateDirectory(target1)); |
| 592 ASSERT_TRUE(WaitForEvents()); | 592 ASSERT_TRUE(WaitForEvents()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 619 FilePath source_subdir(source_dir.AppendASCII("subdir")); | 619 FilePath source_subdir(source_dir.AppendASCII("subdir")); |
| 620 FilePath source_file(source_subdir.AppendASCII("file")); | 620 FilePath source_file(source_subdir.AppendASCII("file")); |
| 621 FilePath dest_dir(temp_dir_.path().AppendASCII("dest")); | 621 FilePath dest_dir(temp_dir_.path().AppendASCII("dest")); |
| 622 FilePath dest_subdir(dest_dir.AppendASCII("subdir")); | 622 FilePath dest_subdir(dest_dir.AppendASCII("subdir")); |
| 623 FilePath dest_file(dest_subdir.AppendASCII("file")); | 623 FilePath dest_file(dest_subdir.AppendASCII("file")); |
| 624 | 624 |
| 625 // Setup a directory hierarchy. | 625 // Setup a directory hierarchy. |
| 626 ASSERT_TRUE(base::CreateDirectory(source_subdir)); | 626 ASSERT_TRUE(base::CreateDirectory(source_subdir)); |
| 627 ASSERT_TRUE(WriteFile(source_file, "content")); | 627 ASSERT_TRUE(WriteFile(source_file, "content")); |
| 628 | 628 |
| 629 scoped_ptr<TestDelegate> file_delegate(new TestDelegate(collector())); | 629 std::unique_ptr<TestDelegate> file_delegate(new TestDelegate(collector())); |
| 630 ASSERT_TRUE(SetupWatch(dest_file, &file_watcher, file_delegate.get(), false)); | 630 ASSERT_TRUE(SetupWatch(dest_file, &file_watcher, file_delegate.get(), false)); |
| 631 scoped_ptr<TestDelegate> subdir_delegate(new TestDelegate(collector())); | 631 std::unique_ptr<TestDelegate> subdir_delegate(new TestDelegate(collector())); |
| 632 ASSERT_TRUE(SetupWatch(dest_subdir, &subdir_watcher, subdir_delegate.get(), | 632 ASSERT_TRUE(SetupWatch(dest_subdir, &subdir_watcher, subdir_delegate.get(), |
| 633 false)); | 633 false)); |
| 634 | 634 |
| 635 // Move the directory into place, s.t. the watched file appears. | 635 // Move the directory into place, s.t. the watched file appears. |
| 636 ASSERT_TRUE(base::Move(source_dir, dest_dir)); | 636 ASSERT_TRUE(base::Move(source_dir, dest_dir)); |
| 637 ASSERT_TRUE(WaitForEvents()); | 637 ASSERT_TRUE(WaitForEvents()); |
| 638 DeleteDelegateOnFileThread(file_delegate.release()); | 638 DeleteDelegateOnFileThread(file_delegate.release()); |
| 639 DeleteDelegateOnFileThread(subdir_delegate.release()); | 639 DeleteDelegateOnFileThread(subdir_delegate.release()); |
| 640 } | 640 } |
| 641 | 641 |
| 642 // Verify that changing attributes on a file is caught | 642 // Verify that changing attributes on a file is caught |
| 643 #if defined(OS_ANDROID) | 643 #if defined(OS_ANDROID) |
| 644 // Apps cannot change file attributes on Android in /sdcard as /sdcard uses the | 644 // Apps cannot change file attributes on Android in /sdcard as /sdcard uses the |
| 645 // "fuse" file system, while /data uses "ext4". Running these tests in /data | 645 // "fuse" file system, while /data uses "ext4". Running these tests in /data |
| 646 // would be preferable and allow testing file attributes and symlinks. | 646 // would be preferable and allow testing file attributes and symlinks. |
| 647 // TODO(pauljensen): Re-enable when crbug.com/475568 is fixed and SetUp() places | 647 // TODO(pauljensen): Re-enable when crbug.com/475568 is fixed and SetUp() places |
| 648 // the |temp_dir_| in /data. | 648 // the |temp_dir_| in /data. |
| 649 #define FileAttributesChanged DISABLED_FileAttributesChanged | 649 #define FileAttributesChanged DISABLED_FileAttributesChanged |
| 650 #endif // defined(OS_ANDROID | 650 #endif // defined(OS_ANDROID |
| 651 TEST_F(FilePathWatcherTest, FileAttributesChanged) { | 651 TEST_F(FilePathWatcherTest, FileAttributesChanged) { |
| 652 ASSERT_TRUE(WriteFile(test_file(), "content")); | 652 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 653 FilePathWatcher watcher; | 653 FilePathWatcher watcher; |
| 654 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 654 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 655 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); | 655 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); |
| 656 | 656 |
| 657 // Now make sure we get notified if the file is modified. | 657 // Now make sure we get notified if the file is modified. |
| 658 ASSERT_TRUE(base::MakeFileUnreadable(test_file())); | 658 ASSERT_TRUE(base::MakeFileUnreadable(test_file())); |
| 659 ASSERT_TRUE(WaitForEvents()); | 659 ASSERT_TRUE(WaitForEvents()); |
| 660 DeleteDelegateOnFileThread(delegate.release()); | 660 DeleteDelegateOnFileThread(delegate.release()); |
| 661 } | 661 } |
| 662 | 662 |
| 663 #if defined(OS_LINUX) | 663 #if defined(OS_LINUX) |
| 664 | 664 |
| 665 // Verify that creating a symlink is caught. | 665 // Verify that creating a symlink is caught. |
| 666 TEST_F(FilePathWatcherTest, CreateLink) { | 666 TEST_F(FilePathWatcherTest, CreateLink) { |
| 667 FilePathWatcher watcher; | 667 FilePathWatcher watcher; |
| 668 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 668 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 669 // Note that we are watching the symlink | 669 // Note that we are watching the symlink |
| 670 ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false)); | 670 ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false)); |
| 671 | 671 |
| 672 // Now make sure we get notified if the link is created. | 672 // Now make sure we get notified if the link is created. |
| 673 // Note that test_file() doesn't have to exist. | 673 // Note that test_file() doesn't have to exist. |
| 674 ASSERT_TRUE(CreateSymbolicLink(test_file(), test_link())); | 674 ASSERT_TRUE(CreateSymbolicLink(test_file(), test_link())); |
| 675 ASSERT_TRUE(WaitForEvents()); | 675 ASSERT_TRUE(WaitForEvents()); |
| 676 DeleteDelegateOnFileThread(delegate.release()); | 676 DeleteDelegateOnFileThread(delegate.release()); |
| 677 } | 677 } |
| 678 | 678 |
| 679 // Verify that deleting a symlink is caught. | 679 // Verify that deleting a symlink is caught. |
| 680 TEST_F(FilePathWatcherTest, DeleteLink) { | 680 TEST_F(FilePathWatcherTest, DeleteLink) { |
| 681 // Unfortunately this test case only works if the link target exists. | 681 // Unfortunately this test case only works if the link target exists. |
| 682 // TODO(craig) fix this as part of crbug.com/91561. | 682 // TODO(craig) fix this as part of crbug.com/91561. |
| 683 ASSERT_TRUE(WriteFile(test_file(), "content")); | 683 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 684 ASSERT_TRUE(CreateSymbolicLink(test_file(), test_link())); | 684 ASSERT_TRUE(CreateSymbolicLink(test_file(), test_link())); |
| 685 FilePathWatcher watcher; | 685 FilePathWatcher watcher; |
| 686 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 686 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 687 ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false)); | 687 ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false)); |
| 688 | 688 |
| 689 // Now make sure we get notified if the link is deleted. | 689 // Now make sure we get notified if the link is deleted. |
| 690 ASSERT_TRUE(base::DeleteFile(test_link(), false)); | 690 ASSERT_TRUE(base::DeleteFile(test_link(), false)); |
| 691 ASSERT_TRUE(WaitForEvents()); | 691 ASSERT_TRUE(WaitForEvents()); |
| 692 DeleteDelegateOnFileThread(delegate.release()); | 692 DeleteDelegateOnFileThread(delegate.release()); |
| 693 } | 693 } |
| 694 | 694 |
| 695 // Verify that modifying a target file that a link is pointing to | 695 // Verify that modifying a target file that a link is pointing to |
| 696 // when we are watching the link is caught. | 696 // when we are watching the link is caught. |
| 697 TEST_F(FilePathWatcherTest, ModifiedLinkedFile) { | 697 TEST_F(FilePathWatcherTest, ModifiedLinkedFile) { |
| 698 ASSERT_TRUE(WriteFile(test_file(), "content")); | 698 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 699 ASSERT_TRUE(CreateSymbolicLink(test_file(), test_link())); | 699 ASSERT_TRUE(CreateSymbolicLink(test_file(), test_link())); |
| 700 FilePathWatcher watcher; | 700 FilePathWatcher watcher; |
| 701 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 701 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 702 // Note that we are watching the symlink. | 702 // Note that we are watching the symlink. |
| 703 ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false)); | 703 ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false)); |
| 704 | 704 |
| 705 // Now make sure we get notified if the file is modified. | 705 // Now make sure we get notified if the file is modified. |
| 706 ASSERT_TRUE(WriteFile(test_file(), "new content")); | 706 ASSERT_TRUE(WriteFile(test_file(), "new content")); |
| 707 ASSERT_TRUE(WaitForEvents()); | 707 ASSERT_TRUE(WaitForEvents()); |
| 708 DeleteDelegateOnFileThread(delegate.release()); | 708 DeleteDelegateOnFileThread(delegate.release()); |
| 709 } | 709 } |
| 710 | 710 |
| 711 // Verify that creating a target file that a link is pointing to | 711 // Verify that creating a target file that a link is pointing to |
| 712 // when we are watching the link is caught. | 712 // when we are watching the link is caught. |
| 713 TEST_F(FilePathWatcherTest, CreateTargetLinkedFile) { | 713 TEST_F(FilePathWatcherTest, CreateTargetLinkedFile) { |
| 714 ASSERT_TRUE(CreateSymbolicLink(test_file(), test_link())); | 714 ASSERT_TRUE(CreateSymbolicLink(test_file(), test_link())); |
| 715 FilePathWatcher watcher; | 715 FilePathWatcher watcher; |
| 716 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 716 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 717 // Note that we are watching the symlink. | 717 // Note that we are watching the symlink. |
| 718 ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false)); | 718 ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false)); |
| 719 | 719 |
| 720 // Now make sure we get notified if the target file is created. | 720 // Now make sure we get notified if the target file is created. |
| 721 ASSERT_TRUE(WriteFile(test_file(), "content")); | 721 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 722 ASSERT_TRUE(WaitForEvents()); | 722 ASSERT_TRUE(WaitForEvents()); |
| 723 DeleteDelegateOnFileThread(delegate.release()); | 723 DeleteDelegateOnFileThread(delegate.release()); |
| 724 } | 724 } |
| 725 | 725 |
| 726 // Verify that deleting a target file that a link is pointing to | 726 // Verify that deleting a target file that a link is pointing to |
| 727 // when we are watching the link is caught. | 727 // when we are watching the link is caught. |
| 728 TEST_F(FilePathWatcherTest, DeleteTargetLinkedFile) { | 728 TEST_F(FilePathWatcherTest, DeleteTargetLinkedFile) { |
| 729 ASSERT_TRUE(WriteFile(test_file(), "content")); | 729 ASSERT_TRUE(WriteFile(test_file(), "content")); |
| 730 ASSERT_TRUE(CreateSymbolicLink(test_file(), test_link())); | 730 ASSERT_TRUE(CreateSymbolicLink(test_file(), test_link())); |
| 731 FilePathWatcher watcher; | 731 FilePathWatcher watcher; |
| 732 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 732 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 733 // Note that we are watching the symlink. | 733 // Note that we are watching the symlink. |
| 734 ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false)); | 734 ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false)); |
| 735 | 735 |
| 736 // Now make sure we get notified if the target file is deleted. | 736 // Now make sure we get notified if the target file is deleted. |
| 737 ASSERT_TRUE(base::DeleteFile(test_file(), false)); | 737 ASSERT_TRUE(base::DeleteFile(test_file(), false)); |
| 738 ASSERT_TRUE(WaitForEvents()); | 738 ASSERT_TRUE(WaitForEvents()); |
| 739 DeleteDelegateOnFileThread(delegate.release()); | 739 DeleteDelegateOnFileThread(delegate.release()); |
| 740 } | 740 } |
| 741 | 741 |
| 742 // Verify that watching a file whose parent directory is a link that | 742 // Verify that watching a file whose parent directory is a link that |
| 743 // doesn't exist yet works if the symlink is created eventually. | 743 // doesn't exist yet works if the symlink is created eventually. |
| 744 TEST_F(FilePathWatcherTest, LinkedDirectoryPart1) { | 744 TEST_F(FilePathWatcherTest, LinkedDirectoryPart1) { |
| 745 FilePathWatcher watcher; | 745 FilePathWatcher watcher; |
| 746 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 746 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 747 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); | 747 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); |
| 748 FilePath file(dir.AppendASCII("file")); | 748 FilePath file(dir.AppendASCII("file")); |
| 749 FilePath linkfile(link_dir.AppendASCII("file")); | 749 FilePath linkfile(link_dir.AppendASCII("file")); |
| 750 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 750 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 751 // dir/file should exist. | 751 // dir/file should exist. |
| 752 ASSERT_TRUE(base::CreateDirectory(dir)); | 752 ASSERT_TRUE(base::CreateDirectory(dir)); |
| 753 ASSERT_TRUE(WriteFile(file, "content")); | 753 ASSERT_TRUE(WriteFile(file, "content")); |
| 754 // Note that we are watching dir.lnk/file which doesn't exist yet. | 754 // Note that we are watching dir.lnk/file which doesn't exist yet. |
| 755 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); | 755 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); |
| 756 | 756 |
| 757 ASSERT_TRUE(CreateSymbolicLink(dir, link_dir)); | 757 ASSERT_TRUE(CreateSymbolicLink(dir, link_dir)); |
| 758 VLOG(1) << "Waiting for link creation"; | 758 VLOG(1) << "Waiting for link creation"; |
| 759 ASSERT_TRUE(WaitForEvents()); | 759 ASSERT_TRUE(WaitForEvents()); |
| 760 | 760 |
| 761 ASSERT_TRUE(WriteFile(file, "content v2")); | 761 ASSERT_TRUE(WriteFile(file, "content v2")); |
| 762 VLOG(1) << "Waiting for file change"; | 762 VLOG(1) << "Waiting for file change"; |
| 763 ASSERT_TRUE(WaitForEvents()); | 763 ASSERT_TRUE(WaitForEvents()); |
| 764 | 764 |
| 765 ASSERT_TRUE(base::DeleteFile(file, false)); | 765 ASSERT_TRUE(base::DeleteFile(file, false)); |
| 766 VLOG(1) << "Waiting for file deletion"; | 766 VLOG(1) << "Waiting for file deletion"; |
| 767 ASSERT_TRUE(WaitForEvents()); | 767 ASSERT_TRUE(WaitForEvents()); |
| 768 DeleteDelegateOnFileThread(delegate.release()); | 768 DeleteDelegateOnFileThread(delegate.release()); |
| 769 } | 769 } |
| 770 | 770 |
| 771 // Verify that watching a file whose parent directory is a | 771 // Verify that watching a file whose parent directory is a |
| 772 // dangling symlink works if the directory is created eventually. | 772 // dangling symlink works if the directory is created eventually. |
| 773 TEST_F(FilePathWatcherTest, LinkedDirectoryPart2) { | 773 TEST_F(FilePathWatcherTest, LinkedDirectoryPart2) { |
| 774 FilePathWatcher watcher; | 774 FilePathWatcher watcher; |
| 775 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 775 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 776 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); | 776 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); |
| 777 FilePath file(dir.AppendASCII("file")); | 777 FilePath file(dir.AppendASCII("file")); |
| 778 FilePath linkfile(link_dir.AppendASCII("file")); | 778 FilePath linkfile(link_dir.AppendASCII("file")); |
| 779 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 779 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 780 // Now create the link from dir.lnk pointing to dir but | 780 // Now create the link from dir.lnk pointing to dir but |
| 781 // neither dir nor dir/file exist yet. | 781 // neither dir nor dir/file exist yet. |
| 782 ASSERT_TRUE(CreateSymbolicLink(dir, link_dir)); | 782 ASSERT_TRUE(CreateSymbolicLink(dir, link_dir)); |
| 783 // Note that we are watching dir.lnk/file. | 783 // Note that we are watching dir.lnk/file. |
| 784 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); | 784 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); |
| 785 | 785 |
| 786 ASSERT_TRUE(base::CreateDirectory(dir)); | 786 ASSERT_TRUE(base::CreateDirectory(dir)); |
| 787 ASSERT_TRUE(WriteFile(file, "content")); | 787 ASSERT_TRUE(WriteFile(file, "content")); |
| 788 VLOG(1) << "Waiting for dir/file creation"; | 788 VLOG(1) << "Waiting for dir/file creation"; |
| 789 ASSERT_TRUE(WaitForEvents()); | 789 ASSERT_TRUE(WaitForEvents()); |
| 790 | 790 |
| 791 ASSERT_TRUE(WriteFile(file, "content v2")); | 791 ASSERT_TRUE(WriteFile(file, "content v2")); |
| 792 VLOG(1) << "Waiting for file change"; | 792 VLOG(1) << "Waiting for file change"; |
| 793 ASSERT_TRUE(WaitForEvents()); | 793 ASSERT_TRUE(WaitForEvents()); |
| 794 | 794 |
| 795 ASSERT_TRUE(base::DeleteFile(file, false)); | 795 ASSERT_TRUE(base::DeleteFile(file, false)); |
| 796 VLOG(1) << "Waiting for file deletion"; | 796 VLOG(1) << "Waiting for file deletion"; |
| 797 ASSERT_TRUE(WaitForEvents()); | 797 ASSERT_TRUE(WaitForEvents()); |
| 798 DeleteDelegateOnFileThread(delegate.release()); | 798 DeleteDelegateOnFileThread(delegate.release()); |
| 799 } | 799 } |
| 800 | 800 |
| 801 // Verify that watching a file with a symlink on the path | 801 // Verify that watching a file with a symlink on the path |
| 802 // to the file works. | 802 // to the file works. |
| 803 TEST_F(FilePathWatcherTest, LinkedDirectoryPart3) { | 803 TEST_F(FilePathWatcherTest, LinkedDirectoryPart3) { |
| 804 FilePathWatcher watcher; | 804 FilePathWatcher watcher; |
| 805 FilePath dir(temp_dir_.path().AppendASCII("dir")); | 805 FilePath dir(temp_dir_.path().AppendASCII("dir")); |
| 806 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); | 806 FilePath link_dir(temp_dir_.path().AppendASCII("dir.lnk")); |
| 807 FilePath file(dir.AppendASCII("file")); | 807 FilePath file(dir.AppendASCII("file")); |
| 808 FilePath linkfile(link_dir.AppendASCII("file")); | 808 FilePath linkfile(link_dir.AppendASCII("file")); |
| 809 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 809 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 810 ASSERT_TRUE(base::CreateDirectory(dir)); | 810 ASSERT_TRUE(base::CreateDirectory(dir)); |
| 811 ASSERT_TRUE(CreateSymbolicLink(dir, link_dir)); | 811 ASSERT_TRUE(CreateSymbolicLink(dir, link_dir)); |
| 812 // Note that we are watching dir.lnk/file but the file doesn't exist yet. | 812 // Note that we are watching dir.lnk/file but the file doesn't exist yet. |
| 813 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); | 813 ASSERT_TRUE(SetupWatch(linkfile, &watcher, delegate.get(), false)); |
| 814 | 814 |
| 815 ASSERT_TRUE(WriteFile(file, "content")); | 815 ASSERT_TRUE(WriteFile(file, "content")); |
| 816 VLOG(1) << "Waiting for file creation"; | 816 VLOG(1) << "Waiting for file creation"; |
| 817 ASSERT_TRUE(WaitForEvents()); | 817 ASSERT_TRUE(WaitForEvents()); |
| 818 | 818 |
| 819 ASSERT_TRUE(WriteFile(file, "content v2")); | 819 ASSERT_TRUE(WriteFile(file, "content v2")); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 TEST_F(FilePathWatcherTest, DirAttributesChanged) { | 876 TEST_F(FilePathWatcherTest, DirAttributesChanged) { |
| 877 FilePath test_dir1(temp_dir_.path().AppendASCII("DirAttributesChangedDir1")); | 877 FilePath test_dir1(temp_dir_.path().AppendASCII("DirAttributesChangedDir1")); |
| 878 FilePath test_dir2(test_dir1.AppendASCII("DirAttributesChangedDir2")); | 878 FilePath test_dir2(test_dir1.AppendASCII("DirAttributesChangedDir2")); |
| 879 FilePath test_file(test_dir2.AppendASCII("DirAttributesChangedFile")); | 879 FilePath test_file(test_dir2.AppendASCII("DirAttributesChangedFile")); |
| 880 // Setup a directory hierarchy. | 880 // Setup a directory hierarchy. |
| 881 ASSERT_TRUE(base::CreateDirectory(test_dir1)); | 881 ASSERT_TRUE(base::CreateDirectory(test_dir1)); |
| 882 ASSERT_TRUE(base::CreateDirectory(test_dir2)); | 882 ASSERT_TRUE(base::CreateDirectory(test_dir2)); |
| 883 ASSERT_TRUE(WriteFile(test_file, "content")); | 883 ASSERT_TRUE(WriteFile(test_file, "content")); |
| 884 | 884 |
| 885 FilePathWatcher watcher; | 885 FilePathWatcher watcher; |
| 886 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); | 886 std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); |
| 887 ASSERT_TRUE(SetupWatch(test_file, &watcher, delegate.get(), false)); | 887 ASSERT_TRUE(SetupWatch(test_file, &watcher, delegate.get(), false)); |
| 888 | 888 |
| 889 // We should not get notified in this case as it hasn't affected our ability | 889 // We should not get notified in this case as it hasn't affected our ability |
| 890 // to access the file. | 890 // to access the file. |
| 891 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Read, false)); | 891 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Read, false)); |
| 892 loop_.PostDelayedTask(FROM_HERE, | 892 loop_.PostDelayedTask(FROM_HERE, |
| 893 MessageLoop::QuitWhenIdleClosure(), | 893 MessageLoop::QuitWhenIdleClosure(), |
| 894 TestTimeouts::tiny_timeout()); | 894 TestTimeouts::tiny_timeout()); |
| 895 ASSERT_FALSE(WaitForEvents()); | 895 ASSERT_FALSE(WaitForEvents()); |
| 896 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Read, true)); | 896 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Read, true)); |
| 897 | 897 |
| 898 // We should get notified in this case because filepathwatcher can no | 898 // We should get notified in this case because filepathwatcher can no |
| 899 // longer access the file | 899 // longer access the file |
| 900 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); | 900 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); |
| 901 ASSERT_TRUE(WaitForEvents()); | 901 ASSERT_TRUE(WaitForEvents()); |
| 902 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); | 902 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); |
| 903 DeleteDelegateOnFileThread(delegate.release()); | 903 DeleteDelegateOnFileThread(delegate.release()); |
| 904 } | 904 } |
| 905 | 905 |
| 906 #endif // OS_MACOSX | 906 #endif // OS_MACOSX |
| 907 } // namespace | 907 } // namespace |
| 908 | 908 |
| 909 } // namespace base | 909 } // namespace base |
| OLD | NEW |