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

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: Review fix/ 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>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/file_util.h" 10 #include "base/file_util.h"
9 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
10 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
11 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
12 #include "chrome/browser/chromeos/drive/drive_test_util.h" 14 #include "chrome/browser/chromeos/drive/drive_test_util.h"
13 #include "chrome/browser/google_apis/drive_api_parser.h" 15 #include "chrome/browser/google_apis/drive_api_parser.h"
14 #include "chrome/browser/google_apis/fake_drive_service.h" 16 #include "chrome/browser/google_apis/fake_drive_service.h"
15 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 17 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
16 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 643
642 // Check the download 644 // Check the download
643 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error); 645 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error);
644 std::string content; 646 std::string content;
645 EXPECT_EQ(output_file_path, kOutputFilePath); 647 EXPECT_EQ(output_file_path, kOutputFilePath);
646 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content)); 648 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content));
647 // The content is "x"s of the file size specified in root_feed.json. 649 // The content is "x"s of the file size specified in root_feed.json.
648 EXPECT_EQ("xxxxxxxxxx", content); 650 EXPECT_EQ("xxxxxxxxxx", content);
649 } 651 }
650 652
653 TEST_F(DriveSchedulerTest, JobInfo) {
654 // Disable background upload/download.
655 ConnectToWimax();
656 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, true);
657
658 base::ScopedTempDir temp_dir;
659 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
660
661 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
662 scoped_ptr<google_apis::ResourceEntry> entry;
663 scoped_ptr<google_apis::AccountMetadata> account_metadata;
664 base::FilePath path;
665
666 std::set<JobType> expected_types;
667
668 // Add many jobs.
669 expected_types.insert(TYPE_ADD_NEW_DIRECTORY);
670 scheduler_->AddNewDirectory(
671 fake_drive_service_->GetRootResourceId(),
672 "New Directory",
673 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
674 expected_types.insert(TYPE_GET_ACCOUNT_METADATA);
675 scheduler_->GetAccountMetadata(
676 google_apis::test_util::CreateCopyResultCallback(
677 &error, &account_metadata));
678 expected_types.insert(TYPE_RENAME_RESOURCE);
679 scheduler_->RenameResource(
680 "file:2_file_resource_id",
681 "New Name",
682 google_apis::test_util::CreateCopyResultCallback(&error));
683 expected_types.insert(TYPE_DOWNLOAD_FILE);
684 scheduler_->DownloadFile(
685 base::FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path
686 temp_dir.path().AppendASCII("whatever.txt"),
687 GURL("https://file_content_url/"),
688 DriveClientContext(BACKGROUND),
689 google_apis::test_util::CreateCopyResultCallback(&error, &path),
690 google_apis::GetContentCallback());
691
692 // The number of jobs queued so far.
693 EXPECT_EQ(4U, scheduler_->GetJobInfoList().size());
694
695 // Add more jobs.
696 expected_types.insert(TYPE_ADD_RESOURCE_TO_DIRECTORY);
697 scheduler_->AddResourceToDirectory(
698 "folder:1_folder_resource_id",
699 "file:2_file_resource_id",
700 google_apis::test_util::CreateCopyResultCallback(&error));
701 expected_types.insert(TYPE_COPY_HOSTED_DOCUMENT);
702 scheduler_->CopyHostedDocument(
703 "document:5_document_resource_id",
704 "New Document",
705 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
706
707 // 6 jobs in total were queued.
708 std::vector<JobInfo> jobs = scheduler_->GetJobInfoList();
709 EXPECT_EQ(6U, jobs.size());
710 std::set<JobType> actual_types;
711 for (size_t i = 0; i < jobs.size(); ++i)
712 actual_types.insert(jobs[i].job_type);
713 EXPECT_EQ(expected_types, actual_types);
714
715 // Run the jobs.
716 google_apis::test_util::RunBlockingPoolTask();
717
718 // All jobs except the BACKGROUND job should have finished.
719 jobs = scheduler_->GetJobInfoList();
720 ASSERT_EQ(1U, jobs.size());
721 EXPECT_EQ(TYPE_DOWNLOAD_FILE, jobs[0].job_type);
722
723 // Run the background downloading job as well.
724 ConnectToWifi();
725 google_apis::test_util::RunBlockingPoolTask();
726
727 // All jobs should have finished.
728 EXPECT_EQ(0U, scheduler_->GetJobInfoList().size());
729 }
730
651 } // namespace drive 731 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698