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/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/prefs/testing_pref_service.h" | 12 #include "base/prefs/testing_pref_service.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "chrome/browser/chromeos/drive/test_util.h" | 16 #include "chrome/browser/chromeos/drive/test_util.h" |
17 #include "chrome/browser/drive/event_logger.h" | 17 #include "chrome/browser/drive/event_logger.h" |
18 #include "chrome/browser/drive/fake_drive_service.h" | 18 #include "chrome/browser/drive/fake_drive_service.h" |
19 #include "chrome/browser/drive/test_util.h" | 19 #include "chrome/browser/drive/test_util.h" |
20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
21 #include "content/public/test/test_browser_thread_bundle.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
22 #include "google_apis/drive/drive_api_parser.h" | 22 #include "google_apis/drive/drive_api_parser.h" |
23 #include "google_apis/drive/gdata_wapi_parser.h" | |
24 #include "google_apis/drive/test_util.h" | 23 #include "google_apis/drive/test_util.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
26 | 25 |
27 namespace drive { | 26 namespace drive { |
28 | 27 |
29 namespace { | 28 namespace { |
30 | 29 |
31 // Dummy value passed for the |expected_file_size| parameter of DownloadFile(). | 30 // Dummy value passed for the |expected_file_size| parameter of DownloadFile(). |
32 const int64 kDummyDownloadFileSize = 0; | 31 const int64 kDummyDownloadFileSize = 0; |
33 | 32 |
34 void CopyTitleFromGetResourceEntryCallback( | 33 void CopyTitleFromFileResourceCallback( |
35 std::vector<std::string>* title_list_out, | 34 std::vector<std::string>* title_list_out, |
36 google_apis::GDataErrorCode error_in, | 35 google_apis::GDataErrorCode error_in, |
37 scoped_ptr<google_apis::ResourceEntry> resource_entry_in) { | 36 scoped_ptr<google_apis::FileResource> entry_in) { |
38 title_list_out->push_back(resource_entry_in->title()); | 37 title_list_out->push_back(entry_in->title()); |
39 } | 38 } |
40 | 39 |
41 class JobListLogger : public JobListObserver { | 40 class JobListLogger : public JobListObserver { |
42 public: | 41 public: |
43 enum EventType { | 42 enum EventType { |
44 ADDED, | 43 ADDED, |
45 UPDATED, | 44 UPDATED, |
46 DONE, | 45 DONE, |
47 }; | 46 }; |
48 | 47 |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 345 |
347 scheduler_->GetRemainingFileList( | 346 scheduler_->GetRemainingFileList( |
348 next_url, | 347 next_url, |
349 google_apis::test_util::CreateCopyResultCallback(&error, &file_list)); | 348 google_apis::test_util::CreateCopyResultCallback(&error, &file_list)); |
350 base::RunLoop().RunUntilIdle(); | 349 base::RunLoop().RunUntilIdle(); |
351 | 350 |
352 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 351 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
353 ASSERT_TRUE(file_list); | 352 ASSERT_TRUE(file_list); |
354 } | 353 } |
355 | 354 |
356 TEST_F(JobSchedulerTest, GetResourceEntry) { | 355 TEST_F(JobSchedulerTest, GetFileResource) { |
357 ConnectToWifi(); | 356 ConnectToWifi(); |
358 | 357 |
359 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 358 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
360 scoped_ptr<google_apis::ResourceEntry> entry; | 359 scoped_ptr<google_apis::FileResource> entry; |
361 | 360 |
362 scheduler_->GetResourceEntry( | 361 scheduler_->GetFileResource( |
363 "file:2_file_resource_id", // resource ID | 362 "file:2_file_resource_id", // resource ID |
364 ClientContext(USER_INITIATED), | 363 ClientContext(USER_INITIATED), |
365 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 364 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
366 base::RunLoop().RunUntilIdle(); | 365 base::RunLoop().RunUntilIdle(); |
367 | 366 |
368 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 367 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
369 ASSERT_TRUE(entry); | 368 ASSERT_TRUE(entry); |
370 } | 369 } |
371 | 370 |
372 TEST_F(JobSchedulerTest, GetShareUrl) { | 371 TEST_F(JobSchedulerTest, GetShareUrl) { |
(...skipping 24 matching lines...) Expand all Loading... |
397 google_apis::test_util::CreateCopyResultCallback(&error)); | 396 google_apis::test_util::CreateCopyResultCallback(&error)); |
398 base::RunLoop().RunUntilIdle(); | 397 base::RunLoop().RunUntilIdle(); |
399 | 398 |
400 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 399 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
401 } | 400 } |
402 | 401 |
403 TEST_F(JobSchedulerTest, CopyResource) { | 402 TEST_F(JobSchedulerTest, CopyResource) { |
404 ConnectToWifi(); | 403 ConnectToWifi(); |
405 | 404 |
406 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 405 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
407 scoped_ptr<google_apis::ResourceEntry> entry; | 406 scoped_ptr<google_apis::FileResource> entry; |
408 | 407 |
409 scheduler_->CopyResource( | 408 scheduler_->CopyResource( |
410 "file:2_file_resource_id", // resource ID | 409 "file:2_file_resource_id", // resource ID |
411 "folder:1_folder_resource_id", // parent resource ID | 410 "folder:1_folder_resource_id", // parent resource ID |
412 "New Document", // new title | 411 "New Document", // new title |
413 base::Time(), | 412 base::Time(), |
414 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 413 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
415 base::RunLoop().RunUntilIdle(); | 414 base::RunLoop().RunUntilIdle(); |
416 | 415 |
417 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 416 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
418 ASSERT_TRUE(entry); | 417 ASSERT_TRUE(entry); |
419 } | 418 } |
420 | 419 |
421 TEST_F(JobSchedulerTest, UpdateResource) { | 420 TEST_F(JobSchedulerTest, UpdateResource) { |
422 ConnectToWifi(); | 421 ConnectToWifi(); |
423 | 422 |
424 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 423 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
425 scoped_ptr<google_apis::ResourceEntry> entry; | 424 scoped_ptr<google_apis::FileResource> entry; |
426 | 425 |
427 scheduler_->UpdateResource( | 426 scheduler_->UpdateResource( |
428 "file:2_file_resource_id", // resource ID | 427 "file:2_file_resource_id", // resource ID |
429 "folder:1_folder_resource_id", // parent resource ID | 428 "folder:1_folder_resource_id", // parent resource ID |
430 "New Document", // new title | 429 "New Document", // new title |
431 base::Time(), | 430 base::Time(), |
432 base::Time(), | 431 base::Time(), |
433 ClientContext(USER_INITIATED), | 432 ClientContext(USER_INITIATED), |
434 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 433 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
435 base::RunLoop().RunUntilIdle(); | 434 base::RunLoop().RunUntilIdle(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 google_apis::test_util::CreateCopyResultCallback(&error)); | 477 google_apis::test_util::CreateCopyResultCallback(&error)); |
479 base::RunLoop().RunUntilIdle(); | 478 base::RunLoop().RunUntilIdle(); |
480 | 479 |
481 ASSERT_EQ(google_apis::HTTP_NO_CONTENT, error); | 480 ASSERT_EQ(google_apis::HTTP_NO_CONTENT, error); |
482 } | 481 } |
483 | 482 |
484 TEST_F(JobSchedulerTest, AddNewDirectory) { | 483 TEST_F(JobSchedulerTest, AddNewDirectory) { |
485 ConnectToWifi(); | 484 ConnectToWifi(); |
486 | 485 |
487 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 486 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
488 scoped_ptr<google_apis::ResourceEntry> entry; | 487 scoped_ptr<google_apis::FileResource> entry; |
489 | 488 |
490 scheduler_->AddNewDirectory( | 489 scheduler_->AddNewDirectory( |
491 fake_drive_service_->GetRootResourceId(), // Root directory. | 490 fake_drive_service_->GetRootResourceId(), // Root directory. |
492 "New Directory", | 491 "New Directory", |
493 DriveServiceInterface::AddNewDirectoryOptions(), | 492 DriveServiceInterface::AddNewDirectoryOptions(), |
494 ClientContext(USER_INITIATED), | 493 ClientContext(USER_INITIATED), |
495 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 494 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
496 base::RunLoop().RunUntilIdle(); | 495 base::RunLoop().RunUntilIdle(); |
497 | 496 |
498 ASSERT_EQ(google_apis::HTTP_CREATED, error); | 497 ASSERT_EQ(google_apis::HTTP_CREATED, error); |
499 ASSERT_TRUE(entry); | 498 ASSERT_TRUE(entry); |
500 } | 499 } |
501 | 500 |
502 TEST_F(JobSchedulerTest, PriorityHandling) { | 501 TEST_F(JobSchedulerTest, PriorityHandling) { |
503 // Saturate the metadata job queue with uninteresting jobs to prevent | 502 // Saturate the metadata job queue with uninteresting jobs to prevent |
504 // following jobs from starting. | 503 // following jobs from starting. |
505 google_apis::GDataErrorCode error_dontcare = google_apis::GDATA_OTHER_ERROR; | 504 google_apis::GDataErrorCode error_dontcare = google_apis::GDATA_OTHER_ERROR; |
506 scoped_ptr<google_apis::ResourceEntry> entry_dontcare; | 505 scoped_ptr<google_apis::FileResource> entry_dontcare; |
507 for (int i = 0; i < GetMetadataQueueMaxJobCount(); ++i) { | 506 for (int i = 0; i < GetMetadataQueueMaxJobCount(); ++i) { |
508 std::string resource_id("file:2_file_resource_id"); | 507 std::string resource_id("file:2_file_resource_id"); |
509 scheduler_->GetResourceEntry( | 508 scheduler_->GetFileResource( |
510 resource_id, | 509 resource_id, |
511 ClientContext(USER_INITIATED), | 510 ClientContext(USER_INITIATED), |
512 google_apis::test_util::CreateCopyResultCallback(&error_dontcare, | 511 google_apis::test_util::CreateCopyResultCallback(&error_dontcare, |
513 &entry_dontcare)); | 512 &entry_dontcare)); |
514 } | 513 } |
515 | 514 |
516 // Start jobs with different priorities. | 515 // Start jobs with different priorities. |
517 std::string title_1("new file 1"); | 516 std::string title_1("new file 1"); |
518 std::string title_2("new file 2"); | 517 std::string title_2("new file 2"); |
519 std::string title_3("new file 3"); | 518 std::string title_3("new file 3"); |
520 std::string title_4("new file 4"); | 519 std::string title_4("new file 4"); |
521 std::vector<std::string> titles; | 520 std::vector<std::string> titles; |
522 | 521 |
523 scheduler_->AddNewDirectory( | 522 scheduler_->AddNewDirectory( |
524 fake_drive_service_->GetRootResourceId(), | 523 fake_drive_service_->GetRootResourceId(), |
525 title_1, | 524 title_1, |
526 DriveServiceInterface::AddNewDirectoryOptions(), | 525 DriveServiceInterface::AddNewDirectoryOptions(), |
527 ClientContext(USER_INITIATED), | 526 ClientContext(USER_INITIATED), |
528 base::Bind(&CopyTitleFromGetResourceEntryCallback, &titles)); | 527 base::Bind(&CopyTitleFromFileResourceCallback, &titles)); |
529 scheduler_->AddNewDirectory( | 528 scheduler_->AddNewDirectory( |
530 fake_drive_service_->GetRootResourceId(), | 529 fake_drive_service_->GetRootResourceId(), |
531 title_2, | 530 title_2, |
532 DriveServiceInterface::AddNewDirectoryOptions(), | 531 DriveServiceInterface::AddNewDirectoryOptions(), |
533 ClientContext(BACKGROUND), | 532 ClientContext(BACKGROUND), |
534 base::Bind(&CopyTitleFromGetResourceEntryCallback, &titles)); | 533 base::Bind(&CopyTitleFromFileResourceCallback, &titles)); |
535 scheduler_->AddNewDirectory( | 534 scheduler_->AddNewDirectory( |
536 fake_drive_service_->GetRootResourceId(), | 535 fake_drive_service_->GetRootResourceId(), |
537 title_3, | 536 title_3, |
538 DriveServiceInterface::AddNewDirectoryOptions(), | 537 DriveServiceInterface::AddNewDirectoryOptions(), |
539 ClientContext(BACKGROUND), | 538 ClientContext(BACKGROUND), |
540 base::Bind(&CopyTitleFromGetResourceEntryCallback, &titles)); | 539 base::Bind(&CopyTitleFromFileResourceCallback, &titles)); |
541 scheduler_->AddNewDirectory( | 540 scheduler_->AddNewDirectory( |
542 fake_drive_service_->GetRootResourceId(), | 541 fake_drive_service_->GetRootResourceId(), |
543 title_4, | 542 title_4, |
544 DriveServiceInterface::AddNewDirectoryOptions(), | 543 DriveServiceInterface::AddNewDirectoryOptions(), |
545 ClientContext(USER_INITIATED), | 544 ClientContext(USER_INITIATED), |
546 base::Bind(&CopyTitleFromGetResourceEntryCallback, &titles)); | 545 base::Bind(&CopyTitleFromFileResourceCallback, &titles)); |
547 | 546 |
548 base::RunLoop().RunUntilIdle(); | 547 base::RunLoop().RunUntilIdle(); |
549 | 548 |
550 ASSERT_EQ(4ul, titles.size()); | 549 ASSERT_EQ(4ul, titles.size()); |
551 EXPECT_EQ(title_1, titles[0]); | 550 EXPECT_EQ(title_1, titles[0]); |
552 EXPECT_EQ(title_4, titles[1]); | 551 EXPECT_EQ(title_4, titles[1]); |
553 EXPECT_EQ(title_2, titles[2]); | 552 EXPECT_EQ(title_2, titles[2]); |
554 EXPECT_EQ(title_3, titles[3]); | 553 EXPECT_EQ(title_3, titles[3]); |
555 } | 554 } |
556 | 555 |
557 TEST_F(JobSchedulerTest, NoConnectionUserInitiated) { | 556 TEST_F(JobSchedulerTest, NoConnectionUserInitiated) { |
558 ConnectToNone(); | 557 ConnectToNone(); |
559 | 558 |
560 std::string resource_id("file:2_file_resource_id"); | 559 std::string resource_id("file:2_file_resource_id"); |
561 | 560 |
562 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 561 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
563 scoped_ptr<google_apis::ResourceEntry> entry; | 562 scoped_ptr<google_apis::FileResource> entry; |
564 scheduler_->GetResourceEntry( | 563 scheduler_->GetFileResource( |
565 resource_id, | 564 resource_id, |
566 ClientContext(USER_INITIATED), | 565 ClientContext(USER_INITIATED), |
567 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 566 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
568 base::RunLoop().RunUntilIdle(); | 567 base::RunLoop().RunUntilIdle(); |
569 | 568 |
570 EXPECT_EQ(google_apis::GDATA_NO_CONNECTION, error); | 569 EXPECT_EQ(google_apis::GDATA_NO_CONNECTION, error); |
571 } | 570 } |
572 | 571 |
573 TEST_F(JobSchedulerTest, NoConnectionBackground) { | 572 TEST_F(JobSchedulerTest, NoConnectionBackground) { |
574 ConnectToNone(); | 573 ConnectToNone(); |
575 | 574 |
576 std::string resource_id("file:2_file_resource_id"); | 575 std::string resource_id("file:2_file_resource_id"); |
577 | 576 |
578 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 577 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
579 scoped_ptr<google_apis::ResourceEntry> entry; | 578 scoped_ptr<google_apis::FileResource> entry; |
580 scheduler_->GetResourceEntry( | 579 scheduler_->GetFileResource( |
581 resource_id, | 580 resource_id, |
582 ClientContext(BACKGROUND), | 581 ClientContext(BACKGROUND), |
583 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 582 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
584 base::RunLoop().RunUntilIdle(); | 583 base::RunLoop().RunUntilIdle(); |
585 | 584 |
586 EXPECT_FALSE(entry); | 585 EXPECT_FALSE(entry); |
587 | 586 |
588 // Reconnect to the net. | 587 // Reconnect to the net. |
589 ConnectToWifi(); | 588 ConnectToWifi(); |
590 | 589 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 scheduler_->AddObserver(&logger); | 794 scheduler_->AddObserver(&logger); |
796 | 795 |
797 // Disable background upload/download. | 796 // Disable background upload/download. |
798 ConnectToWimax(); | 797 ConnectToWimax(); |
799 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true); | 798 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true); |
800 | 799 |
801 base::ScopedTempDir temp_dir; | 800 base::ScopedTempDir temp_dir; |
802 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 801 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
803 | 802 |
804 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 803 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
805 scoped_ptr<google_apis::ResourceEntry> entry; | 804 scoped_ptr<google_apis::FileResource> entry; |
806 scoped_ptr<google_apis::AboutResource> about_resource; | 805 scoped_ptr<google_apis::AboutResource> about_resource; |
807 base::FilePath path; | 806 base::FilePath path; |
808 | 807 |
809 std::set<JobType> expected_types; | 808 std::set<JobType> expected_types; |
810 | 809 |
811 // Add many jobs. | 810 // Add many jobs. |
812 expected_types.insert(TYPE_ADD_NEW_DIRECTORY); | 811 expected_types.insert(TYPE_ADD_NEW_DIRECTORY); |
813 scheduler_->AddNewDirectory( | 812 scheduler_->AddNewDirectory( |
814 fake_drive_service_->GetRootResourceId(), | 813 fake_drive_service_->GetRootResourceId(), |
815 "New Directory", | 814 "New Directory", |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 ASSERT_TRUE(!download_progress.empty()); | 937 ASSERT_TRUE(!download_progress.empty()); |
939 EXPECT_TRUE(base::STLIsSorted(download_progress)); | 938 EXPECT_TRUE(base::STLIsSorted(download_progress)); |
940 EXPECT_GE(download_progress.front(), 0); | 939 EXPECT_GE(download_progress.front(), 0); |
941 EXPECT_LE(download_progress.back(), 26); | 940 EXPECT_LE(download_progress.back(), 26); |
942 | 941 |
943 // Upload job. | 942 // Upload job. |
944 path = temp_dir.path().AppendASCII("new_file.txt"); | 943 path = temp_dir.path().AppendASCII("new_file.txt"); |
945 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(path, "Hello")); | 944 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(path, "Hello")); |
946 google_apis::GDataErrorCode upload_error = | 945 google_apis::GDataErrorCode upload_error = |
947 google_apis::GDATA_OTHER_ERROR; | 946 google_apis::GDATA_OTHER_ERROR; |
948 scoped_ptr<google_apis::ResourceEntry> entry; | 947 scoped_ptr<google_apis::FileResource> entry; |
949 | 948 |
950 scheduler_->UploadNewFile( | 949 scheduler_->UploadNewFile( |
951 fake_drive_service_->GetRootResourceId(), | 950 fake_drive_service_->GetRootResourceId(), |
952 base::FilePath::FromUTF8Unsafe("drive/new_file.txt"), | 951 base::FilePath::FromUTF8Unsafe("drive/new_file.txt"), |
953 path, | 952 path, |
954 "dummy title", | 953 "dummy title", |
955 "plain/plain", | 954 "plain/plain", |
956 DriveUploader::UploadNewFileOptions(), | 955 DriveUploader::UploadNewFileOptions(), |
957 ClientContext(BACKGROUND), | 956 ClientContext(BACKGROUND), |
958 google_apis::test_util::CreateCopyResultCallback(&upload_error, &entry)); | 957 google_apis::test_util::CreateCopyResultCallback(&upload_error, &entry)); |
(...skipping 13 matching lines...) Expand all Loading... |
972 base::FilePath upload_path = temp_dir.path().AppendASCII("new_file.txt"); | 971 base::FilePath upload_path = temp_dir.path().AppendASCII("new_file.txt"); |
973 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(upload_path, "Hello")); | 972 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(upload_path, "Hello")); |
974 | 973 |
975 // To create a pending job for testing, set the mode to cellular connection | 974 // To create a pending job for testing, set the mode to cellular connection |
976 // and issue BACKGROUND jobs. | 975 // and issue BACKGROUND jobs. |
977 ConnectToCellular(); | 976 ConnectToCellular(); |
978 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true); | 977 pref_service_->SetBoolean(prefs::kDisableDriveOverCellular, true); |
979 | 978 |
980 // Start the first job and record its job ID. | 979 // Start the first job and record its job ID. |
981 google_apis::GDataErrorCode error1 = google_apis::GDATA_OTHER_ERROR; | 980 google_apis::GDataErrorCode error1 = google_apis::GDATA_OTHER_ERROR; |
982 scoped_ptr<google_apis::ResourceEntry> entry; | 981 scoped_ptr<google_apis::FileResource> entry; |
983 scheduler_->UploadNewFile( | 982 scheduler_->UploadNewFile( |
984 fake_drive_service_->GetRootResourceId(), | 983 fake_drive_service_->GetRootResourceId(), |
985 base::FilePath::FromUTF8Unsafe("dummy/path"), | 984 base::FilePath::FromUTF8Unsafe("dummy/path"), |
986 upload_path, | 985 upload_path, |
987 "dummy title 1", | 986 "dummy title 1", |
988 "text/plain", | 987 "text/plain", |
989 DriveUploader::UploadNewFileOptions(), | 988 DriveUploader::UploadNewFileOptions(), |
990 ClientContext(BACKGROUND), | 989 ClientContext(BACKGROUND), |
991 google_apis::test_util::CreateCopyResultCallback(&error1, &entry)); | 990 google_apis::test_util::CreateCopyResultCallback(&error1, &entry)); |
992 | 991 |
(...skipping 29 matching lines...) Expand all Loading... |
1022 ConnectToWifi(); | 1021 ConnectToWifi(); |
1023 | 1022 |
1024 base::ScopedTempDir temp_dir; | 1023 base::ScopedTempDir temp_dir; |
1025 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1024 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1026 base::FilePath upload_path = temp_dir.path().AppendASCII("new_file.txt"); | 1025 base::FilePath upload_path = temp_dir.path().AppendASCII("new_file.txt"); |
1027 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(upload_path, "Hello")); | 1026 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(upload_path, "Hello")); |
1028 | 1027 |
1029 // Run as a cancelable task. | 1028 // Run as a cancelable task. |
1030 fake_drive_service_->set_upload_new_file_cancelable(true); | 1029 fake_drive_service_->set_upload_new_file_cancelable(true); |
1031 google_apis::GDataErrorCode error1 = google_apis::GDATA_OTHER_ERROR; | 1030 google_apis::GDataErrorCode error1 = google_apis::GDATA_OTHER_ERROR; |
1032 scoped_ptr<google_apis::ResourceEntry> entry; | 1031 scoped_ptr<google_apis::FileResource> entry; |
1033 scheduler_->UploadNewFile( | 1032 scheduler_->UploadNewFile( |
1034 fake_drive_service_->GetRootResourceId(), | 1033 fake_drive_service_->GetRootResourceId(), |
1035 base::FilePath::FromUTF8Unsafe("dummy/path"), | 1034 base::FilePath::FromUTF8Unsafe("dummy/path"), |
1036 upload_path, | 1035 upload_path, |
1037 "dummy title 1", | 1036 "dummy title 1", |
1038 "text/plain", | 1037 "text/plain", |
1039 DriveUploader::UploadNewFileOptions(), | 1038 DriveUploader::UploadNewFileOptions(), |
1040 ClientContext(USER_INITIATED), | 1039 ClientContext(USER_INITIATED), |
1041 google_apis::test_util::CreateCopyResultCallback(&error1, &entry)); | 1040 google_apis::test_util::CreateCopyResultCallback(&error1, &entry)); |
1042 | 1041 |
(...skipping 19 matching lines...) Expand all Loading... |
1062 scheduler_->CancelJob(first_job_id); | 1061 scheduler_->CancelJob(first_job_id); |
1063 | 1062 |
1064 // Only the first job should be cancelled. | 1063 // Only the first job should be cancelled. |
1065 base::RunLoop().RunUntilIdle(); | 1064 base::RunLoop().RunUntilIdle(); |
1066 EXPECT_EQ(google_apis::GDATA_CANCELLED, error1); | 1065 EXPECT_EQ(google_apis::GDATA_CANCELLED, error1); |
1067 EXPECT_EQ(google_apis::HTTP_SUCCESS, error2); | 1066 EXPECT_EQ(google_apis::HTTP_SUCCESS, error2); |
1068 EXPECT_TRUE(scheduler_->GetJobInfoList().empty()); | 1067 EXPECT_TRUE(scheduler_->GetJobInfoList().empty()); |
1069 } | 1068 } |
1070 | 1069 |
1071 } // namespace drive | 1070 } // namespace drive |
OLD | NEW |