Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Unified Diff: google_apis/drive/drive_api_requests_unittest.cc

Issue 139153006: drive: Add metadata parameters to InitiateUpload* methods (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nits Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « google_apis/drive/drive_api_requests.cc ('k') | google_apis/drive/drive_api_url_generator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: google_apis/drive/drive_api_requests_unittest.cc
diff --git a/google_apis/drive/drive_api_requests_unittest.cc b/google_apis/drive/drive_api_requests_unittest.cc
index 466240cd369d44a69caefc70974b62a1e79cd666..cbbba29eb755fba043c9153f058708361d6c3daa 100644
--- a/google_apis/drive/drive_api_requests_unittest.cc
+++ b/google_apis/drive/drive_api_requests_unittest.cc
@@ -1257,6 +1257,60 @@ TEST_F(DriveApiRequestsTest, UploadNewLargeFileRequest) {
}
}
+TEST_F(DriveApiRequestsTest, UploadNewFileWithMetadataRequest) {
+ const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123};
+ const base::Time::Exploded kLastViewedByMeDate =
+ {2013, 7, 0, 19, 15, 59, 13, 123};
+
+ // Set an expected url for uploading.
+ expected_upload_path_ = kTestUploadNewFilePath;
+
+ const char kTestContentType[] = "text/plain";
+ const std::string kTestContent(100, 'a');
+
+ GDataErrorCode error = GDATA_OTHER_ERROR;
+ GURL upload_url;
+
+ // Initiate uploading a new file to the directory with "parent_resource_id".
+ {
+ base::RunLoop run_loop;
+ drive::InitiateUploadNewFileRequest* request =
+ new drive::InitiateUploadNewFileRequest(
+ request_sender_.get(),
+ *url_generator_,
+ kTestContentType,
+ kTestContent.size(),
+ "parent_resource_id", // The resource id of the parent directory.
+ "new file title", // The title of the file being uploaded.
+ test_util::CreateQuitCallback(
+ &run_loop,
+ test_util::CreateCopyResultCallback(&error, &upload_url)));
+ request->set_modified_date(base::Time::FromUTCExploded(kModifiedDate));
+ request->set_last_viewed_by_me_date(
+ base::Time::FromUTCExploded(kLastViewedByMeDate));
+ request_sender_->StartRequestWithRetry(request);
+ run_loop.Run();
+ }
+
+ EXPECT_EQ(HTTP_SUCCESS, error);
+ EXPECT_EQ(kTestUploadNewFilePath, upload_url.path());
+ EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
+ EXPECT_EQ(base::Int64ToString(kTestContent.size()),
+ http_request_.headers["X-Upload-Content-Length"]);
+
+ EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
+ EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable&setModifiedDate=true",
+ http_request_.relative_url);
+ EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
+ EXPECT_TRUE(http_request_.has_content);
+ EXPECT_EQ("{\"lastViewedByMeDate\":\"2013-07-19T15:59:13.123Z\","
+ "\"modifiedDate\":\"2012-07-19T15:59:13.123Z\","
+ "\"parents\":[{\"id\":\"parent_resource_id\","
+ "\"kind\":\"drive#fileLink\"}],"
+ "\"title\":\"new file title\"}",
+ http_request_.content);
+}
+
TEST_F(DriveApiRequestsTest, UploadExistingFileRequest) {
// Set an expected url for uploading.
expected_upload_path_ = kTestUploadExistingFilePath;
@@ -1573,6 +1627,65 @@ TEST_F(DriveApiRequestsTest,
EXPECT_FALSE(new_entry.get());
}
+TEST_F(DriveApiRequestsTest, UploadExistingFileWithMetadataRequest) {
+ const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123};
+ const base::Time::Exploded kLastViewedByMeDate =
+ {2013, 7, 0, 19, 15, 59, 13, 123};
+
+ // Set an expected url for uploading.
+ expected_upload_path_ = kTestUploadExistingFilePath;
+
+ const char kTestContentType[] = "text/plain";
+ const std::string kTestContent(100, 'a');
+
+ GDataErrorCode error = GDATA_OTHER_ERROR;
+ GURL upload_url;
+
+ // Initiate uploading a new file to the directory with "parent_resource_id".
+ {
+ base::RunLoop run_loop;
+ drive::InitiateUploadExistingFileRequest* request =
+ new drive::InitiateUploadExistingFileRequest(
+ request_sender_.get(),
+ *url_generator_,
+ kTestContentType,
+ kTestContent.size(),
+ "resource_id", // The resource id of the file to be overwritten.
+ kTestETag,
+ test_util::CreateQuitCallback(
+ &run_loop,
+ test_util::CreateCopyResultCallback(&error, &upload_url)));
+ request->set_parent_resource_id("new_parent_resource_id");
+ request->set_title("new file title");
+ request->set_modified_date(base::Time::FromUTCExploded(kModifiedDate));
+ request->set_last_viewed_by_me_date(
+ base::Time::FromUTCExploded(kLastViewedByMeDate));
+
+ request_sender_->StartRequestWithRetry(request);
+ run_loop.Run();
+ }
+
+ EXPECT_EQ(HTTP_SUCCESS, error);
+ EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path());
+ EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
+ EXPECT_EQ(base::Int64ToString(kTestContent.size()),
+ http_request_.headers["X-Upload-Content-Length"]);
+ EXPECT_EQ(kTestETag, http_request_.headers["If-Match"]);
+
+ EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
+ EXPECT_EQ("/upload/drive/v2/files/resource_id?"
+ "uploadType=resumable&setModifiedDate=true",
+ http_request_.relative_url);
+ EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
+ EXPECT_TRUE(http_request_.has_content);
+ EXPECT_EQ("{\"lastViewedByMeDate\":\"2013-07-19T15:59:13.123Z\","
+ "\"modifiedDate\":\"2012-07-19T15:59:13.123Z\","
+ "\"parents\":[{\"id\":\"new_parent_resource_id\","
+ "\"kind\":\"drive#fileLink\"}],"
+ "\"title\":\"new file title\"}",
+ http_request_.content);
+}
+
TEST_F(DriveApiRequestsTest, DownloadFileRequest) {
const base::FilePath kDownloadedFilePath =
temp_dir_.path().AppendASCII("cache_file");
« no previous file with comments | « google_apis/drive/drive_api_requests.cc ('k') | google_apis/drive/drive_api_url_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698