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

Side by Side Diff: base/files/file_path_watcher_unittest.cc

Issue 1087503003: Enable FilePathWatcher base unittests on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « base/files/file_path_watcher.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) 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 13 matching lines...) Expand all
24 #include "base/message_loop/message_loop_proxy.h" 24 #include "base/message_loop/message_loop_proxy.h"
25 #include "base/run_loop.h" 25 #include "base/run_loop.h"
26 #include "base/stl_util.h" 26 #include "base/stl_util.h"
27 #include "base/strings/stringprintf.h" 27 #include "base/strings/stringprintf.h"
28 #include "base/synchronization/waitable_event.h" 28 #include "base/synchronization/waitable_event.h"
29 #include "base/test/test_file_util.h" 29 #include "base/test/test_file_util.h"
30 #include "base/test/test_timeouts.h" 30 #include "base/test/test_timeouts.h"
31 #include "base/threading/thread.h" 31 #include "base/threading/thread.h"
32 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
33 33
34 #if defined(OS_ANDROID)
35 #include "base/android/path_utils.h"
36 #endif // defined(OS_ANDROID)
37
34 namespace base { 38 namespace base {
35 39
36 namespace { 40 namespace {
37 41
38 class TestDelegate; 42 class TestDelegate;
39 43
40 // Aggregates notifications from the test delegates and breaks the message loop 44 // Aggregates notifications from the test delegates and breaks the message loop
41 // the test thread is waiting on once they all came in. 45 // the test thread is waiting on once they all came in.
42 class NotificationCollector 46 class NotificationCollector
43 : public base::RefCountedThreadSafe<NotificationCollector> { 47 : public base::RefCountedThreadSafe<NotificationCollector> {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 FilePathWatcherTest() 147 FilePathWatcherTest()
144 : file_thread_("FilePathWatcherTest") {} 148 : file_thread_("FilePathWatcherTest") {}
145 149
146 ~FilePathWatcherTest() override {} 150 ~FilePathWatcherTest() override {}
147 151
148 protected: 152 protected:
149 void SetUp() override { 153 void SetUp() override {
150 // Create a separate file thread in order to test proper thread usage. 154 // Create a separate file thread in order to test proper thread usage.
151 base::Thread::Options options(MessageLoop::TYPE_IO, 0); 155 base::Thread::Options options(MessageLoop::TYPE_IO, 0);
152 ASSERT_TRUE(file_thread_.StartWithOptions(options)); 156 ASSERT_TRUE(file_thread_.StartWithOptions(options));
157 #if defined(OS_ANDROID)
158 // Watching files is only permitted when all parent directories are
159 // accessible, which is not the case for the default temp directory
160 // on Android which is under /data/data. Use /sdcard instead.
161 // TODO(pauljensen): Remove this when crbug.com/475568 is fixed.
162 FilePath parent_dir;
163 ASSERT_TRUE(android::GetExternalStorageDirectory(&parent_dir));
164 ASSERT_TRUE(temp_dir_.CreateUniqueTempDirUnderPath(parent_dir));
165 #else // defined(OS_ANDROID)
153 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 166 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
167 #endif // defined(OS_ANDROID)
154 collector_ = new NotificationCollector(); 168 collector_ = new NotificationCollector();
155 } 169 }
156 170
157 void TearDown() override { RunLoop().RunUntilIdle(); } 171 void TearDown() override { RunLoop().RunUntilIdle(); }
158 172
159 void DeleteDelegateOnFileThread(TestDelegate* delegate) { 173 void DeleteDelegateOnFileThread(TestDelegate* delegate) {
160 file_thread_.message_loop_proxy()->DeleteSoon(FROM_HERE, delegate); 174 file_thread_.message_loop_proxy()->DeleteSoon(FROM_HERE, delegate);
161 } 175 }
162 176
163 FilePath test_file() { 177 FilePath test_file() {
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 533
520 // Create "$dir/subdir/subdir_child_dir/child_dir_file1". 534 // Create "$dir/subdir/subdir_child_dir/child_dir_file1".
521 FilePath child_dir_file1(subdir_child_dir.AppendASCII("child_dir_file1")); 535 FilePath child_dir_file1(subdir_child_dir.AppendASCII("child_dir_file1"));
522 ASSERT_TRUE(WriteFile(child_dir_file1, "content v2")); 536 ASSERT_TRUE(WriteFile(child_dir_file1, "content v2"));
523 ASSERT_TRUE(WaitForEvents()); 537 ASSERT_TRUE(WaitForEvents());
524 538
525 // Write into "$dir/subdir/subdir_child_dir/child_dir_file1". 539 // Write into "$dir/subdir/subdir_child_dir/child_dir_file1".
526 ASSERT_TRUE(WriteFile(child_dir_file1, "content")); 540 ASSERT_TRUE(WriteFile(child_dir_file1, "content"));
527 ASSERT_TRUE(WaitForEvents()); 541 ASSERT_TRUE(WaitForEvents());
528 542
543 // Apps cannot change file attributes on Android in /sdcard.
544 // TODO(pauljensen): Re-enable when crbug.com/475568 is fixed.
Mattias Nissler (ping if slow) 2015/04/13 13:06:07 It seems that the referenced bug doesn't cover the
pauljensen 2015/04/13 13:27:04 Done.
545 #if !defined(OS_ANDROID)
529 // Modify "$dir/subdir/subdir_child_dir/child_dir_file1" attributes. 546 // Modify "$dir/subdir/subdir_child_dir/child_dir_file1" attributes.
530 ASSERT_TRUE(base::MakeFileUnreadable(child_dir_file1)); 547 ASSERT_TRUE(base::MakeFileUnreadable(child_dir_file1));
531 ASSERT_TRUE(WaitForEvents()); 548 ASSERT_TRUE(WaitForEvents());
549 #endif
532 550
533 // Delete "$dir/subdir/subdir_file1". 551 // Delete "$dir/subdir/subdir_file1".
534 ASSERT_TRUE(base::DeleteFile(subdir_file1, false)); 552 ASSERT_TRUE(base::DeleteFile(subdir_file1, false));
535 ASSERT_TRUE(WaitForEvents()); 553 ASSERT_TRUE(WaitForEvents());
536 554
537 // Delete "$dir/subdir/subdir_child_dir/child_dir_file1". 555 // Delete "$dir/subdir/subdir_child_dir/child_dir_file1".
538 ASSERT_TRUE(base::DeleteFile(child_dir_file1, false)); 556 ASSERT_TRUE(base::DeleteFile(child_dir_file1, false));
539 ASSERT_TRUE(WaitForEvents()); 557 ASSERT_TRUE(WaitForEvents());
540 DeleteDelegateOnFileThread(delegate.release()); 558 DeleteDelegateOnFileThread(delegate.release());
541 } 559 }
542 560
543 #if defined(OS_POSIX) 561 #if defined(OS_POSIX)
562 #if defined(OS_ANDROID)
563 // Apps cannot create symlinks on Android in /sdcard.
564 // TODO(pauljensen): Re-enable when crbug.com/475568 is fixed.
Mattias Nissler (ping if slow) 2015/04/13 13:06:07 ditto re scope of the referenced bug and intended
pauljensen 2015/04/13 13:27:04 Done.
565 #define RecursiveWithSymLink DISABLED_RecursiveWithSymLink
566 #endif // defined(OS_ANDROID)
544 TEST_F(FilePathWatcherTest, RecursiveWithSymLink) { 567 TEST_F(FilePathWatcherTest, RecursiveWithSymLink) {
545 if (!FilePathWatcher::RecursiveWatchAvailable()) 568 if (!FilePathWatcher::RecursiveWatchAvailable())
546 return; 569 return;
547 570
548 FilePathWatcher watcher; 571 FilePathWatcher watcher;
549 FilePath test_dir(temp_dir_.path().AppendASCII("test_dir")); 572 FilePath test_dir(temp_dir_.path().AppendASCII("test_dir"));
550 ASSERT_TRUE(base::CreateDirectory(test_dir)); 573 ASSERT_TRUE(base::CreateDirectory(test_dir));
551 FilePath symlink(test_dir.AppendASCII("symlink")); 574 FilePath symlink(test_dir.AppendASCII("symlink"));
552 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); 575 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector()));
553 ASSERT_TRUE(SetupWatch(symlink, &watcher, delegate.get(), true)); 576 ASSERT_TRUE(SetupWatch(symlink, &watcher, delegate.get(), true));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 false)); 626 false));
604 627
605 // Move the directory into place, s.t. the watched file appears. 628 // Move the directory into place, s.t. the watched file appears.
606 ASSERT_TRUE(base::Move(source_dir, dest_dir)); 629 ASSERT_TRUE(base::Move(source_dir, dest_dir));
607 ASSERT_TRUE(WaitForEvents()); 630 ASSERT_TRUE(WaitForEvents());
608 DeleteDelegateOnFileThread(file_delegate.release()); 631 DeleteDelegateOnFileThread(file_delegate.release());
609 DeleteDelegateOnFileThread(subdir_delegate.release()); 632 DeleteDelegateOnFileThread(subdir_delegate.release());
610 } 633 }
611 634
612 // Verify that changing attributes on a file is caught 635 // Verify that changing attributes on a file is caught
636 #if defined(OS_ANDROID)
637 // Apps don't have permission to change permissions on Android in /sdcard.
638 // TODO(pauljensen): Re-enable when crbug.com/475568 is fixed.
Mattias Nissler (ping if slow) 2015/04/13 13:06:07 ditto
pauljensen 2015/04/13 13:27:04 Done.
639 #define FileAttributesChanged DISABLED_FileAttributesChanged
640 #endif // defined(OS_ANDROID
613 TEST_F(FilePathWatcherTest, FileAttributesChanged) { 641 TEST_F(FilePathWatcherTest, FileAttributesChanged) {
614 ASSERT_TRUE(WriteFile(test_file(), "content")); 642 ASSERT_TRUE(WriteFile(test_file(), "content"));
615 FilePathWatcher watcher; 643 FilePathWatcher watcher;
616 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector())); 644 scoped_ptr<TestDelegate> delegate(new TestDelegate(collector()));
617 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); 645 ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false));
618 646
619 // Now make sure we get notified if the file is modified. 647 // Now make sure we get notified if the file is modified.
620 ASSERT_TRUE(base::MakeFileUnreadable(test_file())); 648 ASSERT_TRUE(base::MakeFileUnreadable(test_file()));
621 ASSERT_TRUE(WaitForEvents()); 649 ASSERT_TRUE(WaitForEvents());
622 DeleteDelegateOnFileThread(delegate.release()); 650 DeleteDelegateOnFileThread(delegate.release());
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); 890 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false));
863 ASSERT_TRUE(WaitForEvents()); 891 ASSERT_TRUE(WaitForEvents());
864 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); 892 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true));
865 DeleteDelegateOnFileThread(delegate.release()); 893 DeleteDelegateOnFileThread(delegate.release());
866 } 894 }
867 895
868 #endif // OS_MACOSX 896 #endif // OS_MACOSX
869 } // namespace 897 } // namespace
870 898
871 } // namespace base 899 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_path_watcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698