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

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

Issue 14148006: Add an observer interface for DriveScheduler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Split DriveJobListInterface. Created 7 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 | 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/drive_scheduler.h" 5 #include "chrome/browser/chromeos/drive/drive_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 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, true); 656 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, true);
657 657
658 base::ScopedTempDir temp_dir; 658 base::ScopedTempDir temp_dir;
659 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 659 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
660 660
661 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 661 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
662 scoped_ptr<google_apis::ResourceEntry> entry; 662 scoped_ptr<google_apis::ResourceEntry> entry;
663 scoped_ptr<google_apis::AccountMetadata> account_metadata; 663 scoped_ptr<google_apis::AccountMetadata> account_metadata;
664 base::FilePath path; 664 base::FilePath path;
665 665
666 std::set<DriveScheduler::JobType> expected_types; 666 std::set<JobType> expected_types;
667 667
668 // Add many jobs. 668 // Add many jobs.
669 expected_types.insert(DriveScheduler::TYPE_ADD_NEW_DIRECTORY); 669 expected_types.insert(TYPE_ADD_NEW_DIRECTORY);
670 scheduler_->AddNewDirectory( 670 scheduler_->AddNewDirectory(
671 fake_drive_service_->GetRootResourceId(), 671 fake_drive_service_->GetRootResourceId(),
672 "New Directory", 672 "New Directory",
673 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); 673 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
674 expected_types.insert(DriveScheduler::TYPE_GET_ACCOUNT_METADATA); 674 expected_types.insert(TYPE_GET_ACCOUNT_METADATA);
675 scheduler_->GetAccountMetadata( 675 scheduler_->GetAccountMetadata(
676 google_apis::test_util::CreateCopyResultCallback( 676 google_apis::test_util::CreateCopyResultCallback(
677 &error, &account_metadata)); 677 &error, &account_metadata));
678 expected_types.insert(DriveScheduler::TYPE_RENAME_RESOURCE); 678 expected_types.insert(TYPE_RENAME_RESOURCE);
679 scheduler_->RenameResource( 679 scheduler_->RenameResource(
680 "file:2_file_resource_id", 680 "file:2_file_resource_id",
681 "New Name", 681 "New Name",
682 google_apis::test_util::CreateCopyResultCallback(&error)); 682 google_apis::test_util::CreateCopyResultCallback(&error));
683 expected_types.insert(DriveScheduler::TYPE_DOWNLOAD_FILE); 683 expected_types.insert(TYPE_DOWNLOAD_FILE);
684 scheduler_->DownloadFile( 684 scheduler_->DownloadFile(
685 base::FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path 685 base::FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path
686 temp_dir.path().AppendASCII("whatever.txt"), 686 temp_dir.path().AppendASCII("whatever.txt"),
687 GURL("https://file_content_url/"), 687 GURL("https://file_content_url/"),
688 DriveClientContext(BACKGROUND), 688 DriveClientContext(BACKGROUND),
689 google_apis::test_util::CreateCopyResultCallback(&error, &path), 689 google_apis::test_util::CreateCopyResultCallback(&error, &path),
690 google_apis::GetContentCallback()); 690 google_apis::GetContentCallback());
691 691
692 // The number of jobs queued so far. 692 // The number of jobs queued so far.
693 EXPECT_EQ(4U, scheduler_->GetJobInfoList().size()); 693 EXPECT_EQ(4U, scheduler_->GetJobInfoList().size());
694 694
695 // Add more jobs. 695 // Add more jobs.
696 expected_types.insert(DriveScheduler::TYPE_ADD_RESOURCE_TO_DIRECTORY); 696 expected_types.insert(TYPE_ADD_RESOURCE_TO_DIRECTORY);
697 scheduler_->AddResourceToDirectory( 697 scheduler_->AddResourceToDirectory(
698 "folder:1_folder_resource_id", 698 "folder:1_folder_resource_id",
699 "file:2_file_resource_id", 699 "file:2_file_resource_id",
700 google_apis::test_util::CreateCopyResultCallback(&error)); 700 google_apis::test_util::CreateCopyResultCallback(&error));
701 expected_types.insert(DriveScheduler::TYPE_COPY_HOSTED_DOCUMENT); 701 expected_types.insert(TYPE_COPY_HOSTED_DOCUMENT);
702 scheduler_->CopyHostedDocument( 702 scheduler_->CopyHostedDocument(
703 "document:5_document_resource_id", 703 "document:5_document_resource_id",
704 "New Document", 704 "New Document",
705 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); 705 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
706 706
707 // 6 jobs in total were queued. 707 // 6 jobs in total were queued.
708 std::vector<DriveScheduler::JobInfo> jobs = scheduler_->GetJobInfoList(); 708 std::vector<JobInfo> jobs = scheduler_->GetJobInfoList();
709 EXPECT_EQ(6U, jobs.size()); 709 EXPECT_EQ(6U, jobs.size());
710 std::set<DriveScheduler::JobType> actual_types; 710 std::set<JobType> actual_types;
711 for (size_t i = 0; i < jobs.size(); ++i) 711 for (size_t i = 0; i < jobs.size(); ++i)
712 actual_types.insert(jobs[i].job_type); 712 actual_types.insert(jobs[i].job_type);
713 EXPECT_EQ(expected_types, actual_types); 713 EXPECT_EQ(expected_types, actual_types);
714 714
715 // Run the jobs. 715 // Run the jobs.
716 google_apis::test_util::RunBlockingPoolTask(); 716 google_apis::test_util::RunBlockingPoolTask();
717 717
718 // All jobs except the BACKGROUND job should have finished. 718 // All jobs except the BACKGROUND job should have finished.
719 jobs = scheduler_->GetJobInfoList(); 719 jobs = scheduler_->GetJobInfoList();
720 ASSERT_EQ(1U, jobs.size()); 720 ASSERT_EQ(1U, jobs.size());
721 EXPECT_EQ(DriveScheduler::TYPE_DOWNLOAD_FILE, jobs[0].job_type); 721 EXPECT_EQ(TYPE_DOWNLOAD_FILE, jobs[0].job_type);
722 722
723 // Run the background downloading job as well. 723 // Run the background downloading job as well.
724 ConnectToWifi(); 724 ConnectToWifi();
725 google_apis::test_util::RunBlockingPoolTask(); 725 google_apis::test_util::RunBlockingPoolTask();
726 726
727 // All jobs should have finished. 727 // All jobs should have finished.
728 EXPECT_EQ(0U, scheduler_->GetJobInfoList().size()); 728 EXPECT_EQ(0U, scheduler_->GetJobInfoList().size());
729 } 729 }
730 730
731 } // namespace drive 731 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698