| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "google_apis/drive/drive_api_requests.h" | 5 #include "google_apis/drive/drive_api_requests.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 EXPECT_FALSE(http_request_.has_content); | 1049 EXPECT_FALSE(http_request_.has_content); |
| 1050 } | 1050 } |
| 1051 | 1051 |
| 1052 TEST_F(DriveApiRequestsTest, UploadNewFileRequest) { | 1052 TEST_F(DriveApiRequestsTest, UploadNewFileRequest) { |
| 1053 // Set an expected url for uploading. | 1053 // Set an expected url for uploading. |
| 1054 expected_upload_path_ = kTestUploadNewFilePath; | 1054 expected_upload_path_ = kTestUploadNewFilePath; |
| 1055 | 1055 |
| 1056 const char kTestContentType[] = "text/plain"; | 1056 const char kTestContentType[] = "text/plain"; |
| 1057 const std::string kTestContent(100, 'a'); | 1057 const std::string kTestContent(100, 'a'); |
| 1058 const base::FilePath kTestFilePath = | 1058 const base::FilePath kTestFilePath = |
| 1059 temp_dir_.path().AppendASCII("upload_file.txt"); | 1059 temp_dir_.GetPath().AppendASCII("upload_file.txt"); |
| 1060 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); | 1060 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); |
| 1061 | 1061 |
| 1062 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1062 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1063 GURL upload_url; | 1063 GURL upload_url; |
| 1064 | 1064 |
| 1065 // Initiate uploading a new file to the directory with | 1065 // Initiate uploading a new file to the directory with |
| 1066 // "parent_resource_id". | 1066 // "parent_resource_id". |
| 1067 { | 1067 { |
| 1068 base::RunLoop run_loop; | 1068 base::RunLoop run_loop; |
| 1069 drive::InitiateUploadNewFileRequest* request = | 1069 drive::InitiateUploadNewFileRequest* request = |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 EXPECT_EQ(-1, response.end_position_received); | 1147 EXPECT_EQ(-1, response.end_position_received); |
| 1148 } | 1148 } |
| 1149 | 1149 |
| 1150 TEST_F(DriveApiRequestsTest, UploadNewEmptyFileRequest) { | 1150 TEST_F(DriveApiRequestsTest, UploadNewEmptyFileRequest) { |
| 1151 // Set an expected url for uploading. | 1151 // Set an expected url for uploading. |
| 1152 expected_upload_path_ = kTestUploadNewFilePath; | 1152 expected_upload_path_ = kTestUploadNewFilePath; |
| 1153 | 1153 |
| 1154 const char kTestContentType[] = "text/plain"; | 1154 const char kTestContentType[] = "text/plain"; |
| 1155 const char kTestContent[] = ""; | 1155 const char kTestContent[] = ""; |
| 1156 const base::FilePath kTestFilePath = | 1156 const base::FilePath kTestFilePath = |
| 1157 temp_dir_.path().AppendASCII("empty_file.txt"); | 1157 temp_dir_.GetPath().AppendASCII("empty_file.txt"); |
| 1158 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); | 1158 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); |
| 1159 | 1159 |
| 1160 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1160 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1161 GURL upload_url; | 1161 GURL upload_url; |
| 1162 | 1162 |
| 1163 // Initiate uploading a new file to the directory with "parent_resource_id". | 1163 // Initiate uploading a new file to the directory with "parent_resource_id". |
| 1164 { | 1164 { |
| 1165 base::RunLoop run_loop; | 1165 base::RunLoop run_loop; |
| 1166 drive::InitiateUploadNewFileRequest* request = | 1166 drive::InitiateUploadNewFileRequest* request = |
| 1167 new drive::InitiateUploadNewFileRequest( | 1167 new drive::InitiateUploadNewFileRequest( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1236 } | 1236 } |
| 1237 | 1237 |
| 1238 TEST_F(DriveApiRequestsTest, UploadNewLargeFileRequest) { | 1238 TEST_F(DriveApiRequestsTest, UploadNewLargeFileRequest) { |
| 1239 // Set an expected url for uploading. | 1239 // Set an expected url for uploading. |
| 1240 expected_upload_path_ = kTestUploadNewFilePath; | 1240 expected_upload_path_ = kTestUploadNewFilePath; |
| 1241 | 1241 |
| 1242 const char kTestContentType[] = "text/plain"; | 1242 const char kTestContentType[] = "text/plain"; |
| 1243 const size_t kNumChunkBytes = 10; // Num bytes in a chunk. | 1243 const size_t kNumChunkBytes = 10; // Num bytes in a chunk. |
| 1244 const std::string kTestContent(100, 'a'); | 1244 const std::string kTestContent(100, 'a'); |
| 1245 const base::FilePath kTestFilePath = | 1245 const base::FilePath kTestFilePath = |
| 1246 temp_dir_.path().AppendASCII("upload_file.txt"); | 1246 temp_dir_.GetPath().AppendASCII("upload_file.txt"); |
| 1247 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); | 1247 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); |
| 1248 | 1248 |
| 1249 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1249 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1250 GURL upload_url; | 1250 GURL upload_url; |
| 1251 | 1251 |
| 1252 // Initiate uploading a new file to the directory with "parent_resource_id". | 1252 // Initiate uploading a new file to the directory with "parent_resource_id". |
| 1253 { | 1253 { |
| 1254 base::RunLoop run_loop; | 1254 base::RunLoop run_loop; |
| 1255 drive::InitiateUploadNewFileRequest* request = | 1255 drive::InitiateUploadNewFileRequest* request = |
| 1256 new drive::InitiateUploadNewFileRequest( | 1256 new drive::InitiateUploadNewFileRequest( |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1469 http_request_.content); | 1469 http_request_.content); |
| 1470 } | 1470 } |
| 1471 | 1471 |
| 1472 TEST_F(DriveApiRequestsTest, UploadExistingFileRequest) { | 1472 TEST_F(DriveApiRequestsTest, UploadExistingFileRequest) { |
| 1473 // Set an expected url for uploading. | 1473 // Set an expected url for uploading. |
| 1474 expected_upload_path_ = kTestUploadExistingFilePath; | 1474 expected_upload_path_ = kTestUploadExistingFilePath; |
| 1475 | 1475 |
| 1476 const char kTestContentType[] = "text/plain"; | 1476 const char kTestContentType[] = "text/plain"; |
| 1477 const std::string kTestContent(100, 'a'); | 1477 const std::string kTestContent(100, 'a'); |
| 1478 const base::FilePath kTestFilePath = | 1478 const base::FilePath kTestFilePath = |
| 1479 temp_dir_.path().AppendASCII("upload_file.txt"); | 1479 temp_dir_.GetPath().AppendASCII("upload_file.txt"); |
| 1480 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); | 1480 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); |
| 1481 | 1481 |
| 1482 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1482 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1483 GURL upload_url; | 1483 GURL upload_url; |
| 1484 | 1484 |
| 1485 // Initiate uploading a new file to the directory with "parent_resource_id". | 1485 // Initiate uploading a new file to the directory with "parent_resource_id". |
| 1486 { | 1486 { |
| 1487 base::RunLoop run_loop; | 1487 base::RunLoop run_loop; |
| 1488 drive::InitiateUploadExistingFileRequest* request = | 1488 drive::InitiateUploadExistingFileRequest* request = |
| 1489 new drive::InitiateUploadExistingFileRequest( | 1489 new drive::InitiateUploadExistingFileRequest( |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1561 EXPECT_EQ(-1, response.end_position_received); | 1561 EXPECT_EQ(-1, response.end_position_received); |
| 1562 } | 1562 } |
| 1563 | 1563 |
| 1564 TEST_F(DriveApiRequestsTest, UploadExistingFileRequestWithETag) { | 1564 TEST_F(DriveApiRequestsTest, UploadExistingFileRequestWithETag) { |
| 1565 // Set an expected url for uploading. | 1565 // Set an expected url for uploading. |
| 1566 expected_upload_path_ = kTestUploadExistingFilePath; | 1566 expected_upload_path_ = kTestUploadExistingFilePath; |
| 1567 | 1567 |
| 1568 const char kTestContentType[] = "text/plain"; | 1568 const char kTestContentType[] = "text/plain"; |
| 1569 const std::string kTestContent(100, 'a'); | 1569 const std::string kTestContent(100, 'a'); |
| 1570 const base::FilePath kTestFilePath = | 1570 const base::FilePath kTestFilePath = |
| 1571 temp_dir_.path().AppendASCII("upload_file.txt"); | 1571 temp_dir_.GetPath().AppendASCII("upload_file.txt"); |
| 1572 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); | 1572 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); |
| 1573 | 1573 |
| 1574 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1574 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1575 GURL upload_url; | 1575 GURL upload_url; |
| 1576 | 1576 |
| 1577 // Initiate uploading a new file to the directory with "parent_resource_id". | 1577 // Initiate uploading a new file to the directory with "parent_resource_id". |
| 1578 { | 1578 { |
| 1579 base::RunLoop run_loop; | 1579 base::RunLoop run_loop; |
| 1580 drive::InitiateUploadExistingFileRequest* request = | 1580 drive::InitiateUploadExistingFileRequest* request = |
| 1581 new drive::InitiateUploadExistingFileRequest( | 1581 new drive::InitiateUploadExistingFileRequest( |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1695 } | 1695 } |
| 1696 | 1696 |
| 1697 TEST_F(DriveApiRequestsTest, | 1697 TEST_F(DriveApiRequestsTest, |
| 1698 UploadExistingFileRequestWithETagConflictOnResumeUpload) { | 1698 UploadExistingFileRequestWithETagConflictOnResumeUpload) { |
| 1699 // Set an expected url for uploading. | 1699 // Set an expected url for uploading. |
| 1700 expected_upload_path_ = kTestUploadExistingFilePath; | 1700 expected_upload_path_ = kTestUploadExistingFilePath; |
| 1701 | 1701 |
| 1702 const char kTestContentType[] = "text/plain"; | 1702 const char kTestContentType[] = "text/plain"; |
| 1703 const std::string kTestContent(100, 'a'); | 1703 const std::string kTestContent(100, 'a'); |
| 1704 const base::FilePath kTestFilePath = | 1704 const base::FilePath kTestFilePath = |
| 1705 temp_dir_.path().AppendASCII("upload_file.txt"); | 1705 temp_dir_.GetPath().AppendASCII("upload_file.txt"); |
| 1706 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); | 1706 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); |
| 1707 | 1707 |
| 1708 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1708 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1709 GURL upload_url; | 1709 GURL upload_url; |
| 1710 | 1710 |
| 1711 // Initiate uploading a new file to the directory with "parent_resource_id". | 1711 // Initiate uploading a new file to the directory with "parent_resource_id". |
| 1712 { | 1712 { |
| 1713 base::RunLoop run_loop; | 1713 base::RunLoop run_loop; |
| 1714 drive::InitiateUploadExistingFileRequest* request = | 1714 drive::InitiateUploadExistingFileRequest* request = |
| 1715 new drive::InitiateUploadExistingFileRequest( | 1715 new drive::InitiateUploadExistingFileRequest( |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1844 EXPECT_EQ("{\"lastViewedByMeDate\":\"2013-07-19T15:59:13.123Z\"," | 1844 EXPECT_EQ("{\"lastViewedByMeDate\":\"2013-07-19T15:59:13.123Z\"," |
| 1845 "\"modifiedDate\":\"2012-07-19T15:59:13.123Z\"," | 1845 "\"modifiedDate\":\"2012-07-19T15:59:13.123Z\"," |
| 1846 "\"parents\":[{\"id\":\"new_parent_resource_id\"," | 1846 "\"parents\":[{\"id\":\"new_parent_resource_id\"," |
| 1847 "\"kind\":\"drive#fileLink\"}]," | 1847 "\"kind\":\"drive#fileLink\"}]," |
| 1848 "\"title\":\"new file title\"}", | 1848 "\"title\":\"new file title\"}", |
| 1849 http_request_.content); | 1849 http_request_.content); |
| 1850 } | 1850 } |
| 1851 | 1851 |
| 1852 TEST_F(DriveApiRequestsTest, DownloadFileRequest) { | 1852 TEST_F(DriveApiRequestsTest, DownloadFileRequest) { |
| 1853 const base::FilePath kDownloadedFilePath = | 1853 const base::FilePath kDownloadedFilePath = |
| 1854 temp_dir_.path().AppendASCII("cache_file"); | 1854 temp_dir_.GetPath().AppendASCII("cache_file"); |
| 1855 const std::string kTestId("dummyId"); | 1855 const std::string kTestId("dummyId"); |
| 1856 | 1856 |
| 1857 DriveApiErrorCode result_code = DRIVE_OTHER_ERROR; | 1857 DriveApiErrorCode result_code = DRIVE_OTHER_ERROR; |
| 1858 base::FilePath temp_file; | 1858 base::FilePath temp_file; |
| 1859 { | 1859 { |
| 1860 base::RunLoop run_loop; | 1860 base::RunLoop run_loop; |
| 1861 drive::DownloadFileRequest* request = new drive::DownloadFileRequest( | 1861 drive::DownloadFileRequest* request = new drive::DownloadFileRequest( |
| 1862 request_sender_.get(), | 1862 request_sender_.get(), |
| 1863 *url_generator_, | 1863 *url_generator_, |
| 1864 kTestId, | 1864 kTestId, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1881 EXPECT_EQ(kTestDownloadPathPrefix + kTestId + "?" + kTestDownloadFileQuery, | 1881 EXPECT_EQ(kTestDownloadPathPrefix + kTestId + "?" + kTestDownloadFileQuery, |
| 1882 http_request_.relative_url); | 1882 http_request_.relative_url); |
| 1883 EXPECT_EQ(kDownloadedFilePath, temp_file); | 1883 EXPECT_EQ(kDownloadedFilePath, temp_file); |
| 1884 | 1884 |
| 1885 const std::string expected_contents = kTestId + kTestId + kTestId; | 1885 const std::string expected_contents = kTestId + kTestId + kTestId; |
| 1886 EXPECT_EQ(expected_contents, contents); | 1886 EXPECT_EQ(expected_contents, contents); |
| 1887 } | 1887 } |
| 1888 | 1888 |
| 1889 TEST_F(DriveApiRequestsTest, DownloadFileRequest_GetContentCallback) { | 1889 TEST_F(DriveApiRequestsTest, DownloadFileRequest_GetContentCallback) { |
| 1890 const base::FilePath kDownloadedFilePath = | 1890 const base::FilePath kDownloadedFilePath = |
| 1891 temp_dir_.path().AppendASCII("cache_file"); | 1891 temp_dir_.GetPath().AppendASCII("cache_file"); |
| 1892 const std::string kTestId("dummyId"); | 1892 const std::string kTestId("dummyId"); |
| 1893 | 1893 |
| 1894 DriveApiErrorCode result_code = DRIVE_OTHER_ERROR; | 1894 DriveApiErrorCode result_code = DRIVE_OTHER_ERROR; |
| 1895 base::FilePath temp_file; | 1895 base::FilePath temp_file; |
| 1896 std::string contents; | 1896 std::string contents; |
| 1897 { | 1897 { |
| 1898 base::RunLoop run_loop; | 1898 base::RunLoop run_loop; |
| 1899 drive::DownloadFileRequest* request = new drive::DownloadFileRequest( | 1899 drive::DownloadFileRequest* request = new drive::DownloadFileRequest( |
| 1900 request_sender_.get(), | 1900 request_sender_.get(), |
| 1901 *url_generator_, | 1901 *url_generator_, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1994 result = base::JSONReader::Read(http_request_.content); | 1994 result = base::JSONReader::Read(http_request_.content); |
| 1995 EXPECT_TRUE(http_request_.has_content); | 1995 EXPECT_TRUE(http_request_.has_content); |
| 1996 EXPECT_TRUE(base::Value::Equals(expected.get(), result.get())); | 1996 EXPECT_TRUE(base::Value::Equals(expected.get(), result.get())); |
| 1997 } | 1997 } |
| 1998 | 1998 |
| 1999 TEST_F(DriveApiRequestsTest, BatchUploadRequest) { | 1999 TEST_F(DriveApiRequestsTest, BatchUploadRequest) { |
| 2000 // Preapre constants. | 2000 // Preapre constants. |
| 2001 const char kTestContentType[] = "text/plain"; | 2001 const char kTestContentType[] = "text/plain"; |
| 2002 const std::string kTestContent(10, 'a'); | 2002 const std::string kTestContent(10, 'a'); |
| 2003 const base::FilePath kTestFilePath = | 2003 const base::FilePath kTestFilePath = |
| 2004 temp_dir_.path().AppendASCII("upload_file.txt"); | 2004 temp_dir_.GetPath().AppendASCII("upload_file.txt"); |
| 2005 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); | 2005 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); |
| 2006 | 2006 |
| 2007 // Create batch request. | 2007 // Create batch request. |
| 2008 drive::BatchUploadRequest* const request = | 2008 drive::BatchUploadRequest* const request = |
| 2009 new drive::BatchUploadRequest(request_sender_.get(), *url_generator_); | 2009 new drive::BatchUploadRequest(request_sender_.get(), *url_generator_); |
| 2010 request->SetBoundaryForTesting("OUTERBOUNDARY"); | 2010 request->SetBoundaryForTesting("OUTERBOUNDARY"); |
| 2011 request_sender_->StartRequestWithAuthRetry(request); | 2011 request_sender_->StartRequestWithAuthRetry(request); |
| 2012 | 2012 |
| 2013 // Create child request. | 2013 // Create child request. |
| 2014 DriveApiErrorCode errors[] = {DRIVE_OTHER_ERROR, DRIVE_OTHER_ERROR}; | 2014 DriveApiErrorCode errors[] = {DRIVE_OTHER_ERROR, DRIVE_OTHER_ERROR}; |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2291 "Header: value\r\n" | 2291 "Header: value\r\n" |
| 2292 "\r\n" | 2292 "\r\n" |
| 2293 "BODY\r\n" | 2293 "BODY\r\n" |
| 2294 "--BOUNDARY-- \t", | 2294 "--BOUNDARY-- \t", |
| 2295 &parts)); | 2295 &parts)); |
| 2296 ASSERT_EQ(1u, parts.size()); | 2296 ASSERT_EQ(1u, parts.size()); |
| 2297 EXPECT_EQ(HTTP_SUCCESS, parts[0].code); | 2297 EXPECT_EQ(HTTP_SUCCESS, parts[0].code); |
| 2298 EXPECT_EQ("BODY", parts[0].body); | 2298 EXPECT_EQ("BODY", parts[0].body); |
| 2299 } | 2299 } |
| 2300 } // namespace google_apis | 2300 } // namespace google_apis |
| OLD | NEW |