Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: components/drive/drive_uploader_unittest.cc

Issue 1546143002: Switch to standard integer types in components/, part 1 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/drive/drive_uploader.cc ('k') | components/drive/dummy_file_system.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "components/drive/drive_uploader.h" 5 #include "components/drive/drive_uploader.h"
6 6
7 #include <stddef.h>
8 #include <stdint.h>
9
7 #include <algorithm> 10 #include <algorithm>
8 #include <string> 11 #include <string>
9 #include <vector> 12 #include <vector>
10 13
11 #include "base/bind.h" 14 #include "base/bind.h"
12 #include "base/files/scoped_temp_dir.h" 15 #include "base/files/scoped_temp_dir.h"
13 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 18 #include "base/run_loop.h"
16 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
(...skipping 25 matching lines...) Expand all
42 namespace { 45 namespace {
43 46
44 const char kTestDummyMd5[] = "dummy_md5"; 47 const char kTestDummyMd5[] = "dummy_md5";
45 const char kTestDocumentTitle[] = "Hello world"; 48 const char kTestDocumentTitle[] = "Hello world";
46 const char kTestInitiateUploadParentResourceId[] = "parent_resource_id"; 49 const char kTestInitiateUploadParentResourceId[] = "parent_resource_id";
47 const char kTestInitiateUploadResourceId[] = "resource_id"; 50 const char kTestInitiateUploadResourceId[] = "resource_id";
48 const char kTestMimeType[] = "text/plain"; 51 const char kTestMimeType[] = "text/plain";
49 const char kTestUploadNewFileURL[] = "http://test/upload_location/new_file"; 52 const char kTestUploadNewFileURL[] = "http://test/upload_location/new_file";
50 const char kTestUploadExistingFileURL[] = 53 const char kTestUploadExistingFileURL[] =
51 "http://test/upload_location/existing_file"; 54 "http://test/upload_location/existing_file";
52 const int64 kUploadChunkSize = 1024 * 1024 * 1024; 55 const int64_t kUploadChunkSize = 1024 * 1024 * 1024;
53 const char kTestETag[] = "test_etag"; 56 const char kTestETag[] = "test_etag";
54 57
55 CancelCallback SendMultipartUploadResult( 58 CancelCallback SendMultipartUploadResult(
56 DriveApiErrorCode response_code, 59 DriveApiErrorCode response_code,
57 int64 content_length, 60 int64_t content_length,
58 const google_apis::FileResourceCallback& callback, 61 const google_apis::FileResourceCallback& callback,
59 const google_apis::ProgressCallback& progress_callback) { 62 const google_apis::ProgressCallback& progress_callback) {
60 // Callback progress 63 // Callback progress
61 if (!progress_callback.is_null()) { 64 if (!progress_callback.is_null()) {
62 // For the testing purpose, it always notifies the progress at the end of 65 // For the testing purpose, it always notifies the progress at the end of
63 // whole file uploading. 66 // whole file uploading.
64 base::ThreadTaskRunnerHandle::Get()->PostTask( 67 base::ThreadTaskRunnerHandle::Get()->PostTask(
65 FROM_HERE, 68 FROM_HERE,
66 base::Bind(progress_callback, content_length, content_length)); 69 base::Bind(progress_callback, content_length, content_length));
67 } 70 }
68 71
69 // MultipartUploadXXXFile is an asynchronous function, so don't callback 72 // MultipartUploadXXXFile is an asynchronous function, so don't callback
70 // directly. 73 // directly.
71 scoped_ptr<FileResource> entry; 74 scoped_ptr<FileResource> entry;
72 entry.reset(new FileResource); 75 entry.reset(new FileResource);
73 entry->set_md5_checksum(kTestDummyMd5); 76 entry->set_md5_checksum(kTestDummyMd5);
74 base::ThreadTaskRunnerHandle::Get()->PostTask( 77 base::ThreadTaskRunnerHandle::Get()->PostTask(
75 FROM_HERE, base::Bind(callback, response_code, base::Passed(&entry))); 78 FROM_HERE, base::Bind(callback, response_code, base::Passed(&entry)));
76 return CancelCallback(); 79 return CancelCallback();
77 } 80 }
78 81
79 // Mock DriveService that verifies if the uploaded content matches the preset 82 // Mock DriveService that verifies if the uploaded content matches the preset
80 // expectation. 83 // expectation.
81 class MockDriveServiceWithUploadExpectation : public DummyDriveService { 84 class MockDriveServiceWithUploadExpectation : public DummyDriveService {
82 public: 85 public:
83 // Sets up an expected upload content. InitiateUpload and ResumeUpload will 86 // Sets up an expected upload content. InitiateUpload and ResumeUpload will
84 // verify that the specified data is correctly uploaded. 87 // verify that the specified data is correctly uploaded.
85 MockDriveServiceWithUploadExpectation( 88 MockDriveServiceWithUploadExpectation(
86 const base::FilePath& expected_upload_file, 89 const base::FilePath& expected_upload_file,
87 int64 expected_content_length) 90 int64_t expected_content_length)
88 : expected_upload_file_(expected_upload_file), 91 : expected_upload_file_(expected_upload_file),
89 expected_content_length_(expected_content_length), 92 expected_content_length_(expected_content_length),
90 received_bytes_(0), 93 received_bytes_(0),
91 resume_upload_call_count_(0), 94 resume_upload_call_count_(0),
92 multipart_upload_call_count_(0) {} 95 multipart_upload_call_count_(0) {}
93 96
94 int64 received_bytes() const { return received_bytes_; } 97 int64_t received_bytes() const { return received_bytes_; }
95 void set_received_bytes(int64 received_bytes) { 98 void set_received_bytes(int64_t received_bytes) {
96 received_bytes_ = received_bytes; 99 received_bytes_ = received_bytes;
97 } 100 }
98 101
99 int64 resume_upload_call_count() const { return resume_upload_call_count_; } 102 int64_t resume_upload_call_count() const { return resume_upload_call_count_; }
100 int64 multipart_upload_call_count() const { 103 int64_t multipart_upload_call_count() const {
101 return multipart_upload_call_count_; 104 return multipart_upload_call_count_;
102 } 105 }
103 106
104 private: 107 private:
105 // DriveServiceInterface overrides. 108 // DriveServiceInterface overrides.
106 // Handles a request for obtaining an upload location URL. 109 // Handles a request for obtaining an upload location URL.
107 CancelCallback InitiateUploadNewFile( 110 CancelCallback InitiateUploadNewFile(
108 const std::string& content_type, 111 const std::string& content_type,
109 int64 content_length, 112 int64_t content_length,
110 const std::string& parent_resource_id, 113 const std::string& parent_resource_id,
111 const std::string& title, 114 const std::string& title,
112 const UploadNewFileOptions& options, 115 const UploadNewFileOptions& options,
113 const InitiateUploadCallback& callback) override { 116 const InitiateUploadCallback& callback) override {
114 EXPECT_EQ(kTestDocumentTitle, title); 117 EXPECT_EQ(kTestDocumentTitle, title);
115 EXPECT_EQ(kTestMimeType, content_type); 118 EXPECT_EQ(kTestMimeType, content_type);
116 EXPECT_EQ(expected_content_length_, content_length); 119 EXPECT_EQ(expected_content_length_, content_length);
117 EXPECT_EQ(kTestInitiateUploadParentResourceId, parent_resource_id); 120 EXPECT_EQ(kTestInitiateUploadParentResourceId, parent_resource_id);
118 121
119 // Calls back the upload URL for subsequent ResumeUpload requests. 122 // Calls back the upload URL for subsequent ResumeUpload requests.
120 // InitiateUpload is an asynchronous function, so don't callback directly. 123 // InitiateUpload is an asynchronous function, so don't callback directly.
121 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 124 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
122 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadNewFileURL))); 125 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadNewFileURL)));
123 return CancelCallback(); 126 return CancelCallback();
124 } 127 }
125 128
126 CancelCallback InitiateUploadExistingFile( 129 CancelCallback InitiateUploadExistingFile(
127 const std::string& content_type, 130 const std::string& content_type,
128 int64 content_length, 131 int64_t content_length,
129 const std::string& resource_id, 132 const std::string& resource_id,
130 const UploadExistingFileOptions& options, 133 const UploadExistingFileOptions& options,
131 const InitiateUploadCallback& callback) override { 134 const InitiateUploadCallback& callback) override {
132 EXPECT_EQ(kTestMimeType, content_type); 135 EXPECT_EQ(kTestMimeType, content_type);
133 EXPECT_EQ(expected_content_length_, content_length); 136 EXPECT_EQ(expected_content_length_, content_length);
134 EXPECT_EQ(kTestInitiateUploadResourceId, resource_id); 137 EXPECT_EQ(kTestInitiateUploadResourceId, resource_id);
135 138
136 if (!options.etag.empty() && options.etag != kTestETag) { 139 if (!options.etag.empty() && options.etag != kTestETag) {
137 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 140 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
138 base::Bind(callback, HTTP_PRECONDITION, GURL())); 141 base::Bind(callback, HTTP_PRECONDITION, GURL()));
139 return CancelCallback(); 142 return CancelCallback();
140 } 143 }
141 144
142 // Calls back the upload URL for subsequent ResumeUpload requests. 145 // Calls back the upload URL for subsequent ResumeUpload requests.
143 // InitiateUpload is an asynchronous function, so don't callback directly. 146 // InitiateUpload is an asynchronous function, so don't callback directly.
144 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 147 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
145 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadExistingFileURL))); 148 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadExistingFileURL)));
146 return CancelCallback(); 149 return CancelCallback();
147 } 150 }
148 151
149 // Handles a request for uploading a chunk of bytes. 152 // Handles a request for uploading a chunk of bytes.
150 CancelCallback ResumeUpload( 153 CancelCallback ResumeUpload(
151 const GURL& upload_location, 154 const GURL& upload_location,
152 int64 start_position, 155 int64_t start_position,
153 int64 end_position, 156 int64_t end_position,
154 int64 content_length, 157 int64_t content_length,
155 const std::string& content_type, 158 const std::string& content_type,
156 const base::FilePath& local_file_path, 159 const base::FilePath& local_file_path,
157 const UploadRangeCallback& callback, 160 const UploadRangeCallback& callback,
158 const ProgressCallback& progress_callback) override { 161 const ProgressCallback& progress_callback) override {
159 // The upload range should start from the current first unreceived byte. 162 // The upload range should start from the current first unreceived byte.
160 EXPECT_EQ(received_bytes_, start_position); 163 EXPECT_EQ(received_bytes_, start_position);
161 EXPECT_EQ(expected_upload_file_, local_file_path); 164 EXPECT_EQ(expected_upload_file_, local_file_path);
162 165
163 // The upload data must be split into 512KB chunks. 166 // The upload data must be split into 512KB chunks.
164 const int64 expected_chunk_end = 167 const int64_t expected_chunk_end =
165 std::min(received_bytes_ + kUploadChunkSize, expected_content_length_); 168 std::min(received_bytes_ + kUploadChunkSize, expected_content_length_);
166 EXPECT_EQ(expected_chunk_end, end_position); 169 EXPECT_EQ(expected_chunk_end, end_position);
167 170
168 // The upload URL returned by InitiateUpload() must be used. 171 // The upload URL returned by InitiateUpload() must be used.
169 EXPECT_TRUE(GURL(kTestUploadNewFileURL) == upload_location || 172 EXPECT_TRUE(GURL(kTestUploadNewFileURL) == upload_location ||
170 GURL(kTestUploadExistingFileURL) == upload_location); 173 GURL(kTestUploadExistingFileURL) == upload_location);
171 174
172 // Other parameters should be the exact values passed to DriveUploader. 175 // Other parameters should be the exact values passed to DriveUploader.
173 EXPECT_EQ(expected_content_length_, content_length); 176 EXPECT_EQ(expected_content_length_, content_length);
174 EXPECT_EQ(kTestMimeType, content_type); 177 EXPECT_EQ(kTestMimeType, content_type);
175 178
176 // Update the internal status of the current upload session. 179 // Update the internal status of the current upload session.
177 resume_upload_call_count_++; 180 resume_upload_call_count_++;
178 received_bytes_ = end_position; 181 received_bytes_ = end_position;
179 182
180 // Callback progress 183 // Callback progress
181 if (!progress_callback.is_null()) { 184 if (!progress_callback.is_null()) {
182 // For the testing purpose, it always notifies the progress at the end of 185 // For the testing purpose, it always notifies the progress at the end of
183 // each chunk uploading. 186 // each chunk uploading.
184 int64 chunk_size = end_position - start_position; 187 int64_t chunk_size = end_position - start_position;
185 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 188 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
186 base::Bind(progress_callback, chunk_size, chunk_size)); 189 base::Bind(progress_callback, chunk_size, chunk_size));
187 } 190 }
188 191
189 SendUploadRangeResponse(upload_location, callback); 192 SendUploadRangeResponse(upload_location, callback);
190 return CancelCallback(); 193 return CancelCallback();
191 } 194 }
192 195
193 // Handles a request to fetch the current upload status. 196 // Handles a request to fetch the current upload status.
194 CancelCallback GetUploadStatus(const GURL& upload_location, 197 CancelCallback GetUploadStatus(const GURL& upload_location,
195 int64 content_length, 198 int64_t content_length,
196 const UploadRangeCallback& callback) override { 199 const UploadRangeCallback& callback) override {
197 EXPECT_EQ(expected_content_length_, content_length); 200 EXPECT_EQ(expected_content_length_, content_length);
198 // The upload URL returned by InitiateUpload() must be used. 201 // The upload URL returned by InitiateUpload() must be used.
199 EXPECT_TRUE(GURL(kTestUploadNewFileURL) == upload_location || 202 EXPECT_TRUE(GURL(kTestUploadNewFileURL) == upload_location ||
200 GURL(kTestUploadExistingFileURL) == upload_location); 203 GURL(kTestUploadExistingFileURL) == upload_location);
201 204
202 SendUploadRangeResponse(upload_location, callback); 205 SendUploadRangeResponse(upload_location, callback);
203 return CancelCallback(); 206 return CancelCallback();
204 } 207 }
205 208
(...skipping 15 matching lines...) Expand all
221 response = UploadRangeResponse( 224 response = UploadRangeResponse(
222 HTTP_RESUME_INCOMPLETE, 0, received_bytes_); 225 HTTP_RESUME_INCOMPLETE, 0, received_bytes_);
223 } 226 }
224 // ResumeUpload is an asynchronous function, so don't callback directly. 227 // ResumeUpload is an asynchronous function, so don't callback directly.
225 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 228 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
226 base::Bind(callback, response, base::Passed(&entry))); 229 base::Bind(callback, response, base::Passed(&entry)));
227 } 230 }
228 231
229 CancelCallback MultipartUploadNewFile( 232 CancelCallback MultipartUploadNewFile(
230 const std::string& content_type, 233 const std::string& content_type,
231 int64 content_length, 234 int64_t content_length,
232 const std::string& parent_resource_id, 235 const std::string& parent_resource_id,
233 const std::string& title, 236 const std::string& title,
234 const base::FilePath& local_file_path, 237 const base::FilePath& local_file_path,
235 const UploadNewFileOptions& options, 238 const UploadNewFileOptions& options,
236 const google_apis::FileResourceCallback& callback, 239 const google_apis::FileResourceCallback& callback,
237 const google_apis::ProgressCallback& progress_callback) override { 240 const google_apis::ProgressCallback& progress_callback) override {
238 EXPECT_EQ(kTestMimeType, content_type); 241 EXPECT_EQ(kTestMimeType, content_type);
239 EXPECT_EQ(expected_content_length_, content_length); 242 EXPECT_EQ(expected_content_length_, content_length);
240 EXPECT_EQ(kTestInitiateUploadParentResourceId, parent_resource_id); 243 EXPECT_EQ(kTestInitiateUploadParentResourceId, parent_resource_id);
241 EXPECT_EQ(kTestDocumentTitle, title); 244 EXPECT_EQ(kTestDocumentTitle, title);
242 EXPECT_EQ(expected_upload_file_, local_file_path); 245 EXPECT_EQ(expected_upload_file_, local_file_path);
243 246
244 received_bytes_ = content_length; 247 received_bytes_ = content_length;
245 multipart_upload_call_count_++; 248 multipart_upload_call_count_++;
246 return SendMultipartUploadResult(HTTP_CREATED, content_length, callback, 249 return SendMultipartUploadResult(HTTP_CREATED, content_length, callback,
247 progress_callback); 250 progress_callback);
248 } 251 }
249 252
250 CancelCallback MultipartUploadExistingFile( 253 CancelCallback MultipartUploadExistingFile(
251 const std::string& content_type, 254 const std::string& content_type,
252 int64 content_length, 255 int64_t content_length,
253 const std::string& resource_id, 256 const std::string& resource_id,
254 const base::FilePath& local_file_path, 257 const base::FilePath& local_file_path,
255 const UploadExistingFileOptions& options, 258 const UploadExistingFileOptions& options,
256 const google_apis::FileResourceCallback& callback, 259 const google_apis::FileResourceCallback& callback,
257 const google_apis::ProgressCallback& progress_callback) override { 260 const google_apis::ProgressCallback& progress_callback) override {
258 EXPECT_EQ(kTestMimeType, content_type); 261 EXPECT_EQ(kTestMimeType, content_type);
259 EXPECT_EQ(expected_content_length_, content_length); 262 EXPECT_EQ(expected_content_length_, content_length);
260 EXPECT_EQ(kTestInitiateUploadResourceId, resource_id); 263 EXPECT_EQ(kTestInitiateUploadResourceId, resource_id);
261 EXPECT_EQ(expected_upload_file_, local_file_path); 264 EXPECT_EQ(expected_upload_file_, local_file_path);
262 265
263 if (!options.etag.empty() && options.etag != kTestETag) { 266 if (!options.etag.empty() && options.etag != kTestETag) {
264 base::ThreadTaskRunnerHandle::Get()->PostTask( 267 base::ThreadTaskRunnerHandle::Get()->PostTask(
265 FROM_HERE, 268 FROM_HERE,
266 base::Bind(callback, HTTP_PRECONDITION, 269 base::Bind(callback, HTTP_PRECONDITION,
267 base::Passed(make_scoped_ptr<FileResource>(NULL)))); 270 base::Passed(make_scoped_ptr<FileResource>(NULL))));
268 return CancelCallback(); 271 return CancelCallback();
269 } 272 }
270 273
271 received_bytes_ = content_length; 274 received_bytes_ = content_length;
272 multipart_upload_call_count_++; 275 multipart_upload_call_count_++;
273 return SendMultipartUploadResult(HTTP_SUCCESS, content_length, callback, 276 return SendMultipartUploadResult(HTTP_SUCCESS, content_length, callback,
274 progress_callback); 277 progress_callback);
275 } 278 }
276 279
277 const base::FilePath expected_upload_file_; 280 const base::FilePath expected_upload_file_;
278 const int64 expected_content_length_; 281 const int64_t expected_content_length_;
279 int64 received_bytes_; 282 int64_t received_bytes_;
280 int64 resume_upload_call_count_; 283 int64_t resume_upload_call_count_;
281 int64 multipart_upload_call_count_; 284 int64_t multipart_upload_call_count_;
282 }; 285 };
283 286
284 // Mock DriveService that returns a failure at InitiateUpload(). 287 // Mock DriveService that returns a failure at InitiateUpload().
285 class MockDriveServiceNoConnectionAtInitiate : public DummyDriveService { 288 class MockDriveServiceNoConnectionAtInitiate : public DummyDriveService {
286 // Returns error. 289 // Returns error.
287 CancelCallback InitiateUploadNewFile( 290 CancelCallback InitiateUploadNewFile(
288 const std::string& content_type, 291 const std::string& content_type,
289 int64 content_length, 292 int64_t content_length,
290 const std::string& parent_resource_id, 293 const std::string& parent_resource_id,
291 const std::string& title, 294 const std::string& title,
292 const UploadNewFileOptions& options, 295 const UploadNewFileOptions& options,
293 const InitiateUploadCallback& callback) override { 296 const InitiateUploadCallback& callback) override {
294 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 297 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
295 base::Bind(callback, DRIVE_NO_CONNECTION, GURL())); 298 base::Bind(callback, DRIVE_NO_CONNECTION, GURL()));
296 return CancelCallback(); 299 return CancelCallback();
297 } 300 }
298 301
299 CancelCallback InitiateUploadExistingFile( 302 CancelCallback InitiateUploadExistingFile(
300 const std::string& content_type, 303 const std::string& content_type,
301 int64 content_length, 304 int64_t content_length,
302 const std::string& resource_id, 305 const std::string& resource_id,
303 const UploadExistingFileOptions& options, 306 const UploadExistingFileOptions& options,
304 const InitiateUploadCallback& callback) override { 307 const InitiateUploadCallback& callback) override {
305 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 308 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
306 base::Bind(callback, DRIVE_NO_CONNECTION, GURL())); 309 base::Bind(callback, DRIVE_NO_CONNECTION, GURL()));
307 return CancelCallback(); 310 return CancelCallback();
308 } 311 }
309 312
310 // Should not be used. 313 // Should not be used.
311 CancelCallback ResumeUpload( 314 CancelCallback ResumeUpload(
312 const GURL& upload_url, 315 const GURL& upload_url,
313 int64 start_position, 316 int64_t start_position,
314 int64 end_position, 317 int64_t end_position,
315 int64 content_length, 318 int64_t content_length,
316 const std::string& content_type, 319 const std::string& content_type,
317 const base::FilePath& local_file_path, 320 const base::FilePath& local_file_path,
318 const UploadRangeCallback& callback, 321 const UploadRangeCallback& callback,
319 const ProgressCallback& progress_callback) override { 322 const ProgressCallback& progress_callback) override {
320 NOTREACHED(); 323 NOTREACHED();
321 return CancelCallback(); 324 return CancelCallback();
322 } 325 }
323 326
324 CancelCallback MultipartUploadNewFile( 327 CancelCallback MultipartUploadNewFile(
325 const std::string& content_type, 328 const std::string& content_type,
326 int64 content_length, 329 int64_t content_length,
327 const std::string& parent_resource_id, 330 const std::string& parent_resource_id,
328 const std::string& title, 331 const std::string& title,
329 const base::FilePath& local_file_path, 332 const base::FilePath& local_file_path,
330 const UploadNewFileOptions& options, 333 const UploadNewFileOptions& options,
331 const google_apis::FileResourceCallback& callback, 334 const google_apis::FileResourceCallback& callback,
332 const google_apis::ProgressCallback& progress_callback) override { 335 const google_apis::ProgressCallback& progress_callback) override {
333 base::ThreadTaskRunnerHandle::Get()->PostTask( 336 base::ThreadTaskRunnerHandle::Get()->PostTask(
334 FROM_HERE, 337 FROM_HERE,
335 base::Bind(callback, DRIVE_NO_CONNECTION, 338 base::Bind(callback, DRIVE_NO_CONNECTION,
336 base::Passed(make_scoped_ptr<FileResource>(NULL)))); 339 base::Passed(make_scoped_ptr<FileResource>(NULL))));
337 return CancelCallback(); 340 return CancelCallback();
338 } 341 }
339 342
340 CancelCallback MultipartUploadExistingFile( 343 CancelCallback MultipartUploadExistingFile(
341 const std::string& content_type, 344 const std::string& content_type,
342 int64 content_length, 345 int64_t content_length,
343 const std::string& resource_id, 346 const std::string& resource_id,
344 const base::FilePath& local_file_path, 347 const base::FilePath& local_file_path,
345 const UploadExistingFileOptions& options, 348 const UploadExistingFileOptions& options,
346 const google_apis::FileResourceCallback& callback, 349 const google_apis::FileResourceCallback& callback,
347 const google_apis::ProgressCallback& progress_callback) override { 350 const google_apis::ProgressCallback& progress_callback) override {
348 base::ThreadTaskRunnerHandle::Get()->PostTask( 351 base::ThreadTaskRunnerHandle::Get()->PostTask(
349 FROM_HERE, 352 FROM_HERE,
350 base::Bind(callback, DRIVE_NO_CONNECTION, 353 base::Bind(callback, DRIVE_NO_CONNECTION,
351 base::Passed(make_scoped_ptr<FileResource>(NULL)))); 354 base::Passed(make_scoped_ptr<FileResource>(NULL))));
352 return CancelCallback(); 355 return CancelCallback();
353 } 356 }
354 }; 357 };
355 358
356 // Mock DriveService that returns a failure at ResumeUpload(). 359 // Mock DriveService that returns a failure at ResumeUpload().
357 class MockDriveServiceNoConnectionAtResume : public DummyDriveService { 360 class MockDriveServiceNoConnectionAtResume : public DummyDriveService {
358 // Succeeds and returns an upload location URL. 361 // Succeeds and returns an upload location URL.
359 CancelCallback InitiateUploadNewFile( 362 CancelCallback InitiateUploadNewFile(
360 const std::string& content_type, 363 const std::string& content_type,
361 int64 content_length, 364 int64_t content_length,
362 const std::string& parent_resource_id, 365 const std::string& parent_resource_id,
363 const std::string& title, 366 const std::string& title,
364 const UploadNewFileOptions& options, 367 const UploadNewFileOptions& options,
365 const InitiateUploadCallback& callback) override { 368 const InitiateUploadCallback& callback) override {
366 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 369 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
367 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadNewFileURL))); 370 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadNewFileURL)));
368 return CancelCallback(); 371 return CancelCallback();
369 } 372 }
370 373
371 CancelCallback InitiateUploadExistingFile( 374 CancelCallback InitiateUploadExistingFile(
372 const std::string& content_type, 375 const std::string& content_type,
373 int64 content_length, 376 int64_t content_length,
374 const std::string& resource_id, 377 const std::string& resource_id,
375 const UploadExistingFileOptions& options, 378 const UploadExistingFileOptions& options,
376 const InitiateUploadCallback& callback) override { 379 const InitiateUploadCallback& callback) override {
377 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 380 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
378 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadExistingFileURL))); 381 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadExistingFileURL)));
379 return CancelCallback(); 382 return CancelCallback();
380 } 383 }
381 384
382 // Returns error. 385 // Returns error.
383 CancelCallback ResumeUpload( 386 CancelCallback ResumeUpload(
384 const GURL& upload_url, 387 const GURL& upload_url,
385 int64 start_position, 388 int64_t start_position,
386 int64 end_position, 389 int64_t end_position,
387 int64 content_length, 390 int64_t content_length,
388 const std::string& content_type, 391 const std::string& content_type,
389 const base::FilePath& local_file_path, 392 const base::FilePath& local_file_path,
390 const UploadRangeCallback& callback, 393 const UploadRangeCallback& callback,
391 const ProgressCallback& progress_callback) override { 394 const ProgressCallback& progress_callback) override {
392 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 395 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
393 base::Bind(callback, 396 base::Bind(callback,
394 UploadRangeResponse(DRIVE_NO_CONNECTION, -1, -1), 397 UploadRangeResponse(DRIVE_NO_CONNECTION, -1, -1),
395 base::Passed(scoped_ptr<FileResource>()))); 398 base::Passed(scoped_ptr<FileResource>())));
396 return CancelCallback(); 399 return CancelCallback();
397 } 400 }
398 }; 401 };
399 402
400 // Mock DriveService that returns a failure at GetUploadStatus(). 403 // Mock DriveService that returns a failure at GetUploadStatus().
401 class MockDriveServiceNoConnectionAtGetUploadStatus : public DummyDriveService { 404 class MockDriveServiceNoConnectionAtGetUploadStatus : public DummyDriveService {
402 // Returns error. 405 // Returns error.
403 CancelCallback GetUploadStatus(const GURL& upload_url, 406 CancelCallback GetUploadStatus(const GURL& upload_url,
404 int64 content_length, 407 int64_t content_length,
405 const UploadRangeCallback& callback) override { 408 const UploadRangeCallback& callback) override {
406 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 409 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
407 base::Bind(callback, 410 base::Bind(callback,
408 UploadRangeResponse(DRIVE_NO_CONNECTION, -1, -1), 411 UploadRangeResponse(DRIVE_NO_CONNECTION, -1, -1),
409 base::Passed(scoped_ptr<FileResource>()))); 412 base::Passed(scoped_ptr<FileResource>())));
410 return CancelCallback(); 413 return CancelCallback();
411 } 414 }
412 }; 415 };
413 416
414 class DriveUploaderTest : public testing::Test { 417 class DriveUploaderTest : public testing::Test {
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 ASSERT_EQ(1U, upload_progress_values.size()); 767 ASSERT_EQ(1U, upload_progress_values.size());
765 EXPECT_EQ(test_util::ProgressInfo(1024 * 1024, 1024 * 1024), 768 EXPECT_EQ(test_util::ProgressInfo(1024 * 1024, 1024 * 1024),
766 upload_progress_values[0]); 769 upload_progress_values[0]);
767 } 770 }
768 771
769 class MockDriveServiceForBatchProcessing : public DummyDriveService { 772 class MockDriveServiceForBatchProcessing : public DummyDriveService {
770 public: 773 public:
771 struct UploadFileInfo { 774 struct UploadFileInfo {
772 enum { NEW_FILE, EXISTING_FILE } type; 775 enum { NEW_FILE, EXISTING_FILE } type;
773 std::string content_type; 776 std::string content_type;
774 uint64 content_length; 777 uint64_t content_length;
775 std::string parent_resource_id; 778 std::string parent_resource_id;
776 std::string resource_id; 779 std::string resource_id;
777 std::string title; 780 std::string title;
778 base::FilePath local_file_path; 781 base::FilePath local_file_path;
779 google_apis::FileResourceCallback callback; 782 google_apis::FileResourceCallback callback;
780 google_apis::ProgressCallback progress_callback; 783 google_apis::ProgressCallback progress_callback;
781 }; 784 };
782 785
783 class BatchRequestConfigurator : public BatchRequestConfiguratorInterface { 786 class BatchRequestConfigurator : public BatchRequestConfiguratorInterface {
784 public: 787 public:
785 explicit BatchRequestConfigurator( 788 explicit BatchRequestConfigurator(
786 MockDriveServiceForBatchProcessing* service) 789 MockDriveServiceForBatchProcessing* service)
787 : service(service) {} 790 : service(service) {}
788 791
789 CancelCallback MultipartUploadNewFile( 792 CancelCallback MultipartUploadNewFile(
790 const std::string& content_type, 793 const std::string& content_type,
791 int64 content_length, 794 int64_t content_length,
792 const std::string& parent_resource_id, 795 const std::string& parent_resource_id,
793 const std::string& title, 796 const std::string& title,
794 const base::FilePath& local_file_path, 797 const base::FilePath& local_file_path,
795 const UploadNewFileOptions& options, 798 const UploadNewFileOptions& options,
796 const google_apis::FileResourceCallback& callback, 799 const google_apis::FileResourceCallback& callback,
797 const google_apis::ProgressCallback& progress_callback) override { 800 const google_apis::ProgressCallback& progress_callback) override {
798 UploadFileInfo info; 801 UploadFileInfo info;
799 info.type = UploadFileInfo::NEW_FILE; 802 info.type = UploadFileInfo::NEW_FILE;
800 info.content_type = content_type; 803 info.content_type = content_type;
801 info.content_length = content_length; 804 info.content_length = content_length;
802 info.parent_resource_id = parent_resource_id; 805 info.parent_resource_id = parent_resource_id;
803 info.title = title; 806 info.title = title;
804 info.local_file_path = local_file_path; 807 info.local_file_path = local_file_path;
805 info.callback = callback; 808 info.callback = callback;
806 info.progress_callback = progress_callback; 809 info.progress_callback = progress_callback;
807 service->files.push_back(info); 810 service->files.push_back(info);
808 return CancelCallback(); 811 return CancelCallback();
809 } 812 }
810 813
811 CancelCallback MultipartUploadExistingFile( 814 CancelCallback MultipartUploadExistingFile(
812 const std::string& content_type, 815 const std::string& content_type,
813 int64 content_length, 816 int64_t content_length,
814 const std::string& resource_id, 817 const std::string& resource_id,
815 const base::FilePath& local_file_path, 818 const base::FilePath& local_file_path,
816 const UploadExistingFileOptions& options, 819 const UploadExistingFileOptions& options,
817 const google_apis::FileResourceCallback& callback, 820 const google_apis::FileResourceCallback& callback,
818 const google_apis::ProgressCallback& progress_callback) override { 821 const google_apis::ProgressCallback& progress_callback) override {
819 UploadFileInfo info; 822 UploadFileInfo info;
820 info.type = UploadFileInfo::EXISTING_FILE; 823 info.type = UploadFileInfo::EXISTING_FILE;
821 info.content_type = content_type; 824 info.content_type = content_type;
822 info.content_length = content_length; 825 info.content_length = content_length;
823 info.resource_id = resource_id; 826 info.resource_id = resource_id;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 949
947 EXPECT_EQ(HTTP_NOT_FOUND, results[0].error); 950 EXPECT_EQ(HTTP_NOT_FOUND, results[0].error);
948 EXPECT_TRUE(results[0].resume_url.is_empty()); 951 EXPECT_TRUE(results[0].resume_url.is_empty());
949 EXPECT_FALSE(results[0].file); 952 EXPECT_FALSE(results[0].file);
950 953
951 EXPECT_EQ(HTTP_NOT_FOUND, results[1].error); 954 EXPECT_EQ(HTTP_NOT_FOUND, results[1].error);
952 EXPECT_TRUE(results[1].resume_url.is_empty()); 955 EXPECT_TRUE(results[1].resume_url.is_empty());
953 EXPECT_FALSE(results[1].file); 956 EXPECT_FALSE(results[1].file);
954 } 957 }
955 } // namespace drive 958 } // namespace drive
OLDNEW
« no previous file with comments | « components/drive/drive_uploader.cc ('k') | components/drive/dummy_file_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698