| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 resume_upload_call_count_(0) {} | 61 resume_upload_call_count_(0) {} |
| 62 | 62 |
| 63 int64 received_bytes() const { return received_bytes_; } | 63 int64 received_bytes() const { return received_bytes_; } |
| 64 | 64 |
| 65 int64 resume_upload_call_count() const { return resume_upload_call_count_; } | 65 int64 resume_upload_call_count() const { return resume_upload_call_count_; } |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 // DriveServiceInterface overrides. | 68 // DriveServiceInterface overrides. |
| 69 // Handles a request for obtaining an upload location URL. | 69 // Handles a request for obtaining an upload location URL. |
| 70 virtual void InitiateUploadNewFile( | 70 virtual void InitiateUploadNewFile( |
| 71 const FilePath& drive_file_path, | 71 const base::FilePath& drive_file_path, |
| 72 const std::string& content_type, | 72 const std::string& content_type, |
| 73 int64 content_length, | 73 int64 content_length, |
| 74 const GURL& parent_upload_url, | 74 const GURL& parent_upload_url, |
| 75 const std::string& title, | 75 const std::string& title, |
| 76 const InitiateUploadCallback& callback) OVERRIDE { | 76 const InitiateUploadCallback& callback) OVERRIDE { |
| 77 EXPECT_EQ(kTestDocumentTitle, title); | 77 EXPECT_EQ(kTestDocumentTitle, title); |
| 78 EXPECT_EQ(kTestMimeType, content_type); | 78 EXPECT_EQ(kTestMimeType, content_type); |
| 79 const int64 expected_size = expected_upload_content_.size(); | 79 const int64 expected_size = expected_upload_content_.size(); |
| 80 EXPECT_EQ(expected_size, content_length); | 80 EXPECT_EQ(expected_size, content_length); |
| 81 EXPECT_EQ(GURL(kTestInitialUploadURL), parent_upload_url); | 81 EXPECT_EQ(GURL(kTestInitialUploadURL), parent_upload_url); |
| 82 | 82 |
| 83 // Calls back the upload URL for subsequent ResumeUpload operations. | 83 // Calls back the upload URL for subsequent ResumeUpload operations. |
| 84 // InitiateUpload is an asynchronous function, so don't callback directly. | 84 // InitiateUpload is an asynchronous function, so don't callback directly. |
| 85 MessageLoop::current()->PostTask(FROM_HERE, | 85 MessageLoop::current()->PostTask(FROM_HERE, |
| 86 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadURL))); | 86 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadURL))); |
| 87 } | 87 } |
| 88 | 88 |
| 89 virtual void InitiateUploadExistingFile( | 89 virtual void InitiateUploadExistingFile( |
| 90 const FilePath& drive_file_path, | 90 const base::FilePath& drive_file_path, |
| 91 const std::string& content_type, | 91 const std::string& content_type, |
| 92 int64 content_length, | 92 int64 content_length, |
| 93 const GURL& upload_url, | 93 const GURL& upload_url, |
| 94 const std::string& etag, | 94 const std::string& etag, |
| 95 const InitiateUploadCallback& callback) OVERRIDE { | 95 const InitiateUploadCallback& callback) OVERRIDE { |
| 96 EXPECT_EQ(kTestMimeType, content_type); | 96 EXPECT_EQ(kTestMimeType, content_type); |
| 97 const int64 expected_size = expected_upload_content_.size(); | 97 const int64 expected_size = expected_upload_content_.size(); |
| 98 EXPECT_EQ(expected_size, content_length); | 98 EXPECT_EQ(expected_size, content_length); |
| 99 EXPECT_EQ(GURL(kTestInitialUploadURL), upload_url); | 99 EXPECT_EQ(GURL(kTestInitialUploadURL), upload_url); |
| 100 | 100 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 164 |
| 165 std::string expected_upload_content_; | 165 std::string expected_upload_content_; |
| 166 int64 received_bytes_; | 166 int64 received_bytes_; |
| 167 int64 resume_upload_call_count_; | 167 int64 resume_upload_call_count_; |
| 168 }; | 168 }; |
| 169 | 169 |
| 170 // Mock DriveService that returns a failure at InitiateUpload(). | 170 // Mock DriveService that returns a failure at InitiateUpload(). |
| 171 class MockDriveServiceNoConnectionAtInitiate : public DummyDriveService { | 171 class MockDriveServiceNoConnectionAtInitiate : public DummyDriveService { |
| 172 // Returns error. | 172 // Returns error. |
| 173 virtual void InitiateUploadNewFile( | 173 virtual void InitiateUploadNewFile( |
| 174 const FilePath& drive_file_path, | 174 const base::FilePath& drive_file_path, |
| 175 const std::string& content_type, | 175 const std::string& content_type, |
| 176 int64 content_length, | 176 int64 content_length, |
| 177 const GURL& parent_upload_url, | 177 const GURL& parent_upload_url, |
| 178 const std::string& title, | 178 const std::string& title, |
| 179 const InitiateUploadCallback& callback) OVERRIDE { | 179 const InitiateUploadCallback& callback) OVERRIDE { |
| 180 MessageLoop::current()->PostTask(FROM_HERE, | 180 MessageLoop::current()->PostTask(FROM_HERE, |
| 181 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); | 181 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); |
| 182 } | 182 } |
| 183 | 183 |
| 184 virtual void InitiateUploadExistingFile( | 184 virtual void InitiateUploadExistingFile( |
| 185 const FilePath& drive_file_path, | 185 const base::FilePath& drive_file_path, |
| 186 const std::string& content_type, | 186 const std::string& content_type, |
| 187 int64 content_length, | 187 int64 content_length, |
| 188 const GURL& upload_url, | 188 const GURL& upload_url, |
| 189 const std::string& etag, | 189 const std::string& etag, |
| 190 const InitiateUploadCallback& callback) OVERRIDE { | 190 const InitiateUploadCallback& callback) OVERRIDE { |
| 191 MessageLoop::current()->PostTask(FROM_HERE, | 191 MessageLoop::current()->PostTask(FROM_HERE, |
| 192 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); | 192 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); |
| 193 } | 193 } |
| 194 | 194 |
| 195 // Should not be used. | 195 // Should not be used. |
| 196 virtual void ResumeUpload(const ResumeUploadParams& params, | 196 virtual void ResumeUpload(const ResumeUploadParams& params, |
| 197 const UploadRangeCallback& callback) OVERRIDE { | 197 const UploadRangeCallback& callback) OVERRIDE { |
| 198 NOTREACHED(); | 198 NOTREACHED(); |
| 199 } | 199 } |
| 200 }; | 200 }; |
| 201 | 201 |
| 202 // Mock DriveService that returns a failure at ResumeUpload(). | 202 // Mock DriveService that returns a failure at ResumeUpload(). |
| 203 class MockDriveServiceNoConnectionAtResume : public DummyDriveService { | 203 class MockDriveServiceNoConnectionAtResume : public DummyDriveService { |
| 204 // Succeeds and returns an upload location URL. | 204 // Succeeds and returns an upload location URL. |
| 205 virtual void InitiateUploadNewFile( | 205 virtual void InitiateUploadNewFile( |
| 206 const FilePath& drive_file_path, | 206 const base::FilePath& drive_file_path, |
| 207 const std::string& content_type, | 207 const std::string& content_type, |
| 208 int64 content_length, | 208 int64 content_length, |
| 209 const GURL& parent_upload_url, | 209 const GURL& parent_upload_url, |
| 210 const std::string& title, | 210 const std::string& title, |
| 211 const InitiateUploadCallback& callback) OVERRIDE { | 211 const InitiateUploadCallback& callback) OVERRIDE { |
| 212 MessageLoop::current()->PostTask(FROM_HERE, | 212 MessageLoop::current()->PostTask(FROM_HERE, |
| 213 base::Bind(callback, HTTP_SUCCESS, GURL(kTestInitialUploadURL))); | 213 base::Bind(callback, HTTP_SUCCESS, GURL(kTestInitialUploadURL))); |
| 214 } | 214 } |
| 215 | 215 |
| 216 virtual void InitiateUploadExistingFile( | 216 virtual void InitiateUploadExistingFile( |
| 217 const FilePath& drive_file_path, | 217 const base::FilePath& drive_file_path, |
| 218 const std::string& content_type, | 218 const std::string& content_type, |
| 219 int64 content_length, | 219 int64 content_length, |
| 220 const GURL& upload_url, | 220 const GURL& upload_url, |
| 221 const std::string& etag, | 221 const std::string& etag, |
| 222 const InitiateUploadCallback& callback) OVERRIDE { | 222 const InitiateUploadCallback& callback) OVERRIDE { |
| 223 MessageLoop::current()->PostTask(FROM_HERE, | 223 MessageLoop::current()->PostTask(FROM_HERE, |
| 224 base::Bind(callback, HTTP_SUCCESS, GURL(kTestInitialUploadURL))); | 224 base::Bind(callback, HTTP_SUCCESS, GURL(kTestInitialUploadURL))); |
| 225 } | 225 } |
| 226 | 226 |
| 227 // Returns error. | 227 // Returns error. |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 kTestMimeType, | 491 kTestMimeType, |
| 492 "", // etag | 492 "", // etag |
| 493 base::Bind(&CopyResultsFromUploadCompletionCallbackAndQuit, &out)); | 493 base::Bind(&CopyResultsFromUploadCompletionCallbackAndQuit, &out)); |
| 494 message_loop_.Run(); | 494 message_loop_.Run(); |
| 495 | 495 |
| 496 // Should return failure without doing any attempt to connect to the server. | 496 // Should return failure without doing any attempt to connect to the server. |
| 497 EXPECT_EQ(DRIVE_UPLOAD_ERROR_NOT_FOUND, out.error); | 497 EXPECT_EQ(DRIVE_UPLOAD_ERROR_NOT_FOUND, out.error); |
| 498 } | 498 } |
| 499 | 499 |
| 500 } // namespace google_apis | 500 } // namespace google_apis |
| OLD | NEW |