| 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 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 namespace drive { | 26 namespace drive { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // Dummy value passed for the |expected_file_size| parameter of DownloadFile(). | 30 // Dummy value passed for the |expected_file_size| parameter of DownloadFile(). |
| 31 const int64 kDummyDownloadFileSize = 0; | 31 const int64 kDummyDownloadFileSize = 0; |
| 32 | 32 |
| 33 void CopyTitleFromFileResourceCallback( | 33 void CopyTitleFromFileResourceCallback( |
| 34 std::vector<std::string>* title_list_out, | 34 std::vector<std::string>* title_list_out, |
| 35 google_apis::GDataErrorCode error_in, | 35 google_apis::DriveApiErrorCode error_in, |
| 36 scoped_ptr<google_apis::FileResource> entry_in) { | 36 scoped_ptr<google_apis::FileResource> entry_in) { |
| 37 title_list_out->push_back(entry_in->title()); | 37 title_list_out->push_back(entry_in->title()); |
| 38 } | 38 } |
| 39 | 39 |
| 40 class JobListLogger : public JobListObserver { | 40 class JobListLogger : public JobListObserver { |
| 41 public: | 41 public: |
| 42 enum EventType { | 42 enum EventType { |
| 43 ADDED, | 43 ADDED, |
| 44 UPDATED, | 44 UPDATED, |
| 45 DONE, | 45 DONE, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 102 } |
| 103 | 103 |
| 104 google_apis::CancelCallback InitiateUploadNewFile( | 104 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 UploadNewFileOptions& options, | 109 const UploadNewFileOptions& 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::DRIVE_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: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 scoped_ptr<test_util::FakeNetworkChangeNotifier> | 185 scoped_ptr<test_util::FakeNetworkChangeNotifier> |
| 186 fake_network_change_notifier_; | 186 fake_network_change_notifier_; |
| 187 scoped_ptr<EventLogger> logger_; | 187 scoped_ptr<EventLogger> logger_; |
| 188 scoped_ptr<CancelTestableFakeDriveService> fake_drive_service_; | 188 scoped_ptr<CancelTestableFakeDriveService> fake_drive_service_; |
| 189 scoped_ptr<JobScheduler> scheduler_; | 189 scoped_ptr<JobScheduler> scheduler_; |
| 190 }; | 190 }; |
| 191 | 191 |
| 192 TEST_F(JobSchedulerTest, GetAboutResource) { | 192 TEST_F(JobSchedulerTest, GetAboutResource) { |
| 193 ConnectToWifi(); | 193 ConnectToWifi(); |
| 194 | 194 |
| 195 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 195 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 196 scoped_ptr<google_apis::AboutResource> about_resource; | 196 scoped_ptr<google_apis::AboutResource> about_resource; |
| 197 scheduler_->GetAboutResource( | 197 scheduler_->GetAboutResource( |
| 198 google_apis::test_util::CreateCopyResultCallback( | 198 google_apis::test_util::CreateCopyResultCallback( |
| 199 &error, &about_resource)); | 199 &error, &about_resource)); |
| 200 base::RunLoop().RunUntilIdle(); | 200 base::RunLoop().RunUntilIdle(); |
| 201 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 201 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 202 ASSERT_TRUE(about_resource); | 202 ASSERT_TRUE(about_resource); |
| 203 } | 203 } |
| 204 | 204 |
| 205 TEST_F(JobSchedulerTest, GetAppList) { | 205 TEST_F(JobSchedulerTest, GetAppList) { |
| 206 ConnectToWifi(); | 206 ConnectToWifi(); |
| 207 | 207 |
| 208 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 208 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 209 scoped_ptr<google_apis::AppList> app_list; | 209 scoped_ptr<google_apis::AppList> app_list; |
| 210 | 210 |
| 211 scheduler_->GetAppList( | 211 scheduler_->GetAppList( |
| 212 google_apis::test_util::CreateCopyResultCallback(&error, &app_list)); | 212 google_apis::test_util::CreateCopyResultCallback(&error, &app_list)); |
| 213 base::RunLoop().RunUntilIdle(); | 213 base::RunLoop().RunUntilIdle(); |
| 214 | 214 |
| 215 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 215 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 216 ASSERT_TRUE(app_list); | 216 ASSERT_TRUE(app_list); |
| 217 } | 217 } |
| 218 | 218 |
| 219 TEST_F(JobSchedulerTest, GetAllFileList) { | 219 TEST_F(JobSchedulerTest, GetAllFileList) { |
| 220 ConnectToWifi(); | 220 ConnectToWifi(); |
| 221 | 221 |
| 222 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 222 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 223 scoped_ptr<google_apis::FileList> file_list; | 223 scoped_ptr<google_apis::FileList> file_list; |
| 224 | 224 |
| 225 scheduler_->GetAllFileList( | 225 scheduler_->GetAllFileList( |
| 226 google_apis::test_util::CreateCopyResultCallback(&error, &file_list)); | 226 google_apis::test_util::CreateCopyResultCallback(&error, &file_list)); |
| 227 base::RunLoop().RunUntilIdle(); | 227 base::RunLoop().RunUntilIdle(); |
| 228 | 228 |
| 229 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 229 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 230 ASSERT_TRUE(file_list); | 230 ASSERT_TRUE(file_list); |
| 231 } | 231 } |
| 232 | 232 |
| 233 TEST_F(JobSchedulerTest, GetFileListInDirectory) { | 233 TEST_F(JobSchedulerTest, GetFileListInDirectory) { |
| 234 ConnectToWifi(); | 234 ConnectToWifi(); |
| 235 | 235 |
| 236 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 236 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 237 scoped_ptr<google_apis::FileList> file_list; | 237 scoped_ptr<google_apis::FileList> file_list; |
| 238 | 238 |
| 239 scheduler_->GetFileListInDirectory( | 239 scheduler_->GetFileListInDirectory( |
| 240 fake_drive_service_->GetRootResourceId(), | 240 fake_drive_service_->GetRootResourceId(), |
| 241 google_apis::test_util::CreateCopyResultCallback(&error, &file_list)); | 241 google_apis::test_util::CreateCopyResultCallback(&error, &file_list)); |
| 242 base::RunLoop().RunUntilIdle(); | 242 base::RunLoop().RunUntilIdle(); |
| 243 | 243 |
| 244 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 244 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 245 ASSERT_TRUE(file_list); | 245 ASSERT_TRUE(file_list); |
| 246 } | 246 } |
| 247 | 247 |
| 248 TEST_F(JobSchedulerTest, Search) { | 248 TEST_F(JobSchedulerTest, Search) { |
| 249 ConnectToWifi(); | 249 ConnectToWifi(); |
| 250 | 250 |
| 251 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 251 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 252 scoped_ptr<google_apis::FileList> file_list; | 252 scoped_ptr<google_apis::FileList> file_list; |
| 253 | 253 |
| 254 scheduler_->Search( | 254 scheduler_->Search( |
| 255 "File", // search query | 255 "File", // search query |
| 256 google_apis::test_util::CreateCopyResultCallback(&error, &file_list)); | 256 google_apis::test_util::CreateCopyResultCallback(&error, &file_list)); |
| 257 base::RunLoop().RunUntilIdle(); | 257 base::RunLoop().RunUntilIdle(); |
| 258 | 258 |
| 259 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 259 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 260 ASSERT_TRUE(file_list); | 260 ASSERT_TRUE(file_list); |
| 261 } | 261 } |
| 262 | 262 |
| 263 TEST_F(JobSchedulerTest, GetChangeList) { | 263 TEST_F(JobSchedulerTest, GetChangeList) { |
| 264 ConnectToWifi(); | 264 ConnectToWifi(); |
| 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::GDataErrorCode error = google_apis::GDATA_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(), |
| 276 "new directory", | 276 "new directory", |
| 277 DriveServiceInterface::AddNewDirectoryOptions(), | 277 DriveServiceInterface::AddNewDirectoryOptions(), |
| 278 google_apis::test_util::CreateCopyResultCallback( | 278 google_apis::test_util::CreateCopyResultCallback( |
| 279 &error, &entry)); | 279 &error, &entry)); |
| 280 base::RunLoop().RunUntilIdle(); | 280 base::RunLoop().RunUntilIdle(); |
| 281 ASSERT_EQ(google_apis::HTTP_CREATED, error); | 281 ASSERT_EQ(google_apis::HTTP_CREATED, error); |
| 282 } | 282 } |
| 283 | 283 |
| 284 error = google_apis::GDATA_OTHER_ERROR; | 284 error = google_apis::DRIVE_OTHER_ERROR; |
| 285 scoped_ptr<google_apis::ChangeList> change_list; | 285 scoped_ptr<google_apis::ChangeList> change_list; |
| 286 scheduler_->GetChangeList( | 286 scheduler_->GetChangeList( |
| 287 old_largest_change_id + 1, | 287 old_largest_change_id + 1, |
| 288 google_apis::test_util::CreateCopyResultCallback(&error, &change_list)); | 288 google_apis::test_util::CreateCopyResultCallback(&error, &change_list)); |
| 289 base::RunLoop().RunUntilIdle(); | 289 base::RunLoop().RunUntilIdle(); |
| 290 | 290 |
| 291 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 291 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 292 ASSERT_TRUE(change_list); | 292 ASSERT_TRUE(change_list); |
| 293 } | 293 } |
| 294 | 294 |
| 295 TEST_F(JobSchedulerTest, GetRemainingChangeList) { | 295 TEST_F(JobSchedulerTest, GetRemainingChangeList) { |
| 296 ConnectToWifi(); | 296 ConnectToWifi(); |
| 297 fake_drive_service_->set_default_max_results(2); | 297 fake_drive_service_->set_default_max_results(2); |
| 298 | 298 |
| 299 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 299 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 300 scoped_ptr<google_apis::ChangeList> change_list; | 300 scoped_ptr<google_apis::ChangeList> change_list; |
| 301 | 301 |
| 302 scheduler_->GetChangeList( | 302 scheduler_->GetChangeList( |
| 303 0, | 303 0, |
| 304 google_apis::test_util::CreateCopyResultCallback(&error, &change_list)); | 304 google_apis::test_util::CreateCopyResultCallback(&error, &change_list)); |
| 305 base::RunLoop().RunUntilIdle(); | 305 base::RunLoop().RunUntilIdle(); |
| 306 | 306 |
| 307 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 307 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 308 ASSERT_TRUE(change_list); | 308 ASSERT_TRUE(change_list); |
| 309 | 309 |
| 310 // Keep the next url before releasing the |change_list|. | 310 // Keep the next url before releasing the |change_list|. |
| 311 GURL next_url(change_list->next_link()); | 311 GURL next_url(change_list->next_link()); |
| 312 | 312 |
| 313 error = google_apis::GDATA_OTHER_ERROR; | 313 error = google_apis::DRIVE_OTHER_ERROR; |
| 314 change_list.reset(); | 314 change_list.reset(); |
| 315 | 315 |
| 316 scheduler_->GetRemainingChangeList( | 316 scheduler_->GetRemainingChangeList( |
| 317 next_url, | 317 next_url, |
| 318 google_apis::test_util::CreateCopyResultCallback(&error, &change_list)); | 318 google_apis::test_util::CreateCopyResultCallback(&error, &change_list)); |
| 319 base::RunLoop().RunUntilIdle(); | 319 base::RunLoop().RunUntilIdle(); |
| 320 | 320 |
| 321 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 321 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 322 ASSERT_TRUE(change_list); | 322 ASSERT_TRUE(change_list); |
| 323 } | 323 } |
| 324 | 324 |
| 325 TEST_F(JobSchedulerTest, GetRemainingFileList) { | 325 TEST_F(JobSchedulerTest, GetRemainingFileList) { |
| 326 ConnectToWifi(); | 326 ConnectToWifi(); |
| 327 fake_drive_service_->set_default_max_results(2); | 327 fake_drive_service_->set_default_max_results(2); |
| 328 | 328 |
| 329 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 329 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 330 scoped_ptr<google_apis::FileList> file_list; | 330 scoped_ptr<google_apis::FileList> file_list; |
| 331 | 331 |
| 332 scheduler_->GetFileListInDirectory( | 332 scheduler_->GetFileListInDirectory( |
| 333 fake_drive_service_->GetRootResourceId(), | 333 fake_drive_service_->GetRootResourceId(), |
| 334 google_apis::test_util::CreateCopyResultCallback(&error, &file_list)); | 334 google_apis::test_util::CreateCopyResultCallback(&error, &file_list)); |
| 335 base::RunLoop().RunUntilIdle(); | 335 base::RunLoop().RunUntilIdle(); |
| 336 | 336 |
| 337 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 337 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 338 ASSERT_TRUE(file_list); | 338 ASSERT_TRUE(file_list); |
| 339 | 339 |
| 340 // Keep the next url before releasing the |file_list|. | 340 // Keep the next url before releasing the |file_list|. |
| 341 GURL next_url(file_list->next_link()); | 341 GURL next_url(file_list->next_link()); |
| 342 | 342 |
| 343 error = google_apis::GDATA_OTHER_ERROR; | 343 error = google_apis::DRIVE_OTHER_ERROR; |
| 344 file_list.reset(); | 344 file_list.reset(); |
| 345 | 345 |
| 346 scheduler_->GetRemainingFileList( | 346 scheduler_->GetRemainingFileList( |
| 347 next_url, | 347 next_url, |
| 348 google_apis::test_util::CreateCopyResultCallback(&error, &file_list)); | 348 google_apis::test_util::CreateCopyResultCallback(&error, &file_list)); |
| 349 base::RunLoop().RunUntilIdle(); | 349 base::RunLoop().RunUntilIdle(); |
| 350 | 350 |
| 351 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 351 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 352 ASSERT_TRUE(file_list); | 352 ASSERT_TRUE(file_list); |
| 353 } | 353 } |
| 354 | 354 |
| 355 TEST_F(JobSchedulerTest, GetFileResource) { | 355 TEST_F(JobSchedulerTest, GetFileResource) { |
| 356 ConnectToWifi(); | 356 ConnectToWifi(); |
| 357 | 357 |
| 358 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 358 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 359 scoped_ptr<google_apis::FileResource> entry; | 359 scoped_ptr<google_apis::FileResource> entry; |
| 360 | 360 |
| 361 scheduler_->GetFileResource( | 361 scheduler_->GetFileResource( |
| 362 "2_file_resource_id", // resource ID | 362 "2_file_resource_id", // resource ID |
| 363 ClientContext(USER_INITIATED), | 363 ClientContext(USER_INITIATED), |
| 364 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 364 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
| 365 base::RunLoop().RunUntilIdle(); | 365 base::RunLoop().RunUntilIdle(); |
| 366 | 366 |
| 367 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 367 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 368 ASSERT_TRUE(entry); | 368 ASSERT_TRUE(entry); |
| 369 } | 369 } |
| 370 | 370 |
| 371 TEST_F(JobSchedulerTest, GetShareUrl) { | 371 TEST_F(JobSchedulerTest, GetShareUrl) { |
| 372 ConnectToWifi(); | 372 ConnectToWifi(); |
| 373 | 373 |
| 374 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 374 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 375 GURL share_url; | 375 GURL share_url; |
| 376 | 376 |
| 377 scheduler_->GetShareUrl( | 377 scheduler_->GetShareUrl( |
| 378 "2_file_resource_id", // resource ID | 378 "2_file_resource_id", // resource ID |
| 379 GURL("chrome-extension://test-id/"), // embed origin | 379 GURL("chrome-extension://test-id/"), // embed origin |
| 380 ClientContext(USER_INITIATED), | 380 ClientContext(USER_INITIATED), |
| 381 google_apis::test_util::CreateCopyResultCallback(&error, &share_url)); | 381 google_apis::test_util::CreateCopyResultCallback(&error, &share_url)); |
| 382 base::RunLoop().RunUntilIdle(); | 382 base::RunLoop().RunUntilIdle(); |
| 383 | 383 |
| 384 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 384 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 385 ASSERT_FALSE(share_url.is_empty()); | 385 ASSERT_FALSE(share_url.is_empty()); |
| 386 } | 386 } |
| 387 | 387 |
| 388 TEST_F(JobSchedulerTest, TrashResource) { | 388 TEST_F(JobSchedulerTest, TrashResource) { |
| 389 ConnectToWifi(); | 389 ConnectToWifi(); |
| 390 | 390 |
| 391 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 391 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 392 | 392 |
| 393 scheduler_->TrashResource( | 393 scheduler_->TrashResource( |
| 394 "2_file_resource_id", | 394 "2_file_resource_id", |
| 395 ClientContext(USER_INITIATED), | 395 ClientContext(USER_INITIATED), |
| 396 google_apis::test_util::CreateCopyResultCallback(&error)); | 396 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 397 base::RunLoop().RunUntilIdle(); | 397 base::RunLoop().RunUntilIdle(); |
| 398 | 398 |
| 399 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 399 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 400 } | 400 } |
| 401 | 401 |
| 402 TEST_F(JobSchedulerTest, CopyResource) { | 402 TEST_F(JobSchedulerTest, CopyResource) { |
| 403 ConnectToWifi(); | 403 ConnectToWifi(); |
| 404 | 404 |
| 405 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 405 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 406 scoped_ptr<google_apis::FileResource> entry; | 406 scoped_ptr<google_apis::FileResource> entry; |
| 407 | 407 |
| 408 scheduler_->CopyResource( | 408 scheduler_->CopyResource( |
| 409 "2_file_resource_id", // resource ID | 409 "2_file_resource_id", // resource ID |
| 410 "1_folder_resource_id", // parent resource ID | 410 "1_folder_resource_id", // parent resource ID |
| 411 "New Document", // new title | 411 "New Document", // new title |
| 412 base::Time(), | 412 base::Time(), |
| 413 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 413 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
| 414 base::RunLoop().RunUntilIdle(); | 414 base::RunLoop().RunUntilIdle(); |
| 415 | 415 |
| 416 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 416 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 417 ASSERT_TRUE(entry); | 417 ASSERT_TRUE(entry); |
| 418 } | 418 } |
| 419 | 419 |
| 420 TEST_F(JobSchedulerTest, UpdateResource) { | 420 TEST_F(JobSchedulerTest, UpdateResource) { |
| 421 ConnectToWifi(); | 421 ConnectToWifi(); |
| 422 | 422 |
| 423 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 423 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 424 scoped_ptr<google_apis::FileResource> entry; | 424 scoped_ptr<google_apis::FileResource> entry; |
| 425 | 425 |
| 426 scheduler_->UpdateResource( | 426 scheduler_->UpdateResource( |
| 427 "2_file_resource_id", // resource ID | 427 "2_file_resource_id", // resource ID |
| 428 "1_folder_resource_id", // parent resource ID | 428 "1_folder_resource_id", // parent resource ID |
| 429 "New Document", // new title | 429 "New Document", // new title |
| 430 base::Time(), | 430 base::Time(), |
| 431 base::Time(), | 431 base::Time(), |
| 432 ClientContext(USER_INITIATED), | 432 ClientContext(USER_INITIATED), |
| 433 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 433 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
| 434 base::RunLoop().RunUntilIdle(); | 434 base::RunLoop().RunUntilIdle(); |
| 435 | 435 |
| 436 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 436 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 437 ASSERT_TRUE(entry); | 437 ASSERT_TRUE(entry); |
| 438 } | 438 } |
| 439 | 439 |
| 440 TEST_F(JobSchedulerTest, AddResourceToDirectory) { | 440 TEST_F(JobSchedulerTest, AddResourceToDirectory) { |
| 441 ConnectToWifi(); | 441 ConnectToWifi(); |
| 442 | 442 |
| 443 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 443 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 444 | 444 |
| 445 scheduler_->AddResourceToDirectory( | 445 scheduler_->AddResourceToDirectory( |
| 446 "1_folder_resource_id", | 446 "1_folder_resource_id", |
| 447 "2_file_resource_id", | 447 "2_file_resource_id", |
| 448 google_apis::test_util::CreateCopyResultCallback(&error)); | 448 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 449 base::RunLoop().RunUntilIdle(); | 449 base::RunLoop().RunUntilIdle(); |
| 450 | 450 |
| 451 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 451 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 452 } | 452 } |
| 453 | 453 |
| 454 TEST_F(JobSchedulerTest, RemoveResourceFromDirectory) { | 454 TEST_F(JobSchedulerTest, RemoveResourceFromDirectory) { |
| 455 ConnectToWifi(); | 455 ConnectToWifi(); |
| 456 | 456 |
| 457 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 457 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 458 | 458 |
| 459 scheduler_->RemoveResourceFromDirectory( | 459 scheduler_->RemoveResourceFromDirectory( |
| 460 "1_folder_resource_id", | 460 "1_folder_resource_id", |
| 461 "subdirectory_file_1_id", // resource ID | 461 "subdirectory_file_1_id", // resource ID |
| 462 ClientContext(USER_INITIATED), | 462 ClientContext(USER_INITIATED), |
| 463 google_apis::test_util::CreateCopyResultCallback(&error)); | 463 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 464 base::RunLoop().RunUntilIdle(); | 464 base::RunLoop().RunUntilIdle(); |
| 465 | 465 |
| 466 ASSERT_EQ(google_apis::HTTP_NO_CONTENT, error); | 466 ASSERT_EQ(google_apis::HTTP_NO_CONTENT, error); |
| 467 } | 467 } |
| 468 | 468 |
| 469 TEST_F(JobSchedulerTest, AddNewDirectory) { | 469 TEST_F(JobSchedulerTest, AddNewDirectory) { |
| 470 ConnectToWifi(); | 470 ConnectToWifi(); |
| 471 | 471 |
| 472 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 472 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 473 scoped_ptr<google_apis::FileResource> entry; | 473 scoped_ptr<google_apis::FileResource> entry; |
| 474 | 474 |
| 475 scheduler_->AddNewDirectory( | 475 scheduler_->AddNewDirectory( |
| 476 fake_drive_service_->GetRootResourceId(), // Root directory. | 476 fake_drive_service_->GetRootResourceId(), // Root directory. |
| 477 "New Directory", | 477 "New Directory", |
| 478 DriveServiceInterface::AddNewDirectoryOptions(), | 478 DriveServiceInterface::AddNewDirectoryOptions(), |
| 479 ClientContext(USER_INITIATED), | 479 ClientContext(USER_INITIATED), |
| 480 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 480 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
| 481 base::RunLoop().RunUntilIdle(); | 481 base::RunLoop().RunUntilIdle(); |
| 482 | 482 |
| 483 ASSERT_EQ(google_apis::HTTP_CREATED, error); | 483 ASSERT_EQ(google_apis::HTTP_CREATED, error); |
| 484 ASSERT_TRUE(entry); | 484 ASSERT_TRUE(entry); |
| 485 } | 485 } |
| 486 | 486 |
| 487 TEST_F(JobSchedulerTest, PriorityHandling) { | 487 TEST_F(JobSchedulerTest, PriorityHandling) { |
| 488 // Saturate the metadata job queue with uninteresting jobs to prevent | 488 // Saturate the metadata job queue with uninteresting jobs to prevent |
| 489 // following jobs from starting. | 489 // following jobs from starting. |
| 490 google_apis::GDataErrorCode error_dontcare = google_apis::GDATA_OTHER_ERROR; | 490 google_apis::DriveApiErrorCode error_dontcare = |
| 491 google_apis::DRIVE_OTHER_ERROR; |
| 491 scoped_ptr<google_apis::FileResource> entry_dontcare; | 492 scoped_ptr<google_apis::FileResource> entry_dontcare; |
| 492 for (int i = 0; i < GetMetadataQueueMaxJobCount(); ++i) { | 493 for (int i = 0; i < GetMetadataQueueMaxJobCount(); ++i) { |
| 493 std::string resource_id("2_file_resource_id"); | 494 std::string resource_id("2_file_resource_id"); |
| 494 scheduler_->GetFileResource( | 495 scheduler_->GetFileResource( |
| 495 resource_id, | 496 resource_id, |
| 496 ClientContext(USER_INITIATED), | 497 ClientContext(USER_INITIATED), |
| 497 google_apis::test_util::CreateCopyResultCallback(&error_dontcare, | 498 google_apis::test_util::CreateCopyResultCallback(&error_dontcare, |
| 498 &entry_dontcare)); | 499 &entry_dontcare)); |
| 499 } | 500 } |
| 500 | 501 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 EXPECT_EQ(title_4, titles[1]); | 538 EXPECT_EQ(title_4, titles[1]); |
| 538 EXPECT_EQ(title_2, titles[2]); | 539 EXPECT_EQ(title_2, titles[2]); |
| 539 EXPECT_EQ(title_3, titles[3]); | 540 EXPECT_EQ(title_3, titles[3]); |
| 540 } | 541 } |
| 541 | 542 |
| 542 TEST_F(JobSchedulerTest, NoConnectionUserInitiated) { | 543 TEST_F(JobSchedulerTest, NoConnectionUserInitiated) { |
| 543 ConnectToNone(); | 544 ConnectToNone(); |
| 544 | 545 |
| 545 std::string resource_id("2_file_resource_id"); | 546 std::string resource_id("2_file_resource_id"); |
| 546 | 547 |
| 547 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 548 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 548 scoped_ptr<google_apis::FileResource> entry; | 549 scoped_ptr<google_apis::FileResource> entry; |
| 549 scheduler_->GetFileResource( | 550 scheduler_->GetFileResource( |
| 550 resource_id, | 551 resource_id, |
| 551 ClientContext(USER_INITIATED), | 552 ClientContext(USER_INITIATED), |
| 552 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 553 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
| 553 base::RunLoop().RunUntilIdle(); | 554 base::RunLoop().RunUntilIdle(); |
| 554 | 555 |
| 555 EXPECT_EQ(google_apis::GDATA_NO_CONNECTION, error); | 556 EXPECT_EQ(google_apis::DRIVE_NO_CONNECTION, error); |
| 556 } | 557 } |
| 557 | 558 |
| 558 TEST_F(JobSchedulerTest, NoConnectionBackground) { | 559 TEST_F(JobSchedulerTest, NoConnectionBackground) { |
| 559 ConnectToNone(); | 560 ConnectToNone(); |
| 560 | 561 |
| 561 std::string resource_id("2_file_resource_id"); | 562 std::string resource_id("2_file_resource_id"); |
| 562 | 563 |
| 563 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 564 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 564 scoped_ptr<google_apis::FileResource> entry; | 565 scoped_ptr<google_apis::FileResource> entry; |
| 565 scheduler_->GetFileResource( | 566 scheduler_->GetFileResource( |
| 566 resource_id, | 567 resource_id, |
| 567 ClientContext(BACKGROUND), | 568 ClientContext(BACKGROUND), |
| 568 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 569 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
| 569 base::RunLoop().RunUntilIdle(); | 570 base::RunLoop().RunUntilIdle(); |
| 570 | 571 |
| 571 EXPECT_FALSE(entry); | 572 EXPECT_FALSE(entry); |
| 572 | 573 |
| 573 // Reconnect to the net. | 574 // Reconnect to the net. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 584 | 585 |
| 585 // Disable fetching over cellular network. | 586 // Disable fetching over cellular network. |
| 586 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true); | 587 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true); |
| 587 | 588 |
| 588 // Try to get a file in the background | 589 // Try to get a file in the background |
| 589 base::ScopedTempDir temp_dir; | 590 base::ScopedTempDir temp_dir; |
| 590 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 591 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 591 | 592 |
| 592 const base::FilePath kOutputFilePath = | 593 const base::FilePath kOutputFilePath = |
| 593 temp_dir.path().AppendASCII("whatever.txt"); | 594 temp_dir.path().AppendASCII("whatever.txt"); |
| 594 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; | 595 google_apis::DriveApiErrorCode download_error = |
| 596 google_apis::DRIVE_OTHER_ERROR; |
| 595 base::FilePath output_file_path; | 597 base::FilePath output_file_path; |
| 596 scheduler_->DownloadFile( | 598 scheduler_->DownloadFile( |
| 597 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path | 599 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path |
| 598 kDummyDownloadFileSize, | 600 kDummyDownloadFileSize, |
| 599 kOutputFilePath, | 601 kOutputFilePath, |
| 600 "2_file_resource_id", | 602 "2_file_resource_id", |
| 601 ClientContext(BACKGROUND), | 603 ClientContext(BACKGROUND), |
| 602 google_apis::test_util::CreateCopyResultCallback( | 604 google_apis::test_util::CreateCopyResultCallback( |
| 603 &download_error, &output_file_path), | 605 &download_error, &output_file_path), |
| 604 google_apis::GetContentCallback()); | 606 google_apis::GetContentCallback()); |
| 605 // Metadata should still work | 607 // Metadata should still work |
| 606 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; | 608 google_apis::DriveApiErrorCode metadata_error = |
| 609 google_apis::DRIVE_OTHER_ERROR; |
| 607 scoped_ptr<google_apis::AboutResource> about_resource; | 610 scoped_ptr<google_apis::AboutResource> about_resource; |
| 608 | 611 |
| 609 // Try to get the metadata | 612 // Try to get the metadata |
| 610 scheduler_->GetAboutResource( | 613 scheduler_->GetAboutResource( |
| 611 google_apis::test_util::CreateCopyResultCallback( | 614 google_apis::test_util::CreateCopyResultCallback( |
| 612 &metadata_error, &about_resource)); | 615 &metadata_error, &about_resource)); |
| 613 base::RunLoop().RunUntilIdle(); | 616 base::RunLoop().RunUntilIdle(); |
| 614 | 617 |
| 615 // Check the metadata | 618 // Check the metadata |
| 616 ASSERT_EQ(google_apis::HTTP_SUCCESS, metadata_error); | 619 ASSERT_EQ(google_apis::HTTP_SUCCESS, metadata_error); |
| 617 ASSERT_TRUE(about_resource); | 620 ASSERT_TRUE(about_resource); |
| 618 | 621 |
| 619 // Check the download | 622 // Check the download |
| 620 EXPECT_EQ(google_apis::GDATA_OTHER_ERROR, download_error); | 623 EXPECT_EQ(google_apis::DRIVE_OTHER_ERROR, download_error); |
| 621 | 624 |
| 622 // Switch to a Wifi connection | 625 // Switch to a Wifi connection |
| 623 ConnectToWifi(); | 626 ConnectToWifi(); |
| 624 | 627 |
| 625 base::RunLoop().RunUntilIdle(); | 628 base::RunLoop().RunUntilIdle(); |
| 626 | 629 |
| 627 // Check the download again | 630 // Check the download again |
| 628 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error); | 631 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error); |
| 629 std::string content; | 632 std::string content; |
| 630 EXPECT_EQ(output_file_path, kOutputFilePath); | 633 EXPECT_EQ(output_file_path, kOutputFilePath); |
| 631 ASSERT_TRUE(base::ReadFileToString(output_file_path, &content)); | 634 ASSERT_TRUE(base::ReadFileToString(output_file_path, &content)); |
| 632 EXPECT_EQ("This is some test content.", content); | 635 EXPECT_EQ("This is some test content.", content); |
| 633 } | 636 } |
| 634 | 637 |
| 635 TEST_F(JobSchedulerTest, DownloadFileWimaxDisabled) { | 638 TEST_F(JobSchedulerTest, DownloadFileWimaxDisabled) { |
| 636 ConnectToWimax(); | 639 ConnectToWimax(); |
| 637 | 640 |
| 638 // Disable fetching over cellular network. | 641 // Disable fetching over cellular network. |
| 639 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true); | 642 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true); |
| 640 | 643 |
| 641 // Try to get a file in the background | 644 // Try to get a file in the background |
| 642 base::ScopedTempDir temp_dir; | 645 base::ScopedTempDir temp_dir; |
| 643 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 646 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 644 | 647 |
| 645 const base::FilePath kOutputFilePath = | 648 const base::FilePath kOutputFilePath = |
| 646 temp_dir.path().AppendASCII("whatever.txt"); | 649 temp_dir.path().AppendASCII("whatever.txt"); |
| 647 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; | 650 google_apis::DriveApiErrorCode download_error = |
| 651 google_apis::DRIVE_OTHER_ERROR; |
| 648 base::FilePath output_file_path; | 652 base::FilePath output_file_path; |
| 649 scheduler_->DownloadFile( | 653 scheduler_->DownloadFile( |
| 650 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path | 654 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path |
| 651 kDummyDownloadFileSize, | 655 kDummyDownloadFileSize, |
| 652 kOutputFilePath, | 656 kOutputFilePath, |
| 653 "2_file_resource_id", | 657 "2_file_resource_id", |
| 654 ClientContext(BACKGROUND), | 658 ClientContext(BACKGROUND), |
| 655 google_apis::test_util::CreateCopyResultCallback( | 659 google_apis::test_util::CreateCopyResultCallback( |
| 656 &download_error, &output_file_path), | 660 &download_error, &output_file_path), |
| 657 google_apis::GetContentCallback()); | 661 google_apis::GetContentCallback()); |
| 658 // Metadata should still work | 662 // Metadata should still work |
| 659 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; | 663 google_apis::DriveApiErrorCode metadata_error = |
| 664 google_apis::DRIVE_OTHER_ERROR; |
| 660 scoped_ptr<google_apis::AboutResource> about_resource; | 665 scoped_ptr<google_apis::AboutResource> about_resource; |
| 661 | 666 |
| 662 // Try to get the metadata | 667 // Try to get the metadata |
| 663 scheduler_->GetAboutResource( | 668 scheduler_->GetAboutResource( |
| 664 google_apis::test_util::CreateCopyResultCallback( | 669 google_apis::test_util::CreateCopyResultCallback( |
| 665 &metadata_error, &about_resource)); | 670 &metadata_error, &about_resource)); |
| 666 base::RunLoop().RunUntilIdle(); | 671 base::RunLoop().RunUntilIdle(); |
| 667 | 672 |
| 668 // Check the metadata | 673 // Check the metadata |
| 669 ASSERT_EQ(google_apis::HTTP_SUCCESS, metadata_error); | 674 ASSERT_EQ(google_apis::HTTP_SUCCESS, metadata_error); |
| 670 ASSERT_TRUE(about_resource); | 675 ASSERT_TRUE(about_resource); |
| 671 | 676 |
| 672 // Check the download | 677 // Check the download |
| 673 EXPECT_EQ(google_apis::GDATA_OTHER_ERROR, download_error); | 678 EXPECT_EQ(google_apis::DRIVE_OTHER_ERROR, download_error); |
| 674 | 679 |
| 675 // Switch to a Wifi connection | 680 // Switch to a Wifi connection |
| 676 ConnectToWifi(); | 681 ConnectToWifi(); |
| 677 | 682 |
| 678 base::RunLoop().RunUntilIdle(); | 683 base::RunLoop().RunUntilIdle(); |
| 679 | 684 |
| 680 // Check the download again | 685 // Check the download again |
| 681 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error); | 686 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error); |
| 682 std::string content; | 687 std::string content; |
| 683 EXPECT_EQ(output_file_path, kOutputFilePath); | 688 EXPECT_EQ(output_file_path, kOutputFilePath); |
| 684 ASSERT_TRUE(base::ReadFileToString(output_file_path, &content)); | 689 ASSERT_TRUE(base::ReadFileToString(output_file_path, &content)); |
| 685 EXPECT_EQ("This is some test content.", content); | 690 EXPECT_EQ("This is some test content.", content); |
| 686 } | 691 } |
| 687 | 692 |
| 688 TEST_F(JobSchedulerTest, DownloadFileCellularEnabled) { | 693 TEST_F(JobSchedulerTest, DownloadFileCellularEnabled) { |
| 689 ConnectToCellular(); | 694 ConnectToCellular(); |
| 690 | 695 |
| 691 // Enable fetching over cellular network. | 696 // Enable fetching over cellular network. |
| 692 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, false); | 697 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, false); |
| 693 | 698 |
| 694 // Try to get a file in the background | 699 // Try to get a file in the background |
| 695 base::ScopedTempDir temp_dir; | 700 base::ScopedTempDir temp_dir; |
| 696 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 701 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 697 | 702 |
| 698 const base::FilePath kOutputFilePath = | 703 const base::FilePath kOutputFilePath = |
| 699 temp_dir.path().AppendASCII("whatever.txt"); | 704 temp_dir.path().AppendASCII("whatever.txt"); |
| 700 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; | 705 google_apis::DriveApiErrorCode download_error = |
| 706 google_apis::DRIVE_OTHER_ERROR; |
| 701 base::FilePath output_file_path; | 707 base::FilePath output_file_path; |
| 702 scheduler_->DownloadFile( | 708 scheduler_->DownloadFile( |
| 703 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path | 709 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path |
| 704 kDummyDownloadFileSize, | 710 kDummyDownloadFileSize, |
| 705 kOutputFilePath, | 711 kOutputFilePath, |
| 706 "2_file_resource_id", | 712 "2_file_resource_id", |
| 707 ClientContext(BACKGROUND), | 713 ClientContext(BACKGROUND), |
| 708 google_apis::test_util::CreateCopyResultCallback( | 714 google_apis::test_util::CreateCopyResultCallback( |
| 709 &download_error, &output_file_path), | 715 &download_error, &output_file_path), |
| 710 google_apis::GetContentCallback()); | 716 google_apis::GetContentCallback()); |
| 711 // Metadata should still work | 717 // Metadata should still work |
| 712 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; | 718 google_apis::DriveApiErrorCode metadata_error = |
| 719 google_apis::DRIVE_OTHER_ERROR; |
| 713 scoped_ptr<google_apis::AboutResource> about_resource; | 720 scoped_ptr<google_apis::AboutResource> about_resource; |
| 714 | 721 |
| 715 // Try to get the metadata | 722 // Try to get the metadata |
| 716 scheduler_->GetAboutResource( | 723 scheduler_->GetAboutResource( |
| 717 google_apis::test_util::CreateCopyResultCallback( | 724 google_apis::test_util::CreateCopyResultCallback( |
| 718 &metadata_error, &about_resource)); | 725 &metadata_error, &about_resource)); |
| 719 base::RunLoop().RunUntilIdle(); | 726 base::RunLoop().RunUntilIdle(); |
| 720 | 727 |
| 721 // Check the metadata | 728 // Check the metadata |
| 722 ASSERT_EQ(google_apis::HTTP_SUCCESS, metadata_error); | 729 ASSERT_EQ(google_apis::HTTP_SUCCESS, metadata_error); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 735 | 742 |
| 736 // Enable fetching over cellular network. | 743 // Enable fetching over cellular network. |
| 737 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, false); | 744 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, false); |
| 738 | 745 |
| 739 // Try to get a file in the background | 746 // Try to get a file in the background |
| 740 base::ScopedTempDir temp_dir; | 747 base::ScopedTempDir temp_dir; |
| 741 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 748 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 742 | 749 |
| 743 const base::FilePath kOutputFilePath = | 750 const base::FilePath kOutputFilePath = |
| 744 temp_dir.path().AppendASCII("whatever.txt"); | 751 temp_dir.path().AppendASCII("whatever.txt"); |
| 745 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; | 752 google_apis::DriveApiErrorCode download_error = |
| 753 google_apis::DRIVE_OTHER_ERROR; |
| 746 base::FilePath output_file_path; | 754 base::FilePath output_file_path; |
| 747 scheduler_->DownloadFile( | 755 scheduler_->DownloadFile( |
| 748 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path | 756 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path |
| 749 kDummyDownloadFileSize, | 757 kDummyDownloadFileSize, |
| 750 kOutputFilePath, | 758 kOutputFilePath, |
| 751 "2_file_resource_id", | 759 "2_file_resource_id", |
| 752 ClientContext(BACKGROUND), | 760 ClientContext(BACKGROUND), |
| 753 google_apis::test_util::CreateCopyResultCallback( | 761 google_apis::test_util::CreateCopyResultCallback( |
| 754 &download_error, &output_file_path), | 762 &download_error, &output_file_path), |
| 755 google_apis::GetContentCallback()); | 763 google_apis::GetContentCallback()); |
| 756 // Metadata should still work | 764 // Metadata should still work |
| 757 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; | 765 google_apis::DriveApiErrorCode metadata_error = |
| 766 google_apis::DRIVE_OTHER_ERROR; |
| 758 scoped_ptr<google_apis::AboutResource> about_resource; | 767 scoped_ptr<google_apis::AboutResource> about_resource; |
| 759 | 768 |
| 760 // Try to get the metadata | 769 // Try to get the metadata |
| 761 scheduler_->GetAboutResource( | 770 scheduler_->GetAboutResource( |
| 762 google_apis::test_util::CreateCopyResultCallback( | 771 google_apis::test_util::CreateCopyResultCallback( |
| 763 &metadata_error, &about_resource)); | 772 &metadata_error, &about_resource)); |
| 764 base::RunLoop().RunUntilIdle(); | 773 base::RunLoop().RunUntilIdle(); |
| 765 | 774 |
| 766 // Check the metadata | 775 // Check the metadata |
| 767 ASSERT_EQ(google_apis::HTTP_SUCCESS, metadata_error); | 776 ASSERT_EQ(google_apis::HTTP_SUCCESS, metadata_error); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 779 JobListLogger logger; | 788 JobListLogger logger; |
| 780 scheduler_->AddObserver(&logger); | 789 scheduler_->AddObserver(&logger); |
| 781 | 790 |
| 782 // Disable background upload/download. | 791 // Disable background upload/download. |
| 783 ConnectToWimax(); | 792 ConnectToWimax(); |
| 784 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true); | 793 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true); |
| 785 | 794 |
| 786 base::ScopedTempDir temp_dir; | 795 base::ScopedTempDir temp_dir; |
| 787 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 796 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 788 | 797 |
| 789 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 798 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 790 scoped_ptr<google_apis::FileResource> entry; | 799 scoped_ptr<google_apis::FileResource> entry; |
| 791 scoped_ptr<google_apis::AboutResource> about_resource; | 800 scoped_ptr<google_apis::AboutResource> about_resource; |
| 792 base::FilePath path; | 801 base::FilePath path; |
| 793 | 802 |
| 794 std::set<JobType> expected_types; | 803 std::set<JobType> expected_types; |
| 795 | 804 |
| 796 // Add many jobs. | 805 // Add many jobs. |
| 797 expected_types.insert(TYPE_ADD_NEW_DIRECTORY); | 806 expected_types.insert(TYPE_ADD_NEW_DIRECTORY); |
| 798 scheduler_->AddNewDirectory( | 807 scheduler_->AddNewDirectory( |
| 799 fake_drive_service_->GetRootResourceId(), | 808 fake_drive_service_->GetRootResourceId(), |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 | 910 |
| 902 TEST_F(JobSchedulerTest, JobInfoProgress) { | 911 TEST_F(JobSchedulerTest, JobInfoProgress) { |
| 903 JobListLogger logger; | 912 JobListLogger logger; |
| 904 scheduler_->AddObserver(&logger); | 913 scheduler_->AddObserver(&logger); |
| 905 | 914 |
| 906 ConnectToWifi(); | 915 ConnectToWifi(); |
| 907 | 916 |
| 908 base::ScopedTempDir temp_dir; | 917 base::ScopedTempDir temp_dir; |
| 909 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 918 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 910 | 919 |
| 911 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 920 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 912 base::FilePath path; | 921 base::FilePath path; |
| 913 | 922 |
| 914 // Download job. | 923 // Download job. |
| 915 scheduler_->DownloadFile( | 924 scheduler_->DownloadFile( |
| 916 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path | 925 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path |
| 917 kDummyDownloadFileSize, | 926 kDummyDownloadFileSize, |
| 918 temp_dir.path().AppendASCII("whatever.txt"), | 927 temp_dir.path().AppendASCII("whatever.txt"), |
| 919 "2_file_resource_id", | 928 "2_file_resource_id", |
| 920 ClientContext(BACKGROUND), | 929 ClientContext(BACKGROUND), |
| 921 google_apis::test_util::CreateCopyResultCallback(&error, &path), | 930 google_apis::test_util::CreateCopyResultCallback(&error, &path), |
| 922 google_apis::GetContentCallback()); | 931 google_apis::GetContentCallback()); |
| 923 base::RunLoop().RunUntilIdle(); | 932 base::RunLoop().RunUntilIdle(); |
| 924 | 933 |
| 925 std::vector<int64> download_progress; | 934 std::vector<int64> download_progress; |
| 926 logger.GetProgressInfo(TYPE_DOWNLOAD_FILE, &download_progress); | 935 logger.GetProgressInfo(TYPE_DOWNLOAD_FILE, &download_progress); |
| 927 ASSERT_TRUE(!download_progress.empty()); | 936 ASSERT_TRUE(!download_progress.empty()); |
| 928 EXPECT_TRUE(base::STLIsSorted(download_progress)); | 937 EXPECT_TRUE(base::STLIsSorted(download_progress)); |
| 929 EXPECT_GE(download_progress.front(), 0); | 938 EXPECT_GE(download_progress.front(), 0); |
| 930 EXPECT_LE(download_progress.back(), 26); | 939 EXPECT_LE(download_progress.back(), 26); |
| 931 | 940 |
| 932 // Upload job. | 941 // Upload job. |
| 933 path = temp_dir.path().AppendASCII("new_file.txt"); | 942 path = temp_dir.path().AppendASCII("new_file.txt"); |
| 934 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(path, "Hello")); | 943 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(path, "Hello")); |
| 935 google_apis::GDataErrorCode upload_error = | 944 google_apis::DriveApiErrorCode upload_error = |
| 936 google_apis::GDATA_OTHER_ERROR; | 945 google_apis::DRIVE_OTHER_ERROR; |
| 937 scoped_ptr<google_apis::FileResource> entry; | 946 scoped_ptr<google_apis::FileResource> entry; |
| 938 | 947 |
| 939 scheduler_->UploadNewFile( | 948 scheduler_->UploadNewFile( |
| 940 fake_drive_service_->GetRootResourceId(), | 949 fake_drive_service_->GetRootResourceId(), |
| 941 base::FilePath::FromUTF8Unsafe("drive/new_file.txt"), | 950 base::FilePath::FromUTF8Unsafe("drive/new_file.txt"), |
| 942 path, | 951 path, |
| 943 "dummy title", | 952 "dummy title", |
| 944 "plain/plain", | 953 "plain/plain", |
| 945 DriveUploader::UploadNewFileOptions(), | 954 DriveUploader::UploadNewFileOptions(), |
| 946 ClientContext(BACKGROUND), | 955 ClientContext(BACKGROUND), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 960 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 969 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 961 base::FilePath upload_path = temp_dir.path().AppendASCII("new_file.txt"); | 970 base::FilePath upload_path = temp_dir.path().AppendASCII("new_file.txt"); |
| 962 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(upload_path, "Hello")); | 971 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(upload_path, "Hello")); |
| 963 | 972 |
| 964 // To create a pending job for testing, set the mode to cellular connection | 973 // To create a pending job for testing, set the mode to cellular connection |
| 965 // and issue BACKGROUND jobs. | 974 // and issue BACKGROUND jobs. |
| 966 ConnectToCellular(); | 975 ConnectToCellular(); |
| 967 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true); | 976 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true); |
| 968 | 977 |
| 969 // Start the first job and record its job ID. | 978 // Start the first job and record its job ID. |
| 970 google_apis::GDataErrorCode error1 = google_apis::GDATA_OTHER_ERROR; | 979 google_apis::DriveApiErrorCode error1 = google_apis::DRIVE_OTHER_ERROR; |
| 971 scoped_ptr<google_apis::FileResource> entry; | 980 scoped_ptr<google_apis::FileResource> entry; |
| 972 scheduler_->UploadNewFile( | 981 scheduler_->UploadNewFile( |
| 973 fake_drive_service_->GetRootResourceId(), | 982 fake_drive_service_->GetRootResourceId(), |
| 974 base::FilePath::FromUTF8Unsafe("dummy/path"), | 983 base::FilePath::FromUTF8Unsafe("dummy/path"), |
| 975 upload_path, | 984 upload_path, |
| 976 "dummy title 1", | 985 "dummy title 1", |
| 977 "text/plain", | 986 "text/plain", |
| 978 DriveUploader::UploadNewFileOptions(), | 987 DriveUploader::UploadNewFileOptions(), |
| 979 ClientContext(BACKGROUND), | 988 ClientContext(BACKGROUND), |
| 980 google_apis::test_util::CreateCopyResultCallback(&error1, &entry)); | 989 google_apis::test_util::CreateCopyResultCallback(&error1, &entry)); |
| 981 | 990 |
| 982 const std::vector<JobInfo>& jobs = scheduler_->GetJobInfoList(); | 991 const std::vector<JobInfo>& jobs = scheduler_->GetJobInfoList(); |
| 983 ASSERT_EQ(1u, jobs.size()); | 992 ASSERT_EQ(1u, jobs.size()); |
| 984 ASSERT_EQ(STATE_NONE, jobs[0].state); // Not started yet. | 993 ASSERT_EQ(STATE_NONE, jobs[0].state); // Not started yet. |
| 985 JobID first_job_id = jobs[0].job_id; | 994 JobID first_job_id = jobs[0].job_id; |
| 986 | 995 |
| 987 // Start the second job. | 996 // Start the second job. |
| 988 google_apis::GDataErrorCode error2 = google_apis::GDATA_OTHER_ERROR; | 997 google_apis::DriveApiErrorCode error2 = google_apis::DRIVE_OTHER_ERROR; |
| 989 scheduler_->UploadNewFile( | 998 scheduler_->UploadNewFile( |
| 990 fake_drive_service_->GetRootResourceId(), | 999 fake_drive_service_->GetRootResourceId(), |
| 991 base::FilePath::FromUTF8Unsafe("dummy/path"), | 1000 base::FilePath::FromUTF8Unsafe("dummy/path"), |
| 992 upload_path, | 1001 upload_path, |
| 993 "dummy title 2", | 1002 "dummy title 2", |
| 994 "text/plain", | 1003 "text/plain", |
| 995 DriveUploader::UploadNewFileOptions(), | 1004 DriveUploader::UploadNewFileOptions(), |
| 996 ClientContext(BACKGROUND), | 1005 ClientContext(BACKGROUND), |
| 997 google_apis::test_util::CreateCopyResultCallback(&error2, &entry)); | 1006 google_apis::test_util::CreateCopyResultCallback(&error2, &entry)); |
| 998 | 1007 |
| 999 // Cancel the first one. | 1008 // Cancel the first one. |
| 1000 scheduler_->CancelJob(first_job_id); | 1009 scheduler_->CancelJob(first_job_id); |
| 1001 | 1010 |
| 1002 // Only the first job should be cancelled. | 1011 // Only the first job should be cancelled. |
| 1003 ConnectToWifi(); | 1012 ConnectToWifi(); |
| 1004 base::RunLoop().RunUntilIdle(); | 1013 base::RunLoop().RunUntilIdle(); |
| 1005 EXPECT_EQ(google_apis::GDATA_CANCELLED, error1); | 1014 EXPECT_EQ(google_apis::DRIVE_CANCELLED, error1); |
| 1006 EXPECT_EQ(google_apis::HTTP_SUCCESS, error2); | 1015 EXPECT_EQ(google_apis::HTTP_SUCCESS, error2); |
| 1007 EXPECT_TRUE(scheduler_->GetJobInfoList().empty()); | 1016 EXPECT_TRUE(scheduler_->GetJobInfoList().empty()); |
| 1008 } | 1017 } |
| 1009 | 1018 |
| 1010 TEST_F(JobSchedulerTest, CancelRunningJob) { | 1019 TEST_F(JobSchedulerTest, CancelRunningJob) { |
| 1011 ConnectToWifi(); | 1020 ConnectToWifi(); |
| 1012 | 1021 |
| 1013 base::ScopedTempDir temp_dir; | 1022 base::ScopedTempDir temp_dir; |
| 1014 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1023 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1015 base::FilePath upload_path = temp_dir.path().AppendASCII("new_file.txt"); | 1024 base::FilePath upload_path = temp_dir.path().AppendASCII("new_file.txt"); |
| 1016 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(upload_path, "Hello")); | 1025 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(upload_path, "Hello")); |
| 1017 | 1026 |
| 1018 // Run as a cancelable task. | 1027 // Run as a cancelable task. |
| 1019 fake_drive_service_->set_upload_new_file_cancelable(true); | 1028 fake_drive_service_->set_upload_new_file_cancelable(true); |
| 1020 google_apis::GDataErrorCode error1 = google_apis::GDATA_OTHER_ERROR; | 1029 google_apis::DriveApiErrorCode error1 = google_apis::DRIVE_OTHER_ERROR; |
| 1021 scoped_ptr<google_apis::FileResource> entry; | 1030 scoped_ptr<google_apis::FileResource> entry; |
| 1022 scheduler_->UploadNewFile( | 1031 scheduler_->UploadNewFile( |
| 1023 fake_drive_service_->GetRootResourceId(), | 1032 fake_drive_service_->GetRootResourceId(), |
| 1024 base::FilePath::FromUTF8Unsafe("dummy/path"), | 1033 base::FilePath::FromUTF8Unsafe("dummy/path"), |
| 1025 upload_path, | 1034 upload_path, |
| 1026 "dummy title 1", | 1035 "dummy title 1", |
| 1027 "text/plain", | 1036 "text/plain", |
| 1028 DriveUploader::UploadNewFileOptions(), | 1037 DriveUploader::UploadNewFileOptions(), |
| 1029 ClientContext(USER_INITIATED), | 1038 ClientContext(USER_INITIATED), |
| 1030 google_apis::test_util::CreateCopyResultCallback(&error1, &entry)); | 1039 google_apis::test_util::CreateCopyResultCallback(&error1, &entry)); |
| 1031 | 1040 |
| 1032 const std::vector<JobInfo>& jobs = scheduler_->GetJobInfoList(); | 1041 const std::vector<JobInfo>& jobs = scheduler_->GetJobInfoList(); |
| 1033 ASSERT_EQ(1u, jobs.size()); | 1042 ASSERT_EQ(1u, jobs.size()); |
| 1034 ASSERT_EQ(STATE_RUNNING, jobs[0].state); // It's running. | 1043 ASSERT_EQ(STATE_RUNNING, jobs[0].state); // It's running. |
| 1035 JobID first_job_id = jobs[0].job_id; | 1044 JobID first_job_id = jobs[0].job_id; |
| 1036 | 1045 |
| 1037 // Start the second job normally. | 1046 // Start the second job normally. |
| 1038 fake_drive_service_->set_upload_new_file_cancelable(false); | 1047 fake_drive_service_->set_upload_new_file_cancelable(false); |
| 1039 google_apis::GDataErrorCode error2 = google_apis::GDATA_OTHER_ERROR; | 1048 google_apis::DriveApiErrorCode error2 = google_apis::DRIVE_OTHER_ERROR; |
| 1040 scheduler_->UploadNewFile( | 1049 scheduler_->UploadNewFile( |
| 1041 fake_drive_service_->GetRootResourceId(), | 1050 fake_drive_service_->GetRootResourceId(), |
| 1042 base::FilePath::FromUTF8Unsafe("dummy/path"), | 1051 base::FilePath::FromUTF8Unsafe("dummy/path"), |
| 1043 upload_path, | 1052 upload_path, |
| 1044 "dummy title 2", | 1053 "dummy title 2", |
| 1045 "text/plain", | 1054 "text/plain", |
| 1046 DriveUploader::UploadNewFileOptions(), | 1055 DriveUploader::UploadNewFileOptions(), |
| 1047 ClientContext(USER_INITIATED), | 1056 ClientContext(USER_INITIATED), |
| 1048 google_apis::test_util::CreateCopyResultCallback(&error2, &entry)); | 1057 google_apis::test_util::CreateCopyResultCallback(&error2, &entry)); |
| 1049 | 1058 |
| 1050 // Cancel the first one. | 1059 // Cancel the first one. |
| 1051 scheduler_->CancelJob(first_job_id); | 1060 scheduler_->CancelJob(first_job_id); |
| 1052 | 1061 |
| 1053 // Only the first job should be cancelled. | 1062 // Only the first job should be cancelled. |
| 1054 base::RunLoop().RunUntilIdle(); | 1063 base::RunLoop().RunUntilIdle(); |
| 1055 EXPECT_EQ(google_apis::GDATA_CANCELLED, error1); | 1064 EXPECT_EQ(google_apis::DRIVE_CANCELLED, error1); |
| 1056 EXPECT_EQ(google_apis::HTTP_SUCCESS, error2); | 1065 EXPECT_EQ(google_apis::HTTP_SUCCESS, error2); |
| 1057 EXPECT_TRUE(scheduler_->GetJobInfoList().empty()); | 1066 EXPECT_TRUE(scheduler_->GetJobInfoList().empty()); |
| 1058 } | 1067 } |
| 1059 | 1068 |
| 1060 } // namespace drive | 1069 } // namespace drive |
| OLD | NEW |