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

Side by Side Diff: chrome/browser/drive/drive_uploader_unittest.cc

Issue 1115573002: [chrome/browser/drive] Avoid use of MessageLoopProxy by TTRH (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Review Comments : MessageLoop postTask replacements Created 5 years, 7 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 | « no previous file | chrome/browser/drive/fake_drive_service.cc » ('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 "chrome/browser/drive/drive_uploader.h" 5 #include "chrome/browser/drive/drive_uploader.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/thread_task_runner_handle.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/drive/dummy_drive_service.h" 16 #include "chrome/browser/drive/dummy_drive_service.h"
17 #include "google_apis/drive/drive_api_parser.h" 17 #include "google_apis/drive/drive_api_parser.h"
18 #include "google_apis/drive/test_util.h" 18 #include "google_apis/drive/test_util.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 using google_apis::CancelCallback; 21 using google_apis::CancelCallback;
22 using google_apis::FileResource; 22 using google_apis::FileResource;
23 using google_apis::DriveApiErrorCode; 23 using google_apis::DriveApiErrorCode;
24 using google_apis::DRIVE_NO_CONNECTION; 24 using google_apis::DRIVE_NO_CONNECTION;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 const std::string& title, 85 const std::string& title,
86 const UploadNewFileOptions& options, 86 const UploadNewFileOptions& options,
87 const InitiateUploadCallback& callback) override { 87 const InitiateUploadCallback& callback) override {
88 EXPECT_EQ(kTestDocumentTitle, title); 88 EXPECT_EQ(kTestDocumentTitle, title);
89 EXPECT_EQ(kTestMimeType, content_type); 89 EXPECT_EQ(kTestMimeType, content_type);
90 EXPECT_EQ(expected_content_length_, content_length); 90 EXPECT_EQ(expected_content_length_, content_length);
91 EXPECT_EQ(kTestInitiateUploadParentResourceId, parent_resource_id); 91 EXPECT_EQ(kTestInitiateUploadParentResourceId, parent_resource_id);
92 92
93 // Calls back the upload URL for subsequent ResumeUpload requests. 93 // Calls back the upload URL for subsequent ResumeUpload requests.
94 // InitiateUpload is an asynchronous function, so don't callback directly. 94 // InitiateUpload is an asynchronous function, so don't callback directly.
95 base::MessageLoop::current()->PostTask(FROM_HERE, 95 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
96 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadNewFileURL))); 96 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadNewFileURL)));
97 return CancelCallback(); 97 return CancelCallback();
98 } 98 }
99 99
100 CancelCallback InitiateUploadExistingFile( 100 CancelCallback InitiateUploadExistingFile(
101 const std::string& content_type, 101 const std::string& content_type,
102 int64 content_length, 102 int64 content_length,
103 const std::string& resource_id, 103 const std::string& resource_id,
104 const UploadExistingFileOptions& options, 104 const UploadExistingFileOptions& options,
105 const InitiateUploadCallback& callback) override { 105 const InitiateUploadCallback& callback) override {
106 EXPECT_EQ(kTestMimeType, content_type); 106 EXPECT_EQ(kTestMimeType, content_type);
107 EXPECT_EQ(expected_content_length_, content_length); 107 EXPECT_EQ(expected_content_length_, content_length);
108 EXPECT_EQ(kTestInitiateUploadResourceId, resource_id); 108 EXPECT_EQ(kTestInitiateUploadResourceId, resource_id);
109 109
110 if (!options.etag.empty() && options.etag != kTestETag) { 110 if (!options.etag.empty() && options.etag != kTestETag) {
111 base::MessageLoop::current()->PostTask(FROM_HERE, 111 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
112 base::Bind(callback, HTTP_PRECONDITION, GURL())); 112 base::Bind(callback, HTTP_PRECONDITION, GURL()));
113 return CancelCallback(); 113 return CancelCallback();
114 } 114 }
115 115
116 // Calls back the upload URL for subsequent ResumeUpload requests. 116 // Calls back the upload URL for subsequent ResumeUpload requests.
117 // InitiateUpload is an asynchronous function, so don't callback directly. 117 // InitiateUpload is an asynchronous function, so don't callback directly.
118 base::MessageLoop::current()->PostTask(FROM_HERE, 118 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
119 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadExistingFileURL))); 119 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadExistingFileURL)));
120 return CancelCallback(); 120 return CancelCallback();
121 } 121 }
122 122
123 // Handles a request for uploading a chunk of bytes. 123 // Handles a request for uploading a chunk of bytes.
124 CancelCallback ResumeUpload( 124 CancelCallback ResumeUpload(
125 const GURL& upload_location, 125 const GURL& upload_location,
126 int64 start_position, 126 int64 start_position,
127 int64 end_position, 127 int64 end_position,
128 int64 content_length, 128 int64 content_length,
(...skipping 20 matching lines...) Expand all
149 149
150 // Update the internal status of the current upload session. 150 // Update the internal status of the current upload session.
151 resume_upload_call_count_++; 151 resume_upload_call_count_++;
152 received_bytes_ = end_position; 152 received_bytes_ = end_position;
153 153
154 // Callback progress 154 // Callback progress
155 if (!progress_callback.is_null()) { 155 if (!progress_callback.is_null()) {
156 // For the testing purpose, it always notifies the progress at the end of 156 // For the testing purpose, it always notifies the progress at the end of
157 // each chunk uploading. 157 // each chunk uploading.
158 int64 chunk_size = end_position - start_position; 158 int64 chunk_size = end_position - start_position;
159 base::MessageLoop::current()->PostTask(FROM_HERE, 159 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
160 base::Bind(progress_callback, chunk_size, chunk_size)); 160 base::Bind(progress_callback, chunk_size, chunk_size));
161 } 161 }
162 162
163 SendUploadRangeResponse(upload_location, callback); 163 SendUploadRangeResponse(upload_location, callback);
164 return CancelCallback(); 164 return CancelCallback();
165 } 165 }
166 166
167 // Handles a request to fetch the current upload status. 167 // Handles a request to fetch the current upload status.
168 CancelCallback GetUploadStatus(const GURL& upload_location, 168 CancelCallback GetUploadStatus(const GURL& upload_location,
169 int64 content_length, 169 int64 content_length,
(...skipping 19 matching lines...) Expand all
189 HTTP_CREATED : HTTP_SUCCESS; 189 HTTP_CREATED : HTTP_SUCCESS;
190 response = UploadRangeResponse(response_code, -1, -1); 190 response = UploadRangeResponse(response_code, -1, -1);
191 191
192 entry.reset(new FileResource); 192 entry.reset(new FileResource);
193 entry->set_md5_checksum(kTestDummyMd5); 193 entry->set_md5_checksum(kTestDummyMd5);
194 } else { 194 } else {
195 response = UploadRangeResponse( 195 response = UploadRangeResponse(
196 HTTP_RESUME_INCOMPLETE, 0, received_bytes_); 196 HTTP_RESUME_INCOMPLETE, 0, received_bytes_);
197 } 197 }
198 // ResumeUpload is an asynchronous function, so don't callback directly. 198 // ResumeUpload is an asynchronous function, so don't callback directly.
199 base::MessageLoop::current()->PostTask(FROM_HERE, 199 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
200 base::Bind(callback, response, base::Passed(&entry))); 200 base::Bind(callback, response, base::Passed(&entry)));
201 } 201 }
202 202
203 CancelCallback MultipartUploadNewFile( 203 CancelCallback MultipartUploadNewFile(
204 const std::string& content_type, 204 const std::string& content_type,
205 int64 content_length, 205 int64 content_length,
206 const std::string& parent_resource_id, 206 const std::string& parent_resource_id,
207 const std::string& title, 207 const std::string& title,
208 const base::FilePath& local_file_path, 208 const base::FilePath& local_file_path,
209 const UploadNewFileOptions& options, 209 const UploadNewFileOptions& options,
(...skipping 16 matching lines...) Expand all
226 const base::FilePath& local_file_path, 226 const base::FilePath& local_file_path,
227 const UploadExistingFileOptions& options, 227 const UploadExistingFileOptions& options,
228 const google_apis::FileResourceCallback& callback, 228 const google_apis::FileResourceCallback& callback,
229 const google_apis::ProgressCallback& progress_callback) override { 229 const google_apis::ProgressCallback& progress_callback) override {
230 EXPECT_EQ(kTestMimeType, content_type); 230 EXPECT_EQ(kTestMimeType, content_type);
231 EXPECT_EQ(expected_content_length_, content_length); 231 EXPECT_EQ(expected_content_length_, content_length);
232 EXPECT_EQ(kTestInitiateUploadResourceId, resource_id); 232 EXPECT_EQ(kTestInitiateUploadResourceId, resource_id);
233 EXPECT_EQ(expected_upload_file_, local_file_path); 233 EXPECT_EQ(expected_upload_file_, local_file_path);
234 234
235 if (!options.etag.empty() && options.etag != kTestETag) { 235 if (!options.etag.empty() && options.etag != kTestETag) {
236 base::MessageLoop::current()->PostTask( 236 base::ThreadTaskRunnerHandle::Get()->PostTask(
237 FROM_HERE, 237 FROM_HERE,
238 base::Bind(callback, HTTP_PRECONDITION, 238 base::Bind(callback, HTTP_PRECONDITION,
239 base::Passed(make_scoped_ptr<FileResource>(NULL)))); 239 base::Passed(make_scoped_ptr<FileResource>(NULL))));
240 return CancelCallback(); 240 return CancelCallback();
241 } 241 }
242 242
243 return SendMultipartUploadResult(HTTP_SUCCESS, content_length, callback, 243 return SendMultipartUploadResult(HTTP_SUCCESS, content_length, callback,
244 progress_callback); 244 progress_callback);
245 } 245 }
246 246
247 CancelCallback SendMultipartUploadResult( 247 CancelCallback SendMultipartUploadResult(
248 DriveApiErrorCode response_code, 248 DriveApiErrorCode response_code,
249 int64 content_length, 249 int64 content_length,
250 const google_apis::FileResourceCallback& callback, 250 const google_apis::FileResourceCallback& callback,
251 const google_apis::ProgressCallback& progress_callback) { 251 const google_apis::ProgressCallback& progress_callback) {
252 received_bytes_ = content_length; 252 received_bytes_ = content_length;
253 multipart_upload_call_count_++; 253 multipart_upload_call_count_++;
254 254
255 // Callback progress 255 // Callback progress
256 if (!progress_callback.is_null()) { 256 if (!progress_callback.is_null()) {
257 // For the testing purpose, it always notifies the progress at the end of 257 // For the testing purpose, it always notifies the progress at the end of
258 // whole file uploading. 258 // whole file uploading.
259 base::MessageLoop::current()->PostTask( 259 base::ThreadTaskRunnerHandle::Get()->PostTask(
260 FROM_HERE, 260 FROM_HERE,
261 base::Bind(progress_callback, content_length, content_length)); 261 base::Bind(progress_callback, content_length, content_length));
262 } 262 }
263 263
264 // MultipartUploadXXXFile is an asynchronous function, so don't callback 264 // MultipartUploadXXXFile is an asynchronous function, so don't callback
265 // directly. 265 // directly.
266 scoped_ptr<FileResource> entry; 266 scoped_ptr<FileResource> entry;
267 entry.reset(new FileResource); 267 entry.reset(new FileResource);
268 entry->set_md5_checksum(kTestDummyMd5); 268 entry->set_md5_checksum(kTestDummyMd5);
269 base::MessageLoop::current()->PostTask( 269 base::ThreadTaskRunnerHandle::Get()->PostTask(
270 FROM_HERE, base::Bind(callback, response_code, base::Passed(&entry))); 270 FROM_HERE, base::Bind(callback, response_code, base::Passed(&entry)));
271 return CancelCallback(); 271 return CancelCallback();
272 } 272 }
273 273
274 const base::FilePath expected_upload_file_; 274 const base::FilePath expected_upload_file_;
275 const int64 expected_content_length_; 275 const int64 expected_content_length_;
276 int64 received_bytes_; 276 int64 received_bytes_;
277 int64 resume_upload_call_count_; 277 int64 resume_upload_call_count_;
278 int64 multipart_upload_call_count_; 278 int64 multipart_upload_call_count_;
279 }; 279 };
280 280
281 // Mock DriveService that returns a failure at InitiateUpload(). 281 // Mock DriveService that returns a failure at InitiateUpload().
282 class MockDriveServiceNoConnectionAtInitiate : public DummyDriveService { 282 class MockDriveServiceNoConnectionAtInitiate : public DummyDriveService {
283 // Returns error. 283 // Returns error.
284 CancelCallback InitiateUploadNewFile( 284 CancelCallback InitiateUploadNewFile(
285 const std::string& content_type, 285 const std::string& content_type,
286 int64 content_length, 286 int64 content_length,
287 const std::string& parent_resource_id, 287 const std::string& parent_resource_id,
288 const std::string& title, 288 const std::string& title,
289 const UploadNewFileOptions& options, 289 const UploadNewFileOptions& options,
290 const InitiateUploadCallback& callback) override { 290 const InitiateUploadCallback& callback) override {
291 base::MessageLoop::current()->PostTask(FROM_HERE, 291 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
292 base::Bind(callback, DRIVE_NO_CONNECTION, GURL())); 292 base::Bind(callback, DRIVE_NO_CONNECTION, GURL()));
293 return CancelCallback(); 293 return CancelCallback();
294 } 294 }
295 295
296 CancelCallback InitiateUploadExistingFile( 296 CancelCallback InitiateUploadExistingFile(
297 const std::string& content_type, 297 const std::string& content_type,
298 int64 content_length, 298 int64 content_length,
299 const std::string& resource_id, 299 const std::string& resource_id,
300 const UploadExistingFileOptions& options, 300 const UploadExistingFileOptions& options,
301 const InitiateUploadCallback& callback) override { 301 const InitiateUploadCallback& callback) override {
302 base::MessageLoop::current()->PostTask(FROM_HERE, 302 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
303 base::Bind(callback, DRIVE_NO_CONNECTION, GURL())); 303 base::Bind(callback, DRIVE_NO_CONNECTION, GURL()));
304 return CancelCallback(); 304 return CancelCallback();
305 } 305 }
306 306
307 // Should not be used. 307 // Should not be used.
308 CancelCallback ResumeUpload( 308 CancelCallback ResumeUpload(
309 const GURL& upload_url, 309 const GURL& upload_url,
310 int64 start_position, 310 int64 start_position,
311 int64 end_position, 311 int64 end_position,
312 int64 content_length, 312 int64 content_length,
313 const std::string& content_type, 313 const std::string& content_type,
314 const base::FilePath& local_file_path, 314 const base::FilePath& local_file_path,
315 const UploadRangeCallback& callback, 315 const UploadRangeCallback& callback,
316 const ProgressCallback& progress_callback) override { 316 const ProgressCallback& progress_callback) override {
317 NOTREACHED(); 317 NOTREACHED();
318 return CancelCallback(); 318 return CancelCallback();
319 } 319 }
320 320
321 CancelCallback MultipartUploadNewFile( 321 CancelCallback MultipartUploadNewFile(
322 const std::string& content_type, 322 const std::string& content_type,
323 int64 content_length, 323 int64 content_length,
324 const std::string& parent_resource_id, 324 const std::string& parent_resource_id,
325 const std::string& title, 325 const std::string& title,
326 const base::FilePath& local_file_path, 326 const base::FilePath& local_file_path,
327 const UploadNewFileOptions& options, 327 const UploadNewFileOptions& options,
328 const google_apis::FileResourceCallback& callback, 328 const google_apis::FileResourceCallback& callback,
329 const google_apis::ProgressCallback& progress_callback) override { 329 const google_apis::ProgressCallback& progress_callback) override {
330 base::MessageLoop::current()->PostTask( 330 base::ThreadTaskRunnerHandle::Get()->PostTask(
331 FROM_HERE, 331 FROM_HERE,
332 base::Bind(callback, DRIVE_NO_CONNECTION, 332 base::Bind(callback, DRIVE_NO_CONNECTION,
333 base::Passed(make_scoped_ptr<FileResource>(NULL)))); 333 base::Passed(make_scoped_ptr<FileResource>(NULL))));
334 return CancelCallback(); 334 return CancelCallback();
335 } 335 }
336 336
337 CancelCallback MultipartUploadExistingFile( 337 CancelCallback MultipartUploadExistingFile(
338 const std::string& content_type, 338 const std::string& content_type,
339 int64 content_length, 339 int64 content_length,
340 const std::string& resource_id, 340 const std::string& resource_id,
341 const base::FilePath& local_file_path, 341 const base::FilePath& local_file_path,
342 const UploadExistingFileOptions& options, 342 const UploadExistingFileOptions& options,
343 const google_apis::FileResourceCallback& callback, 343 const google_apis::FileResourceCallback& callback,
344 const google_apis::ProgressCallback& progress_callback) override { 344 const google_apis::ProgressCallback& progress_callback) override {
345 base::MessageLoop::current()->PostTask( 345 base::ThreadTaskRunnerHandle::Get()->PostTask(
346 FROM_HERE, 346 FROM_HERE,
347 base::Bind(callback, DRIVE_NO_CONNECTION, 347 base::Bind(callback, DRIVE_NO_CONNECTION,
348 base::Passed(make_scoped_ptr<FileResource>(NULL)))); 348 base::Passed(make_scoped_ptr<FileResource>(NULL))));
349 return CancelCallback(); 349 return CancelCallback();
350 } 350 }
351 }; 351 };
352 352
353 // Mock DriveService that returns a failure at ResumeUpload(). 353 // Mock DriveService that returns a failure at ResumeUpload().
354 class MockDriveServiceNoConnectionAtResume : public DummyDriveService { 354 class MockDriveServiceNoConnectionAtResume : public DummyDriveService {
355 // Succeeds and returns an upload location URL. 355 // Succeeds and returns an upload location URL.
356 CancelCallback InitiateUploadNewFile( 356 CancelCallback InitiateUploadNewFile(
357 const std::string& content_type, 357 const std::string& content_type,
358 int64 content_length, 358 int64 content_length,
359 const std::string& parent_resource_id, 359 const std::string& parent_resource_id,
360 const std::string& title, 360 const std::string& title,
361 const UploadNewFileOptions& options, 361 const UploadNewFileOptions& options,
362 const InitiateUploadCallback& callback) override { 362 const InitiateUploadCallback& callback) override {
363 base::MessageLoop::current()->PostTask(FROM_HERE, 363 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
364 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadNewFileURL))); 364 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadNewFileURL)));
365 return CancelCallback(); 365 return CancelCallback();
366 } 366 }
367 367
368 CancelCallback InitiateUploadExistingFile( 368 CancelCallback InitiateUploadExistingFile(
369 const std::string& content_type, 369 const std::string& content_type,
370 int64 content_length, 370 int64 content_length,
371 const std::string& resource_id, 371 const std::string& resource_id,
372 const UploadExistingFileOptions& options, 372 const UploadExistingFileOptions& options,
373 const InitiateUploadCallback& callback) override { 373 const InitiateUploadCallback& callback) override {
374 base::MessageLoop::current()->PostTask(FROM_HERE, 374 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
375 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadExistingFileURL))); 375 base::Bind(callback, HTTP_SUCCESS, GURL(kTestUploadExistingFileURL)));
376 return CancelCallback(); 376 return CancelCallback();
377 } 377 }
378 378
379 // Returns error. 379 // Returns error.
380 CancelCallback ResumeUpload( 380 CancelCallback ResumeUpload(
381 const GURL& upload_url, 381 const GURL& upload_url,
382 int64 start_position, 382 int64 start_position,
383 int64 end_position, 383 int64 end_position,
384 int64 content_length, 384 int64 content_length,
385 const std::string& content_type, 385 const std::string& content_type,
386 const base::FilePath& local_file_path, 386 const base::FilePath& local_file_path,
387 const UploadRangeCallback& callback, 387 const UploadRangeCallback& callback,
388 const ProgressCallback& progress_callback) override { 388 const ProgressCallback& progress_callback) override {
389 base::MessageLoop::current()->PostTask(FROM_HERE, 389 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
390 base::Bind(callback, 390 base::Bind(callback,
391 UploadRangeResponse(DRIVE_NO_CONNECTION, -1, -1), 391 UploadRangeResponse(DRIVE_NO_CONNECTION, -1, -1),
392 base::Passed(scoped_ptr<FileResource>()))); 392 base::Passed(scoped_ptr<FileResource>())));
393 return CancelCallback(); 393 return CancelCallback();
394 } 394 }
395 }; 395 };
396 396
397 // Mock DriveService that returns a failure at GetUploadStatus(). 397 // Mock DriveService that returns a failure at GetUploadStatus().
398 class MockDriveServiceNoConnectionAtGetUploadStatus : public DummyDriveService { 398 class MockDriveServiceNoConnectionAtGetUploadStatus : public DummyDriveService {
399 // Returns error. 399 // Returns error.
400 CancelCallback GetUploadStatus(const GURL& upload_url, 400 CancelCallback GetUploadStatus(const GURL& upload_url,
401 int64 content_length, 401 int64 content_length,
402 const UploadRangeCallback& callback) override { 402 const UploadRangeCallback& callback) override {
403 base::MessageLoop::current()->PostTask(FROM_HERE, 403 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
404 base::Bind(callback, 404 base::Bind(callback,
405 UploadRangeResponse(DRIVE_NO_CONNECTION, -1, -1), 405 UploadRangeResponse(DRIVE_NO_CONNECTION, -1, -1),
406 base::Passed(scoped_ptr<FileResource>()))); 406 base::Passed(scoped_ptr<FileResource>())));
407 return CancelCallback(); 407 return CancelCallback();
408 } 408 }
409 }; 409 };
410 410
411 class DriveUploaderTest : public testing::Test { 411 class DriveUploaderTest : public testing::Test {
412 public: 412 public:
413 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); } 413 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); }
414 414
415 protected: 415 protected:
hashimoto 2015/05/07 09:49:41 Sorry for being unclear, message_loop.h include ca
Pranay 2015/05/07 10:01:08 Done.
416 base::MessageLoop message_loop_;
417 base::ScopedTempDir temp_dir_; 416 base::ScopedTempDir temp_dir_;
418 }; 417 };
419 418
420 } // namespace 419 } // namespace
421 420
422 TEST_F(DriveUploaderTest, UploadExisting0KB) { 421 TEST_F(DriveUploaderTest, UploadExisting0KB) {
423 base::FilePath local_path; 422 base::FilePath local_path;
424 std::string data; 423 std::string data;
425 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 424 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
426 temp_dir_.path(), 0, &local_path, &data)); 425 temp_dir_.path(), 0, &local_path, &data));
427 426
428 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 427 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
429 GURL upload_location; 428 GURL upload_location;
430 scoped_ptr<FileResource> entry; 429 scoped_ptr<FileResource> entry;
431 430
432 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 431 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
433 DriveUploader uploader(&mock_service, 432 DriveUploader uploader(&mock_service,
434 base::MessageLoopProxy::current().get()); 433 base::ThreadTaskRunnerHandle::Get().get());
435 std::vector<test_util::ProgressInfo> upload_progress_values; 434 std::vector<test_util::ProgressInfo> upload_progress_values;
436 uploader.UploadExistingFile( 435 uploader.UploadExistingFile(
437 kTestInitiateUploadResourceId, local_path, kTestMimeType, 436 kTestInitiateUploadResourceId, local_path, kTestMimeType,
438 UploadExistingFileOptions(), 437 UploadExistingFileOptions(),
439 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 438 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
440 base::Bind(&test_util::AppendProgressCallbackResult, 439 base::Bind(&test_util::AppendProgressCallbackResult,
441 &upload_progress_values)); 440 &upload_progress_values));
442 base::RunLoop().RunUntilIdle(); 441 base::RunLoop().RunUntilIdle();
443 442
444 EXPECT_EQ(0, mock_service.resume_upload_call_count()); 443 EXPECT_EQ(0, mock_service.resume_upload_call_count());
(...skipping 12 matching lines...) Expand all
457 std::string data; 456 std::string data;
458 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 457 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
459 temp_dir_.path(), 512 * 1024, &local_path, &data)); 458 temp_dir_.path(), 512 * 1024, &local_path, &data));
460 459
461 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 460 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
462 GURL upload_location; 461 GURL upload_location;
463 scoped_ptr<FileResource> entry; 462 scoped_ptr<FileResource> entry;
464 463
465 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 464 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
466 DriveUploader uploader(&mock_service, 465 DriveUploader uploader(&mock_service,
467 base::MessageLoopProxy::current().get()); 466 base::ThreadTaskRunnerHandle::Get().get());
468 std::vector<test_util::ProgressInfo> upload_progress_values; 467 std::vector<test_util::ProgressInfo> upload_progress_values;
469 uploader.UploadExistingFile( 468 uploader.UploadExistingFile(
470 kTestInitiateUploadResourceId, local_path, kTestMimeType, 469 kTestInitiateUploadResourceId, local_path, kTestMimeType,
471 UploadExistingFileOptions(), 470 UploadExistingFileOptions(),
472 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 471 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
473 base::Bind(&test_util::AppendProgressCallbackResult, 472 base::Bind(&test_util::AppendProgressCallbackResult,
474 &upload_progress_values)); 473 &upload_progress_values));
475 base::RunLoop().RunUntilIdle(); 474 base::RunLoop().RunUntilIdle();
476 475
477 // 512KB upload should be uploaded as multipart body. 476 // 512KB upload should be uploaded as multipart body.
(...skipping 14 matching lines...) Expand all
492 std::string data; 491 std::string data;
493 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 492 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
494 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); 493 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data));
495 494
496 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 495 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
497 GURL upload_location; 496 GURL upload_location;
498 scoped_ptr<FileResource> entry; 497 scoped_ptr<FileResource> entry;
499 498
500 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 499 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
501 DriveUploader uploader(&mock_service, 500 DriveUploader uploader(&mock_service,
502 base::MessageLoopProxy::current().get()); 501 base::ThreadTaskRunnerHandle::Get().get());
503 std::vector<test_util::ProgressInfo> upload_progress_values; 502 std::vector<test_util::ProgressInfo> upload_progress_values;
504 uploader.UploadExistingFile( 503 uploader.UploadExistingFile(
505 kTestInitiateUploadResourceId, local_path, kTestMimeType, 504 kTestInitiateUploadResourceId, local_path, kTestMimeType,
506 UploadExistingFileOptions(), 505 UploadExistingFileOptions(),
507 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 506 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
508 base::Bind(&test_util::AppendProgressCallbackResult, 507 base::Bind(&test_util::AppendProgressCallbackResult,
509 &upload_progress_values)); 508 &upload_progress_values));
510 base::RunLoop().RunUntilIdle(); 509 base::RunLoop().RunUntilIdle();
511 510
512 // 2MB upload should not be split into multiple chunks. 511 // 2MB upload should not be split into multiple chunks.
(...skipping 14 matching lines...) Expand all
527 std::string data; 526 std::string data;
528 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 527 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
529 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); 528 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data));
530 529
531 DriveApiErrorCode error = HTTP_SUCCESS; 530 DriveApiErrorCode error = HTTP_SUCCESS;
532 GURL upload_location; 531 GURL upload_location;
533 scoped_ptr<FileResource> entry; 532 scoped_ptr<FileResource> entry;
534 533
535 MockDriveServiceNoConnectionAtInitiate mock_service; 534 MockDriveServiceNoConnectionAtInitiate mock_service;
536 DriveUploader uploader(&mock_service, 535 DriveUploader uploader(&mock_service,
537 base::MessageLoopProxy::current().get()); 536 base::ThreadTaskRunnerHandle::Get().get());
538 uploader.UploadExistingFile( 537 uploader.UploadExistingFile(
539 kTestInitiateUploadResourceId, local_path, kTestMimeType, 538 kTestInitiateUploadResourceId, local_path, kTestMimeType,
540 UploadExistingFileOptions(), 539 UploadExistingFileOptions(),
541 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 540 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
542 google_apis::ProgressCallback()); 541 google_apis::ProgressCallback());
543 base::RunLoop().RunUntilIdle(); 542 base::RunLoop().RunUntilIdle();
544 543
545 EXPECT_EQ(DRIVE_NO_CONNECTION, error); 544 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
546 EXPECT_TRUE(upload_location.is_empty()); 545 EXPECT_TRUE(upload_location.is_empty());
547 EXPECT_FALSE(entry); 546 EXPECT_FALSE(entry);
548 } 547 }
549 548
550 TEST_F(DriveUploaderTest, MultipartUploadFail) { 549 TEST_F(DriveUploaderTest, MultipartUploadFail) {
551 base::FilePath local_path; 550 base::FilePath local_path;
552 std::string data; 551 std::string data;
553 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(temp_dir_.path(), 512 * 1024, 552 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(temp_dir_.path(), 512 * 1024,
554 &local_path, &data)); 553 &local_path, &data));
555 554
556 DriveApiErrorCode error = HTTP_SUCCESS; 555 DriveApiErrorCode error = HTTP_SUCCESS;
557 GURL upload_location; 556 GURL upload_location;
558 scoped_ptr<FileResource> entry; 557 scoped_ptr<FileResource> entry;
559 558
560 MockDriveServiceNoConnectionAtInitiate mock_service; 559 MockDriveServiceNoConnectionAtInitiate mock_service;
561 DriveUploader uploader(&mock_service, 560 DriveUploader uploader(&mock_service,
562 base::MessageLoopProxy::current().get()); 561 base::ThreadTaskRunnerHandle::Get().get());
563 uploader.UploadExistingFile( 562 uploader.UploadExistingFile(
564 kTestInitiateUploadResourceId, local_path, kTestMimeType, 563 kTestInitiateUploadResourceId, local_path, kTestMimeType,
565 UploadExistingFileOptions(), 564 UploadExistingFileOptions(),
566 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 565 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
567 google_apis::ProgressCallback()); 566 google_apis::ProgressCallback());
568 base::RunLoop().RunUntilIdle(); 567 base::RunLoop().RunUntilIdle();
569 568
570 EXPECT_EQ(DRIVE_NO_CONNECTION, error); 569 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
571 EXPECT_TRUE(upload_location.is_empty()); 570 EXPECT_TRUE(upload_location.is_empty());
572 EXPECT_FALSE(entry); 571 EXPECT_FALSE(entry);
573 } 572 }
574 573
575 TEST_F(DriveUploaderTest, InitiateUploadNoConflict) { 574 TEST_F(DriveUploaderTest, InitiateUploadNoConflict) {
576 base::FilePath local_path; 575 base::FilePath local_path;
577 std::string data; 576 std::string data;
578 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 577 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
579 temp_dir_.path(), 512 * 1024, &local_path, &data)); 578 temp_dir_.path(), 512 * 1024, &local_path, &data));
580 579
581 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 580 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
582 GURL upload_location; 581 GURL upload_location;
583 scoped_ptr<FileResource> entry; 582 scoped_ptr<FileResource> entry;
584 583
585 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 584 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
586 DriveUploader uploader(&mock_service, 585 DriveUploader uploader(&mock_service,
587 base::MessageLoopProxy::current().get()); 586 base::ThreadTaskRunnerHandle::Get().get());
588 UploadExistingFileOptions options; 587 UploadExistingFileOptions options;
589 options.etag = kTestETag; 588 options.etag = kTestETag;
590 uploader.UploadExistingFile(kTestInitiateUploadResourceId, 589 uploader.UploadExistingFile(kTestInitiateUploadResourceId,
591 local_path, 590 local_path,
592 kTestMimeType, 591 kTestMimeType,
593 options, 592 options,
594 test_util::CreateCopyResultCallback( 593 test_util::CreateCopyResultCallback(
595 &error, &upload_location, &entry), 594 &error, &upload_location, &entry),
596 google_apis::ProgressCallback()); 595 google_apis::ProgressCallback());
597 base::RunLoop().RunUntilIdle(); 596 base::RunLoop().RunUntilIdle();
598 597
599 EXPECT_EQ(HTTP_SUCCESS, error); 598 EXPECT_EQ(HTTP_SUCCESS, error);
600 EXPECT_TRUE(upload_location.is_empty()); 599 EXPECT_TRUE(upload_location.is_empty());
601 } 600 }
602 601
603 TEST_F(DriveUploaderTest, MultipartUploadConflict) { 602 TEST_F(DriveUploaderTest, MultipartUploadConflict) {
604 base::FilePath local_path; 603 base::FilePath local_path;
605 std::string data; 604 std::string data;
606 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 605 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
607 temp_dir_.path(), 512 * 1024, &local_path, &data)); 606 temp_dir_.path(), 512 * 1024, &local_path, &data));
608 const std::string kDestinationETag("destination_etag"); 607 const std::string kDestinationETag("destination_etag");
609 608
610 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 609 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
611 GURL upload_location; 610 GURL upload_location;
612 scoped_ptr<FileResource> entry; 611 scoped_ptr<FileResource> entry;
613 612
614 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 613 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
615 DriveUploader uploader(&mock_service, 614 DriveUploader uploader(&mock_service,
616 base::MessageLoopProxy::current().get()); 615 base::ThreadTaskRunnerHandle::Get().get());
617 UploadExistingFileOptions options; 616 UploadExistingFileOptions options;
618 options.etag = kDestinationETag; 617 options.etag = kDestinationETag;
619 uploader.UploadExistingFile(kTestInitiateUploadResourceId, 618 uploader.UploadExistingFile(kTestInitiateUploadResourceId,
620 local_path, 619 local_path,
621 kTestMimeType, 620 kTestMimeType,
622 options, 621 options,
623 test_util::CreateCopyResultCallback( 622 test_util::CreateCopyResultCallback(
624 &error, &upload_location, &entry), 623 &error, &upload_location, &entry),
625 google_apis::ProgressCallback()); 624 google_apis::ProgressCallback());
626 base::RunLoop().RunUntilIdle(); 625 base::RunLoop().RunUntilIdle();
627 626
628 EXPECT_EQ(HTTP_CONFLICT, error); 627 EXPECT_EQ(HTTP_CONFLICT, error);
629 EXPECT_TRUE(upload_location.is_empty()); 628 EXPECT_TRUE(upload_location.is_empty());
630 } 629 }
631 630
632 TEST_F(DriveUploaderTest, InitiateUploadConflict) { 631 TEST_F(DriveUploaderTest, InitiateUploadConflict) {
633 base::FilePath local_path; 632 base::FilePath local_path;
634 std::string data; 633 std::string data;
635 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 634 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
636 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); 635 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data));
637 const std::string kDestinationETag("destination_etag"); 636 const std::string kDestinationETag("destination_etag");
638 637
639 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 638 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
640 GURL upload_location; 639 GURL upload_location;
641 scoped_ptr<FileResource> entry; 640 scoped_ptr<FileResource> entry;
642 641
643 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 642 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
644 DriveUploader uploader(&mock_service, 643 DriveUploader uploader(&mock_service,
645 base::MessageLoopProxy::current().get()); 644 base::ThreadTaskRunnerHandle::Get().get());
646 UploadExistingFileOptions options; 645 UploadExistingFileOptions options;
647 options.etag = kDestinationETag; 646 options.etag = kDestinationETag;
648 uploader.UploadExistingFile( 647 uploader.UploadExistingFile(
649 kTestInitiateUploadResourceId, local_path, kTestMimeType, options, 648 kTestInitiateUploadResourceId, local_path, kTestMimeType, options,
650 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 649 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
651 google_apis::ProgressCallback()); 650 google_apis::ProgressCallback());
652 base::RunLoop().RunUntilIdle(); 651 base::RunLoop().RunUntilIdle();
653 652
654 EXPECT_EQ(HTTP_CONFLICT, error); 653 EXPECT_EQ(HTTP_CONFLICT, error);
655 EXPECT_TRUE(upload_location.is_empty()); 654 EXPECT_TRUE(upload_location.is_empty());
656 } 655 }
657 656
658 TEST_F(DriveUploaderTest, ResumeUploadFail) { 657 TEST_F(DriveUploaderTest, ResumeUploadFail) {
659 base::FilePath local_path; 658 base::FilePath local_path;
660 std::string data; 659 std::string data;
661 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 660 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
662 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); 661 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data));
663 662
664 DriveApiErrorCode error = HTTP_SUCCESS; 663 DriveApiErrorCode error = HTTP_SUCCESS;
665 GURL upload_location; 664 GURL upload_location;
666 scoped_ptr<FileResource> entry; 665 scoped_ptr<FileResource> entry;
667 666
668 MockDriveServiceNoConnectionAtResume mock_service; 667 MockDriveServiceNoConnectionAtResume mock_service;
669 DriveUploader uploader(&mock_service, 668 DriveUploader uploader(&mock_service,
670 base::MessageLoopProxy::current().get()); 669 base::ThreadTaskRunnerHandle::Get().get());
671 uploader.UploadExistingFile( 670 uploader.UploadExistingFile(
672 kTestInitiateUploadResourceId, local_path, kTestMimeType, 671 kTestInitiateUploadResourceId, local_path, kTestMimeType,
673 UploadExistingFileOptions(), 672 UploadExistingFileOptions(),
674 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 673 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
675 google_apis::ProgressCallback()); 674 google_apis::ProgressCallback());
676 base::RunLoop().RunUntilIdle(); 675 base::RunLoop().RunUntilIdle();
677 676
678 EXPECT_EQ(DRIVE_NO_CONNECTION, error); 677 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
679 EXPECT_EQ(GURL(kTestUploadExistingFileURL), upload_location); 678 EXPECT_EQ(GURL(kTestUploadExistingFileURL), upload_location);
680 } 679 }
681 680
682 TEST_F(DriveUploaderTest, GetUploadStatusFail) { 681 TEST_F(DriveUploaderTest, GetUploadStatusFail) {
683 base::FilePath local_path; 682 base::FilePath local_path;
684 std::string data; 683 std::string data;
685 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 684 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
686 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data)); 685 temp_dir_.path(), 2 * 1024 * 1024, &local_path, &data));
687 686
688 DriveApiErrorCode error = HTTP_SUCCESS; 687 DriveApiErrorCode error = HTTP_SUCCESS;
689 GURL upload_location; 688 GURL upload_location;
690 scoped_ptr<FileResource> entry; 689 scoped_ptr<FileResource> entry;
691 690
692 MockDriveServiceNoConnectionAtGetUploadStatus mock_service; 691 MockDriveServiceNoConnectionAtGetUploadStatus mock_service;
693 DriveUploader uploader(&mock_service, 692 DriveUploader uploader(&mock_service,
694 base::MessageLoopProxy::current().get()); 693 base::ThreadTaskRunnerHandle::Get().get());
695 uploader.ResumeUploadFile(GURL(kTestUploadExistingFileURL), 694 uploader.ResumeUploadFile(GURL(kTestUploadExistingFileURL),
696 local_path, 695 local_path,
697 kTestMimeType, 696 kTestMimeType,
698 test_util::CreateCopyResultCallback( 697 test_util::CreateCopyResultCallback(
699 &error, &upload_location, &entry), 698 &error, &upload_location, &entry),
700 google_apis::ProgressCallback()); 699 google_apis::ProgressCallback());
701 base::RunLoop().RunUntilIdle(); 700 base::RunLoop().RunUntilIdle();
702 701
703 EXPECT_EQ(DRIVE_NO_CONNECTION, error); 702 EXPECT_EQ(DRIVE_NO_CONNECTION, error);
704 EXPECT_TRUE(upload_location.is_empty()); 703 EXPECT_TRUE(upload_location.is_empty());
705 } 704 }
706 705
707 TEST_F(DriveUploaderTest, NonExistingSourceFile) { 706 TEST_F(DriveUploaderTest, NonExistingSourceFile) {
708 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 707 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
709 GURL upload_location; 708 GURL upload_location;
710 scoped_ptr<FileResource> entry; 709 scoped_ptr<FileResource> entry;
711 710
712 DriveUploader uploader(NULL, // NULL, the service won't be used. 711 DriveUploader uploader(NULL, // NULL, the service won't be used.
713 base::MessageLoopProxy::current().get()); 712 base::ThreadTaskRunnerHandle::Get().get());
714 uploader.UploadExistingFile( 713 uploader.UploadExistingFile(
715 kTestInitiateUploadResourceId, 714 kTestInitiateUploadResourceId,
716 temp_dir_.path().AppendASCII("_this_path_should_not_exist_"), 715 temp_dir_.path().AppendASCII("_this_path_should_not_exist_"),
717 kTestMimeType, UploadExistingFileOptions(), 716 kTestMimeType, UploadExistingFileOptions(),
718 test_util::CreateCopyResultCallback(&error, &upload_location, &entry), 717 test_util::CreateCopyResultCallback(&error, &upload_location, &entry),
719 google_apis::ProgressCallback()); 718 google_apis::ProgressCallback());
720 base::RunLoop().RunUntilIdle(); 719 base::RunLoop().RunUntilIdle();
721 720
722 // Should return failure without doing any attempt to connect to the server. 721 // Should return failure without doing any attempt to connect to the server.
723 EXPECT_EQ(HTTP_NOT_FOUND, error); 722 EXPECT_EQ(HTTP_NOT_FOUND, error);
724 EXPECT_TRUE(upload_location.is_empty()); 723 EXPECT_TRUE(upload_location.is_empty());
725 } 724 }
726 725
727 TEST_F(DriveUploaderTest, ResumeUpload) { 726 TEST_F(DriveUploaderTest, ResumeUpload) {
728 base::FilePath local_path; 727 base::FilePath local_path;
729 std::string data; 728 std::string data;
730 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( 729 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize(
731 temp_dir_.path(), 1024 * 1024, &local_path, &data)); 730 temp_dir_.path(), 1024 * 1024, &local_path, &data));
732 731
733 DriveApiErrorCode error = DRIVE_OTHER_ERROR; 732 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
734 GURL upload_location; 733 GURL upload_location;
735 scoped_ptr<FileResource> entry; 734 scoped_ptr<FileResource> entry;
736 735
737 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); 736 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size());
738 DriveUploader uploader(&mock_service, 737 DriveUploader uploader(&mock_service,
739 base::MessageLoopProxy::current().get()); 738 base::ThreadTaskRunnerHandle::Get().get());
740 // Emulate the situation that the only first part is successfully uploaded, 739 // Emulate the situation that the only first part is successfully uploaded,
741 // but not the latter half. 740 // but not the latter half.
742 mock_service.set_received_bytes(512 * 1024); 741 mock_service.set_received_bytes(512 * 1024);
743 742
744 std::vector<test_util::ProgressInfo> upload_progress_values; 743 std::vector<test_util::ProgressInfo> upload_progress_values;
745 uploader.ResumeUploadFile( 744 uploader.ResumeUploadFile(
746 GURL(kTestUploadExistingFileURL), 745 GURL(kTestUploadExistingFileURL),
747 local_path, 746 local_path,
748 kTestMimeType, 747 kTestMimeType,
749 test_util::CreateCopyResultCallback( 748 test_util::CreateCopyResultCallback(
750 &error, &upload_location, &entry), 749 &error, &upload_location, &entry),
751 base::Bind(&test_util::AppendProgressCallbackResult, 750 base::Bind(&test_util::AppendProgressCallbackResult,
752 &upload_progress_values)); 751 &upload_progress_values));
753 base::RunLoop().RunUntilIdle(); 752 base::RunLoop().RunUntilIdle();
754 753
755 EXPECT_EQ(1, mock_service.resume_upload_call_count()); 754 EXPECT_EQ(1, mock_service.resume_upload_call_count());
756 EXPECT_EQ(1024 * 1024, mock_service.received_bytes()); 755 EXPECT_EQ(1024 * 1024, mock_service.received_bytes());
757 EXPECT_EQ(HTTP_SUCCESS, error); 756 EXPECT_EQ(HTTP_SUCCESS, error);
758 EXPECT_TRUE(upload_location.is_empty()); 757 EXPECT_TRUE(upload_location.is_empty());
759 ASSERT_TRUE(entry); 758 ASSERT_TRUE(entry);
760 EXPECT_EQ(kTestDummyMd5, entry->md5_checksum()); 759 EXPECT_EQ(kTestDummyMd5, entry->md5_checksum());
761 ASSERT_EQ(1U, upload_progress_values.size()); 760 ASSERT_EQ(1U, upload_progress_values.size());
762 EXPECT_EQ(test_util::ProgressInfo(1024 * 1024, 1024 * 1024), 761 EXPECT_EQ(test_util::ProgressInfo(1024 * 1024, 1024 * 1024),
763 upload_progress_values[0]); 762 upload_progress_values[0]);
764 } 763 }
765 764
766 } // namespace drive 765 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/drive/fake_drive_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698