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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 received_bytes_(0), | 60 received_bytes_(0), |
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 InitiateUpload(const InitiateUploadParams& params, | 70 virtual void InitiateUploadNewFile( |
71 const InitiateUploadCallback& callback) OVERRIDE { | 71 const FilePath& drive_file_path, |
| 72 const std::string& content_type, |
| 73 int64 content_length, |
| 74 const GURL& parent_upload_url, |
| 75 const std::string& title, |
| 76 const InitiateUploadCallback& callback) OVERRIDE { |
| 77 EXPECT_EQ(kTestDocumentTitle, title); |
| 78 EXPECT_EQ(kTestMimeType, content_type); |
72 const int64 expected_size = expected_upload_content_.size(); | 79 const int64 expected_size = expected_upload_content_.size(); |
| 80 EXPECT_EQ(expected_size, content_length); |
| 81 EXPECT_EQ(GURL(kTestInitialUploadURL), parent_upload_url); |
73 | 82 |
74 // Verify that the expected parameters are passed. | 83 // Calls back the upload URL for subsequent ResumeUpload operations. |
75 if (params.upload_mode == UPLOAD_NEW_FILE) | 84 // InitiateUpload is an asynchronous function, so don't callback directly. |
76 EXPECT_EQ(kTestDocumentTitle, params.title); | 85 MessageLoop::current()->PostTask(FROM_HERE, |
77 else | 86 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadURL))); |
78 EXPECT_EQ("", params.title); | 87 } |
79 EXPECT_EQ(kTestMimeType, params.content_type); | |
80 EXPECT_EQ(expected_size, params.content_length); | |
81 EXPECT_EQ(GURL(kTestInitialUploadURL), params.upload_location); | |
82 | 88 |
83 if (!params.etag.empty() && params.etag != kTestETag) { | 89 virtual void InitiateUploadExistingFile( |
| 90 const FilePath& drive_file_path, |
| 91 const std::string& content_type, |
| 92 int64 content_length, |
| 93 const GURL& upload_url, |
| 94 const std::string& etag, |
| 95 const InitiateUploadCallback& callback) OVERRIDE { |
| 96 EXPECT_EQ(kTestMimeType, content_type); |
| 97 const int64 expected_size = expected_upload_content_.size(); |
| 98 EXPECT_EQ(expected_size, content_length); |
| 99 EXPECT_EQ(GURL(kTestInitialUploadURL), upload_url); |
| 100 |
| 101 if (!etag.empty() && etag != kTestETag) { |
84 MessageLoop::current()->PostTask(FROM_HERE, | 102 MessageLoop::current()->PostTask(FROM_HERE, |
85 base::Bind(callback, HTTP_PRECONDITION, GURL())); | 103 base::Bind(callback, HTTP_PRECONDITION, GURL())); |
86 return; | 104 return; |
87 } | 105 } |
88 | 106 |
89 // Calls back the upload URL for subsequent ResumeUpload operations. | 107 // Calls back the upload URL for subsequent ResumeUpload operations. |
90 // InitiateUpload is an asynchronous function, so don't callback directly. | 108 // InitiateUpload is an asynchronous function, so don't callback directly. |
91 MessageLoop::current()->PostTask(FROM_HERE, | 109 MessageLoop::current()->PostTask(FROM_HERE, |
92 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadURL))); | 110 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadURL))); |
93 } | 111 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 163 } |
146 | 164 |
147 std::string expected_upload_content_; | 165 std::string expected_upload_content_; |
148 int64 received_bytes_; | 166 int64 received_bytes_; |
149 int64 resume_upload_call_count_; | 167 int64 resume_upload_call_count_; |
150 }; | 168 }; |
151 | 169 |
152 // Mock DriveService that returns a failure at InitiateUpload(). | 170 // Mock DriveService that returns a failure at InitiateUpload(). |
153 class MockDriveServiceNoConnectionAtInitiate : public DummyDriveService { | 171 class MockDriveServiceNoConnectionAtInitiate : public DummyDriveService { |
154 // Returns error. | 172 // Returns error. |
155 virtual void InitiateUpload(const InitiateUploadParams& params, | 173 virtual void InitiateUploadNewFile( |
156 const InitiateUploadCallback& callback) OVERRIDE { | 174 const FilePath& drive_file_path, |
| 175 const std::string& content_type, |
| 176 int64 content_length, |
| 177 const GURL& parent_upload_url, |
| 178 const std::string& title, |
| 179 const InitiateUploadCallback& callback) OVERRIDE { |
157 MessageLoop::current()->PostTask(FROM_HERE, | 180 MessageLoop::current()->PostTask(FROM_HERE, |
158 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); | 181 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); |
159 } | 182 } |
| 183 |
| 184 virtual void InitiateUploadExistingFile( |
| 185 const FilePath& drive_file_path, |
| 186 const std::string& content_type, |
| 187 int64 content_length, |
| 188 const GURL& upload_url, |
| 189 const std::string& etag, |
| 190 const InitiateUploadCallback& callback) OVERRIDE { |
| 191 MessageLoop::current()->PostTask(FROM_HERE, |
| 192 base::Bind(callback, GDATA_NO_CONNECTION, GURL())); |
| 193 } |
160 | 194 |
161 // Should not be used. | 195 // Should not be used. |
162 virtual void ResumeUpload(const ResumeUploadParams& params, | 196 virtual void ResumeUpload(const ResumeUploadParams& params, |
163 const UploadRangeCallback& callback) OVERRIDE { | 197 const UploadRangeCallback& callback) OVERRIDE { |
164 NOTREACHED(); | 198 NOTREACHED(); |
165 } | 199 } |
166 }; | 200 }; |
167 | 201 |
168 // Mock DriveService that returns a failure at ResumeUpload(). | 202 // Mock DriveService that returns a failure at ResumeUpload(). |
169 class MockDriveServiceNoConnectionAtResume : public DummyDriveService { | 203 class MockDriveServiceNoConnectionAtResume : public DummyDriveService { |
170 // Succeeds and returns an upload location URL. | 204 // Succeeds and returns an upload location URL. |
171 virtual void InitiateUpload(const InitiateUploadParams& params, | 205 virtual void InitiateUploadNewFile( |
172 const InitiateUploadCallback& callback) OVERRIDE { | 206 const FilePath& drive_file_path, |
| 207 const std::string& content_type, |
| 208 int64 content_length, |
| 209 const GURL& parent_upload_url, |
| 210 const std::string& title, |
| 211 const InitiateUploadCallback& callback) OVERRIDE { |
173 MessageLoop::current()->PostTask(FROM_HERE, | 212 MessageLoop::current()->PostTask(FROM_HERE, |
174 base::Bind(callback, HTTP_SUCCESS, GURL(kTestInitialUploadURL))); | 213 base::Bind(callback, HTTP_SUCCESS, GURL(kTestInitialUploadURL))); |
175 } | 214 } |
| 215 |
| 216 virtual void InitiateUploadExistingFile( |
| 217 const FilePath& drive_file_path, |
| 218 const std::string& content_type, |
| 219 int64 content_length, |
| 220 const GURL& upload_url, |
| 221 const std::string& etag, |
| 222 const InitiateUploadCallback& callback) OVERRIDE { |
| 223 MessageLoop::current()->PostTask(FROM_HERE, |
| 224 base::Bind(callback, HTTP_SUCCESS, GURL(kTestInitialUploadURL))); |
| 225 } |
176 | 226 |
177 // Returns error. | 227 // Returns error. |
178 virtual void ResumeUpload(const ResumeUploadParams& params, | 228 virtual void ResumeUpload(const ResumeUploadParams& params, |
179 const UploadRangeCallback& callback) OVERRIDE { | 229 const UploadRangeCallback& callback) OVERRIDE { |
180 MessageLoop::current()->PostTask(FROM_HERE, | 230 MessageLoop::current()->PostTask(FROM_HERE, |
181 base::Bind(callback, | 231 base::Bind(callback, |
182 UploadRangeResponse(GDATA_NO_CONNECTION, -1, -1), | 232 UploadRangeResponse(GDATA_NO_CONNECTION, -1, -1), |
183 base::Passed(scoped_ptr<ResourceEntry>()))); | 233 base::Passed(scoped_ptr<ResourceEntry>()))); |
184 } | 234 } |
185 }; | 235 }; |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 kTestMimeType, | 491 kTestMimeType, |
442 "", // etag | 492 "", // etag |
443 base::Bind(&CopyResultsFromUploadCompletionCallbackAndQuit, &out)); | 493 base::Bind(&CopyResultsFromUploadCompletionCallbackAndQuit, &out)); |
444 message_loop_.Run(); | 494 message_loop_.Run(); |
445 | 495 |
446 // 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. |
447 EXPECT_EQ(DRIVE_UPLOAD_ERROR_NOT_FOUND, out.error); | 497 EXPECT_EQ(DRIVE_UPLOAD_ERROR_NOT_FOUND, out.error); |
448 } | 498 } |
449 | 499 |
450 } // namespace google_apis | 500 } // namespace google_apis |
OLD | NEW |