| OLD | NEW |
| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 // Gets the progress event information of the specified type. | 65 // Gets the progress event information of the specified type. |
| 66 void GetProgressInfo(JobType job_type, std::vector<int64>* progress) { | 66 void GetProgressInfo(JobType job_type, std::vector<int64>* progress) { |
| 67 for (size_t i = 0; i < events.size(); ++i) { | 67 for (size_t i = 0; i < events.size(); ++i) { |
| 68 if (events[i].type == UPDATED && events[i].info.job_type == job_type) | 68 if (events[i].type == UPDATED && events[i].info.job_type == job_type) |
| 69 progress->push_back(events[i].info.num_completed_bytes); | 69 progress->push_back(events[i].info.num_completed_bytes); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 // JobListObserver overrides. | 73 // JobListObserver overrides. |
| 74 virtual void OnJobAdded(const JobInfo& info) OVERRIDE { | 74 virtual void OnJobAdded(const JobInfo& info) override { |
| 75 events.push_back(EventLog(ADDED, info)); | 75 events.push_back(EventLog(ADDED, info)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 virtual void OnJobUpdated(const JobInfo& info) OVERRIDE { | 78 virtual void OnJobUpdated(const JobInfo& info) override { |
| 79 events.push_back(EventLog(UPDATED, info)); | 79 events.push_back(EventLog(UPDATED, info)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 virtual void OnJobDone(const JobInfo& info, FileError error) OVERRIDE { | 82 virtual void OnJobDone(const JobInfo& info, FileError error) override { |
| 83 events.push_back(EventLog(DONE, info)); | 83 events.push_back(EventLog(DONE, info)); |
| 84 } | 84 } |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 std::vector<EventLog> events; | 87 std::vector<EventLog> events; |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 // Fake drive service extended for testing cancellation. | 90 // Fake drive service extended for testing cancellation. |
| 91 // When upload_new_file_cancelable is set, this Drive service starts | 91 // When upload_new_file_cancelable is set, this Drive service starts |
| 92 // returning a closure to cancel from InitiateUploadNewFile(). The task will | 92 // returning a closure to cancel from InitiateUploadNewFile(). The task will |
| 93 // finish only when the cancel closure is called. | 93 // finish only when the cancel closure is called. |
| 94 class CancelTestableFakeDriveService : public FakeDriveService { | 94 class CancelTestableFakeDriveService : public FakeDriveService { |
| 95 public: | 95 public: |
| 96 CancelTestableFakeDriveService() | 96 CancelTestableFakeDriveService() |
| 97 : upload_new_file_cancelable_(false) { | 97 : upload_new_file_cancelable_(false) { |
| 98 } | 98 } |
| 99 | 99 |
| 100 void set_upload_new_file_cancelable(bool cancelable) { | 100 void set_upload_new_file_cancelable(bool cancelable) { |
| 101 upload_new_file_cancelable_ = cancelable; | 101 upload_new_file_cancelable_ = cancelable; |
| 102 } | 102 } |
| 103 | 103 |
| 104 virtual google_apis::CancelCallback InitiateUploadNewFile( | 104 virtual google_apis::CancelCallback InitiateUploadNewFile( |
| 105 const std::string& content_type, | 105 const std::string& content_type, |
| 106 int64 content_length, | 106 int64 content_length, |
| 107 const std::string& parent_resource_id, | 107 const std::string& parent_resource_id, |
| 108 const std::string& title, | 108 const std::string& title, |
| 109 const InitiateUploadNewFileOptions& options, | 109 const InitiateUploadNewFileOptions& options, |
| 110 const google_apis::InitiateUploadCallback& callback) OVERRIDE { | 110 const google_apis::InitiateUploadCallback& callback) override { |
| 111 if (upload_new_file_cancelable_) | 111 if (upload_new_file_cancelable_) |
| 112 return base::Bind(callback, google_apis::GDATA_CANCELLED, GURL()); | 112 return base::Bind(callback, google_apis::GDATA_CANCELLED, GURL()); |
| 113 | 113 |
| 114 return FakeDriveService::InitiateUploadNewFile(content_type, | 114 return FakeDriveService::InitiateUploadNewFile(content_type, |
| 115 content_length, | 115 content_length, |
| 116 parent_resource_id, | 116 parent_resource_id, |
| 117 title, | 117 title, |
| 118 options, | 118 options, |
| 119 callback); | 119 callback); |
| 120 } | 120 } |
| 121 | 121 |
| 122 private: | 122 private: |
| 123 bool upload_new_file_cancelable_; | 123 bool upload_new_file_cancelable_; |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 } // namespace | 126 } // namespace |
| 127 | 127 |
| 128 class JobSchedulerTest : public testing::Test { | 128 class JobSchedulerTest : public testing::Test { |
| 129 public: | 129 public: |
| 130 JobSchedulerTest() | 130 JobSchedulerTest() |
| 131 : pref_service_(new TestingPrefServiceSimple) { | 131 : pref_service_(new TestingPrefServiceSimple) { |
| 132 test_util::RegisterDrivePrefs(pref_service_->registry()); | 132 test_util::RegisterDrivePrefs(pref_service_->registry()); |
| 133 } | 133 } |
| 134 | 134 |
| 135 virtual void SetUp() OVERRIDE { | 135 virtual void SetUp() override { |
| 136 fake_network_change_notifier_.reset( | 136 fake_network_change_notifier_.reset( |
| 137 new test_util::FakeNetworkChangeNotifier); | 137 new test_util::FakeNetworkChangeNotifier); |
| 138 | 138 |
| 139 logger_.reset(new EventLogger); | 139 logger_.reset(new EventLogger); |
| 140 | 140 |
| 141 fake_drive_service_.reset(new CancelTestableFakeDriveService); | 141 fake_drive_service_.reset(new CancelTestableFakeDriveService); |
| 142 test_util::SetUpTestEntries(fake_drive_service_.get()); | 142 test_util::SetUpTestEntries(fake_drive_service_.get()); |
| 143 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json"); | 143 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json"); |
| 144 | 144 |
| 145 scheduler_.reset(new JobScheduler(pref_service_.get(), | 145 scheduler_.reset(new JobScheduler(pref_service_.get(), |
| (...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 scheduler_->CancelJob(first_job_id); | 1051 scheduler_->CancelJob(first_job_id); |
| 1052 | 1052 |
| 1053 // Only the first job should be cancelled. | 1053 // Only the first job should be cancelled. |
| 1054 base::RunLoop().RunUntilIdle(); | 1054 base::RunLoop().RunUntilIdle(); |
| 1055 EXPECT_EQ(google_apis::GDATA_CANCELLED, error1); | 1055 EXPECT_EQ(google_apis::GDATA_CANCELLED, error1); |
| 1056 EXPECT_EQ(google_apis::HTTP_SUCCESS, error2); | 1056 EXPECT_EQ(google_apis::HTTP_SUCCESS, error2); |
| 1057 EXPECT_TRUE(scheduler_->GetJobInfoList().empty()); | 1057 EXPECT_TRUE(scheduler_->GetJobInfoList().empty()); |
| 1058 } | 1058 } |
| 1059 | 1059 |
| 1060 } // namespace drive | 1060 } // namespace drive |
| OLD | NEW |