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

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

Issue 1042803002: Drive: Move inner structures of DriveAPIService under drive namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests. Created 5 years, 8 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 "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/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 265
266 int64 old_largest_change_id = 266 int64 old_largest_change_id =
267 fake_drive_service_->about_resource().largest_change_id(); 267 fake_drive_service_->about_resource().largest_change_id();
268 268
269 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 269 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
270 270
271 // Create a new directory. 271 // Create a new directory.
272 { 272 {
273 scoped_ptr<google_apis::FileResource> entry; 273 scoped_ptr<google_apis::FileResource> entry;
274 fake_drive_service_->AddNewDirectory( 274 fake_drive_service_->AddNewDirectory(
275 fake_drive_service_->GetRootResourceId(), 275 fake_drive_service_->GetRootResourceId(), "new directory",
276 "new directory", 276 AddNewDirectoryOptions(),
277 DriveServiceInterface::AddNewDirectoryOptions(), 277 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
278 google_apis::test_util::CreateCopyResultCallback(
279 &error, &entry));
280 base::RunLoop().RunUntilIdle(); 278 base::RunLoop().RunUntilIdle();
281 ASSERT_EQ(google_apis::HTTP_CREATED, error); 279 ASSERT_EQ(google_apis::HTTP_CREATED, error);
282 } 280 }
283 281
284 error = google_apis::DRIVE_OTHER_ERROR; 282 error = google_apis::DRIVE_OTHER_ERROR;
285 scoped_ptr<google_apis::ChangeList> change_list; 283 scoped_ptr<google_apis::ChangeList> change_list;
286 scheduler_->GetChangeList( 284 scheduler_->GetChangeList(
287 old_largest_change_id + 1, 285 old_largest_change_id + 1,
288 google_apis::test_util::CreateCopyResultCallback(&error, &change_list)); 286 google_apis::test_util::CreateCopyResultCallback(&error, &change_list));
289 base::RunLoop().RunUntilIdle(); 287 base::RunLoop().RunUntilIdle();
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 } 464 }
467 465
468 TEST_F(JobSchedulerTest, AddNewDirectory) { 466 TEST_F(JobSchedulerTest, AddNewDirectory) {
469 ConnectToWifi(); 467 ConnectToWifi();
470 468
471 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 469 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
472 scoped_ptr<google_apis::FileResource> entry; 470 scoped_ptr<google_apis::FileResource> entry;
473 471
474 scheduler_->AddNewDirectory( 472 scheduler_->AddNewDirectory(
475 fake_drive_service_->GetRootResourceId(), // Root directory. 473 fake_drive_service_->GetRootResourceId(), // Root directory.
476 "New Directory", 474 "New Directory", AddNewDirectoryOptions(), ClientContext(USER_INITIATED),
477 DriveServiceInterface::AddNewDirectoryOptions(),
478 ClientContext(USER_INITIATED),
479 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); 475 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
480 base::RunLoop().RunUntilIdle(); 476 base::RunLoop().RunUntilIdle();
481 477
482 ASSERT_EQ(google_apis::HTTP_CREATED, error); 478 ASSERT_EQ(google_apis::HTTP_CREATED, error);
483 ASSERT_TRUE(entry); 479 ASSERT_TRUE(entry);
484 } 480 }
485 481
486 TEST_F(JobSchedulerTest, PriorityHandling) { 482 TEST_F(JobSchedulerTest, PriorityHandling) {
487 // Saturate the metadata job queue with uninteresting jobs to prevent 483 // Saturate the metadata job queue with uninteresting jobs to prevent
488 // following jobs from starting. 484 // following jobs from starting.
(...skipping 10 matching lines...) Expand all
499 } 495 }
500 496
501 // Start jobs with different priorities. 497 // Start jobs with different priorities.
502 std::string title_1("new file 1"); 498 std::string title_1("new file 1");
503 std::string title_2("new file 2"); 499 std::string title_2("new file 2");
504 std::string title_3("new file 3"); 500 std::string title_3("new file 3");
505 std::string title_4("new file 4"); 501 std::string title_4("new file 4");
506 std::vector<std::string> titles; 502 std::vector<std::string> titles;
507 503
508 scheduler_->AddNewDirectory( 504 scheduler_->AddNewDirectory(
509 fake_drive_service_->GetRootResourceId(), 505 fake_drive_service_->GetRootResourceId(), title_1,
510 title_1, 506 AddNewDirectoryOptions(), ClientContext(USER_INITIATED),
511 DriveServiceInterface::AddNewDirectoryOptions(),
512 ClientContext(USER_INITIATED),
513 base::Bind(&CopyTitleFromFileResourceCallback, &titles)); 507 base::Bind(&CopyTitleFromFileResourceCallback, &titles));
514 scheduler_->AddNewDirectory( 508 scheduler_->AddNewDirectory(
515 fake_drive_service_->GetRootResourceId(), 509 fake_drive_service_->GetRootResourceId(), title_2,
516 title_2, 510 AddNewDirectoryOptions(), ClientContext(BACKGROUND),
517 DriveServiceInterface::AddNewDirectoryOptions(),
518 ClientContext(BACKGROUND),
519 base::Bind(&CopyTitleFromFileResourceCallback, &titles)); 511 base::Bind(&CopyTitleFromFileResourceCallback, &titles));
520 scheduler_->AddNewDirectory( 512 scheduler_->AddNewDirectory(
521 fake_drive_service_->GetRootResourceId(), 513 fake_drive_service_->GetRootResourceId(), title_3,
522 title_3, 514 AddNewDirectoryOptions(), ClientContext(BACKGROUND),
523 DriveServiceInterface::AddNewDirectoryOptions(),
524 ClientContext(BACKGROUND),
525 base::Bind(&CopyTitleFromFileResourceCallback, &titles)); 515 base::Bind(&CopyTitleFromFileResourceCallback, &titles));
526 scheduler_->AddNewDirectory( 516 scheduler_->AddNewDirectory(
527 fake_drive_service_->GetRootResourceId(), 517 fake_drive_service_->GetRootResourceId(), title_4,
528 title_4, 518 AddNewDirectoryOptions(), ClientContext(USER_INITIATED),
529 DriveServiceInterface::AddNewDirectoryOptions(),
530 ClientContext(USER_INITIATED),
531 base::Bind(&CopyTitleFromFileResourceCallback, &titles)); 519 base::Bind(&CopyTitleFromFileResourceCallback, &titles));
532 520
533 base::RunLoop().RunUntilIdle(); 521 base::RunLoop().RunUntilIdle();
534 522
535 ASSERT_EQ(4ul, titles.size()); 523 ASSERT_EQ(4ul, titles.size());
536 EXPECT_EQ(title_1, titles[0]); 524 EXPECT_EQ(title_1, titles[0]);
537 EXPECT_EQ(title_4, titles[1]); 525 EXPECT_EQ(title_4, titles[1]);
538 EXPECT_EQ(title_2, titles[2]); 526 EXPECT_EQ(title_2, titles[2]);
539 EXPECT_EQ(title_3, titles[3]); 527 EXPECT_EQ(title_3, titles[3]);
540 } 528 }
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; 785 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
798 scoped_ptr<google_apis::FileResource> entry; 786 scoped_ptr<google_apis::FileResource> entry;
799 scoped_ptr<google_apis::AboutResource> about_resource; 787 scoped_ptr<google_apis::AboutResource> about_resource;
800 base::FilePath path; 788 base::FilePath path;
801 789
802 std::set<JobType> expected_types; 790 std::set<JobType> expected_types;
803 791
804 // Add many jobs. 792 // Add many jobs.
805 expected_types.insert(TYPE_ADD_NEW_DIRECTORY); 793 expected_types.insert(TYPE_ADD_NEW_DIRECTORY);
806 scheduler_->AddNewDirectory( 794 scheduler_->AddNewDirectory(
807 fake_drive_service_->GetRootResourceId(), 795 fake_drive_service_->GetRootResourceId(), "New Directory",
808 "New Directory", 796 AddNewDirectoryOptions(), ClientContext(USER_INITIATED),
809 DriveServiceInterface::AddNewDirectoryOptions(),
810 ClientContext(USER_INITIATED),
811 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); 797 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
812 expected_types.insert(TYPE_GET_ABOUT_RESOURCE); 798 expected_types.insert(TYPE_GET_ABOUT_RESOURCE);
813 scheduler_->GetAboutResource( 799 scheduler_->GetAboutResource(
814 google_apis::test_util::CreateCopyResultCallback( 800 google_apis::test_util::CreateCopyResultCallback(
815 &error, &about_resource)); 801 &error, &about_resource));
816 expected_types.insert(TYPE_UPDATE_RESOURCE); 802 expected_types.insert(TYPE_UPDATE_RESOURCE);
817 scheduler_->UpdateResource( 803 scheduler_->UpdateResource(
818 "2_file_resource_id", std::string(), "New Title", base::Time(), 804 "2_file_resource_id", std::string(), "New Title", base::Time(),
819 base::Time(), google_apis::drive::Properties(), 805 base::Time(), google_apis::drive::Properties(),
820 ClientContext(USER_INITIATED), 806 ClientContext(USER_INITIATED),
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 922
937 // Upload job. 923 // Upload job.
938 path = temp_dir.path().AppendASCII("new_file.txt"); 924 path = temp_dir.path().AppendASCII("new_file.txt");
939 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(path, "Hello")); 925 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(path, "Hello"));
940 google_apis::DriveApiErrorCode upload_error = 926 google_apis::DriveApiErrorCode upload_error =
941 google_apis::DRIVE_OTHER_ERROR; 927 google_apis::DRIVE_OTHER_ERROR;
942 scoped_ptr<google_apis::FileResource> entry; 928 scoped_ptr<google_apis::FileResource> entry;
943 929
944 scheduler_->UploadNewFile( 930 scheduler_->UploadNewFile(
945 fake_drive_service_->GetRootResourceId(), 931 fake_drive_service_->GetRootResourceId(),
946 base::FilePath::FromUTF8Unsafe("drive/new_file.txt"), 932 base::FilePath::FromUTF8Unsafe("drive/new_file.txt"), path, "dummy title",
947 path, 933 "plain/plain", UploadNewFileOptions(), ClientContext(BACKGROUND),
948 "dummy title",
949 "plain/plain",
950 DriveUploader::UploadNewFileOptions(),
951 ClientContext(BACKGROUND),
952 google_apis::test_util::CreateCopyResultCallback(&upload_error, &entry)); 934 google_apis::test_util::CreateCopyResultCallback(&upload_error, &entry));
953 base::RunLoop().RunUntilIdle(); 935 base::RunLoop().RunUntilIdle();
954 936
955 std::vector<int64> upload_progress; 937 std::vector<int64> upload_progress;
956 logger.GetProgressInfo(TYPE_UPLOAD_NEW_FILE, &upload_progress); 938 logger.GetProgressInfo(TYPE_UPLOAD_NEW_FILE, &upload_progress);
957 ASSERT_TRUE(!upload_progress.empty()); 939 ASSERT_TRUE(!upload_progress.empty());
958 EXPECT_TRUE(base::STLIsSorted(upload_progress)); 940 EXPECT_TRUE(base::STLIsSorted(upload_progress));
959 EXPECT_GE(upload_progress.front(), 0); 941 EXPECT_GE(upload_progress.front(), 0);
960 EXPECT_LE(upload_progress.back(), 13); 942 EXPECT_LE(upload_progress.back(), 13);
961 } 943 }
962 944
963 TEST_F(JobSchedulerTest, CancelPendingJob) { 945 TEST_F(JobSchedulerTest, CancelPendingJob) {
964 base::ScopedTempDir temp_dir; 946 base::ScopedTempDir temp_dir;
965 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 947 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
966 base::FilePath upload_path = temp_dir.path().AppendASCII("new_file.txt"); 948 base::FilePath upload_path = temp_dir.path().AppendASCII("new_file.txt");
967 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(upload_path, "Hello")); 949 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(upload_path, "Hello"));
968 950
969 // To create a pending job for testing, set the mode to cellular connection 951 // To create a pending job for testing, set the mode to cellular connection
970 // and issue BACKGROUND jobs. 952 // and issue BACKGROUND jobs.
971 ConnectToCellular(); 953 ConnectToCellular();
972 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true); 954 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true);
973 955
974 // Start the first job and record its job ID. 956 // Start the first job and record its job ID.
975 google_apis::DriveApiErrorCode error1 = google_apis::DRIVE_OTHER_ERROR; 957 google_apis::DriveApiErrorCode error1 = google_apis::DRIVE_OTHER_ERROR;
976 scoped_ptr<google_apis::FileResource> entry; 958 scoped_ptr<google_apis::FileResource> entry;
977 scheduler_->UploadNewFile( 959 scheduler_->UploadNewFile(
978 fake_drive_service_->GetRootResourceId(), 960 fake_drive_service_->GetRootResourceId(),
979 base::FilePath::FromUTF8Unsafe("dummy/path"), 961 base::FilePath::FromUTF8Unsafe("dummy/path"), upload_path,
980 upload_path, 962 "dummy title 1", "text/plain", UploadNewFileOptions(),
981 "dummy title 1",
982 "text/plain",
983 DriveUploader::UploadNewFileOptions(),
984 ClientContext(BACKGROUND), 963 ClientContext(BACKGROUND),
985 google_apis::test_util::CreateCopyResultCallback(&error1, &entry)); 964 google_apis::test_util::CreateCopyResultCallback(&error1, &entry));
986 965
987 const std::vector<JobInfo>& jobs = scheduler_->GetJobInfoList(); 966 const std::vector<JobInfo>& jobs = scheduler_->GetJobInfoList();
988 ASSERT_EQ(1u, jobs.size()); 967 ASSERT_EQ(1u, jobs.size());
989 ASSERT_EQ(STATE_NONE, jobs[0].state); // Not started yet. 968 ASSERT_EQ(STATE_NONE, jobs[0].state); // Not started yet.
990 JobID first_job_id = jobs[0].job_id; 969 JobID first_job_id = jobs[0].job_id;
991 970
992 // Start the second job. 971 // Start the second job.
993 google_apis::DriveApiErrorCode error2 = google_apis::DRIVE_OTHER_ERROR; 972 google_apis::DriveApiErrorCode error2 = google_apis::DRIVE_OTHER_ERROR;
994 scheduler_->UploadNewFile( 973 scheduler_->UploadNewFile(
995 fake_drive_service_->GetRootResourceId(), 974 fake_drive_service_->GetRootResourceId(),
996 base::FilePath::FromUTF8Unsafe("dummy/path"), 975 base::FilePath::FromUTF8Unsafe("dummy/path"), upload_path,
997 upload_path, 976 "dummy title 2", "text/plain", UploadNewFileOptions(),
998 "dummy title 2",
999 "text/plain",
1000 DriveUploader::UploadNewFileOptions(),
1001 ClientContext(BACKGROUND), 977 ClientContext(BACKGROUND),
1002 google_apis::test_util::CreateCopyResultCallback(&error2, &entry)); 978 google_apis::test_util::CreateCopyResultCallback(&error2, &entry));
1003 979
1004 // Cancel the first one. 980 // Cancel the first one.
1005 scheduler_->CancelJob(first_job_id); 981 scheduler_->CancelJob(first_job_id);
1006 982
1007 // Only the first job should be cancelled. 983 // Only the first job should be cancelled.
1008 ConnectToWifi(); 984 ConnectToWifi();
1009 base::RunLoop().RunUntilIdle(); 985 base::RunLoop().RunUntilIdle();
1010 EXPECT_EQ(google_apis::DRIVE_CANCELLED, error1); 986 EXPECT_EQ(google_apis::DRIVE_CANCELLED, error1);
1011 EXPECT_EQ(google_apis::HTTP_SUCCESS, error2); 987 EXPECT_EQ(google_apis::HTTP_SUCCESS, error2);
1012 EXPECT_TRUE(scheduler_->GetJobInfoList().empty()); 988 EXPECT_TRUE(scheduler_->GetJobInfoList().empty());
1013 } 989 }
1014 990
1015 TEST_F(JobSchedulerTest, CancelRunningJob) { 991 TEST_F(JobSchedulerTest, CancelRunningJob) {
1016 ConnectToWifi(); 992 ConnectToWifi();
1017 993
1018 base::ScopedTempDir temp_dir; 994 base::ScopedTempDir temp_dir;
1019 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 995 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1020 base::FilePath upload_path = temp_dir.path().AppendASCII("new_file.txt"); 996 base::FilePath upload_path = temp_dir.path().AppendASCII("new_file.txt");
1021 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(upload_path, "Hello")); 997 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(upload_path, "Hello"));
1022 998
1023 // Run as a cancelable task. 999 // Run as a cancelable task.
1024 fake_drive_service_->set_upload_new_file_cancelable(true); 1000 fake_drive_service_->set_upload_new_file_cancelable(true);
1025 google_apis::DriveApiErrorCode error1 = google_apis::DRIVE_OTHER_ERROR; 1001 google_apis::DriveApiErrorCode error1 = google_apis::DRIVE_OTHER_ERROR;
1026 scoped_ptr<google_apis::FileResource> entry; 1002 scoped_ptr<google_apis::FileResource> entry;
1027 scheduler_->UploadNewFile( 1003 scheduler_->UploadNewFile(
1028 fake_drive_service_->GetRootResourceId(), 1004 fake_drive_service_->GetRootResourceId(),
1029 base::FilePath::FromUTF8Unsafe("dummy/path"), 1005 base::FilePath::FromUTF8Unsafe("dummy/path"), upload_path,
1030 upload_path, 1006 "dummy title 1", "text/plain", UploadNewFileOptions(),
1031 "dummy title 1",
1032 "text/plain",
1033 DriveUploader::UploadNewFileOptions(),
1034 ClientContext(USER_INITIATED), 1007 ClientContext(USER_INITIATED),
1035 google_apis::test_util::CreateCopyResultCallback(&error1, &entry)); 1008 google_apis::test_util::CreateCopyResultCallback(&error1, &entry));
1036 1009
1037 const std::vector<JobInfo>& jobs = scheduler_->GetJobInfoList(); 1010 const std::vector<JobInfo>& jobs = scheduler_->GetJobInfoList();
1038 ASSERT_EQ(1u, jobs.size()); 1011 ASSERT_EQ(1u, jobs.size());
1039 ASSERT_EQ(STATE_RUNNING, jobs[0].state); // It's running. 1012 ASSERT_EQ(STATE_RUNNING, jobs[0].state); // It's running.
1040 JobID first_job_id = jobs[0].job_id; 1013 JobID first_job_id = jobs[0].job_id;
1041 1014
1042 // Start the second job normally. 1015 // Start the second job normally.
1043 fake_drive_service_->set_upload_new_file_cancelable(false); 1016 fake_drive_service_->set_upload_new_file_cancelable(false);
1044 google_apis::DriveApiErrorCode error2 = google_apis::DRIVE_OTHER_ERROR; 1017 google_apis::DriveApiErrorCode error2 = google_apis::DRIVE_OTHER_ERROR;
1045 scheduler_->UploadNewFile( 1018 scheduler_->UploadNewFile(
1046 fake_drive_service_->GetRootResourceId(), 1019 fake_drive_service_->GetRootResourceId(),
1047 base::FilePath::FromUTF8Unsafe("dummy/path"), 1020 base::FilePath::FromUTF8Unsafe("dummy/path"), upload_path,
1048 upload_path, 1021 "dummy title 2", "text/plain", UploadNewFileOptions(),
1049 "dummy title 2",
1050 "text/plain",
1051 DriveUploader::UploadNewFileOptions(),
1052 ClientContext(USER_INITIATED), 1022 ClientContext(USER_INITIATED),
1053 google_apis::test_util::CreateCopyResultCallback(&error2, &entry)); 1023 google_apis::test_util::CreateCopyResultCallback(&error2, &entry));
1054 1024
1055 // Cancel the first one. 1025 // Cancel the first one.
1056 scheduler_->CancelJob(first_job_id); 1026 scheduler_->CancelJob(first_job_id);
1057 1027
1058 // Only the first job should be cancelled. 1028 // Only the first job should be cancelled.
1059 base::RunLoop().RunUntilIdle(); 1029 base::RunLoop().RunUntilIdle();
1060 EXPECT_EQ(google_apis::DRIVE_CANCELLED, error1); 1030 EXPECT_EQ(google_apis::DRIVE_CANCELLED, error1);
1061 EXPECT_EQ(google_apis::HTTP_SUCCESS, error2); 1031 EXPECT_EQ(google_apis::HTTP_SUCCESS, error2);
1062 EXPECT_TRUE(scheduler_->GetJobInfoList().empty()); 1032 EXPECT_TRUE(scheduler_->GetJobInfoList().empty());
1063 } 1033 }
1064 1034
1065 } // namespace drive 1035 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/job_scheduler.cc ('k') | chrome/browser/chromeos/drive/sync/entry_update_performer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698