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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 scoped_ptr<test_server::HttpResponse> HandleUploadRequest( | 322 scoped_ptr<test_server::HttpResponse> HandleUploadRequest( |
323 const test_server::HttpRequest& request) { | 323 const test_server::HttpRequest& request) { |
324 http_request_ = request; | 324 http_request_ = request; |
325 | 325 |
326 const GURL absolute_url = test_server_.GetURL(request.relative_url); | 326 const GURL absolute_url = test_server_.GetURL(request.relative_url); |
327 if (absolute_url.path() != "/upload_new_file" && | 327 if (absolute_url.path() != "/upload_new_file" && |
328 absolute_url.path() != "/upload_existing_file") { | 328 absolute_url.path() != "/upload_existing_file") { |
329 return scoped_ptr<test_server::HttpResponse>(); | 329 return scoped_ptr<test_server::HttpResponse>(); |
330 } | 330 } |
331 | 331 |
332 // TODO(satorux): We should create a correct entry for the uploaded file, | 332 // TODO(satorux): We should create a correct JSON data for the uploaded |
333 // but for now, just return entry.xml. | 333 // file, but for now, just return file_entry.json. |
334 scoped_ptr<test_server::HttpResponse> response = | 334 scoped_ptr<test_server::HttpResponse> response = |
335 test_util::CreateHttpResponseFromFile( | 335 test_util::CreateHttpResponseFromFile( |
336 test_util::GetTestFilePath("gdata/entry.xml")); | 336 test_util::GetTestFilePath("gdata/file_entry.json")); |
337 // response.code() is set to SUCCESS. Change it to CREATED if it's a new | 337 // response.code() is set to SUCCESS. Change it to CREATED if it's a new |
338 // file. | 338 // file. |
339 if (absolute_url.path() == "/upload_new_file") | 339 if (absolute_url.path() == "/upload_new_file") |
340 response->set_code(test_server::CREATED); | 340 response->set_code(test_server::CREATED); |
341 | 341 |
342 // Check if the Content-Range header is present. This must be present if | 342 // Check if the Content-Range header is present. This must be present if |
343 // the request body is not empty. | 343 // the request body is not empty. |
344 if (!request.content.empty()) { | 344 if (!request.content.empty()) { |
345 std::map<std::string, std::string>::const_iterator iter = | 345 std::map<std::string, std::string>::const_iterator iter = |
346 request.headers.find("Content-Range"); | 346 request.headers.find("Content-Range"); |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 initiate_params); | 886 initiate_params); |
887 | 887 |
888 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 888 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, |
889 base::Bind(&DoNothingForReAuthenticateCallback)); | 889 base::Bind(&DoNothingForReAuthenticateCallback)); |
890 MessageLoop::current()->Run(); | 890 MessageLoop::current()->Run(); |
891 | 891 |
892 EXPECT_EQ(HTTP_SUCCESS, result_code); | 892 EXPECT_EQ(HTTP_SUCCESS, result_code); |
893 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); | 893 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); |
894 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); | 894 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); |
895 // convert=false should be passed as files should be uploaded as-is. | 895 // convert=false should be passed as files should be uploaded as-is. |
896 EXPECT_EQ("/feeds/upload/create-session/default/private/full?convert=false", | 896 EXPECT_EQ("/feeds/upload/create-session/default/private/full" |
| 897 "?convert=false&v=3&alt=json", |
897 http_request_.relative_url); | 898 http_request_.relative_url); |
898 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 899 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
899 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 900 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
900 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 901 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
901 http_request_.headers["X-Upload-Content-Length"]); | 902 http_request_.headers["X-Upload-Content-Length"]); |
902 | 903 |
903 EXPECT_TRUE(http_request_.has_content); | 904 EXPECT_TRUE(http_request_.has_content); |
904 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 905 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
905 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " | 906 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " |
906 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" | 907 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 initiate_params); | 985 initiate_params); |
985 | 986 |
986 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 987 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, |
987 base::Bind(&DoNothingForReAuthenticateCallback)); | 988 base::Bind(&DoNothingForReAuthenticateCallback)); |
988 MessageLoop::current()->Run(); | 989 MessageLoop::current()->Run(); |
989 | 990 |
990 EXPECT_EQ(HTTP_SUCCESS, result_code); | 991 EXPECT_EQ(HTTP_SUCCESS, result_code); |
991 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); | 992 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); |
992 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); | 993 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); |
993 // convert=false should be passed as files should be uploaded as-is. | 994 // convert=false should be passed as files should be uploaded as-is. |
994 EXPECT_EQ("/feeds/upload/create-session/default/private/full?convert=false", | 995 EXPECT_EQ("/feeds/upload/create-session/default/private/full?convert=false" |
| 996 "&v=3&alt=json", |
995 http_request_.relative_url); | 997 http_request_.relative_url); |
996 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 998 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
997 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 999 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
998 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 1000 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
999 http_request_.headers["X-Upload-Content-Length"]); | 1001 http_request_.headers["X-Upload-Content-Length"]); |
1000 | 1002 |
1001 EXPECT_TRUE(http_request_.has_content); | 1003 EXPECT_TRUE(http_request_.has_content); |
1002 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 1004 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
1003 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " | 1005 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " |
1004 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" | 1006 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 initiate_params); | 1109 initiate_params); |
1108 | 1110 |
1109 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 1111 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, |
1110 base::Bind(&DoNothingForReAuthenticateCallback)); | 1112 base::Bind(&DoNothingForReAuthenticateCallback)); |
1111 MessageLoop::current()->Run(); | 1113 MessageLoop::current()->Run(); |
1112 | 1114 |
1113 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1115 EXPECT_EQ(HTTP_SUCCESS, result_code); |
1114 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); | 1116 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); |
1115 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); | 1117 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); |
1116 // convert=false should be passed as files should be uploaded as-is. | 1118 // convert=false should be passed as files should be uploaded as-is. |
1117 EXPECT_EQ("/feeds/upload/create-session/default/private/full?convert=false", | 1119 EXPECT_EQ("/feeds/upload/create-session/default/private/full?convert=false" |
| 1120 "&v=3&alt=json", |
1118 http_request_.relative_url); | 1121 http_request_.relative_url); |
1119 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 1122 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
1120 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 1123 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
1121 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 1124 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
1122 http_request_.headers["X-Upload-Content-Length"]); | 1125 http_request_.headers["X-Upload-Content-Length"]); |
1123 | 1126 |
1124 EXPECT_TRUE(http_request_.has_content); | 1127 EXPECT_TRUE(http_request_.has_content); |
1125 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 1128 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
1126 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " | 1129 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " |
1127 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" | 1130 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 1205 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, |
1203 base::Bind(&DoNothingForReAuthenticateCallback)); | 1206 base::Bind(&DoNothingForReAuthenticateCallback)); |
1204 MessageLoop::current()->Run(); | 1207 MessageLoop::current()->Run(); |
1205 | 1208 |
1206 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1209 EXPECT_EQ(HTTP_SUCCESS, result_code); |
1207 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); | 1210 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); |
1208 // For updating an existing file, METHOD_PUT should be used. | 1211 // For updating an existing file, METHOD_PUT should be used. |
1209 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); | 1212 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); |
1210 // convert=false should be passed as files should be uploaded as-is. | 1213 // convert=false should be passed as files should be uploaded as-is. |
1211 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file:foo" | 1214 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file:foo" |
1212 "?convert=false", | 1215 "?convert=false&v=3&alt=json", |
1213 http_request_.relative_url); | 1216 http_request_.relative_url); |
1214 // Even though the body is empty, the content type should be set to | 1217 // Even though the body is empty, the content type should be set to |
1215 // "text/plain". | 1218 // "text/plain". |
1216 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); | 1219 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); |
1217 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 1220 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
1218 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 1221 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
1219 http_request_.headers["X-Upload-Content-Length"]); | 1222 http_request_.headers["X-Upload-Content-Length"]); |
1220 // For updating an existing file, an empty body should be attached (PUT | 1223 // For updating an existing file, an empty body should be attached (PUT |
1221 // requires a body) | 1224 // requires a body) |
1222 EXPECT_TRUE(http_request_.has_content); | 1225 EXPECT_TRUE(http_request_.has_content); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1263 EXPECT_EQ(kUploadContent, http_request_.content); | 1266 EXPECT_EQ(kUploadContent, http_request_.content); |
1264 | 1267 |
1265 // Check the response. | 1268 // Check the response. |
1266 EXPECT_EQ(HTTP_SUCCESS, response.code); // Because it's an existing file. | 1269 EXPECT_EQ(HTTP_SUCCESS, response.code); // Because it's an existing file. |
1267 // The start and end positions should be set to -1, if an upload is complete. | 1270 // The start and end positions should be set to -1, if an upload is complete. |
1268 EXPECT_EQ(-1, response.start_position_received); | 1271 EXPECT_EQ(-1, response.start_position_received); |
1269 EXPECT_EQ(-1, response.end_position_received); | 1272 EXPECT_EQ(-1, response.end_position_received); |
1270 } | 1273 } |
1271 | 1274 |
1272 } // namespace google_apis | 1275 } // namespace google_apis |
OLD | NEW |