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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1250 EXPECT_TRUE(http_request_.content.empty()); | 1250 EXPECT_TRUE(http_request_.content.empty()); |
1251 | 1251 |
1252 // Check the response. | 1252 // Check the response. |
1253 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); | 1253 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); |
1254 EXPECT_EQ(0, response.start_position_received); | 1254 EXPECT_EQ(0, response.start_position_received); |
1255 EXPECT_EQ(static_cast<int64>(end_position), | 1255 EXPECT_EQ(static_cast<int64>(end_position), |
1256 response.end_position_received); | 1256 response.end_position_received); |
1257 } | 1257 } |
1258 } | 1258 } |
1259 | 1259 |
| 1260 TEST_F(DriveApiRequestsTest, UploadNewFileWithMetadataRequest) { |
| 1261 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; |
| 1262 const base::Time::Exploded kLastViewedByMeDate = |
| 1263 {2013, 7, 0, 19, 15, 59, 13, 123}; |
| 1264 |
| 1265 // Set an expected url for uploading. |
| 1266 expected_upload_path_ = kTestUploadNewFilePath; |
| 1267 |
| 1268 const char kTestContentType[] = "text/plain"; |
| 1269 const std::string kTestContent(100, 'a'); |
| 1270 |
| 1271 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 1272 GURL upload_url; |
| 1273 |
| 1274 // Initiate uploading a new file to the directory with "parent_resource_id". |
| 1275 { |
| 1276 base::RunLoop run_loop; |
| 1277 drive::InitiateUploadNewFileRequest* request = |
| 1278 new drive::InitiateUploadNewFileRequest( |
| 1279 request_sender_.get(), |
| 1280 *url_generator_, |
| 1281 kTestContentType, |
| 1282 kTestContent.size(), |
| 1283 "parent_resource_id", // The resource id of the parent directory. |
| 1284 "new file title", // The title of the file being uploaded. |
| 1285 test_util::CreateQuitCallback( |
| 1286 &run_loop, |
| 1287 test_util::CreateCopyResultCallback(&error, &upload_url))); |
| 1288 request->set_modified_date(base::Time::FromUTCExploded(kModifiedDate)); |
| 1289 request->set_last_viewed_by_me_date( |
| 1290 base::Time::FromUTCExploded(kLastViewedByMeDate)); |
| 1291 request_sender_->StartRequestWithRetry(request); |
| 1292 run_loop.Run(); |
| 1293 } |
| 1294 |
| 1295 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1296 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); |
| 1297 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); |
| 1298 EXPECT_EQ(base::Int64ToString(kTestContent.size()), |
| 1299 http_request_.headers["X-Upload-Content-Length"]); |
| 1300 |
| 1301 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
| 1302 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable&setModifiedDate=true", |
| 1303 http_request_.relative_url); |
| 1304 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); |
| 1305 EXPECT_TRUE(http_request_.has_content); |
| 1306 EXPECT_EQ("{\"lastViewedByMeDate\":\"2013-07-19T15:59:13.123Z\"," |
| 1307 "\"modifiedDate\":\"2012-07-19T15:59:13.123Z\"," |
| 1308 "\"parents\":[{\"id\":\"parent_resource_id\"," |
| 1309 "\"kind\":\"drive#fileLink\"}]," |
| 1310 "\"title\":\"new file title\"}", |
| 1311 http_request_.content); |
| 1312 } |
| 1313 |
1260 TEST_F(DriveApiRequestsTest, UploadExistingFileRequest) { | 1314 TEST_F(DriveApiRequestsTest, UploadExistingFileRequest) { |
1261 // Set an expected url for uploading. | 1315 // Set an expected url for uploading. |
1262 expected_upload_path_ = kTestUploadExistingFilePath; | 1316 expected_upload_path_ = kTestUploadExistingFilePath; |
1263 | 1317 |
1264 const char kTestContentType[] = "text/plain"; | 1318 const char kTestContentType[] = "text/plain"; |
1265 const std::string kTestContent(100, 'a'); | 1319 const std::string kTestContent(100, 'a'); |
1266 const base::FilePath kTestFilePath = | 1320 const base::FilePath kTestFilePath = |
1267 temp_dir_.path().AppendASCII("upload_file.txt"); | 1321 temp_dir_.path().AppendASCII("upload_file.txt"); |
1268 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); | 1322 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); |
1269 | 1323 |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 // Check the response. | 1620 // Check the response. |
1567 EXPECT_EQ(HTTP_PRECONDITION, response.code); | 1621 EXPECT_EQ(HTTP_PRECONDITION, response.code); |
1568 // The start and end positions should be set to -1 for error. | 1622 // The start and end positions should be set to -1 for error. |
1569 EXPECT_EQ(-1, response.start_position_received); | 1623 EXPECT_EQ(-1, response.start_position_received); |
1570 EXPECT_EQ(-1, response.end_position_received); | 1624 EXPECT_EQ(-1, response.end_position_received); |
1571 | 1625 |
1572 // New entry should be NULL. | 1626 // New entry should be NULL. |
1573 EXPECT_FALSE(new_entry.get()); | 1627 EXPECT_FALSE(new_entry.get()); |
1574 } | 1628 } |
1575 | 1629 |
| 1630 TEST_F(DriveApiRequestsTest, UploadExistingFileWithMetadataRequest) { |
| 1631 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; |
| 1632 const base::Time::Exploded kLastViewedByMeDate = |
| 1633 {2013, 7, 0, 19, 15, 59, 13, 123}; |
| 1634 |
| 1635 // Set an expected url for uploading. |
| 1636 expected_upload_path_ = kTestUploadExistingFilePath; |
| 1637 |
| 1638 const char kTestContentType[] = "text/plain"; |
| 1639 const std::string kTestContent(100, 'a'); |
| 1640 |
| 1641 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 1642 GURL upload_url; |
| 1643 |
| 1644 // Initiate uploading a new file to the directory with "parent_resource_id". |
| 1645 { |
| 1646 base::RunLoop run_loop; |
| 1647 drive::InitiateUploadExistingFileRequest* request = |
| 1648 new drive::InitiateUploadExistingFileRequest( |
| 1649 request_sender_.get(), |
| 1650 *url_generator_, |
| 1651 kTestContentType, |
| 1652 kTestContent.size(), |
| 1653 "resource_id", // The resource id of the file to be overwritten. |
| 1654 kTestETag, |
| 1655 test_util::CreateQuitCallback( |
| 1656 &run_loop, |
| 1657 test_util::CreateCopyResultCallback(&error, &upload_url))); |
| 1658 request->set_parent_resource_id("new_parent_resource_id"); |
| 1659 request->set_title("new file title"); |
| 1660 request->set_modified_date(base::Time::FromUTCExploded(kModifiedDate)); |
| 1661 request->set_last_viewed_by_me_date( |
| 1662 base::Time::FromUTCExploded(kLastViewedByMeDate)); |
| 1663 |
| 1664 request_sender_->StartRequestWithRetry(request); |
| 1665 run_loop.Run(); |
| 1666 } |
| 1667 |
| 1668 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1669 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path()); |
| 1670 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); |
| 1671 EXPECT_EQ(base::Int64ToString(kTestContent.size()), |
| 1672 http_request_.headers["X-Upload-Content-Length"]); |
| 1673 EXPECT_EQ(kTestETag, http_request_.headers["If-Match"]); |
| 1674 |
| 1675 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
| 1676 EXPECT_EQ("/upload/drive/v2/files/resource_id?" |
| 1677 "uploadType=resumable&setModifiedDate=true", |
| 1678 http_request_.relative_url); |
| 1679 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); |
| 1680 EXPECT_TRUE(http_request_.has_content); |
| 1681 EXPECT_EQ("{\"lastViewedByMeDate\":\"2013-07-19T15:59:13.123Z\"," |
| 1682 "\"modifiedDate\":\"2012-07-19T15:59:13.123Z\"," |
| 1683 "\"parents\":[{\"id\":\"new_parent_resource_id\"," |
| 1684 "\"kind\":\"drive#fileLink\"}]," |
| 1685 "\"title\":\"new file title\"}", |
| 1686 http_request_.content); |
| 1687 } |
| 1688 |
1576 TEST_F(DriveApiRequestsTest, DownloadFileRequest) { | 1689 TEST_F(DriveApiRequestsTest, DownloadFileRequest) { |
1577 const base::FilePath kDownloadedFilePath = | 1690 const base::FilePath kDownloadedFilePath = |
1578 temp_dir_.path().AppendASCII("cache_file"); | 1691 temp_dir_.path().AppendASCII("cache_file"); |
1579 const std::string kTestId("dummyId"); | 1692 const std::string kTestId("dummyId"); |
1580 | 1693 |
1581 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 1694 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
1582 base::FilePath temp_file; | 1695 base::FilePath temp_file; |
1583 { | 1696 { |
1584 base::RunLoop run_loop; | 1697 base::RunLoop run_loop; |
1585 drive::DownloadFileRequest* request = new drive::DownloadFileRequest( | 1698 drive::DownloadFileRequest* request = new drive::DownloadFileRequest( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1638 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1751 EXPECT_EQ(HTTP_SUCCESS, result_code); |
1639 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 1752 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
1640 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url); | 1753 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url); |
1641 EXPECT_EQ(kDownloadedFilePath, temp_file); | 1754 EXPECT_EQ(kDownloadedFilePath, temp_file); |
1642 | 1755 |
1643 const std::string expected_contents = kTestId + kTestId + kTestId; | 1756 const std::string expected_contents = kTestId + kTestId + kTestId; |
1644 EXPECT_EQ(expected_contents, contents); | 1757 EXPECT_EQ(expected_contents, contents); |
1645 } | 1758 } |
1646 | 1759 |
1647 } // namespace google_apis | 1760 } // namespace google_apis |
OLD | NEW |