| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <map> | 6 #include <map> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 | 909 |
| 910 // 1) Get the upload URL for uploading a new file. | 910 // 1) Get the upload URL for uploading a new file. |
| 911 InitiateUploadNewFileRequest* initiate_request = | 911 InitiateUploadNewFileRequest* initiate_request = |
| 912 new InitiateUploadNewFileRequest( | 912 new InitiateUploadNewFileRequest( |
| 913 request_sender_.get(), | 913 request_sender_.get(), |
| 914 request_context_getter_.get(), | 914 request_context_getter_.get(), |
| 915 *url_generator_, | 915 *url_generator_, |
| 916 CreateComposedCallback( | 916 CreateComposedCallback( |
| 917 base::Bind(&test_util::RunAndQuit), | 917 base::Bind(&test_util::RunAndQuit), |
| 918 test_util::CreateCopyResultCallback(&result_code, &upload_url)), | 918 test_util::CreateCopyResultCallback(&result_code, &upload_url)), |
| 919 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), | |
| 920 "text/plain", | 919 "text/plain", |
| 921 kUploadContent.size(), | 920 kUploadContent.size(), |
| 922 "folder:id", | 921 "folder:id", |
| 923 "New file"); | 922 "New file"); |
| 924 | 923 |
| 925 request_sender_->StartRequestWithRetry(initiate_request); | 924 request_sender_->StartRequestWithRetry(initiate_request); |
| 926 base::MessageLoop::current()->Run(); | 925 base::MessageLoop::current()->Run(); |
| 927 | 926 |
| 928 EXPECT_EQ(HTTP_SUCCESS, result_code); | 927 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 929 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); | 928 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 950 UploadRangeResponse response; | 949 UploadRangeResponse response; |
| 951 scoped_ptr<ResourceEntry> new_entry; | 950 scoped_ptr<ResourceEntry> new_entry; |
| 952 | 951 |
| 953 ResumeUploadRequest* resume_request = new ResumeUploadRequest( | 952 ResumeUploadRequest* resume_request = new ResumeUploadRequest( |
| 954 request_sender_.get(), | 953 request_sender_.get(), |
| 955 request_context_getter_.get(), | 954 request_context_getter_.get(), |
| 956 CreateComposedCallback( | 955 CreateComposedCallback( |
| 957 base::Bind(&test_util::RunAndQuit), | 956 base::Bind(&test_util::RunAndQuit), |
| 958 test_util::CreateCopyResultCallback(&response, &new_entry)), | 957 test_util::CreateCopyResultCallback(&response, &new_entry)), |
| 959 ProgressCallback(), | 958 ProgressCallback(), |
| 960 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), | |
| 961 upload_url, | 959 upload_url, |
| 962 0, // start_position | 960 0, // start_position |
| 963 kUploadContent.size(), // end_position (exclusive) | 961 kUploadContent.size(), // end_position (exclusive) |
| 964 kUploadContent.size(), // content_length, | 962 kUploadContent.size(), // content_length, |
| 965 "text/plain", // content_type | 963 "text/plain", // content_type |
| 966 kTestFilePath); | 964 kTestFilePath); |
| 967 | 965 |
| 968 request_sender_->StartRequestWithRetry(resume_request); | 966 request_sender_->StartRequestWithRetry(resume_request); |
| 969 base::MessageLoop::current()->Run(); | 967 base::MessageLoop::current()->Run(); |
| 970 | 968 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 981 EXPECT_TRUE(http_request_.has_content); | 979 EXPECT_TRUE(http_request_.has_content); |
| 982 EXPECT_EQ(kUploadContent, http_request_.content); | 980 EXPECT_EQ(kUploadContent, http_request_.content); |
| 983 | 981 |
| 984 // Check the response. | 982 // Check the response. |
| 985 EXPECT_EQ(HTTP_CREATED, response.code); // Because it's a new file | 983 EXPECT_EQ(HTTP_CREATED, response.code); // Because it's a new file |
| 986 // The start and end positions should be set to -1, if an upload is complete. | 984 // The start and end positions should be set to -1, if an upload is complete. |
| 987 EXPECT_EQ(-1, response.start_position_received); | 985 EXPECT_EQ(-1, response.start_position_received); |
| 988 EXPECT_EQ(-1, response.end_position_received); | 986 EXPECT_EQ(-1, response.end_position_received); |
| 989 } | 987 } |
| 990 | 988 |
| 991 // TODO(kinaba): crbug.com/{241241,164098} Re-enable the test. | |
| 992 #define NO_GET_UPLOAD_STATUS_TEST | |
| 993 | |
| 994 // This test exercises InitiateUploadNewFileRequest and ResumeUploadRequest | 989 // This test exercises InitiateUploadNewFileRequest and ResumeUploadRequest |
| 995 // for a scenario of uploading a new *large* file, which requires multiple | 990 // for a scenario of uploading a new *large* file, which requires multiple |
| 996 // requests of ResumeUploadRequest. GetUploadRequest is also tested in this | 991 // requests of ResumeUploadRequest. GetUploadRequest is also tested in this |
| 997 // test case. | 992 // test case. |
| 998 TEST_F(GDataWapiRequestsTest, UploadNewLargeFile) { | 993 TEST_F(GDataWapiRequestsTest, UploadNewLargeFile) { |
| 999 const size_t kMaxNumBytes = 10; | 994 const size_t kMaxNumBytes = 10; |
| 1000 // This is big enough to cause multiple requests of ResumeUploadRequest | 995 // This is big enough to cause multiple requests of ResumeUploadRequest |
| 1001 // as we are going to send at most kMaxNumBytes at a time. | 996 // as we are going to send at most kMaxNumBytes at a time. |
| 1002 // So, sending "kMaxNumBytes * 2 + 1" bytes ensures three | 997 // So, sending "kMaxNumBytes * 2 + 1" bytes ensures three |
| 1003 // ResumeUploadRequests, which are start, middle and last requests. | 998 // ResumeUploadRequests, which are start, middle and last requests. |
| 1004 const std::string kUploadContent(kMaxNumBytes * 2 + 1, 'a'); | 999 const std::string kUploadContent(kMaxNumBytes * 2 + 1, 'a'); |
| 1005 const base::FilePath kTestFilePath = | 1000 const base::FilePath kTestFilePath = |
| 1006 temp_dir_.path().AppendASCII("upload_file.txt"); | 1001 temp_dir_.path().AppendASCII("upload_file.txt"); |
| 1007 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); | 1002 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); |
| 1008 | 1003 |
| 1009 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 1004 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 1010 GURL upload_url; | 1005 GURL upload_url; |
| 1011 | 1006 |
| 1012 // 1) Get the upload URL for uploading a new file. | 1007 // 1) Get the upload URL for uploading a new file. |
| 1013 InitiateUploadNewFileRequest* initiate_request = | 1008 InitiateUploadNewFileRequest* initiate_request = |
| 1014 new InitiateUploadNewFileRequest( | 1009 new InitiateUploadNewFileRequest( |
| 1015 request_sender_.get(), | 1010 request_sender_.get(), |
| 1016 request_context_getter_.get(), | 1011 request_context_getter_.get(), |
| 1017 *url_generator_, | 1012 *url_generator_, |
| 1018 CreateComposedCallback( | 1013 CreateComposedCallback( |
| 1019 base::Bind(&test_util::RunAndQuit), | 1014 base::Bind(&test_util::RunAndQuit), |
| 1020 test_util::CreateCopyResultCallback(&result_code, &upload_url)), | 1015 test_util::CreateCopyResultCallback(&result_code, &upload_url)), |
| 1021 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), | |
| 1022 "text/plain", | 1016 "text/plain", |
| 1023 kUploadContent.size(), | 1017 kUploadContent.size(), |
| 1024 "folder:id", | 1018 "folder:id", |
| 1025 "New file"); | 1019 "New file"); |
| 1026 | 1020 |
| 1027 request_sender_->StartRequestWithRetry(initiate_request); | 1021 request_sender_->StartRequestWithRetry(initiate_request); |
| 1028 base::MessageLoop::current()->Run(); | 1022 base::MessageLoop::current()->Run(); |
| 1029 | 1023 |
| 1030 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1024 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 1031 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); | 1025 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); |
| 1032 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 1026 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
| 1033 // convert=false should be passed as files should be uploaded as-is. | 1027 // convert=false should be passed as files should be uploaded as-is. |
| 1034 EXPECT_EQ( | 1028 EXPECT_EQ( |
| 1035 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents" | 1029 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents" |
| 1036 "?convert=false&v=3&alt=json&showroot=true", | 1030 "?convert=false&v=3&alt=json&showroot=true", |
| 1037 http_request_.relative_url); | 1031 http_request_.relative_url); |
| 1038 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 1032 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
| 1039 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 1033 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
| 1040 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 1034 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
| 1041 http_request_.headers["X-Upload-Content-Length"]); | 1035 http_request_.headers["X-Upload-Content-Length"]); |
| 1042 | 1036 |
| 1043 EXPECT_TRUE(http_request_.has_content); | 1037 EXPECT_TRUE(http_request_.has_content); |
| 1044 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 1038 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
| 1045 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " | 1039 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " |
| 1046 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" | 1040 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" |
| 1047 " <title>New file</title>\n" | 1041 " <title>New file</title>\n" |
| 1048 "</entry>\n", | 1042 "</entry>\n", |
| 1049 http_request_.content); | 1043 http_request_.content); |
| 1050 | 1044 |
| 1051 #if !defined(NO_GET_UPLOAD_STATUS_TEST) | |
| 1052 // 2) Before sending any data, check the current status. | 1045 // 2) Before sending any data, check the current status. |
| 1053 // This is an edge case test for GetUploadStatusRequest | 1046 // This is an edge case test for GetUploadStatusRequest |
| 1054 // (UploadRangeRequestBase). | 1047 // (UploadRangeRequestBase). |
| 1055 { | 1048 { |
| 1056 UploadRangeResponse response; | 1049 UploadRangeResponse response; |
| 1057 scoped_ptr<ResourceEntry> new_entry; | 1050 scoped_ptr<ResourceEntry> new_entry; |
| 1058 | 1051 |
| 1059 // Check the response by GetUploadStatusRequest. | 1052 // Check the response by GetUploadStatusRequest. |
| 1060 GetUploadStatusRequest* get_upload_status_request = | 1053 GetUploadStatusRequest* get_upload_status_request = |
| 1061 new GetUploadStatusRequest( | 1054 new GetUploadStatusRequest( |
| 1062 request_sender_.get(), | 1055 request_sender_.get(), |
| 1063 request_context_getter_.get(), | 1056 request_context_getter_.get(), |
| 1064 CreateComposedCallback( | 1057 CreateComposedCallback( |
| 1065 base::Bind(&test_util::RunAndQuit), | 1058 base::Bind(&test_util::RunAndQuit), |
| 1066 test_util::CreateCopyResultCallback(&response, &new_entry)), | 1059 test_util::CreateCopyResultCallback(&response, &new_entry)), |
| 1067 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), | |
| 1068 upload_url, | 1060 upload_url, |
| 1069 kUploadContent.size()); | 1061 kUploadContent.size()); |
| 1070 request_sender_->StartRequestWithRetry(get_upload_status_request); | 1062 request_sender_->StartRequestWithRetry(get_upload_status_request); |
| 1071 base::MessageLoop::current()->Run(); | 1063 base::MessageLoop::current()->Run(); |
| 1072 | 1064 |
| 1073 // METHOD_PUT should be used to upload data. | 1065 // METHOD_PUT should be used to upload data. |
| 1074 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1066 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
| 1075 // Request should go to the upload URL. | 1067 // Request should go to the upload URL. |
| 1076 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 1068 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
| 1077 // Content-Range header should be added. | 1069 // Content-Range header should be added. |
| 1078 EXPECT_EQ("bytes */" + base::Int64ToString(kUploadContent.size()), | 1070 EXPECT_EQ("bytes */" + base::Int64ToString(kUploadContent.size()), |
| 1079 http_request_.headers["Content-Range"]); | 1071 http_request_.headers["Content-Range"]); |
| 1080 EXPECT_TRUE(http_request_.has_content); | 1072 EXPECT_TRUE(http_request_.has_content); |
| 1081 EXPECT_TRUE(http_request_.content.empty()); | 1073 EXPECT_TRUE(http_request_.content.empty()); |
| 1082 | 1074 |
| 1083 // Check the response. | 1075 // Check the response. |
| 1084 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); | 1076 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); |
| 1085 EXPECT_EQ(0, response.start_position_received); | 1077 EXPECT_EQ(0, response.start_position_received); |
| 1086 EXPECT_EQ(0, response.end_position_received); | 1078 EXPECT_EQ(0, response.end_position_received); |
| 1087 } | 1079 } |
| 1088 #endif // NO_GET_UPLOAD_STATUS_TEST | |
| 1089 | 1080 |
| 1090 // 3) Upload the content to the upload URL with multiple requests. | 1081 // 3) Upload the content to the upload URL with multiple requests. |
| 1091 size_t num_bytes_consumed = 0; | 1082 size_t num_bytes_consumed = 0; |
| 1092 for (size_t start_position = 0; start_position < kUploadContent.size(); | 1083 for (size_t start_position = 0; start_position < kUploadContent.size(); |
| 1093 start_position += kMaxNumBytes) { | 1084 start_position += kMaxNumBytes) { |
| 1094 SCOPED_TRACE(testing::Message("start_position: ") << start_position); | 1085 SCOPED_TRACE(testing::Message("start_position: ") << start_position); |
| 1095 | 1086 |
| 1096 // The payload is at most kMaxNumBytes. | 1087 // The payload is at most kMaxNumBytes. |
| 1097 const size_t remaining_size = kUploadContent.size() - start_position; | 1088 const size_t remaining_size = kUploadContent.size() - start_position; |
| 1098 const std::string payload = kUploadContent.substr( | 1089 const std::string payload = kUploadContent.substr( |
| 1099 start_position, std::min(kMaxNumBytes, remaining_size)); | 1090 start_position, std::min(kMaxNumBytes, remaining_size)); |
| 1100 num_bytes_consumed += payload.size(); | 1091 num_bytes_consumed += payload.size(); |
| 1101 // The end position is exclusive. | 1092 // The end position is exclusive. |
| 1102 const size_t end_position = start_position + payload.size(); | 1093 const size_t end_position = start_position + payload.size(); |
| 1103 | 1094 |
| 1104 UploadRangeResponse response; | 1095 UploadRangeResponse response; |
| 1105 scoped_ptr<ResourceEntry> new_entry; | 1096 scoped_ptr<ResourceEntry> new_entry; |
| 1106 | 1097 |
| 1107 ResumeUploadRequest* resume_request = new ResumeUploadRequest( | 1098 ResumeUploadRequest* resume_request = new ResumeUploadRequest( |
| 1108 request_sender_.get(), | 1099 request_sender_.get(), |
| 1109 request_context_getter_.get(), | 1100 request_context_getter_.get(), |
| 1110 CreateComposedCallback( | 1101 CreateComposedCallback( |
| 1111 base::Bind(&test_util::RunAndQuit), | 1102 base::Bind(&test_util::RunAndQuit), |
| 1112 test_util::CreateCopyResultCallback(&response, &new_entry)), | 1103 test_util::CreateCopyResultCallback(&response, &new_entry)), |
| 1113 ProgressCallback(), | 1104 ProgressCallback(), |
| 1114 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), | |
| 1115 upload_url, | 1105 upload_url, |
| 1116 start_position, | 1106 start_position, |
| 1117 end_position, | 1107 end_position, |
| 1118 kUploadContent.size(), // content_length, | 1108 kUploadContent.size(), // content_length, |
| 1119 "text/plain", // content_type | 1109 "text/plain", // content_type |
| 1120 kTestFilePath); | 1110 kTestFilePath); |
| 1121 | 1111 |
| 1122 request_sender_->StartRequestWithRetry(resume_request); | 1112 request_sender_->StartRequestWithRetry(resume_request); |
| 1123 base::MessageLoop::current()->Run(); | 1113 base::MessageLoop::current()->Run(); |
| 1124 | 1114 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1145 EXPECT_EQ(-1, response.end_position_received); | 1135 EXPECT_EQ(-1, response.end_position_received); |
| 1146 // The upload process is completed, so exit from the loop. | 1136 // The upload process is completed, so exit from the loop. |
| 1147 break; | 1137 break; |
| 1148 } | 1138 } |
| 1149 | 1139 |
| 1150 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); | 1140 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); |
| 1151 EXPECT_EQ(0, response.start_position_received); | 1141 EXPECT_EQ(0, response.start_position_received); |
| 1152 EXPECT_EQ(static_cast<int64>(end_position), | 1142 EXPECT_EQ(static_cast<int64>(end_position), |
| 1153 response.end_position_received); | 1143 response.end_position_received); |
| 1154 | 1144 |
| 1155 #if !defined(NO_GET_UPLOAD_STATUS_TEST) | |
| 1156 // Check the response by GetUploadStatusRequest. | 1145 // Check the response by GetUploadStatusRequest. |
| 1157 GetUploadStatusRequest* get_upload_status_request = | 1146 GetUploadStatusRequest* get_upload_status_request = |
| 1158 new GetUploadStatusRequest( | 1147 new GetUploadStatusRequest( |
| 1159 request_sender_.get(), | 1148 request_sender_.get(), |
| 1160 request_context_getter_.get(), | 1149 request_context_getter_.get(), |
| 1161 CreateComposedCallback( | 1150 CreateComposedCallback( |
| 1162 base::Bind(&test_util::RunAndQuit), | 1151 base::Bind(&test_util::RunAndQuit), |
| 1163 test_util::CreateCopyResultCallback(&response, &new_entry)), | 1152 test_util::CreateCopyResultCallback(&response, &new_entry)), |
| 1164 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), | |
| 1165 upload_url, | 1153 upload_url, |
| 1166 kUploadContent.size()); | 1154 kUploadContent.size()); |
| 1167 request_sender_->StartRequestWithRetry(get_upload_request); | 1155 request_sender_->StartRequestWithRetry(get_upload_status_request); |
| 1168 base::MessageLoop::current()->Run(); | 1156 base::MessageLoop::current()->Run(); |
| 1169 | 1157 |
| 1170 // METHOD_PUT should be used to upload data. | 1158 // METHOD_PUT should be used to upload data. |
| 1171 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1159 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
| 1172 // Request should go to the upload URL. | 1160 // Request should go to the upload URL. |
| 1173 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 1161 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
| 1174 // Content-Range header should be added. | 1162 // Content-Range header should be added. |
| 1175 EXPECT_EQ("bytes */" + base::Int64ToString(kUploadContent.size()), | 1163 EXPECT_EQ("bytes */" + base::Int64ToString(kUploadContent.size()), |
| 1176 http_request_.headers["Content-Range"]); | 1164 http_request_.headers["Content-Range"]); |
| 1177 EXPECT_TRUE(http_request_.has_content); | 1165 EXPECT_TRUE(http_request_.has_content); |
| 1178 EXPECT_TRUE(http_request_.content.empty()); | 1166 EXPECT_TRUE(http_request_.content.empty()); |
| 1179 | 1167 |
| 1180 // Check the response. | 1168 // Check the response. |
| 1181 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); | 1169 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); |
| 1182 EXPECT_EQ(0, response.start_position_received); | 1170 EXPECT_EQ(0, response.start_position_received); |
| 1183 EXPECT_EQ(static_cast<int64>(end_position), | 1171 EXPECT_EQ(static_cast<int64>(end_position), |
| 1184 response.end_position_received); | 1172 response.end_position_received); |
| 1185 #endif // NO_GET_UPLOAD_STATUS_TEST | |
| 1186 } | 1173 } |
| 1187 | 1174 |
| 1188 EXPECT_EQ(kUploadContent.size(), num_bytes_consumed); | 1175 EXPECT_EQ(kUploadContent.size(), num_bytes_consumed); |
| 1189 } | 1176 } |
| 1190 | 1177 |
| 1191 // This test exercises InitiateUploadNewFileRequest and ResumeUploadRequest | 1178 // This test exercises InitiateUploadNewFileRequest and ResumeUploadRequest |
| 1192 // for a scenario of uploading a new *empty* file. | 1179 // for a scenario of uploading a new *empty* file. |
| 1193 // | 1180 // |
| 1194 // The test is almost identical to UploadNewFile. The only difference is the | 1181 // The test is almost identical to UploadNewFile. The only difference is the |
| 1195 // expectation for the Content-Range header. | 1182 // expectation for the Content-Range header. |
| 1196 TEST_F(GDataWapiRequestsTest, UploadNewEmptyFile) { | 1183 TEST_F(GDataWapiRequestsTest, UploadNewEmptyFile) { |
| 1197 const std::string kUploadContent; | 1184 const std::string kUploadContent; |
| 1198 const base::FilePath kTestFilePath = | 1185 const base::FilePath kTestFilePath = |
| 1199 temp_dir_.path().AppendASCII("empty_file.txt"); | 1186 temp_dir_.path().AppendASCII("empty_file.txt"); |
| 1200 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); | 1187 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); |
| 1201 | 1188 |
| 1202 GDataErrorCode result_code = GDATA_OTHER_ERROR; | 1189 GDataErrorCode result_code = GDATA_OTHER_ERROR; |
| 1203 GURL upload_url; | 1190 GURL upload_url; |
| 1204 | 1191 |
| 1205 // 1) Get the upload URL for uploading a new file. | 1192 // 1) Get the upload URL for uploading a new file. |
| 1206 InitiateUploadNewFileRequest* initiate_request = | 1193 InitiateUploadNewFileRequest* initiate_request = |
| 1207 new InitiateUploadNewFileRequest( | 1194 new InitiateUploadNewFileRequest( |
| 1208 request_sender_.get(), | 1195 request_sender_.get(), |
| 1209 request_context_getter_.get(), | 1196 request_context_getter_.get(), |
| 1210 *url_generator_, | 1197 *url_generator_, |
| 1211 CreateComposedCallback( | 1198 CreateComposedCallback( |
| 1212 base::Bind(&test_util::RunAndQuit), | 1199 base::Bind(&test_util::RunAndQuit), |
| 1213 test_util::CreateCopyResultCallback(&result_code, &upload_url)), | 1200 test_util::CreateCopyResultCallback(&result_code, &upload_url)), |
| 1214 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), | |
| 1215 "text/plain", | 1201 "text/plain", |
| 1216 kUploadContent.size(), | 1202 kUploadContent.size(), |
| 1217 "folder:id", | 1203 "folder:id", |
| 1218 "New file"); | 1204 "New file"); |
| 1219 | 1205 |
| 1220 request_sender_->StartRequestWithRetry(initiate_request); | 1206 request_sender_->StartRequestWithRetry(initiate_request); |
| 1221 base::MessageLoop::current()->Run(); | 1207 base::MessageLoop::current()->Run(); |
| 1222 | 1208 |
| 1223 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1209 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 1224 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); | 1210 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1245 UploadRangeResponse response; | 1231 UploadRangeResponse response; |
| 1246 scoped_ptr<ResourceEntry> new_entry; | 1232 scoped_ptr<ResourceEntry> new_entry; |
| 1247 | 1233 |
| 1248 ResumeUploadRequest* resume_request = new ResumeUploadRequest( | 1234 ResumeUploadRequest* resume_request = new ResumeUploadRequest( |
| 1249 request_sender_.get(), | 1235 request_sender_.get(), |
| 1250 request_context_getter_.get(), | 1236 request_context_getter_.get(), |
| 1251 CreateComposedCallback( | 1237 CreateComposedCallback( |
| 1252 base::Bind(&test_util::RunAndQuit), | 1238 base::Bind(&test_util::RunAndQuit), |
| 1253 test_util::CreateCopyResultCallback(&response, &new_entry)), | 1239 test_util::CreateCopyResultCallback(&response, &new_entry)), |
| 1254 ProgressCallback(), | 1240 ProgressCallback(), |
| 1255 base::FilePath::FromUTF8Unsafe("drive/newfile.txt"), | |
| 1256 upload_url, | 1241 upload_url, |
| 1257 0, // start_position | 1242 0, // start_position |
| 1258 kUploadContent.size(), // end_position (exclusive) | 1243 kUploadContent.size(), // end_position (exclusive) |
| 1259 kUploadContent.size(), // content_length, | 1244 kUploadContent.size(), // content_length, |
| 1260 "text/plain", // content_type | 1245 "text/plain", // content_type |
| 1261 kTestFilePath); | 1246 kTestFilePath); |
| 1262 | 1247 |
| 1263 request_sender_->StartRequestWithRetry(resume_request); | 1248 request_sender_->StartRequestWithRetry(resume_request); |
| 1264 base::MessageLoop::current()->Run(); | 1249 base::MessageLoop::current()->Run(); |
| 1265 | 1250 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1294 | 1279 |
| 1295 // 1) Get the upload URL for uploading an existing file. | 1280 // 1) Get the upload URL for uploading an existing file. |
| 1296 InitiateUploadExistingFileRequest* initiate_request = | 1281 InitiateUploadExistingFileRequest* initiate_request = |
| 1297 new InitiateUploadExistingFileRequest( | 1282 new InitiateUploadExistingFileRequest( |
| 1298 request_sender_.get(), | 1283 request_sender_.get(), |
| 1299 request_context_getter_.get(), | 1284 request_context_getter_.get(), |
| 1300 *url_generator_, | 1285 *url_generator_, |
| 1301 CreateComposedCallback( | 1286 CreateComposedCallback( |
| 1302 base::Bind(&test_util::RunAndQuit), | 1287 base::Bind(&test_util::RunAndQuit), |
| 1303 test_util::CreateCopyResultCallback(&result_code, &upload_url)), | 1288 test_util::CreateCopyResultCallback(&result_code, &upload_url)), |
| 1304 base::FilePath::FromUTF8Unsafe("drive/existingfile.txt"), | |
| 1305 "text/plain", | 1289 "text/plain", |
| 1306 kUploadContent.size(), | 1290 kUploadContent.size(), |
| 1307 "file:foo", | 1291 "file:foo", |
| 1308 std::string() /* etag */); | 1292 std::string() /* etag */); |
| 1309 | 1293 |
| 1310 request_sender_->StartRequestWithRetry(initiate_request); | 1294 request_sender_->StartRequestWithRetry(initiate_request); |
| 1311 base::MessageLoop::current()->Run(); | 1295 base::MessageLoop::current()->Run(); |
| 1312 | 1296 |
| 1313 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1297 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 1314 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); | 1298 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1334 UploadRangeResponse response; | 1318 UploadRangeResponse response; |
| 1335 scoped_ptr<ResourceEntry> new_entry; | 1319 scoped_ptr<ResourceEntry> new_entry; |
| 1336 | 1320 |
| 1337 ResumeUploadRequest* resume_request = new ResumeUploadRequest( | 1321 ResumeUploadRequest* resume_request = new ResumeUploadRequest( |
| 1338 request_sender_.get(), | 1322 request_sender_.get(), |
| 1339 request_context_getter_.get(), | 1323 request_context_getter_.get(), |
| 1340 CreateComposedCallback( | 1324 CreateComposedCallback( |
| 1341 base::Bind(&test_util::RunAndQuit), | 1325 base::Bind(&test_util::RunAndQuit), |
| 1342 test_util::CreateCopyResultCallback(&response, &new_entry)), | 1326 test_util::CreateCopyResultCallback(&response, &new_entry)), |
| 1343 ProgressCallback(), | 1327 ProgressCallback(), |
| 1344 base::FilePath::FromUTF8Unsafe("drive/existingfile.txt"), | |
| 1345 upload_url, | 1328 upload_url, |
| 1346 0, // start_position | 1329 0, // start_position |
| 1347 kUploadContent.size(), // end_position (exclusive) | 1330 kUploadContent.size(), // end_position (exclusive) |
| 1348 kUploadContent.size(), // content_length, | 1331 kUploadContent.size(), // content_length, |
| 1349 "text/plain", // content_type | 1332 "text/plain", // content_type |
| 1350 kTestFilePath); | 1333 kTestFilePath); |
| 1351 | 1334 |
| 1352 request_sender_->StartRequestWithRetry(resume_request); | 1335 request_sender_->StartRequestWithRetry(resume_request); |
| 1353 base::MessageLoop::current()->Run(); | 1336 base::MessageLoop::current()->Run(); |
| 1354 | 1337 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1385 | 1368 |
| 1386 // 1) Get the upload URL for uploading an existing file. | 1369 // 1) Get the upload URL for uploading an existing file. |
| 1387 InitiateUploadExistingFileRequest* initiate_request = | 1370 InitiateUploadExistingFileRequest* initiate_request = |
| 1388 new InitiateUploadExistingFileRequest( | 1371 new InitiateUploadExistingFileRequest( |
| 1389 request_sender_.get(), | 1372 request_sender_.get(), |
| 1390 request_context_getter_.get(), | 1373 request_context_getter_.get(), |
| 1391 *url_generator_, | 1374 *url_generator_, |
| 1392 CreateComposedCallback( | 1375 CreateComposedCallback( |
| 1393 base::Bind(&test_util::RunAndQuit), | 1376 base::Bind(&test_util::RunAndQuit), |
| 1394 test_util::CreateCopyResultCallback(&result_code, &upload_url)), | 1377 test_util::CreateCopyResultCallback(&result_code, &upload_url)), |
| 1395 base::FilePath::FromUTF8Unsafe("drive/existingfile.txt"), | |
| 1396 "text/plain", | 1378 "text/plain", |
| 1397 kUploadContent.size(), | 1379 kUploadContent.size(), |
| 1398 "file:foo", | 1380 "file:foo", |
| 1399 kTestETag); | 1381 kTestETag); |
| 1400 | 1382 |
| 1401 request_sender_->StartRequestWithRetry(initiate_request); | 1383 request_sender_->StartRequestWithRetry(initiate_request); |
| 1402 base::MessageLoop::current()->Run(); | 1384 base::MessageLoop::current()->Run(); |
| 1403 | 1385 |
| 1404 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1386 EXPECT_EQ(HTTP_SUCCESS, result_code); |
| 1405 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); | 1387 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1425 UploadRangeResponse response; | 1407 UploadRangeResponse response; |
| 1426 scoped_ptr<ResourceEntry> new_entry; | 1408 scoped_ptr<ResourceEntry> new_entry; |
| 1427 | 1409 |
| 1428 ResumeUploadRequest* resume_request = new ResumeUploadRequest( | 1410 ResumeUploadRequest* resume_request = new ResumeUploadRequest( |
| 1429 request_sender_.get(), | 1411 request_sender_.get(), |
| 1430 request_context_getter_.get(), | 1412 request_context_getter_.get(), |
| 1431 CreateComposedCallback( | 1413 CreateComposedCallback( |
| 1432 base::Bind(&test_util::RunAndQuit), | 1414 base::Bind(&test_util::RunAndQuit), |
| 1433 test_util::CreateCopyResultCallback(&response, &new_entry)), | 1415 test_util::CreateCopyResultCallback(&response, &new_entry)), |
| 1434 ProgressCallback(), | 1416 ProgressCallback(), |
| 1435 base::FilePath::FromUTF8Unsafe("drive/existingfile.txt"), | |
| 1436 upload_url, | 1417 upload_url, |
| 1437 0, // start_position | 1418 0, // start_position |
| 1438 kUploadContent.size(), // end_position (exclusive) | 1419 kUploadContent.size(), // end_position (exclusive) |
| 1439 kUploadContent.size(), // content_length, | 1420 kUploadContent.size(), // content_length, |
| 1440 "text/plain", // content_type | 1421 "text/plain", // content_type |
| 1441 kTestFilePath); | 1422 kTestFilePath); |
| 1442 | 1423 |
| 1443 request_sender_->StartRequestWithRetry(resume_request); | 1424 request_sender_->StartRequestWithRetry(resume_request); |
| 1444 base::MessageLoop::current()->Run(); | 1425 base::MessageLoop::current()->Run(); |
| 1445 | 1426 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1472 GURL upload_url; | 1453 GURL upload_url; |
| 1473 | 1454 |
| 1474 InitiateUploadExistingFileRequest* initiate_request = | 1455 InitiateUploadExistingFileRequest* initiate_request = |
| 1475 new InitiateUploadExistingFileRequest( | 1456 new InitiateUploadExistingFileRequest( |
| 1476 request_sender_.get(), | 1457 request_sender_.get(), |
| 1477 request_context_getter_.get(), | 1458 request_context_getter_.get(), |
| 1478 *url_generator_, | 1459 *url_generator_, |
| 1479 CreateComposedCallback( | 1460 CreateComposedCallback( |
| 1480 base::Bind(&test_util::RunAndQuit), | 1461 base::Bind(&test_util::RunAndQuit), |
| 1481 test_util::CreateCopyResultCallback(&result_code, &upload_url)), | 1462 test_util::CreateCopyResultCallback(&result_code, &upload_url)), |
| 1482 base::FilePath::FromUTF8Unsafe("drive/existingfile.txt"), | |
| 1483 "text/plain", | 1463 "text/plain", |
| 1484 kUploadContent.size(), | 1464 kUploadContent.size(), |
| 1485 "file:foo", | 1465 "file:foo", |
| 1486 kWrongETag); | 1466 kWrongETag); |
| 1487 | 1467 |
| 1488 request_sender_->StartRequestWithRetry(initiate_request); | 1468 request_sender_->StartRequestWithRetry(initiate_request); |
| 1489 base::MessageLoop::current()->Run(); | 1469 base::MessageLoop::current()->Run(); |
| 1490 | 1470 |
| 1491 EXPECT_EQ(HTTP_PRECONDITION, result_code); | 1471 EXPECT_EQ(HTTP_PRECONDITION, result_code); |
| 1492 // For updating an existing file, METHOD_PUT should be used. | 1472 // For updating an existing file, METHOD_PUT should be used. |
| 1493 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1473 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
| 1494 // convert=false should be passed as files should be uploaded as-is. | 1474 // convert=false should be passed as files should be uploaded as-is. |
| 1495 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo" | 1475 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo" |
| 1496 "?convert=false&v=3&alt=json&showroot=true", | 1476 "?convert=false&v=3&alt=json&showroot=true", |
| 1497 http_request_.relative_url); | 1477 http_request_.relative_url); |
| 1498 // Even though the body is empty, the content type should be set to | 1478 // Even though the body is empty, the content type should be set to |
| 1499 // "text/plain". | 1479 // "text/plain". |
| 1500 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); | 1480 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); |
| 1501 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 1481 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
| 1502 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 1482 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
| 1503 http_request_.headers["X-Upload-Content-Length"]); | 1483 http_request_.headers["X-Upload-Content-Length"]); |
| 1504 // For updating an existing file, an empty body should be attached (PUT | 1484 // For updating an existing file, an empty body should be attached (PUT |
| 1505 // requires a body) | 1485 // requires a body) |
| 1506 EXPECT_TRUE(http_request_.has_content); | 1486 EXPECT_TRUE(http_request_.has_content); |
| 1507 EXPECT_EQ("", http_request_.content); | 1487 EXPECT_EQ("", http_request_.content); |
| 1508 EXPECT_EQ(kWrongETag, http_request_.headers["If-Match"]); | 1488 EXPECT_EQ(kWrongETag, http_request_.headers["If-Match"]); |
| 1509 } | 1489 } |
| 1510 | 1490 |
| 1511 } // namespace google_apis | 1491 } // namespace google_apis |
| OLD | NEW |