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/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" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 base::FilePath local_path; | 307 base::FilePath local_path; |
308 std::string data; | 308 std::string data; |
309 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 309 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
310 temp_dir_.path(), 0, &local_path, &data)); | 310 temp_dir_.path(), 0, &local_path, &data)); |
311 | 311 |
312 GDataErrorCode error = GDATA_OTHER_ERROR; | 312 GDataErrorCode error = GDATA_OTHER_ERROR; |
313 GURL upload_location; | 313 GURL upload_location; |
314 scoped_ptr<ResourceEntry> resource_entry; | 314 scoped_ptr<ResourceEntry> resource_entry; |
315 | 315 |
316 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); | 316 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); |
317 DriveUploader uploader(&mock_service, base::MessageLoopProxy::current()); | 317 DriveUploader uploader(&mock_service, |
| 318 base::MessageLoopProxy::current().get()); |
318 std::vector<test_util::ProgressInfo> upload_progress_values; | 319 std::vector<test_util::ProgressInfo> upload_progress_values; |
319 uploader.UploadExistingFile( | 320 uploader.UploadExistingFile( |
320 kTestInitiateUploadResourceId, | 321 kTestInitiateUploadResourceId, |
321 local_path, | 322 local_path, |
322 kTestMimeType, | 323 kTestMimeType, |
323 std::string(), // etag | 324 std::string(), // etag |
324 test_util::CreateCopyResultCallback( | 325 test_util::CreateCopyResultCallback( |
325 &error, &upload_location, &resource_entry), | 326 &error, &upload_location, &resource_entry), |
326 base::Bind(&test_util::AppendProgressCallbackResult, | 327 base::Bind(&test_util::AppendProgressCallbackResult, |
327 &upload_progress_values)); | 328 &upload_progress_values)); |
(...skipping 13 matching lines...) Expand all Loading... |
341 base::FilePath local_path; | 342 base::FilePath local_path; |
342 std::string data; | 343 std::string data; |
343 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 344 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
344 temp_dir_.path(), 512 * 1024, &local_path, &data)); | 345 temp_dir_.path(), 512 * 1024, &local_path, &data)); |
345 | 346 |
346 GDataErrorCode error = GDATA_OTHER_ERROR; | 347 GDataErrorCode error = GDATA_OTHER_ERROR; |
347 GURL upload_location; | 348 GURL upload_location; |
348 scoped_ptr<ResourceEntry> resource_entry; | 349 scoped_ptr<ResourceEntry> resource_entry; |
349 | 350 |
350 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); | 351 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); |
351 DriveUploader uploader(&mock_service, base::MessageLoopProxy::current()); | 352 DriveUploader uploader(&mock_service, |
| 353 base::MessageLoopProxy::current().get()); |
352 std::vector<test_util::ProgressInfo> upload_progress_values; | 354 std::vector<test_util::ProgressInfo> upload_progress_values; |
353 uploader.UploadExistingFile( | 355 uploader.UploadExistingFile( |
354 kTestInitiateUploadResourceId, | 356 kTestInitiateUploadResourceId, |
355 local_path, | 357 local_path, |
356 kTestMimeType, | 358 kTestMimeType, |
357 std::string(), // etag | 359 std::string(), // etag |
358 test_util::CreateCopyResultCallback( | 360 test_util::CreateCopyResultCallback( |
359 &error, &upload_location, &resource_entry), | 361 &error, &upload_location, &resource_entry), |
360 base::Bind(&test_util::AppendProgressCallbackResult, | 362 base::Bind(&test_util::AppendProgressCallbackResult, |
361 &upload_progress_values)); | 363 &upload_progress_values)); |
(...skipping 15 matching lines...) Expand all Loading... |
377 base::FilePath local_path; | 379 base::FilePath local_path; |
378 std::string data; | 380 std::string data; |
379 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 381 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
380 temp_dir_.path(), 512 * 1024, &local_path, &data)); | 382 temp_dir_.path(), 512 * 1024, &local_path, &data)); |
381 | 383 |
382 GDataErrorCode error = HTTP_SUCCESS; | 384 GDataErrorCode error = HTTP_SUCCESS; |
383 GURL upload_location; | 385 GURL upload_location; |
384 scoped_ptr<ResourceEntry> resource_entry; | 386 scoped_ptr<ResourceEntry> resource_entry; |
385 | 387 |
386 MockDriveServiceNoConnectionAtInitiate mock_service; | 388 MockDriveServiceNoConnectionAtInitiate mock_service; |
387 DriveUploader uploader(&mock_service, base::MessageLoopProxy::current()); | 389 DriveUploader uploader(&mock_service, |
388 uploader.UploadExistingFile( | 390 base::MessageLoopProxy::current().get()); |
389 kTestInitiateUploadResourceId, | 391 uploader.UploadExistingFile(kTestInitiateUploadResourceId, |
390 local_path, | 392 local_path, |
391 kTestMimeType, | 393 kTestMimeType, |
392 std::string(), // etag | 394 std::string(), // etag |
393 test_util::CreateCopyResultCallback( | 395 test_util::CreateCopyResultCallback( |
394 &error, &upload_location, &resource_entry), | 396 &error, &upload_location, &resource_entry), |
395 google_apis::ProgressCallback()); | 397 google_apis::ProgressCallback()); |
396 base::RunLoop().RunUntilIdle(); | 398 base::RunLoop().RunUntilIdle(); |
397 | 399 |
398 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 400 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
399 EXPECT_TRUE(upload_location.is_empty()); | 401 EXPECT_TRUE(upload_location.is_empty()); |
400 EXPECT_FALSE(resource_entry); | 402 EXPECT_FALSE(resource_entry); |
401 } | 403 } |
402 | 404 |
403 TEST_F(DriveUploaderTest, InitiateUploadNoConflict) { | 405 TEST_F(DriveUploaderTest, InitiateUploadNoConflict) { |
404 base::FilePath local_path; | 406 base::FilePath local_path; |
405 std::string data; | 407 std::string data; |
406 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 408 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
407 temp_dir_.path(), 512 * 1024, &local_path, &data)); | 409 temp_dir_.path(), 512 * 1024, &local_path, &data)); |
408 | 410 |
409 GDataErrorCode error = GDATA_OTHER_ERROR; | 411 GDataErrorCode error = GDATA_OTHER_ERROR; |
410 GURL upload_location; | 412 GURL upload_location; |
411 scoped_ptr<ResourceEntry> resource_entry; | 413 scoped_ptr<ResourceEntry> resource_entry; |
412 | 414 |
413 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); | 415 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); |
414 DriveUploader uploader(&mock_service, base::MessageLoopProxy::current()); | 416 DriveUploader uploader(&mock_service, |
415 uploader.UploadExistingFile( | 417 base::MessageLoopProxy::current().get()); |
416 kTestInitiateUploadResourceId, | 418 uploader.UploadExistingFile(kTestInitiateUploadResourceId, |
417 local_path, | 419 local_path, |
418 kTestMimeType, | 420 kTestMimeType, |
419 kTestETag, | 421 kTestETag, |
420 test_util::CreateCopyResultCallback( | 422 test_util::CreateCopyResultCallback( |
421 &error, &upload_location, &resource_entry), | 423 &error, &upload_location, &resource_entry), |
422 google_apis::ProgressCallback()); | 424 google_apis::ProgressCallback()); |
423 base::RunLoop().RunUntilIdle(); | 425 base::RunLoop().RunUntilIdle(); |
424 | 426 |
425 EXPECT_EQ(HTTP_SUCCESS, error); | 427 EXPECT_EQ(HTTP_SUCCESS, error); |
426 EXPECT_TRUE(upload_location.is_empty()); | 428 EXPECT_TRUE(upload_location.is_empty()); |
427 } | 429 } |
428 | 430 |
429 TEST_F(DriveUploaderTest, InitiateUploadConflict) { | 431 TEST_F(DriveUploaderTest, InitiateUploadConflict) { |
430 base::FilePath local_path; | 432 base::FilePath local_path; |
431 std::string data; | 433 std::string data; |
432 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 434 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
433 temp_dir_.path(), 512 * 1024, &local_path, &data)); | 435 temp_dir_.path(), 512 * 1024, &local_path, &data)); |
434 const std::string kDestinationETag("destination_etag"); | 436 const std::string kDestinationETag("destination_etag"); |
435 | 437 |
436 GDataErrorCode error = GDATA_OTHER_ERROR; | 438 GDataErrorCode error = GDATA_OTHER_ERROR; |
437 GURL upload_location; | 439 GURL upload_location; |
438 scoped_ptr<ResourceEntry> resource_entry; | 440 scoped_ptr<ResourceEntry> resource_entry; |
439 | 441 |
440 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); | 442 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); |
441 DriveUploader uploader(&mock_service, base::MessageLoopProxy::current()); | 443 DriveUploader uploader(&mock_service, |
442 uploader.UploadExistingFile( | 444 base::MessageLoopProxy::current().get()); |
443 kTestInitiateUploadResourceId, | 445 uploader.UploadExistingFile(kTestInitiateUploadResourceId, |
444 local_path, | 446 local_path, |
445 kTestMimeType, | 447 kTestMimeType, |
446 kDestinationETag, | 448 kDestinationETag, |
447 test_util::CreateCopyResultCallback( | 449 test_util::CreateCopyResultCallback( |
448 &error, &upload_location, &resource_entry), | 450 &error, &upload_location, &resource_entry), |
449 google_apis::ProgressCallback()); | 451 google_apis::ProgressCallback()); |
450 base::RunLoop().RunUntilIdle(); | 452 base::RunLoop().RunUntilIdle(); |
451 | 453 |
452 EXPECT_EQ(HTTP_CONFLICT, error); | 454 EXPECT_EQ(HTTP_CONFLICT, error); |
453 EXPECT_TRUE(upload_location.is_empty()); | 455 EXPECT_TRUE(upload_location.is_empty()); |
454 } | 456 } |
455 | 457 |
456 TEST_F(DriveUploaderTest, ResumeUploadFail) { | 458 TEST_F(DriveUploaderTest, ResumeUploadFail) { |
457 base::FilePath local_path; | 459 base::FilePath local_path; |
458 std::string data; | 460 std::string data; |
459 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 461 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
460 temp_dir_.path(), 512 * 1024, &local_path, &data)); | 462 temp_dir_.path(), 512 * 1024, &local_path, &data)); |
461 | 463 |
462 GDataErrorCode error = HTTP_SUCCESS; | 464 GDataErrorCode error = HTTP_SUCCESS; |
463 GURL upload_location; | 465 GURL upload_location; |
464 scoped_ptr<ResourceEntry> resource_entry; | 466 scoped_ptr<ResourceEntry> resource_entry; |
465 | 467 |
466 MockDriveServiceNoConnectionAtResume mock_service; | 468 MockDriveServiceNoConnectionAtResume mock_service; |
467 DriveUploader uploader(&mock_service, base::MessageLoopProxy::current()); | 469 DriveUploader uploader(&mock_service, |
468 uploader.UploadExistingFile( | 470 base::MessageLoopProxy::current().get()); |
469 kTestInitiateUploadResourceId, | 471 uploader.UploadExistingFile(kTestInitiateUploadResourceId, |
470 local_path, | 472 local_path, |
471 kTestMimeType, | 473 kTestMimeType, |
472 std::string(), // etag | 474 std::string(), // etag |
473 test_util::CreateCopyResultCallback( | 475 test_util::CreateCopyResultCallback( |
474 &error, &upload_location, &resource_entry), | 476 &error, &upload_location, &resource_entry), |
475 google_apis::ProgressCallback()); | 477 google_apis::ProgressCallback()); |
476 base::RunLoop().RunUntilIdle(); | 478 base::RunLoop().RunUntilIdle(); |
477 | 479 |
478 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 480 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
479 EXPECT_EQ(GURL(kTestUploadExistingFileURL), upload_location); | 481 EXPECT_EQ(GURL(kTestUploadExistingFileURL), upload_location); |
480 } | 482 } |
481 | 483 |
482 TEST_F(DriveUploaderTest, NonExistingSourceFile) { | 484 TEST_F(DriveUploaderTest, NonExistingSourceFile) { |
483 GDataErrorCode error = GDATA_OTHER_ERROR; | 485 GDataErrorCode error = GDATA_OTHER_ERROR; |
484 GURL upload_location; | 486 GURL upload_location; |
485 scoped_ptr<ResourceEntry> resource_entry; | 487 scoped_ptr<ResourceEntry> resource_entry; |
486 | 488 |
487 DriveUploader uploader(NULL, // NULL, the service won't be used. | 489 DriveUploader uploader(NULL, // NULL, the service won't be used. |
488 base::MessageLoopProxy::current()); | 490 base::MessageLoopProxy::current().get()); |
489 uploader.UploadExistingFile( | 491 uploader.UploadExistingFile( |
490 kTestInitiateUploadResourceId, | 492 kTestInitiateUploadResourceId, |
491 temp_dir_.path().AppendASCII("_this_path_should_not_exist_"), | 493 temp_dir_.path().AppendASCII("_this_path_should_not_exist_"), |
492 kTestMimeType, | 494 kTestMimeType, |
493 std::string(), // etag | 495 std::string(), // etag |
494 test_util::CreateCopyResultCallback( | 496 test_util::CreateCopyResultCallback( |
495 &error, &upload_location, &resource_entry), | 497 &error, &upload_location, &resource_entry), |
496 google_apis::ProgressCallback()); | 498 google_apis::ProgressCallback()); |
497 base::RunLoop().RunUntilIdle(); | 499 base::RunLoop().RunUntilIdle(); |
498 | 500 |
499 // Should return failure without doing any attempt to connect to the server. | 501 // Should return failure without doing any attempt to connect to the server. |
500 EXPECT_EQ(HTTP_NOT_FOUND, error); | 502 EXPECT_EQ(HTTP_NOT_FOUND, error); |
501 EXPECT_TRUE(upload_location.is_empty()); | 503 EXPECT_TRUE(upload_location.is_empty()); |
502 } | 504 } |
503 | 505 |
504 TEST_F(DriveUploaderTest, ResumeUpload) { | 506 TEST_F(DriveUploaderTest, ResumeUpload) { |
505 base::FilePath local_path; | 507 base::FilePath local_path; |
506 std::string data; | 508 std::string data; |
507 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( | 509 ASSERT_TRUE(test_util::CreateFileOfSpecifiedSize( |
508 temp_dir_.path(), 1024 * 1024, &local_path, &data)); | 510 temp_dir_.path(), 1024 * 1024, &local_path, &data)); |
509 | 511 |
510 GDataErrorCode error = GDATA_OTHER_ERROR; | 512 GDataErrorCode error = GDATA_OTHER_ERROR; |
511 GURL upload_location; | 513 GURL upload_location; |
512 scoped_ptr<ResourceEntry> resource_entry; | 514 scoped_ptr<ResourceEntry> resource_entry; |
513 | 515 |
514 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); | 516 MockDriveServiceWithUploadExpectation mock_service(local_path, data.size()); |
515 DriveUploader uploader(&mock_service, base::MessageLoopProxy::current()); | 517 DriveUploader uploader(&mock_service, |
| 518 base::MessageLoopProxy::current().get()); |
516 // Emulate the situation that the only first part is successfully uploaded, | 519 // Emulate the situation that the only first part is successfully uploaded, |
517 // but not the latter half. | 520 // but not the latter half. |
518 mock_service.set_received_bytes(512 * 1024); | 521 mock_service.set_received_bytes(512 * 1024); |
519 | 522 |
520 std::vector<test_util::ProgressInfo> upload_progress_values; | 523 std::vector<test_util::ProgressInfo> upload_progress_values; |
521 uploader.ResumeUploadFile( | 524 uploader.ResumeUploadFile( |
522 GURL(kTestUploadExistingFileURL), | 525 GURL(kTestUploadExistingFileURL), |
523 local_path, | 526 local_path, |
524 kTestMimeType, | 527 kTestMimeType, |
525 test_util::CreateCopyResultCallback( | 528 test_util::CreateCopyResultCallback( |
526 &error, &upload_location, &resource_entry), | 529 &error, &upload_location, &resource_entry), |
527 base::Bind(&test_util::AppendProgressCallbackResult, | 530 base::Bind(&test_util::AppendProgressCallbackResult, |
528 &upload_progress_values)); | 531 &upload_progress_values)); |
529 base::RunLoop().RunUntilIdle(); | 532 base::RunLoop().RunUntilIdle(); |
530 | 533 |
531 EXPECT_EQ(1, mock_service.resume_upload_call_count()); | 534 EXPECT_EQ(1, mock_service.resume_upload_call_count()); |
532 EXPECT_EQ(1024 * 1024, mock_service.received_bytes()); | 535 EXPECT_EQ(1024 * 1024, mock_service.received_bytes()); |
533 EXPECT_EQ(HTTP_SUCCESS, error); | 536 EXPECT_EQ(HTTP_SUCCESS, error); |
534 EXPECT_TRUE(upload_location.is_empty()); | 537 EXPECT_TRUE(upload_location.is_empty()); |
535 ASSERT_TRUE(resource_entry); | 538 ASSERT_TRUE(resource_entry); |
536 EXPECT_EQ(kTestDummyId, resource_entry->id()); | 539 EXPECT_EQ(kTestDummyId, resource_entry->id()); |
537 ASSERT_EQ(1U, upload_progress_values.size()); | 540 ASSERT_EQ(1U, upload_progress_values.size()); |
538 EXPECT_EQ(test_util::ProgressInfo(1024 * 1024, 1024 * 1024), | 541 EXPECT_EQ(test_util::ProgressInfo(1024 * 1024, 1024 * 1024), |
539 upload_progress_values[0]); | 542 upload_progress_values[0]); |
540 } | 543 } |
541 | 544 |
542 } // namespace drive | 545 } // namespace drive |
OLD | NEW |