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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 scoped_ptr<test_server::HttpResponse> HandleUploadRequest( | 344 scoped_ptr<test_server::HttpResponse> HandleUploadRequest( |
345 const test_server::HttpRequest& request) { | 345 const test_server::HttpRequest& request) { |
346 http_request_ = request; | 346 http_request_ = request; |
347 | 347 |
348 const GURL absolute_url = test_server_.GetURL(request.relative_url); | 348 const GURL absolute_url = test_server_.GetURL(request.relative_url); |
349 if (absolute_url.path() != "/upload_new_file" && | 349 if (absolute_url.path() != "/upload_new_file" && |
350 absolute_url.path() != "/upload_existing_file") { | 350 absolute_url.path() != "/upload_existing_file") { |
351 return scoped_ptr<test_server::HttpResponse>(); | 351 return scoped_ptr<test_server::HttpResponse>(); |
352 } | 352 } |
353 | 353 |
354 // TODO(satorux): We should create a correct entry for the uploaded file, | 354 // TODO(satorux): We should create a correct JSON data for the uploaded |
355 // but for now, just return entry.xml. | 355 // file, but for now, just return file_entry.json. |
356 scoped_ptr<test_server::HttpResponse> response = | 356 scoped_ptr<test_server::HttpResponse> response = |
357 CreateHttpResponseFromFile( | 357 CreateHttpResponseFromFile( |
358 test_util::GetTestFilePath("gdata/entry.xml")); | 358 test_util::GetTestFilePath("gdata/file_entry.json")); |
359 // response.code() is set to SUCCESS. Change it to CREATED if it's a new | 359 // response.code() is set to SUCCESS. Change it to CREATED if it's a new |
360 // file. | 360 // file. |
361 if (absolute_url.path() == "/upload_new_file") | 361 if (absolute_url.path() == "/upload_new_file") |
362 response->set_code(test_server::CREATED); | 362 response->set_code(test_server::CREATED); |
363 | 363 |
364 // Check if the Content-Range header is present. This must be present if | 364 // Check if the Content-Range header is present. This must be present if |
365 // the request body is not empty. | 365 // the request body is not empty. |
366 if (!request.content.empty()) { | 366 if (!request.content.empty()) { |
367 std::map<std::string, std::string>::const_iterator iter = | 367 std::map<std::string, std::string>::const_iterator iter = |
368 request.headers.find("Content-Range"); | 368 request.headers.find("Content-Range"); |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 initiate_params); | 908 initiate_params); |
909 | 909 |
910 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 910 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, |
911 base::Bind(&DoNothingForReAuthenticateCallback)); | 911 base::Bind(&DoNothingForReAuthenticateCallback)); |
912 MessageLoop::current()->Run(); | 912 MessageLoop::current()->Run(); |
913 | 913 |
914 EXPECT_EQ(HTTP_SUCCESS, result_code); | 914 EXPECT_EQ(HTTP_SUCCESS, result_code); |
915 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); | 915 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); |
916 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); | 916 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); |
917 // convert=false should be passed as files should be uploaded as-is. | 917 // convert=false should be passed as files should be uploaded as-is. |
918 EXPECT_EQ("/feeds/upload/create-session/default/private/full?convert=false", | 918 EXPECT_EQ("/feeds/upload/create-session/default/private/full" |
| 919 "?convert=false&v=3&alt=json", |
919 http_request_.relative_url); | 920 http_request_.relative_url); |
920 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 921 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
921 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 922 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
922 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 923 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
923 http_request_.headers["X-Upload-Content-Length"]); | 924 http_request_.headers["X-Upload-Content-Length"]); |
924 | 925 |
925 EXPECT_TRUE(http_request_.has_content); | 926 EXPECT_TRUE(http_request_.has_content); |
926 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 927 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
927 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " | 928 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " |
928 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" | 929 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 initiate_params); | 1007 initiate_params); |
1007 | 1008 |
1008 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 1009 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, |
1009 base::Bind(&DoNothingForReAuthenticateCallback)); | 1010 base::Bind(&DoNothingForReAuthenticateCallback)); |
1010 MessageLoop::current()->Run(); | 1011 MessageLoop::current()->Run(); |
1011 | 1012 |
1012 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1013 EXPECT_EQ(HTTP_SUCCESS, result_code); |
1013 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); | 1014 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); |
1014 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); | 1015 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); |
1015 // convert=false should be passed as files should be uploaded as-is. | 1016 // convert=false should be passed as files should be uploaded as-is. |
1016 EXPECT_EQ("/feeds/upload/create-session/default/private/full?convert=false", | 1017 EXPECT_EQ("/feeds/upload/create-session/default/private/full?convert=false" |
| 1018 "&v=3&alt=json", |
1017 http_request_.relative_url); | 1019 http_request_.relative_url); |
1018 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 1020 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
1019 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 1021 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
1020 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 1022 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
1021 http_request_.headers["X-Upload-Content-Length"]); | 1023 http_request_.headers["X-Upload-Content-Length"]); |
1022 | 1024 |
1023 EXPECT_TRUE(http_request_.has_content); | 1025 EXPECT_TRUE(http_request_.has_content); |
1024 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 1026 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
1025 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " | 1027 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " |
1026 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" | 1028 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 initiate_params); | 1131 initiate_params); |
1130 | 1132 |
1131 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 1133 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, |
1132 base::Bind(&DoNothingForReAuthenticateCallback)); | 1134 base::Bind(&DoNothingForReAuthenticateCallback)); |
1133 MessageLoop::current()->Run(); | 1135 MessageLoop::current()->Run(); |
1134 | 1136 |
1135 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1137 EXPECT_EQ(HTTP_SUCCESS, result_code); |
1136 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); | 1138 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); |
1137 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); | 1139 EXPECT_EQ(test_server::METHOD_POST, http_request_.method); |
1138 // convert=false should be passed as files should be uploaded as-is. | 1140 // convert=false should be passed as files should be uploaded as-is. |
1139 EXPECT_EQ("/feeds/upload/create-session/default/private/full?convert=false", | 1141 EXPECT_EQ("/feeds/upload/create-session/default/private/full?convert=false" |
| 1142 "&v=3&alt=json", |
1140 http_request_.relative_url); | 1143 http_request_.relative_url); |
1141 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 1144 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
1142 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); | 1145 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); |
1143 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 1146 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
1144 http_request_.headers["X-Upload-Content-Length"]); | 1147 http_request_.headers["X-Upload-Content-Length"]); |
1145 | 1148 |
1146 EXPECT_TRUE(http_request_.has_content); | 1149 EXPECT_TRUE(http_request_.has_content); |
1147 EXPECT_EQ("<?xml version=\"1.0\"?>\n" | 1150 EXPECT_EQ("<?xml version=\"1.0\"?>\n" |
1148 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " | 1151 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " |
1149 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" | 1152 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, | 1227 initiate_operation->Start(kTestGDataAuthToken, kTestUserAgent, |
1225 base::Bind(&DoNothingForReAuthenticateCallback)); | 1228 base::Bind(&DoNothingForReAuthenticateCallback)); |
1226 MessageLoop::current()->Run(); | 1229 MessageLoop::current()->Run(); |
1227 | 1230 |
1228 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1231 EXPECT_EQ(HTTP_SUCCESS, result_code); |
1229 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); | 1232 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); |
1230 // For updating an existing file, METHOD_PUT should be used. | 1233 // For updating an existing file, METHOD_PUT should be used. |
1231 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); | 1234 EXPECT_EQ(test_server::METHOD_PUT, http_request_.method); |
1232 // convert=false should be passed as files should be uploaded as-is. | 1235 // convert=false should be passed as files should be uploaded as-is. |
1233 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file:foo" | 1236 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file:foo" |
1234 "?convert=false", | 1237 "?convert=false&v=3&alt=json", |
1235 http_request_.relative_url); | 1238 http_request_.relative_url); |
1236 // Even though the body is empty, the content type should be set to | 1239 // Even though the body is empty, the content type should be set to |
1237 // "text/plain". | 1240 // "text/plain". |
1238 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); | 1241 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); |
1239 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); | 1242 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); |
1240 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), | 1243 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), |
1241 http_request_.headers["X-Upload-Content-Length"]); | 1244 http_request_.headers["X-Upload-Content-Length"]); |
1242 // For updating an existing file, an empty body should be attached (PUT | 1245 // For updating an existing file, an empty body should be attached (PUT |
1243 // requires a body) | 1246 // requires a body) |
1244 EXPECT_TRUE(http_request_.has_content); | 1247 EXPECT_TRUE(http_request_.has_content); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 EXPECT_EQ(kUploadContent, http_request_.content); | 1288 EXPECT_EQ(kUploadContent, http_request_.content); |
1286 | 1289 |
1287 // Check the response. | 1290 // Check the response. |
1288 EXPECT_EQ(HTTP_SUCCESS, response.code); // Because it's an existing file. | 1291 EXPECT_EQ(HTTP_SUCCESS, response.code); // Because it's an existing file. |
1289 // The start and end positions should be set to -1, if an upload is complete. | 1292 // The start and end positions should be set to -1, if an upload is complete. |
1290 EXPECT_EQ(-1, response.start_position_received); | 1293 EXPECT_EQ(-1, response.start_position_received); |
1291 EXPECT_EQ(-1, response.end_position_received); | 1294 EXPECT_EQ(-1, response.end_position_received); |
1292 } | 1295 } |
1293 | 1296 |
1294 } // namespace google_apis | 1297 } // namespace google_apis |
OLD | NEW |