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 "chrome/browser/chromeos/drive/file_system.h" | 5 #include "chrome/browser/chromeos/drive/file_system.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 ASSERT_TRUE(LoadFullResourceList()); | 734 ASSERT_TRUE(LoadFullResourceList()); |
735 | 735 |
736 const base::FilePath kFileInRoot(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 736 const base::FilePath kFileInRoot(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
737 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(kFileInRoot)); | 737 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(kFileInRoot)); |
738 const std::string& file_resource_id = entry->resource_id(); | 738 const std::string& file_resource_id = entry->resource_id(); |
739 const std::string& md5 = entry->file_specific_info().md5(); | 739 const std::string& md5 = entry->file_specific_info().md5(); |
740 | 740 |
741 // Open kFileInRoot ("drive/root/File 1.txt"). | 741 // Open kFileInRoot ("drive/root/File 1.txt"). |
742 FileError error = FILE_ERROR_FAILED; | 742 FileError error = FILE_ERROR_FAILED; |
743 base::FilePath file_path; | 743 base::FilePath file_path; |
| 744 base::Closure close_callback; |
744 file_system_->OpenFile( | 745 file_system_->OpenFile( |
745 kFileInRoot, | 746 kFileInRoot, |
746 OPEN_FILE, | 747 OPEN_FILE, |
747 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); | 748 google_apis::test_util::CreateCopyResultCallback( |
| 749 &error, &file_path, &close_callback)); |
748 test_util::RunBlockingPoolTask(); | 750 test_util::RunBlockingPoolTask(); |
749 const base::FilePath opened_file_path = file_path; | 751 const base::FilePath opened_file_path = file_path; |
750 | 752 |
751 // Verify that the file was properly opened. | 753 // Verify that the file was properly opened. |
752 EXPECT_EQ(FILE_ERROR_OK, error); | 754 EXPECT_EQ(FILE_ERROR_OK, error); |
753 | 755 |
754 // The opened file is downloaded, which means the file is available | 756 // The opened file is downloaded, which means the file is available |
755 // offline. The directory change should be notified so Files.app can change | 757 // offline. The directory change should be notified so Files.app can change |
756 // the offline availability status of the file. | 758 // the offline availability status of the file. |
757 ASSERT_EQ(1u, mock_directory_observer_->changed_directories().size()); | 759 ASSERT_EQ(1u, mock_directory_observer_->changed_directories().size()); |
(...skipping 15 matching lines...) Expand all Loading... |
773 EXPECT_EQ(FILE_ERROR_OK, | 775 EXPECT_EQ(FILE_ERROR_OK, |
774 cache_->GetFile(file_resource_id, md5, &cache_file_path)); | 776 cache_->GetFile(file_resource_id, md5, &cache_file_path)); |
775 EXPECT_EQ(cache_file_path, opened_file_path); | 777 EXPECT_EQ(cache_file_path, opened_file_path); |
776 | 778 |
777 // Write a new content. | 779 // Write a new content. |
778 const std::string kNewContent = kExpectedContent + kExpectedContent; | 780 const std::string kNewContent = kExpectedContent + kExpectedContent; |
779 EXPECT_TRUE(google_apis::test_util::WriteStringToFile(cache_file_path, | 781 EXPECT_TRUE(google_apis::test_util::WriteStringToFile(cache_file_path, |
780 kNewContent)); | 782 kNewContent)); |
781 | 783 |
782 // Close kFileInRoot ("drive/root/File 1.txt"). | 784 // Close kFileInRoot ("drive/root/File 1.txt"). |
783 file_system_->CloseFile( | 785 ASSERT_FALSE(close_callback.is_null()); |
784 kFileInRoot, | 786 close_callback.Run(); |
785 google_apis::test_util::CreateCopyResultCallback(&error)); | |
786 test_util::RunBlockingPoolTask(); | 787 test_util::RunBlockingPoolTask(); |
787 | 788 |
788 // Verify that the file was properly closed. | 789 // Verify that the file was properly closed. |
789 EXPECT_EQ(FILE_ERROR_OK, error); | 790 EXPECT_EQ(FILE_ERROR_OK, error); |
790 | 791 |
791 // Verify that the file was synced as expected. | 792 // Verify that the file was synced as expected. |
792 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_FILE_ERROR; | 793 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_FILE_ERROR; |
793 scoped_ptr<google_apis::ResourceEntry> gdata_entry; | 794 scoped_ptr<google_apis::ResourceEntry> gdata_entry; |
794 fake_drive_service_->GetResourceEntry( | 795 fake_drive_service_->GetResourceEntry( |
795 file_resource_id, | 796 file_resource_id, |
796 google_apis::test_util::CreateCopyResultCallback( | 797 google_apis::test_util::CreateCopyResultCallback( |
797 &gdata_error, &gdata_entry)); | 798 &gdata_error, &gdata_entry)); |
798 test_util::RunBlockingPoolTask(); | 799 test_util::RunBlockingPoolTask(); |
799 EXPECT_EQ(gdata_error, google_apis::HTTP_SUCCESS); | 800 EXPECT_EQ(gdata_error, google_apis::HTTP_SUCCESS); |
800 ASSERT_TRUE(gdata_entry); | 801 ASSERT_TRUE(gdata_entry); |
801 EXPECT_EQ(static_cast<int>(kNewContent.size()), gdata_entry->file_size()); | 802 EXPECT_EQ(static_cast<int>(kNewContent.size()), gdata_entry->file_size()); |
802 | 803 |
803 // The modified file is uploaded. The directory change should be notified | 804 // The modified file is uploaded. The directory change should be notified |
804 // so Files.app can show new metadata of the modified file. | 805 // so Files.app can show new metadata of the modified file. |
805 ASSERT_EQ(2u, mock_directory_observer_->changed_directories().size()); | 806 ASSERT_EQ(2u, mock_directory_observer_->changed_directories().size()); |
806 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("drive/root")), | 807 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("drive/root")), |
807 mock_directory_observer_->changed_directories()[1]); | 808 mock_directory_observer_->changed_directories()[1]); |
808 | |
809 // Try to close the same file twice. | |
810 file_system_->CloseFile( | |
811 kFileInRoot, | |
812 google_apis::test_util::CreateCopyResultCallback(&error)); | |
813 test_util::RunBlockingPoolTask(); | |
814 | |
815 // It must fail. | |
816 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); | |
817 // There should be no new directory change. | |
818 ASSERT_EQ(2u, mock_directory_observer_->changed_directories().size()); | |
819 } | 809 } |
820 | 810 |
821 TEST_F(FileSystemTest, MarkCacheFileAsMountedAndUnmounted) { | 811 TEST_F(FileSystemTest, MarkCacheFileAsMountedAndUnmounted) { |
822 ASSERT_TRUE(LoadFullResourceList()); | 812 ASSERT_TRUE(LoadFullResourceList()); |
823 | 813 |
824 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 814 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
825 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); | 815 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); |
826 ASSERT_TRUE(entry); | 816 ASSERT_TRUE(entry); |
827 | 817 |
828 // Write to cache. | 818 // Write to cache. |
(...skipping 21 matching lines...) Expand all Loading... |
850 file_path, | 840 file_path, |
851 google_apis::test_util::CreateCopyResultCallback(&error)); | 841 google_apis::test_util::CreateCopyResultCallback(&error)); |
852 test_util::RunBlockingPoolTask(); | 842 test_util::RunBlockingPoolTask(); |
853 EXPECT_EQ(FILE_ERROR_OK, error); | 843 EXPECT_EQ(FILE_ERROR_OK, error); |
854 | 844 |
855 // Now able to remove the cache entry. | 845 // Now able to remove the cache entry. |
856 EXPECT_EQ(FILE_ERROR_OK, cache_->Remove(entry->resource_id())); | 846 EXPECT_EQ(FILE_ERROR_OK, cache_->Remove(entry->resource_id())); |
857 } | 847 } |
858 | 848 |
859 } // namespace drive | 849 } // namespace drive |
OLD | NEW |