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 on_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, &on_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 14 matching lines...) Expand all Loading... | |
772 base::FilePath cache_file_path; | 774 base::FilePath cache_file_path; |
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"). |
hashimoto
2013/07/23 11:24:58
nit: How about ASSERT_FALSE(on_close_callback.is_n
hidehiko
2013/07/23 14:32:24
Done.
| |
783 file_system_->CloseFile( | 785 on_close_callback.Run(); |
784 kFileInRoot, | |
785 google_apis::test_util::CreateCopyResultCallback(&error)); | |
786 test_util::RunBlockingPoolTask(); | 786 test_util::RunBlockingPoolTask(); |
787 | 787 |
788 // Verify that the file was properly closed. | 788 // Verify that the file was properly closed. |
789 EXPECT_EQ(FILE_ERROR_OK, error); | 789 EXPECT_EQ(FILE_ERROR_OK, error); |
790 | 790 |
791 // Verify that the file was synced as expected. | 791 // Verify that the file was synced as expected. |
792 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_FILE_ERROR; | 792 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_FILE_ERROR; |
793 scoped_ptr<google_apis::ResourceEntry> gdata_entry; | 793 scoped_ptr<google_apis::ResourceEntry> gdata_entry; |
794 fake_drive_service_->GetResourceEntry( | 794 fake_drive_service_->GetResourceEntry( |
795 file_resource_id, | 795 file_resource_id, |
796 google_apis::test_util::CreateCopyResultCallback( | 796 google_apis::test_util::CreateCopyResultCallback( |
797 &gdata_error, &gdata_entry)); | 797 &gdata_error, &gdata_entry)); |
798 test_util::RunBlockingPoolTask(); | 798 test_util::RunBlockingPoolTask(); |
799 EXPECT_EQ(gdata_error, google_apis::HTTP_SUCCESS); | 799 EXPECT_EQ(gdata_error, google_apis::HTTP_SUCCESS); |
800 ASSERT_TRUE(gdata_entry); | 800 ASSERT_TRUE(gdata_entry); |
801 EXPECT_EQ(static_cast<int>(kNewContent.size()), gdata_entry->file_size()); | 801 EXPECT_EQ(static_cast<int>(kNewContent.size()), gdata_entry->file_size()); |
802 | 802 |
803 // The modified file is uploaded. The directory change should be notified | 803 // The modified file is uploaded. The directory change should be notified |
804 // so Files.app can show new metadata of the modified file. | 804 // so Files.app can show new metadata of the modified file. |
805 ASSERT_EQ(2u, mock_directory_observer_->changed_directories().size()); | 805 ASSERT_EQ(2u, mock_directory_observer_->changed_directories().size()); |
806 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("drive/root")), | 806 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("drive/root")), |
807 mock_directory_observer_->changed_directories()[1]); | 807 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 } | 808 } |
820 | 809 |
821 TEST_F(FileSystemTest, MarkCacheFileAsMountedAndUnmounted) { | 810 TEST_F(FileSystemTest, MarkCacheFileAsMountedAndUnmounted) { |
822 ASSERT_TRUE(LoadFullResourceList()); | 811 ASSERT_TRUE(LoadFullResourceList()); |
823 | 812 |
824 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 813 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
825 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); | 814 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); |
826 ASSERT_TRUE(entry); | 815 ASSERT_TRUE(entry); |
827 | 816 |
828 // Write to cache. | 817 // Write to cache. |
(...skipping 21 matching lines...) Expand all Loading... | |
850 file_path, | 839 file_path, |
851 google_apis::test_util::CreateCopyResultCallback(&error)); | 840 google_apis::test_util::CreateCopyResultCallback(&error)); |
852 test_util::RunBlockingPoolTask(); | 841 test_util::RunBlockingPoolTask(); |
853 EXPECT_EQ(FILE_ERROR_OK, error); | 842 EXPECT_EQ(FILE_ERROR_OK, error); |
854 | 843 |
855 // Now able to remove the cache entry. | 844 // Now able to remove the cache entry. |
856 EXPECT_EQ(FILE_ERROR_OK, cache_->Remove(entry->resource_id())); | 845 EXPECT_EQ(FILE_ERROR_OK, cache_->Remove(entry->resource_id())); |
857 } | 846 } |
858 | 847 |
859 } // namespace drive | 848 } // namespace drive |
OLD | NEW |