| 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 "components/drive/service/fake_drive_service.h" | 5 #include "components/drive/service/fake_drive_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 | 980 |
| 981 TEST_F(FakeDriveServiceTest, DownloadFile_ExistingFile) { | 981 TEST_F(FakeDriveServiceTest, DownloadFile_ExistingFile) { |
| 982 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 982 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 983 | 983 |
| 984 base::ScopedTempDir temp_dir; | 984 base::ScopedTempDir temp_dir; |
| 985 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 985 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 986 | 986 |
| 987 std::vector<test_util::ProgressInfo> download_progress_values; | 987 std::vector<test_util::ProgressInfo> download_progress_values; |
| 988 | 988 |
| 989 const base::FilePath kOutputFilePath = | 989 const base::FilePath kOutputFilePath = |
| 990 temp_dir.path().AppendASCII("whatever.txt"); | 990 temp_dir.GetPath().AppendASCII("whatever.txt"); |
| 991 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 991 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 992 base::FilePath output_file_path; | 992 base::FilePath output_file_path; |
| 993 test_util::TestGetContentCallback get_content_callback; | 993 test_util::TestGetContentCallback get_content_callback; |
| 994 fake_service_.DownloadFile( | 994 fake_service_.DownloadFile( |
| 995 kOutputFilePath, | 995 kOutputFilePath, |
| 996 "2_file_resource_id", | 996 "2_file_resource_id", |
| 997 test_util::CreateCopyResultCallback(&error, &output_file_path), | 997 test_util::CreateCopyResultCallback(&error, &output_file_path), |
| 998 get_content_callback.callback(), | 998 get_content_callback.callback(), |
| 999 base::Bind(&test_util::AppendProgressCallbackResult, | 999 base::Bind(&test_util::AppendProgressCallbackResult, |
| 1000 &download_progress_values)); | 1000 &download_progress_values)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1012 EXPECT_EQ(content, get_content_callback.GetConcatenatedData()); | 1012 EXPECT_EQ(content, get_content_callback.GetConcatenatedData()); |
| 1013 } | 1013 } |
| 1014 | 1014 |
| 1015 TEST_F(FakeDriveServiceTest, DownloadFile_NonexistingFile) { | 1015 TEST_F(FakeDriveServiceTest, DownloadFile_NonexistingFile) { |
| 1016 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1016 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1017 | 1017 |
| 1018 base::ScopedTempDir temp_dir; | 1018 base::ScopedTempDir temp_dir; |
| 1019 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1019 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1020 | 1020 |
| 1021 const base::FilePath kOutputFilePath = | 1021 const base::FilePath kOutputFilePath = |
| 1022 temp_dir.path().AppendASCII("whatever.txt"); | 1022 temp_dir.GetPath().AppendASCII("whatever.txt"); |
| 1023 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1023 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1024 base::FilePath output_file_path; | 1024 base::FilePath output_file_path; |
| 1025 fake_service_.DownloadFile( | 1025 fake_service_.DownloadFile( |
| 1026 kOutputFilePath, | 1026 kOutputFilePath, |
| 1027 "non_existent_file_resource_id", | 1027 "non_existent_file_resource_id", |
| 1028 test_util::CreateCopyResultCallback(&error, &output_file_path), | 1028 test_util::CreateCopyResultCallback(&error, &output_file_path), |
| 1029 GetContentCallback(), | 1029 GetContentCallback(), |
| 1030 ProgressCallback()); | 1030 ProgressCallback()); |
| 1031 base::RunLoop().RunUntilIdle(); | 1031 base::RunLoop().RunUntilIdle(); |
| 1032 | 1032 |
| 1033 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1033 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 1034 } | 1034 } |
| 1035 | 1035 |
| 1036 TEST_F(FakeDriveServiceTest, DownloadFile_Offline) { | 1036 TEST_F(FakeDriveServiceTest, DownloadFile_Offline) { |
| 1037 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1037 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1038 fake_service_.set_offline(true); | 1038 fake_service_.set_offline(true); |
| 1039 | 1039 |
| 1040 base::ScopedTempDir temp_dir; | 1040 base::ScopedTempDir temp_dir; |
| 1041 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1041 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1042 | 1042 |
| 1043 const base::FilePath kOutputFilePath = | 1043 const base::FilePath kOutputFilePath = |
| 1044 temp_dir.path().AppendASCII("whatever.txt"); | 1044 temp_dir.GetPath().AppendASCII("whatever.txt"); |
| 1045 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1045 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1046 base::FilePath output_file_path; | 1046 base::FilePath output_file_path; |
| 1047 fake_service_.DownloadFile( | 1047 fake_service_.DownloadFile( |
| 1048 kOutputFilePath, | 1048 kOutputFilePath, |
| 1049 "2_file_resource_id", | 1049 "2_file_resource_id", |
| 1050 test_util::CreateCopyResultCallback(&error, &output_file_path), | 1050 test_util::CreateCopyResultCallback(&error, &output_file_path), |
| 1051 GetContentCallback(), | 1051 GetContentCallback(), |
| 1052 ProgressCallback()); | 1052 ProgressCallback()); |
| 1053 base::RunLoop().RunUntilIdle(); | 1053 base::RunLoop().RunUntilIdle(); |
| 1054 | 1054 |
| (...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1796 base::RunLoop().RunUntilIdle(); | 1796 base::RunLoop().RunUntilIdle(); |
| 1797 | 1797 |
| 1798 EXPECT_EQ(HTTP_NOT_FOUND, response.code); | 1798 EXPECT_EQ(HTTP_NOT_FOUND, response.code); |
| 1799 EXPECT_FALSE(entry.get()); | 1799 EXPECT_FALSE(entry.get()); |
| 1800 } | 1800 } |
| 1801 | 1801 |
| 1802 TEST_F(FakeDriveServiceTest, ResumeUpload_ExistingFile) { | 1802 TEST_F(FakeDriveServiceTest, ResumeUpload_ExistingFile) { |
| 1803 base::ScopedTempDir temp_dir; | 1803 base::ScopedTempDir temp_dir; |
| 1804 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1804 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1805 base::FilePath local_file_path = | 1805 base::FilePath local_file_path = |
| 1806 temp_dir.path().Append(FILE_PATH_LITERAL("File 1.txt")); | 1806 temp_dir.GetPath().Append(FILE_PATH_LITERAL("File 1.txt")); |
| 1807 std::string contents("hogefugapiyo"); | 1807 std::string contents("hogefugapiyo"); |
| 1808 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents)); | 1808 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents)); |
| 1809 | 1809 |
| 1810 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1810 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1811 | 1811 |
| 1812 std::unique_ptr<FileResource> entry = FindEntry("2_file_resource_id"); | 1812 std::unique_ptr<FileResource> entry = FindEntry("2_file_resource_id"); |
| 1813 ASSERT_TRUE(entry); | 1813 ASSERT_TRUE(entry); |
| 1814 | 1814 |
| 1815 UploadExistingFileOptions options; | 1815 UploadExistingFileOptions options; |
| 1816 options.etag = entry->etag(); | 1816 options.etag = entry->etag(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1866 EXPECT_LE(0, upload_progress_values.front().first); | 1866 EXPECT_LE(0, upload_progress_values.front().first); |
| 1867 EXPECT_GE(static_cast<int64_t>(contents.size() - contents.size() / 2), | 1867 EXPECT_GE(static_cast<int64_t>(contents.size() - contents.size() / 2), |
| 1868 upload_progress_values.back().first); | 1868 upload_progress_values.back().first); |
| 1869 EXPECT_EQ(base::MD5String(contents), entry->md5_checksum()); | 1869 EXPECT_EQ(base::MD5String(contents), entry->md5_checksum()); |
| 1870 } | 1870 } |
| 1871 | 1871 |
| 1872 TEST_F(FakeDriveServiceTest, ResumeUpload_NewFile) { | 1872 TEST_F(FakeDriveServiceTest, ResumeUpload_NewFile) { |
| 1873 base::ScopedTempDir temp_dir; | 1873 base::ScopedTempDir temp_dir; |
| 1874 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1874 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1875 base::FilePath local_file_path = | 1875 base::FilePath local_file_path = |
| 1876 temp_dir.path().Append(FILE_PATH_LITERAL("new file.foo")); | 1876 temp_dir.GetPath().Append(FILE_PATH_LITERAL("new file.foo")); |
| 1877 std::string contents("hogefugapiyo"); | 1877 std::string contents("hogefugapiyo"); |
| 1878 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents)); | 1878 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents)); |
| 1879 | 1879 |
| 1880 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1880 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1881 | 1881 |
| 1882 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1882 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1883 GURL upload_location; | 1883 GURL upload_location; |
| 1884 fake_service_.InitiateUploadNewFile( | 1884 fake_service_.InitiateUploadNewFile( |
| 1885 "test/foo", contents.size(), "1_folder_resource_id", "new file.foo", | 1885 "test/foo", contents.size(), "1_folder_resource_id", "new file.foo", |
| 1886 UploadNewFileOptions(), | 1886 UploadNewFileOptions(), |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2171 test_util::CreateCopyResultCallback(&error, &entry)); | 2171 test_util::CreateCopyResultCallback(&error, &entry)); |
| 2172 base::RunLoop().RunUntilIdle(); | 2172 base::RunLoop().RunUntilIdle(); |
| 2173 | 2173 |
| 2174 EXPECT_EQ(DRIVE_NO_CONNECTION, error); | 2174 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 2175 EXPECT_FALSE(entry); | 2175 EXPECT_FALSE(entry); |
| 2176 } | 2176 } |
| 2177 | 2177 |
| 2178 } // namespace | 2178 } // namespace |
| 2179 | 2179 |
| 2180 } // namespace drive | 2180 } // namespace drive |
| OLD | NEW |