| 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 "chrome/browser/google_apis/drive_uploader.h" | 5 #include "chrome/browser/google_apis/drive_uploader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstdlib> | 8 #include <cstdlib> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // Handles a request for uploading a chunk of bytes. | 115 // Handles a request for uploading a chunk of bytes. |
| 116 virtual void ResumeUpload( | 116 virtual void ResumeUpload( |
| 117 UploadMode upload_mode, | 117 UploadMode upload_mode, |
| 118 const base::FilePath& drive_file_path, | 118 const base::FilePath& drive_file_path, |
| 119 const GURL& upload_url, | 119 const GURL& upload_url, |
| 120 int64 start_position, | 120 int64 start_position, |
| 121 int64 end_position, | 121 int64 end_position, |
| 122 int64 content_length, | 122 int64 content_length, |
| 123 const std::string& content_type, | 123 const std::string& content_type, |
| 124 const scoped_refptr<net::IOBuffer>& buf, | 124 const scoped_refptr<net::IOBuffer>& buf, |
| 125 const UploadRangeCallback& callback) OVERRIDE { | 125 const UploadRangeCallback& callback, |
| 126 const ProgressCallback& progress_callback) OVERRIDE { |
| 126 const int64 expected_size = expected_upload_content_.size(); | 127 const int64 expected_size = expected_upload_content_.size(); |
| 127 | 128 |
| 128 // The upload range should start from the current first unreceived byte. | 129 // The upload range should start from the current first unreceived byte. |
| 129 EXPECT_EQ(received_bytes_, start_position); | 130 EXPECT_EQ(received_bytes_, start_position); |
| 130 | 131 |
| 131 // The upload data must be split into 512KB chunks. | 132 // The upload data must be split into 512KB chunks. |
| 132 const int64 expected_chunk_end = | 133 const int64 expected_chunk_end = |
| 133 std::min(received_bytes_ + kUploadChunkSize, expected_size); | 134 std::min(received_bytes_ + kUploadChunkSize, expected_size); |
| 134 EXPECT_EQ(expected_chunk_end, end_position); | 135 EXPECT_EQ(expected_chunk_end, end_position); |
| 135 | 136 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // Should not be used. | 204 // Should not be used. |
| 204 virtual void ResumeUpload( | 205 virtual void ResumeUpload( |
| 205 UploadMode upload_mode, | 206 UploadMode upload_mode, |
| 206 const base::FilePath& drive_file_path, | 207 const base::FilePath& drive_file_path, |
| 207 const GURL& upload_url, | 208 const GURL& upload_url, |
| 208 int64 start_position, | 209 int64 start_position, |
| 209 int64 end_position, | 210 int64 end_position, |
| 210 int64 content_length, | 211 int64 content_length, |
| 211 const std::string& content_type, | 212 const std::string& content_type, |
| 212 const scoped_refptr<net::IOBuffer>& buf, | 213 const scoped_refptr<net::IOBuffer>& buf, |
| 213 const UploadRangeCallback& callback) OVERRIDE { | 214 const UploadRangeCallback& callback, |
| 215 const ProgressCallback& progress_callback) OVERRIDE { |
| 214 NOTREACHED(); | 216 NOTREACHED(); |
| 215 } | 217 } |
| 216 }; | 218 }; |
| 217 | 219 |
| 218 // Mock DriveService that returns a failure at ResumeUpload(). | 220 // Mock DriveService that returns a failure at ResumeUpload(). |
| 219 class MockDriveServiceNoConnectionAtResume : public DummyDriveService { | 221 class MockDriveServiceNoConnectionAtResume : public DummyDriveService { |
| 220 // Succeeds and returns an upload location URL. | 222 // Succeeds and returns an upload location URL. |
| 221 virtual void InitiateUploadNewFile( | 223 virtual void InitiateUploadNewFile( |
| 222 const base::FilePath& drive_file_path, | 224 const base::FilePath& drive_file_path, |
| 223 const std::string& content_type, | 225 const std::string& content_type, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 243 // Returns error. | 245 // Returns error. |
| 244 virtual void ResumeUpload( | 246 virtual void ResumeUpload( |
| 245 UploadMode upload_mode, | 247 UploadMode upload_mode, |
| 246 const base::FilePath& drive_file_path, | 248 const base::FilePath& drive_file_path, |
| 247 const GURL& upload_url, | 249 const GURL& upload_url, |
| 248 int64 start_position, | 250 int64 start_position, |
| 249 int64 end_position, | 251 int64 end_position, |
| 250 int64 content_length, | 252 int64 content_length, |
| 251 const std::string& content_type, | 253 const std::string& content_type, |
| 252 const scoped_refptr<net::IOBuffer>& buf, | 254 const scoped_refptr<net::IOBuffer>& buf, |
| 253 const UploadRangeCallback& callback) OVERRIDE { | 255 const UploadRangeCallback& callback, |
| 256 const ProgressCallback& progress_callback) OVERRIDE { |
| 254 MessageLoop::current()->PostTask(FROM_HERE, | 257 MessageLoop::current()->PostTask(FROM_HERE, |
| 255 base::Bind(callback, | 258 base::Bind(callback, |
| 256 UploadRangeResponse(GDATA_NO_CONNECTION, -1, -1), | 259 UploadRangeResponse(GDATA_NO_CONNECTION, -1, -1), |
| 257 base::Passed(scoped_ptr<ResourceEntry>()))); | 260 base::Passed(scoped_ptr<ResourceEntry>()))); |
| 258 } | 261 } |
| 259 }; | 262 }; |
| 260 | 263 |
| 261 class DriveUploaderTest : public testing::Test { | 264 class DriveUploaderTest : public testing::Test { |
| 262 public: | 265 public: |
| 263 DriveUploaderTest() | 266 DriveUploaderTest() |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 "", // etag | 534 "", // etag |
| 532 test_util::CreateCopyResultCallback( | 535 test_util::CreateCopyResultCallback( |
| 533 &error, &drive_path, &file_path, &resource_entry)); | 536 &error, &drive_path, &file_path, &resource_entry)); |
| 534 test_util::RunBlockingPoolTask(); | 537 test_util::RunBlockingPoolTask(); |
| 535 | 538 |
| 536 // Should return failure without doing any attempt to connect to the server. | 539 // Should return failure without doing any attempt to connect to the server. |
| 537 EXPECT_EQ(DRIVE_UPLOAD_ERROR_NOT_FOUND, error); | 540 EXPECT_EQ(DRIVE_UPLOAD_ERROR_NOT_FOUND, error); |
| 538 } | 541 } |
| 539 | 542 |
| 540 } // namespace google_apis | 543 } // namespace google_apis |
| OLD | NEW |