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

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

Issue 2317993003: //chrome/browser and //components A-E: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Just rebased Created 4 years, 3 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
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/job_scheduler.h" 5 #include "components/drive/job_scheduler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 ConnectToCellular(); 580 ConnectToCellular();
581 581
582 // Disable fetching over cellular network. 582 // Disable fetching over cellular network.
583 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true); 583 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true);
584 584
585 // Try to get a file in the background 585 // Try to get a file in the background
586 base::ScopedTempDir temp_dir; 586 base::ScopedTempDir temp_dir;
587 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 587 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
588 588
589 const base::FilePath kOutputFilePath = 589 const base::FilePath kOutputFilePath =
590 temp_dir.path().AppendASCII("whatever.txt"); 590 temp_dir.GetPath().AppendASCII("whatever.txt");
591 google_apis::DriveApiErrorCode download_error = 591 google_apis::DriveApiErrorCode download_error =
592 google_apis::DRIVE_OTHER_ERROR; 592 google_apis::DRIVE_OTHER_ERROR;
593 base::FilePath output_file_path; 593 base::FilePath output_file_path;
594 scheduler_->DownloadFile( 594 scheduler_->DownloadFile(
595 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path 595 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path
596 kDummyDownloadFileSize, 596 kDummyDownloadFileSize,
597 kOutputFilePath, 597 kOutputFilePath,
598 "2_file_resource_id", 598 "2_file_resource_id",
599 ClientContext(BACKGROUND), 599 ClientContext(BACKGROUND),
600 google_apis::test_util::CreateCopyResultCallback( 600 google_apis::test_util::CreateCopyResultCallback(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 ConnectToWimax(); 635 ConnectToWimax();
636 636
637 // Disable fetching over cellular network. 637 // Disable fetching over cellular network.
638 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true); 638 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true);
639 639
640 // Try to get a file in the background 640 // Try to get a file in the background
641 base::ScopedTempDir temp_dir; 641 base::ScopedTempDir temp_dir;
642 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 642 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
643 643
644 const base::FilePath kOutputFilePath = 644 const base::FilePath kOutputFilePath =
645 temp_dir.path().AppendASCII("whatever.txt"); 645 temp_dir.GetPath().AppendASCII("whatever.txt");
646 google_apis::DriveApiErrorCode download_error = 646 google_apis::DriveApiErrorCode download_error =
647 google_apis::DRIVE_OTHER_ERROR; 647 google_apis::DRIVE_OTHER_ERROR;
648 base::FilePath output_file_path; 648 base::FilePath output_file_path;
649 scheduler_->DownloadFile( 649 scheduler_->DownloadFile(
650 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path 650 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path
651 kDummyDownloadFileSize, 651 kDummyDownloadFileSize,
652 kOutputFilePath, 652 kOutputFilePath,
653 "2_file_resource_id", 653 "2_file_resource_id",
654 ClientContext(BACKGROUND), 654 ClientContext(BACKGROUND),
655 google_apis::test_util::CreateCopyResultCallback( 655 google_apis::test_util::CreateCopyResultCallback(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 ConnectToCellular(); 690 ConnectToCellular();
691 691
692 // Enable fetching over cellular network. 692 // Enable fetching over cellular network.
693 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, false); 693 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, false);
694 694
695 // Try to get a file in the background 695 // Try to get a file in the background
696 base::ScopedTempDir temp_dir; 696 base::ScopedTempDir temp_dir;
697 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 697 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
698 698
699 const base::FilePath kOutputFilePath = 699 const base::FilePath kOutputFilePath =
700 temp_dir.path().AppendASCII("whatever.txt"); 700 temp_dir.GetPath().AppendASCII("whatever.txt");
701 google_apis::DriveApiErrorCode download_error = 701 google_apis::DriveApiErrorCode download_error =
702 google_apis::DRIVE_OTHER_ERROR; 702 google_apis::DRIVE_OTHER_ERROR;
703 base::FilePath output_file_path; 703 base::FilePath output_file_path;
704 scheduler_->DownloadFile( 704 scheduler_->DownloadFile(
705 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path 705 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path
706 kDummyDownloadFileSize, 706 kDummyDownloadFileSize,
707 kOutputFilePath, 707 kOutputFilePath,
708 "2_file_resource_id", 708 "2_file_resource_id",
709 ClientContext(BACKGROUND), 709 ClientContext(BACKGROUND),
710 google_apis::test_util::CreateCopyResultCallback( 710 google_apis::test_util::CreateCopyResultCallback(
(...skipping 26 matching lines...) Expand all
737 ConnectToWimax(); 737 ConnectToWimax();
738 738
739 // Enable fetching over cellular network. 739 // Enable fetching over cellular network.
740 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, false); 740 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, false);
741 741
742 // Try to get a file in the background 742 // Try to get a file in the background
743 base::ScopedTempDir temp_dir; 743 base::ScopedTempDir temp_dir;
744 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 744 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
745 745
746 const base::FilePath kOutputFilePath = 746 const base::FilePath kOutputFilePath =
747 temp_dir.path().AppendASCII("whatever.txt"); 747 temp_dir.GetPath().AppendASCII("whatever.txt");
748 google_apis::DriveApiErrorCode download_error = 748 google_apis::DriveApiErrorCode download_error =
749 google_apis::DRIVE_OTHER_ERROR; 749 google_apis::DRIVE_OTHER_ERROR;
750 base::FilePath output_file_path; 750 base::FilePath output_file_path;
751 scheduler_->DownloadFile( 751 scheduler_->DownloadFile(
752 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path 752 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path
753 kDummyDownloadFileSize, 753 kDummyDownloadFileSize,
754 kOutputFilePath, 754 kOutputFilePath,
755 "2_file_resource_id", 755 "2_file_resource_id",
756 ClientContext(BACKGROUND), 756 ClientContext(BACKGROUND),
757 google_apis::test_util::CreateCopyResultCallback( 757 google_apis::test_util::CreateCopyResultCallback(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 &error, &about_resource)); 810 &error, &about_resource));
811 expected_types.insert(TYPE_UPDATE_RESOURCE); 811 expected_types.insert(TYPE_UPDATE_RESOURCE);
812 scheduler_->UpdateResource( 812 scheduler_->UpdateResource(
813 "2_file_resource_id", std::string(), "New Title", base::Time(), 813 "2_file_resource_id", std::string(), "New Title", base::Time(),
814 base::Time(), google_apis::drive::Properties(), 814 base::Time(), google_apis::drive::Properties(),
815 ClientContext(USER_INITIATED), 815 ClientContext(USER_INITIATED),
816 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); 816 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
817 expected_types.insert(TYPE_DOWNLOAD_FILE); 817 expected_types.insert(TYPE_DOWNLOAD_FILE);
818 scheduler_->DownloadFile( 818 scheduler_->DownloadFile(
819 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path 819 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path
820 kDummyDownloadFileSize, 820 kDummyDownloadFileSize, temp_dir.GetPath().AppendASCII("whatever.txt"),
821 temp_dir.path().AppendASCII("whatever.txt"), 821 "2_file_resource_id", ClientContext(BACKGROUND),
822 "2_file_resource_id",
823 ClientContext(BACKGROUND),
824 google_apis::test_util::CreateCopyResultCallback(&error, &path), 822 google_apis::test_util::CreateCopyResultCallback(&error, &path),
825 google_apis::GetContentCallback()); 823 google_apis::GetContentCallback());
826 824
827 // The number of jobs queued so far. 825 // The number of jobs queued so far.
828 EXPECT_EQ(4U, scheduler_->GetJobInfoList().size()); 826 EXPECT_EQ(4U, scheduler_->GetJobInfoList().size());
829 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_ADD_NEW_DIRECTORY)); 827 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_ADD_NEW_DIRECTORY));
830 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_GET_ABOUT_RESOURCE)); 828 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_GET_ABOUT_RESOURCE));
831 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_UPDATE_RESOURCE)); 829 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_UPDATE_RESOURCE));
832 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_DOWNLOAD_FILE)); 830 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_DOWNLOAD_FILE));
833 EXPECT_FALSE(logger.Has(JobListLogger::DONE, TYPE_ADD_NEW_DIRECTORY)); 831 EXPECT_FALSE(logger.Has(JobListLogger::DONE, TYPE_ADD_NEW_DIRECTORY));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 905
908 base::ScopedTempDir temp_dir; 906 base::ScopedTempDir temp_dir;
909 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 907 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
910 908
911 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 909 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
912 base::FilePath path; 910 base::FilePath path;
913 911
914 // Download job. 912 // Download job.
915 scheduler_->DownloadFile( 913 scheduler_->DownloadFile(
916 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path 914 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path
917 kDummyDownloadFileSize, 915 kDummyDownloadFileSize, temp_dir.GetPath().AppendASCII("whatever.txt"),
918 temp_dir.path().AppendASCII("whatever.txt"), 916 "2_file_resource_id", ClientContext(BACKGROUND),
919 "2_file_resource_id",
920 ClientContext(BACKGROUND),
921 google_apis::test_util::CreateCopyResultCallback(&error, &path), 917 google_apis::test_util::CreateCopyResultCallback(&error, &path),
922 google_apis::GetContentCallback()); 918 google_apis::GetContentCallback());
923 base::RunLoop().RunUntilIdle(); 919 base::RunLoop().RunUntilIdle();
924 920
925 std::vector<int64_t> download_progress; 921 std::vector<int64_t> download_progress;
926 logger.GetProgressInfo(TYPE_DOWNLOAD_FILE, &download_progress); 922 logger.GetProgressInfo(TYPE_DOWNLOAD_FILE, &download_progress);
927 ASSERT_TRUE(!download_progress.empty()); 923 ASSERT_TRUE(!download_progress.empty());
928 EXPECT_TRUE(base::STLIsSorted(download_progress)); 924 EXPECT_TRUE(base::STLIsSorted(download_progress));
929 EXPECT_GE(download_progress.front(), 0); 925 EXPECT_GE(download_progress.front(), 0);
930 EXPECT_LE(download_progress.back(), 26); 926 EXPECT_LE(download_progress.back(), 26);
931 927
932 // Upload job. 928 // Upload job.
933 path = temp_dir.path().AppendASCII("new_file.txt"); 929 path = temp_dir.GetPath().AppendASCII("new_file.txt");
934 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(path, kHello)); 930 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(path, kHello));
935 google_apis::DriveApiErrorCode upload_error = 931 google_apis::DriveApiErrorCode upload_error =
936 google_apis::DRIVE_OTHER_ERROR; 932 google_apis::DRIVE_OTHER_ERROR;
937 std::unique_ptr<google_apis::FileResource> entry; 933 std::unique_ptr<google_apis::FileResource> entry;
938 934
939 scheduler_->UploadNewFile( 935 scheduler_->UploadNewFile(
940 fake_drive_service_->GetRootResourceId(), kHelloLen, 936 fake_drive_service_->GetRootResourceId(), kHelloLen,
941 base::FilePath::FromUTF8Unsafe("drive/new_file.txt"), path, "dummy title", 937 base::FilePath::FromUTF8Unsafe("drive/new_file.txt"), path, "dummy title",
942 "plain/plain", UploadNewFileOptions(), ClientContext(BACKGROUND), 938 "plain/plain", UploadNewFileOptions(), ClientContext(BACKGROUND),
943 google_apis::test_util::CreateCopyResultCallback(&upload_error, &entry)); 939 google_apis::test_util::CreateCopyResultCallback(&upload_error, &entry));
944 base::RunLoop().RunUntilIdle(); 940 base::RunLoop().RunUntilIdle();
945 941
946 std::vector<int64_t> upload_progress; 942 std::vector<int64_t> upload_progress;
947 logger.GetProgressInfo(TYPE_UPLOAD_NEW_FILE, &upload_progress); 943 logger.GetProgressInfo(TYPE_UPLOAD_NEW_FILE, &upload_progress);
948 ASSERT_TRUE(!upload_progress.empty()); 944 ASSERT_TRUE(!upload_progress.empty());
949 EXPECT_TRUE(base::STLIsSorted(upload_progress)); 945 EXPECT_TRUE(base::STLIsSorted(upload_progress));
950 EXPECT_GE(upload_progress.front(), 0); 946 EXPECT_GE(upload_progress.front(), 0);
951 EXPECT_LE(upload_progress.back(), 13); 947 EXPECT_LE(upload_progress.back(), 13);
952 } 948 }
953 949
954 TEST_F(JobSchedulerTest, CancelPendingJob) { 950 TEST_F(JobSchedulerTest, CancelPendingJob) {
955 base::ScopedTempDir temp_dir; 951 base::ScopedTempDir temp_dir;
956 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 952 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
957 base::FilePath upload_path = temp_dir.path().AppendASCII("new_file.txt"); 953 base::FilePath upload_path = temp_dir.GetPath().AppendASCII("new_file.txt");
958 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(upload_path, kHello)); 954 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(upload_path, kHello));
959 955
960 // To create a pending job for testing, set the mode to cellular connection 956 // To create a pending job for testing, set the mode to cellular connection
961 // and issue BACKGROUND jobs. 957 // and issue BACKGROUND jobs.
962 ConnectToCellular(); 958 ConnectToCellular();
963 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true); 959 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true);
964 960
965 // Start the first job and record its job ID. 961 // Start the first job and record its job ID.
966 google_apis::DriveApiErrorCode error1 = google_apis::DRIVE_OTHER_ERROR; 962 google_apis::DriveApiErrorCode error1 = google_apis::DRIVE_OTHER_ERROR;
967 std::unique_ptr<google_apis::FileResource> entry; 963 std::unique_ptr<google_apis::FileResource> entry;
(...skipping 27 matching lines...) Expand all
995 EXPECT_EQ(google_apis::DRIVE_CANCELLED, error1); 991 EXPECT_EQ(google_apis::DRIVE_CANCELLED, error1);
996 EXPECT_EQ(google_apis::HTTP_SUCCESS, error2); 992 EXPECT_EQ(google_apis::HTTP_SUCCESS, error2);
997 EXPECT_TRUE(scheduler_->GetJobInfoList().empty()); 993 EXPECT_TRUE(scheduler_->GetJobInfoList().empty());
998 } 994 }
999 995
1000 TEST_F(JobSchedulerTest, CancelRunningJob) { 996 TEST_F(JobSchedulerTest, CancelRunningJob) {
1001 ConnectToWifi(); 997 ConnectToWifi();
1002 998
1003 base::ScopedTempDir temp_dir; 999 base::ScopedTempDir temp_dir;
1004 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1000 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1005 base::FilePath upload_path = temp_dir.path().AppendASCII("new_file.txt"); 1001 base::FilePath upload_path = temp_dir.GetPath().AppendASCII("new_file.txt");
1006 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(upload_path, kHello)); 1002 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(upload_path, kHello));
1007 1003
1008 // Run as a cancelable task. 1004 // Run as a cancelable task.
1009 fake_drive_service_->set_upload_new_file_cancelable(true); 1005 fake_drive_service_->set_upload_new_file_cancelable(true);
1010 google_apis::DriveApiErrorCode error1 = google_apis::DRIVE_OTHER_ERROR; 1006 google_apis::DriveApiErrorCode error1 = google_apis::DRIVE_OTHER_ERROR;
1011 std::unique_ptr<google_apis::FileResource> entry; 1007 std::unique_ptr<google_apis::FileResource> entry;
1012 scheduler_->UploadNewFile( 1008 scheduler_->UploadNewFile(
1013 fake_drive_service_->GetRootResourceId(), kHelloLen, 1009 fake_drive_service_->GetRootResourceId(), kHelloLen,
1014 base::FilePath::FromUTF8Unsafe("dummy/path"), upload_path, 1010 base::FilePath::FromUTF8Unsafe("dummy/path"), upload_path,
1015 "dummy title 1", "text/plain", UploadNewFileOptions(), 1011 "dummy title 1", "text/plain", UploadNewFileOptions(),
(...skipping 19 matching lines...) Expand all
1035 scheduler_->CancelJob(first_job_id); 1031 scheduler_->CancelJob(first_job_id);
1036 1032
1037 // Only the first job should be cancelled. 1033 // Only the first job should be cancelled.
1038 base::RunLoop().RunUntilIdle(); 1034 base::RunLoop().RunUntilIdle();
1039 EXPECT_EQ(google_apis::DRIVE_CANCELLED, error1); 1035 EXPECT_EQ(google_apis::DRIVE_CANCELLED, error1);
1040 EXPECT_EQ(google_apis::HTTP_SUCCESS, error2); 1036 EXPECT_EQ(google_apis::HTTP_SUCCESS, error2);
1041 EXPECT_TRUE(scheduler_->GetJobInfoList().empty()); 1037 EXPECT_TRUE(scheduler_->GetJobInfoList().empty());
1042 } 1038 }
1043 1039
1044 } // namespace drive 1040 } // namespace drive
OLDNEW
« no previous file with comments | « components/drive/file_write_watcher_unittest.cc ('k') | components/drive/local_file_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698