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

Side by Side Diff: chrome/browser/chromeos/drive/job_scheduler_unittest.cc

Issue 15650008: drive: Rename drive::DriveClientContext to drive::ClientContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 6 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 | Annotate | Revision Log
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/chromeos/drive/job_scheduler.h" 5 #include "chrome/browser/chromeos/drive/job_scheduler.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } 309 }
310 310
311 TEST_F(JobSchedulerTest, GetResourceEntry) { 311 TEST_F(JobSchedulerTest, GetResourceEntry) {
312 ConnectToWifi(); 312 ConnectToWifi();
313 313
314 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 314 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
315 scoped_ptr<google_apis::ResourceEntry> entry; 315 scoped_ptr<google_apis::ResourceEntry> entry;
316 316
317 scheduler_->GetResourceEntry( 317 scheduler_->GetResourceEntry(
318 "file:2_file_resource_id", // resource ID 318 "file:2_file_resource_id", // resource ID
319 DriveClientContext(USER_INITIATED), 319 ClientContext(USER_INITIATED),
320 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); 320 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
321 google_apis::test_util::RunBlockingPoolTask(); 321 google_apis::test_util::RunBlockingPoolTask();
322 322
323 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); 323 ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
324 ASSERT_TRUE(entry); 324 ASSERT_TRUE(entry);
325 } 325 }
326 326
327 TEST_F(JobSchedulerTest, DeleteResource) { 327 TEST_F(JobSchedulerTest, DeleteResource) {
328 ConnectToWifi(); 328 ConnectToWifi();
329 329
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 ConnectToNone(); 433 ConnectToNone();
434 434
435 std::string resource_1("file:1_file_resource_id"); 435 std::string resource_1("file:1_file_resource_id");
436 std::string resource_2("file:2_file_resource_id"); 436 std::string resource_2("file:2_file_resource_id");
437 std::string resource_3("file:3_file_resource_id"); 437 std::string resource_3("file:3_file_resource_id");
438 std::string resource_4("file:4_file_resource_id"); 438 std::string resource_4("file:4_file_resource_id");
439 std::vector<std::string> resource_ids; 439 std::vector<std::string> resource_ids;
440 440
441 scheduler_->GetResourceEntry( 441 scheduler_->GetResourceEntry(
442 resource_1, // resource ID 442 resource_1, // resource ID
443 DriveClientContext(USER_INITIATED), 443 ClientContext(USER_INITIATED),
444 base::Bind(&CopyResourceIdFromGetResourceEntryCallback, 444 base::Bind(&CopyResourceIdFromGetResourceEntryCallback,
445 &resource_ids, 445 &resource_ids,
446 resource_1)); 446 resource_1));
447 scheduler_->GetResourceEntry( 447 scheduler_->GetResourceEntry(
448 resource_2, // resource ID 448 resource_2, // resource ID
449 DriveClientContext(BACKGROUND), 449 ClientContext(BACKGROUND),
450 base::Bind(&CopyResourceIdFromGetResourceEntryCallback, 450 base::Bind(&CopyResourceIdFromGetResourceEntryCallback,
451 &resource_ids, 451 &resource_ids,
452 resource_2)); 452 resource_2));
453 scheduler_->GetResourceEntry( 453 scheduler_->GetResourceEntry(
454 resource_3, // resource ID 454 resource_3, // resource ID
455 DriveClientContext(BACKGROUND), 455 ClientContext(BACKGROUND),
456 base::Bind(&CopyResourceIdFromGetResourceEntryCallback, 456 base::Bind(&CopyResourceIdFromGetResourceEntryCallback,
457 &resource_ids, 457 &resource_ids,
458 resource_3)); 458 resource_3));
459 scheduler_->GetResourceEntry( 459 scheduler_->GetResourceEntry(
460 resource_4, // resource ID 460 resource_4, // resource ID
461 DriveClientContext(USER_INITIATED), 461 ClientContext(USER_INITIATED),
462 base::Bind(&CopyResourceIdFromGetResourceEntryCallback, 462 base::Bind(&CopyResourceIdFromGetResourceEntryCallback,
463 &resource_ids, 463 &resource_ids,
464 resource_4)); 464 resource_4));
465 465
466 // Reconnect to the network to start all jobs. 466 // Reconnect to the network to start all jobs.
467 ConnectToWifi(); 467 ConnectToWifi();
468 google_apis::test_util::RunBlockingPoolTask(); 468 google_apis::test_util::RunBlockingPoolTask();
469 469
470 ASSERT_EQ(resource_ids.size(), 4ul); 470 ASSERT_EQ(resource_ids.size(), 4ul);
471 ASSERT_EQ(resource_ids[0], resource_1); 471 ASSERT_EQ(resource_ids[0], resource_1);
472 ASSERT_EQ(resource_ids[1], resource_4); 472 ASSERT_EQ(resource_ids[1], resource_4);
473 ASSERT_EQ(resource_ids[2], resource_2); 473 ASSERT_EQ(resource_ids[2], resource_2);
474 ASSERT_EQ(resource_ids[3], resource_3); 474 ASSERT_EQ(resource_ids[3], resource_3);
475 } 475 }
476 476
477 TEST_F(JobSchedulerTest, GetResourceEntryNoConnection) { 477 TEST_F(JobSchedulerTest, GetResourceEntryNoConnection) {
478 ConnectToNone(); 478 ConnectToNone();
479 479
480 std::string resource("file:1_file_resource_id"); 480 std::string resource("file:1_file_resource_id");
481 std::vector<std::string> resource_ids; 481 std::vector<std::string> resource_ids;
482 482
483 scheduler_->GetResourceEntry( 483 scheduler_->GetResourceEntry(
484 resource, // resource ID 484 resource, // resource ID
485 DriveClientContext(BACKGROUND), 485 ClientContext(BACKGROUND),
486 base::Bind(&CopyResourceIdFromGetResourceEntryCallback, 486 base::Bind(&CopyResourceIdFromGetResourceEntryCallback,
487 &resource_ids, 487 &resource_ids,
488 resource)); 488 resource));
489 google_apis::test_util::RunBlockingPoolTask(); 489 google_apis::test_util::RunBlockingPoolTask();
490 490
491 ASSERT_EQ(resource_ids.size(), 0ul); 491 ASSERT_EQ(resource_ids.size(), 0ul);
492 492
493 // Reconnect to the net. 493 // Reconnect to the net.
494 ConnectToWifi(); 494 ConnectToWifi();
495 495
(...skipping 15 matching lines...) Expand all
511 511
512 const GURL kContentUrl("https://file_content_url/"); 512 const GURL kContentUrl("https://file_content_url/");
513 const base::FilePath kOutputFilePath = 513 const base::FilePath kOutputFilePath =
514 temp_dir.path().AppendASCII("whatever.txt"); 514 temp_dir.path().AppendASCII("whatever.txt");
515 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; 515 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR;
516 base::FilePath output_file_path; 516 base::FilePath output_file_path;
517 scheduler_->DownloadFile( 517 scheduler_->DownloadFile(
518 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path 518 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path
519 kOutputFilePath, 519 kOutputFilePath,
520 kContentUrl, 520 kContentUrl,
521 DriveClientContext(BACKGROUND), 521 ClientContext(BACKGROUND),
522 google_apis::test_util::CreateCopyResultCallback( 522 google_apis::test_util::CreateCopyResultCallback(
523 &download_error, &output_file_path), 523 &download_error, &output_file_path),
524 google_apis::GetContentCallback()); 524 google_apis::GetContentCallback());
525 // Metadata should still work 525 // Metadata should still work
526 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; 526 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR;
527 scoped_ptr<google_apis::AboutResource> about_resource; 527 scoped_ptr<google_apis::AboutResource> about_resource;
528 528
529 // Try to get the metadata 529 // Try to get the metadata
530 scheduler_->GetAboutResource( 530 scheduler_->GetAboutResource(
531 google_apis::test_util::CreateCopyResultCallback( 531 google_apis::test_util::CreateCopyResultCallback(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 564
565 const GURL kContentUrl("https://file_content_url/"); 565 const GURL kContentUrl("https://file_content_url/");
566 const base::FilePath kOutputFilePath = 566 const base::FilePath kOutputFilePath =
567 temp_dir.path().AppendASCII("whatever.txt"); 567 temp_dir.path().AppendASCII("whatever.txt");
568 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; 568 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR;
569 base::FilePath output_file_path; 569 base::FilePath output_file_path;
570 scheduler_->DownloadFile( 570 scheduler_->DownloadFile(
571 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path 571 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path
572 kOutputFilePath, 572 kOutputFilePath,
573 kContentUrl, 573 kContentUrl,
574 DriveClientContext(BACKGROUND), 574 ClientContext(BACKGROUND),
575 google_apis::test_util::CreateCopyResultCallback( 575 google_apis::test_util::CreateCopyResultCallback(
576 &download_error, &output_file_path), 576 &download_error, &output_file_path),
577 google_apis::GetContentCallback()); 577 google_apis::GetContentCallback());
578 // Metadata should still work 578 // Metadata should still work
579 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; 579 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR;
580 scoped_ptr<google_apis::AboutResource> about_resource; 580 scoped_ptr<google_apis::AboutResource> about_resource;
581 581
582 // Try to get the metadata 582 // Try to get the metadata
583 scheduler_->GetAboutResource( 583 scheduler_->GetAboutResource(
584 google_apis::test_util::CreateCopyResultCallback( 584 google_apis::test_util::CreateCopyResultCallback(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 617
618 const GURL kContentUrl("https://file_content_url/"); 618 const GURL kContentUrl("https://file_content_url/");
619 const base::FilePath kOutputFilePath = 619 const base::FilePath kOutputFilePath =
620 temp_dir.path().AppendASCII("whatever.txt"); 620 temp_dir.path().AppendASCII("whatever.txt");
621 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; 621 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR;
622 base::FilePath output_file_path; 622 base::FilePath output_file_path;
623 scheduler_->DownloadFile( 623 scheduler_->DownloadFile(
624 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path 624 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path
625 kOutputFilePath, 625 kOutputFilePath,
626 kContentUrl, 626 kContentUrl,
627 DriveClientContext(BACKGROUND), 627 ClientContext(BACKGROUND),
628 google_apis::test_util::CreateCopyResultCallback( 628 google_apis::test_util::CreateCopyResultCallback(
629 &download_error, &output_file_path), 629 &download_error, &output_file_path),
630 google_apis::GetContentCallback()); 630 google_apis::GetContentCallback());
631 // Metadata should still work 631 // Metadata should still work
632 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; 632 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR;
633 scoped_ptr<google_apis::AboutResource> about_resource; 633 scoped_ptr<google_apis::AboutResource> about_resource;
634 634
635 // Try to get the metadata 635 // Try to get the metadata
636 scheduler_->GetAboutResource( 636 scheduler_->GetAboutResource(
637 google_apis::test_util::CreateCopyResultCallback( 637 google_apis::test_util::CreateCopyResultCallback(
(...skipping 24 matching lines...) Expand all
662 662
663 const GURL kContentUrl("https://file_content_url/"); 663 const GURL kContentUrl("https://file_content_url/");
664 const base::FilePath kOutputFilePath = 664 const base::FilePath kOutputFilePath =
665 temp_dir.path().AppendASCII("whatever.txt"); 665 temp_dir.path().AppendASCII("whatever.txt");
666 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; 666 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR;
667 base::FilePath output_file_path; 667 base::FilePath output_file_path;
668 scheduler_->DownloadFile( 668 scheduler_->DownloadFile(
669 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path 669 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path
670 kOutputFilePath, 670 kOutputFilePath,
671 kContentUrl, 671 kContentUrl,
672 DriveClientContext(BACKGROUND), 672 ClientContext(BACKGROUND),
673 google_apis::test_util::CreateCopyResultCallback( 673 google_apis::test_util::CreateCopyResultCallback(
674 &download_error, &output_file_path), 674 &download_error, &output_file_path),
675 google_apis::GetContentCallback()); 675 google_apis::GetContentCallback());
676 // Metadata should still work 676 // Metadata should still work
677 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; 677 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR;
678 scoped_ptr<google_apis::AboutResource> about_resource; 678 scoped_ptr<google_apis::AboutResource> about_resource;
679 679
680 // Try to get the metadata 680 // Try to get the metadata
681 scheduler_->GetAboutResource( 681 scheduler_->GetAboutResource(
682 google_apis::test_util::CreateCopyResultCallback( 682 google_apis::test_util::CreateCopyResultCallback(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 expected_types.insert(TYPE_RENAME_RESOURCE); 726 expected_types.insert(TYPE_RENAME_RESOURCE);
727 scheduler_->RenameResource( 727 scheduler_->RenameResource(
728 "file:2_file_resource_id", 728 "file:2_file_resource_id",
729 "New Name", 729 "New Name",
730 google_apis::test_util::CreateCopyResultCallback(&error)); 730 google_apis::test_util::CreateCopyResultCallback(&error));
731 expected_types.insert(TYPE_DOWNLOAD_FILE); 731 expected_types.insert(TYPE_DOWNLOAD_FILE);
732 scheduler_->DownloadFile( 732 scheduler_->DownloadFile(
733 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path 733 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path
734 temp_dir.path().AppendASCII("whatever.txt"), 734 temp_dir.path().AppendASCII("whatever.txt"),
735 GURL("https://file_content_url/"), 735 GURL("https://file_content_url/"),
736 DriveClientContext(BACKGROUND), 736 ClientContext(BACKGROUND),
737 google_apis::test_util::CreateCopyResultCallback(&error, &path), 737 google_apis::test_util::CreateCopyResultCallback(&error, &path),
738 google_apis::GetContentCallback()); 738 google_apis::GetContentCallback());
739 739
740 // The number of jobs queued so far. 740 // The number of jobs queued so far.
741 EXPECT_EQ(4U, scheduler_->GetJobInfoList().size()); 741 EXPECT_EQ(4U, scheduler_->GetJobInfoList().size());
742 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_ADD_NEW_DIRECTORY)); 742 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_ADD_NEW_DIRECTORY));
743 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_GET_ABOUT_RESOURCE)); 743 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_GET_ABOUT_RESOURCE));
744 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_RENAME_RESOURCE)); 744 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_RENAME_RESOURCE));
745 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_DOWNLOAD_FILE)); 745 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_DOWNLOAD_FILE));
746 EXPECT_FALSE(logger.Has(JobListLogger::DONE, TYPE_ADD_NEW_DIRECTORY)); 746 EXPECT_FALSE(logger.Has(JobListLogger::DONE, TYPE_ADD_NEW_DIRECTORY));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 821 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
822 822
823 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 823 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
824 base::FilePath path; 824 base::FilePath path;
825 825
826 // Download job. 826 // Download job.
827 scheduler_->DownloadFile( 827 scheduler_->DownloadFile(
828 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path 828 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path
829 temp_dir.path().AppendASCII("whatever.txt"), 829 temp_dir.path().AppendASCII("whatever.txt"),
830 GURL("https://file_content_url/"), 830 GURL("https://file_content_url/"),
831 DriveClientContext(BACKGROUND), 831 ClientContext(BACKGROUND),
832 google_apis::test_util::CreateCopyResultCallback(&error, &path), 832 google_apis::test_util::CreateCopyResultCallback(&error, &path),
833 google_apis::GetContentCallback()); 833 google_apis::GetContentCallback());
834 google_apis::test_util::RunBlockingPoolTask(); 834 google_apis::test_util::RunBlockingPoolTask();
835 835
836 std::vector<int64> download_progress; 836 std::vector<int64> download_progress;
837 logger.GetProgressInfo(TYPE_DOWNLOAD_FILE, &download_progress); 837 logger.GetProgressInfo(TYPE_DOWNLOAD_FILE, &download_progress);
838 ASSERT_TRUE(!download_progress.empty()); 838 ASSERT_TRUE(!download_progress.empty());
839 EXPECT_TRUE(base::STLIsSorted(download_progress)); 839 EXPECT_TRUE(base::STLIsSorted(download_progress));
840 EXPECT_GE(download_progress.front(), 0); 840 EXPECT_GE(download_progress.front(), 0);
841 EXPECT_LE(download_progress.back(), 26); 841 EXPECT_LE(download_progress.back(), 26);
842 842
843 // Upload job. 843 // Upload job.
844 path = temp_dir.path().AppendASCII("new_file.txt"); 844 path = temp_dir.path().AppendASCII("new_file.txt");
845 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(path, "Hello")); 845 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(path, "Hello"));
846 google_apis::GDataErrorCode upload_error = 846 google_apis::GDataErrorCode upload_error =
847 google_apis::GDATA_OTHER_ERROR; 847 google_apis::GDATA_OTHER_ERROR;
848 scoped_ptr<google_apis::ResourceEntry> entry; 848 scoped_ptr<google_apis::ResourceEntry> entry;
849 849
850 scheduler_->UploadNewFile( 850 scheduler_->UploadNewFile(
851 fake_drive_service_->GetRootResourceId(), 851 fake_drive_service_->GetRootResourceId(),
852 base::FilePath::FromUTF8Unsafe("drive/new_file.txt"), 852 base::FilePath::FromUTF8Unsafe("drive/new_file.txt"),
853 path, 853 path,
854 "dummy title", 854 "dummy title",
855 "plain/plain", 855 "plain/plain",
856 DriveClientContext(BACKGROUND), 856 ClientContext(BACKGROUND),
857 google_apis::test_util::CreateCopyResultCallback(&upload_error, &entry)); 857 google_apis::test_util::CreateCopyResultCallback(&upload_error, &entry));
858 google_apis::test_util::RunBlockingPoolTask(); 858 google_apis::test_util::RunBlockingPoolTask();
859 859
860 std::vector<int64> upload_progress; 860 std::vector<int64> upload_progress;
861 logger.GetProgressInfo(TYPE_UPLOAD_NEW_FILE, &upload_progress); 861 logger.GetProgressInfo(TYPE_UPLOAD_NEW_FILE, &upload_progress);
862 ASSERT_TRUE(!upload_progress.empty()); 862 ASSERT_TRUE(!upload_progress.empty());
863 EXPECT_TRUE(base::STLIsSorted(upload_progress)); 863 EXPECT_TRUE(base::STLIsSorted(upload_progress));
864 EXPECT_GE(upload_progress.front(), 0); 864 EXPECT_GE(upload_progress.front(), 0);
865 EXPECT_LE(upload_progress.back(), 13); 865 EXPECT_LE(upload_progress.back(), 13);
866 } 866 }
867 867
868 } // namespace drive 868 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/job_scheduler.cc ('k') | chrome/browser/chromeos/drive/mock_file_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698