| 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 <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
| 5 #include "base/bind.h" | 8 #include "base/bind.h" |
| 6 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 7 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 10 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 12 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 14 #include "base/values.h" | 17 #include "base/values.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 return true; | 88 return true; |
| 86 } | 89 } |
| 87 void NotifyError(DriveApiErrorCode code) override { callback_.Run(); } | 90 void NotifyError(DriveApiErrorCode code) override { callback_.Run(); } |
| 88 void NotifyResult(DriveApiErrorCode code, | 91 void NotifyResult(DriveApiErrorCode code, |
| 89 const std::string& body, | 92 const std::string& body, |
| 90 const base::Closure& closure) override { | 93 const base::Closure& closure) override { |
| 91 callback_.Run(); | 94 callback_.Run(); |
| 92 closure.Run(); | 95 closure.Run(); |
| 93 } | 96 } |
| 94 void NotifyUploadProgress(const net::URLFetcher* source, | 97 void NotifyUploadProgress(const net::URLFetcher* source, |
| 95 int64 current, | 98 int64_t current, |
| 96 int64 total) override { | 99 int64_t total) override { |
| 97 progress_values_.push_back(current); | 100 progress_values_.push_back(current); |
| 98 } | 101 } |
| 99 const std::vector<int64>& progress_values() const { return progress_values_; } | 102 const std::vector<int64_t>& progress_values() const { |
| 103 return progress_values_; |
| 104 } |
| 100 | 105 |
| 101 private: | 106 private: |
| 102 GURL url_; | 107 GURL url_; |
| 103 std::string content_type_; | 108 std::string content_type_; |
| 104 std::string content_data_; | 109 std::string content_data_; |
| 105 base::Closure callback_; | 110 base::Closure callback_; |
| 106 std::vector<int64> progress_values_; | 111 std::vector<int64_t> progress_values_; |
| 107 }; | 112 }; |
| 108 | 113 |
| 109 void EmptyPreapreCallback(DriveApiErrorCode) { | 114 void EmptyPreapreCallback(DriveApiErrorCode) { |
| 110 } | 115 } |
| 111 void EmptyClosure() { | 116 void EmptyClosure() { |
| 112 } | 117 } |
| 113 | 118 |
| 114 } // namespace | 119 } // namespace |
| 115 | 120 |
| 116 class DriveApiRequestsTest : public testing::Test { | 121 class DriveApiRequestsTest : public testing::Test { |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 | 357 |
| 353 http_request_ = request; | 358 http_request_ = request; |
| 354 | 359 |
| 355 if (!request.content.empty()) { | 360 if (!request.content.empty()) { |
| 356 auto iter = request.headers.find("Content-Range"); | 361 auto iter = request.headers.find("Content-Range"); |
| 357 if (iter == request.headers.end()) { | 362 if (iter == request.headers.end()) { |
| 358 // The range must be set. | 363 // The range must be set. |
| 359 return scoped_ptr<net::test_server::HttpResponse>(); | 364 return scoped_ptr<net::test_server::HttpResponse>(); |
| 360 } | 365 } |
| 361 | 366 |
| 362 int64 length = 0; | 367 int64_t length = 0; |
| 363 int64 start_position = 0; | 368 int64_t start_position = 0; |
| 364 int64 end_position = 0; | 369 int64_t end_position = 0; |
| 365 if (!test_util::ParseContentRangeHeader( | 370 if (!test_util::ParseContentRangeHeader( |
| 366 iter->second, &start_position, &end_position, &length)) { | 371 iter->second, &start_position, &end_position, &length)) { |
| 367 // Invalid "Content-Range" value. | 372 // Invalid "Content-Range" value. |
| 368 return scoped_ptr<net::test_server::HttpResponse>(); | 373 return scoped_ptr<net::test_server::HttpResponse>(); |
| 369 } | 374 } |
| 370 | 375 |
| 371 EXPECT_EQ(start_position, received_bytes_); | 376 EXPECT_EQ(start_position, received_bytes_); |
| 372 EXPECT_EQ(length, content_length_); | 377 EXPECT_EQ(length, content_length_); |
| 373 | 378 |
| 374 // end_position is inclusive, but so +1 to change the range to byte size. | 379 // end_position is inclusive, but so +1 to change the range to byte size. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 "Content-Type: application/json; charset=UTF-8\r\n" | 486 "Content-Type: application/json; charset=UTF-8\r\n" |
| 482 "\r\n" | 487 "\r\n" |
| 483 "{\"error\":{\"errors\": [" | 488 "{\"error\":{\"errors\": [" |
| 484 " {\"reason\": \"userRateLimitExceeded\"}]}}\r\n" | 489 " {\"reason\": \"userRateLimitExceeded\"}]}}\r\n" |
| 485 "\r\n" | 490 "\r\n" |
| 486 "--BOUNDARY--\r\n"); | 491 "--BOUNDARY--\r\n"); |
| 487 return response.Pass(); | 492 return response.Pass(); |
| 488 } | 493 } |
| 489 | 494 |
| 490 // These are for the current upload file status. | 495 // These are for the current upload file status. |
| 491 int64 received_bytes_; | 496 int64_t received_bytes_; |
| 492 int64 content_length_; | 497 int64_t content_length_; |
| 493 }; | 498 }; |
| 494 | 499 |
| 495 TEST_F(DriveApiRequestsTest, DriveApiDataRequest_Fields) { | 500 TEST_F(DriveApiRequestsTest, DriveApiDataRequest_Fields) { |
| 496 // Make sure that "fields" query param is supported by using its subclass, | 501 // Make sure that "fields" query param is supported by using its subclass, |
| 497 // AboutGetRequest. | 502 // AboutGetRequest. |
| 498 | 503 |
| 499 // Set an expected data file containing valid result. | 504 // Set an expected data file containing valid result. |
| 500 expected_data_file_path_ = test_util::GetTestFilePath( | 505 expected_data_file_path_ = test_util::GetTestFilePath( |
| 501 "drive/about.json"); | 506 "drive/about.json"); |
| 502 | 507 |
| (...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1366 // The start and end positions should be set to -1, if an upload is | 1371 // The start and end positions should be set to -1, if an upload is |
| 1367 // complete. | 1372 // complete. |
| 1368 EXPECT_EQ(-1, response.start_position_received); | 1373 EXPECT_EQ(-1, response.start_position_received); |
| 1369 EXPECT_EQ(-1, response.end_position_received); | 1374 EXPECT_EQ(-1, response.end_position_received); |
| 1370 break; | 1375 break; |
| 1371 } | 1376 } |
| 1372 | 1377 |
| 1373 // Check the response. | 1378 // Check the response. |
| 1374 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); | 1379 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); |
| 1375 EXPECT_EQ(0, response.start_position_received); | 1380 EXPECT_EQ(0, response.start_position_received); |
| 1376 EXPECT_EQ(static_cast<int64>(end_position), response.end_position_received); | 1381 EXPECT_EQ(static_cast<int64_t>(end_position), |
| 1382 response.end_position_received); |
| 1377 | 1383 |
| 1378 // Check the response by GetUploadStatusRequest. | 1384 // Check the response by GetUploadStatusRequest. |
| 1379 { | 1385 { |
| 1380 base::RunLoop run_loop; | 1386 base::RunLoop run_loop; |
| 1381 drive::GetUploadStatusRequest* get_upload_status_request = | 1387 drive::GetUploadStatusRequest* get_upload_status_request = |
| 1382 new drive::GetUploadStatusRequest( | 1388 new drive::GetUploadStatusRequest( |
| 1383 request_sender_.get(), | 1389 request_sender_.get(), |
| 1384 upload_url, | 1390 upload_url, |
| 1385 kTestContent.size(), | 1391 kTestContent.size(), |
| 1386 test_util::CreateQuitCallback( | 1392 test_util::CreateQuitCallback( |
| 1387 &run_loop, | 1393 &run_loop, |
| 1388 test_util::CreateCopyResultCallback(&response, &new_entry))); | 1394 test_util::CreateCopyResultCallback(&response, &new_entry))); |
| 1389 request_sender_->StartRequestWithAuthRetry(get_upload_status_request); | 1395 request_sender_->StartRequestWithAuthRetry(get_upload_status_request); |
| 1390 run_loop.Run(); | 1396 run_loop.Run(); |
| 1391 } | 1397 } |
| 1392 | 1398 |
| 1393 // METHOD_PUT should be used to upload data. | 1399 // METHOD_PUT should be used to upload data. |
| 1394 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1400 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
| 1395 // Request should go to the upload URL. | 1401 // Request should go to the upload URL. |
| 1396 EXPECT_EQ(upload_url.path(), http_request_.relative_url); | 1402 EXPECT_EQ(upload_url.path(), http_request_.relative_url); |
| 1397 // Content-Range header should be added. | 1403 // Content-Range header should be added. |
| 1398 EXPECT_EQ("bytes */" + base::SizeTToString(kTestContent.size()), | 1404 EXPECT_EQ("bytes */" + base::SizeTToString(kTestContent.size()), |
| 1399 http_request_.headers["Content-Range"]); | 1405 http_request_.headers["Content-Range"]); |
| 1400 EXPECT_TRUE(http_request_.has_content); | 1406 EXPECT_TRUE(http_request_.has_content); |
| 1401 EXPECT_TRUE(http_request_.content.empty()); | 1407 EXPECT_TRUE(http_request_.content.empty()); |
| 1402 | 1408 |
| 1403 // Check the response. | 1409 // Check the response. |
| 1404 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); | 1410 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); |
| 1405 EXPECT_EQ(0, response.start_position_received); | 1411 EXPECT_EQ(0, response.start_position_received); |
| 1406 EXPECT_EQ(static_cast<int64>(end_position), | 1412 EXPECT_EQ(static_cast<int64_t>(end_position), |
| 1407 response.end_position_received); | 1413 response.end_position_received); |
| 1408 } | 1414 } |
| 1409 } | 1415 } |
| 1410 | 1416 |
| 1411 TEST_F(DriveApiRequestsTest, UploadNewFileWithMetadataRequest) { | 1417 TEST_F(DriveApiRequestsTest, UploadNewFileWithMetadataRequest) { |
| 1412 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; | 1418 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; |
| 1413 const base::Time::Exploded kLastViewedByMeDate = | 1419 const base::Time::Exploded kLastViewedByMeDate = |
| 1414 {2013, 7, 0, 19, 15, 59, 13, 123}; | 1420 {2013, 7, 0, 19, 15, 59, 13, 123}; |
| 1415 | 1421 |
| 1416 // Set an expected url for uploading. | 1422 // Set an expected url for uploading. |
| (...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2282 "Header: value\r\n" | 2288 "Header: value\r\n" |
| 2283 "\r\n" | 2289 "\r\n" |
| 2284 "BODY\r\n" | 2290 "BODY\r\n" |
| 2285 "--BOUNDARY-- \t", | 2291 "--BOUNDARY-- \t", |
| 2286 &parts)); | 2292 &parts)); |
| 2287 ASSERT_EQ(1u, parts.size()); | 2293 ASSERT_EQ(1u, parts.size()); |
| 2288 EXPECT_EQ(HTTP_SUCCESS, parts[0].code); | 2294 EXPECT_EQ(HTTP_SUCCESS, parts[0].code); |
| 2289 EXPECT_EQ("BODY", parts[0].body); | 2295 EXPECT_EQ("BODY", parts[0].body); |
| 2290 } | 2296 } |
| 2291 } // namespace google_apis | 2297 } // namespace google_apis |
| OLD | NEW |