OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/file_system_provider/provided_file_system.h" | 5 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 EXPECT_EQ(1u, watchers->size()); | 750 EXPECT_EQ(1u, watchers->size()); |
751 provided_file_system_->GetWatchers(); | 751 provided_file_system_->GetWatchers(); |
752 EXPECT_EQ("", watchers->begin()->second.last_tag); | 752 EXPECT_EQ("", watchers->begin()->second.last_tag); |
753 } | 753 } |
754 | 754 |
755 { | 755 { |
756 // Notify about a change. | 756 // Notify about a change. |
757 const storage::WatcherManager::ChangeType change_type = | 757 const storage::WatcherManager::ChangeType change_type = |
758 storage::WatcherManager::CHANGED; | 758 storage::WatcherManager::CHANGED; |
759 const std::string tag = "hello-world"; | 759 const std::string tag = "hello-world"; |
760 EXPECT_TRUE(provided_file_system_->Notify( | 760 |
761 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 761 Log log; |
762 false /* recursive */, | 762 provided_file_system_->Notify( |
763 change_type, | 763 base::FilePath::FromUTF8Unsafe(kDirectoryPath), false /* recursive */, |
764 make_scoped_ptr(new ProvidedFileSystemObserver::Changes), | 764 change_type, make_scoped_ptr(new ProvidedFileSystemObserver::Changes), |
765 tag)); | 765 tag, base::Bind(&LogStatus, base::Unretained(&log))); |
766 | 766 |
767 // Confirm that the notification callback was called. | 767 // Confirm that the notification callback was called. |
768 ASSERT_EQ(1u, notification_log.size()); | 768 ASSERT_EQ(1u, notification_log.size()); |
769 EXPECT_EQ(change_type, notification_log[0]); | 769 EXPECT_EQ(change_type, notification_log[0]); |
770 | 770 |
771 // Verify the observer event. | 771 // Verify the observer event. |
772 ASSERT_EQ(1u, observer.change_events().size()); | 772 ASSERT_EQ(1u, observer.change_events().size()); |
773 const Observer::ChangeEvent* const change_event = | 773 const Observer::ChangeEvent* const change_event = |
774 observer.change_events()[0]; | 774 observer.change_events()[0]; |
775 EXPECT_EQ(change_type, change_event->change_type()); | 775 EXPECT_EQ(change_type, change_event->change_type()); |
776 EXPECT_EQ(0u, change_event->changes().size()); | 776 EXPECT_EQ(0u, change_event->changes().size()); |
777 | 777 |
778 // The tag should not be updated in advance, before all observers handle | 778 // The tag should not be updated in advance, before all observers handle |
779 // the notification. | 779 // the notification. |
780 Watchers* const watchers = provided_file_system_->GetWatchers(); | 780 Watchers* const watchers = provided_file_system_->GetWatchers(); |
781 EXPECT_EQ(1u, watchers->size()); | 781 EXPECT_EQ(1u, watchers->size()); |
782 provided_file_system_->GetWatchers(); | 782 provided_file_system_->GetWatchers(); |
783 EXPECT_EQ("", watchers->begin()->second.last_tag); | 783 EXPECT_EQ("", watchers->begin()->second.last_tag); |
784 | 784 |
785 // Wait until all observers finish handling the notification. | 785 // Wait until all observers finish handling the notification. |
786 base::RunLoop().RunUntilIdle(); | 786 base::RunLoop().RunUntilIdle(); |
787 | 787 |
| 788 ASSERT_EQ(1u, log.size()); |
| 789 EXPECT_EQ(base::File::FILE_OK, log[0]); |
| 790 |
788 // Confirm, that the watcher still exists, and that the tag is updated. | 791 // Confirm, that the watcher still exists, and that the tag is updated. |
789 ASSERT_EQ(1u, watchers->size()); | 792 ASSERT_EQ(1u, watchers->size()); |
790 EXPECT_EQ(tag, watchers->begin()->second.last_tag); | 793 EXPECT_EQ(tag, watchers->begin()->second.last_tag); |
791 EXPECT_EQ(1, observer.list_changed_counter()); | 794 EXPECT_EQ(1, observer.list_changed_counter()); |
792 EXPECT_EQ(1, observer.tag_updated_counter()); | 795 EXPECT_EQ(1, observer.tag_updated_counter()); |
793 } | 796 } |
794 | 797 |
795 { | 798 { |
796 // Notify about deleting of the watched entry. | 799 // Notify about deleting of the watched entry. |
797 const storage::WatcherManager::ChangeType change_type = | 800 const storage::WatcherManager::ChangeType change_type = |
798 storage::WatcherManager::DELETED; | 801 storage::WatcherManager::DELETED; |
799 const ProvidedFileSystemObserver::Changes changes; | 802 const ProvidedFileSystemObserver::Changes changes; |
800 const std::string tag = "chocolate-disco"; | 803 const std::string tag = "chocolate-disco"; |
801 EXPECT_TRUE(provided_file_system_->Notify( | 804 |
802 base::FilePath::FromUTF8Unsafe(kDirectoryPath), | 805 Log log; |
803 false /* recursive */, | 806 provided_file_system_->Notify( |
804 change_type, | 807 base::FilePath::FromUTF8Unsafe(kDirectoryPath), false /* recursive */, |
805 make_scoped_ptr(new ProvidedFileSystemObserver::Changes), | 808 change_type, make_scoped_ptr(new ProvidedFileSystemObserver::Changes), |
806 tag)); | 809 tag, base::Bind(&LogStatus, base::Unretained(&log))); |
807 base::RunLoop().RunUntilIdle(); | 810 base::RunLoop().RunUntilIdle(); |
| 811 ASSERT_EQ(1u, log.size()); |
| 812 EXPECT_EQ(base::File::FILE_OK, log[0]); |
808 | 813 |
809 // Confirm that the notification callback was called. | 814 // Confirm that the notification callback was called. |
810 ASSERT_EQ(2u, notification_log.size()); | 815 ASSERT_EQ(2u, notification_log.size()); |
811 EXPECT_EQ(change_type, notification_log[1]); | 816 EXPECT_EQ(change_type, notification_log[1]); |
812 | 817 |
813 // Verify the observer event. | 818 // Verify the observer event. |
814 ASSERT_EQ(2u, observer.change_events().size()); | 819 ASSERT_EQ(2u, observer.change_events().size()); |
815 const Observer::ChangeEvent* const change_event = | 820 const Observer::ChangeEvent* const change_event = |
816 observer.change_events()[1]; | 821 observer.change_events()[1]; |
817 EXPECT_EQ(change_type, change_event->change_type()); | 822 EXPECT_EQ(change_type, change_event->change_type()); |
818 EXPECT_EQ(0u, change_event->changes().size()); | 823 EXPECT_EQ(0u, change_event->changes().size()); |
819 } | 824 } |
820 | 825 |
821 // Confirm, that the watcher is removed. | 826 // Confirm, that the watcher is removed. |
822 { | 827 { |
823 Watchers* const watchers = provided_file_system_->GetWatchers(); | 828 Watchers* const watchers = provided_file_system_->GetWatchers(); |
824 EXPECT_EQ(0u, watchers->size()); | 829 EXPECT_EQ(0u, watchers->size()); |
825 EXPECT_EQ(2, observer.list_changed_counter()); | 830 EXPECT_EQ(2, observer.list_changed_counter()); |
826 EXPECT_EQ(2, observer.tag_updated_counter()); | 831 EXPECT_EQ(2, observer.tag_updated_counter()); |
827 } | 832 } |
828 | 833 |
829 provided_file_system_->RemoveObserver(&observer); | 834 provided_file_system_->RemoveObserver(&observer); |
830 } | 835 } |
831 | 836 |
832 } // namespace file_system_provider | 837 } // namespace file_system_provider |
833 } // namespace chromeos | 838 } // namespace chromeos |
OLD | NEW |