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" |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 TEST_F(JobSchedulerTest, DownloadFileCellularDisabled) { | 514 TEST_F(JobSchedulerTest, DownloadFileCellularDisabled) { |
515 ConnectToCellular(); | 515 ConnectToCellular(); |
516 | 516 |
517 // Disable fetching over cellular network. | 517 // Disable fetching over cellular network. |
518 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, true); | 518 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, true); |
519 | 519 |
520 // Try to get a file in the background | 520 // Try to get a file in the background |
521 base::ScopedTempDir temp_dir; | 521 base::ScopedTempDir temp_dir; |
522 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 522 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
523 | 523 |
524 const GURL kContentUrl("https://file_content_url/"); | |
525 const base::FilePath kOutputFilePath = | 524 const base::FilePath kOutputFilePath = |
526 temp_dir.path().AppendASCII("whatever.txt"); | 525 temp_dir.path().AppendASCII("whatever.txt"); |
527 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; | 526 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; |
528 base::FilePath output_file_path; | 527 base::FilePath output_file_path; |
529 scheduler_->DownloadFile( | 528 scheduler_->DownloadFile( |
530 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path | 529 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path |
531 kOutputFilePath, | 530 kOutputFilePath, |
532 kContentUrl, | 531 "file:2_file_resource_id", |
533 ClientContext(BACKGROUND), | 532 ClientContext(BACKGROUND), |
534 google_apis::test_util::CreateCopyResultCallback( | 533 google_apis::test_util::CreateCopyResultCallback( |
535 &download_error, &output_file_path), | 534 &download_error, &output_file_path), |
536 google_apis::GetContentCallback()); | 535 google_apis::GetContentCallback()); |
537 // Metadata should still work | 536 // Metadata should still work |
538 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; | 537 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; |
539 scoped_ptr<google_apis::AboutResource> about_resource; | 538 scoped_ptr<google_apis::AboutResource> about_resource; |
540 | 539 |
541 // Try to get the metadata | 540 // Try to get the metadata |
542 scheduler_->GetAboutResource( | 541 scheduler_->GetAboutResource( |
(...skipping 24 matching lines...) Expand all Loading... |
567 TEST_F(JobSchedulerTest, DownloadFileWimaxDisabled) { | 566 TEST_F(JobSchedulerTest, DownloadFileWimaxDisabled) { |
568 ConnectToWimax(); | 567 ConnectToWimax(); |
569 | 568 |
570 // Disable fetching over cellular network. | 569 // Disable fetching over cellular network. |
571 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, true); | 570 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, true); |
572 | 571 |
573 // Try to get a file in the background | 572 // Try to get a file in the background |
574 base::ScopedTempDir temp_dir; | 573 base::ScopedTempDir temp_dir; |
575 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 574 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
576 | 575 |
577 const GURL kContentUrl("https://file_content_url/"); | |
578 const base::FilePath kOutputFilePath = | 576 const base::FilePath kOutputFilePath = |
579 temp_dir.path().AppendASCII("whatever.txt"); | 577 temp_dir.path().AppendASCII("whatever.txt"); |
580 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; | 578 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; |
581 base::FilePath output_file_path; | 579 base::FilePath output_file_path; |
582 scheduler_->DownloadFile( | 580 scheduler_->DownloadFile( |
583 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path | 581 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path |
584 kOutputFilePath, | 582 kOutputFilePath, |
585 kContentUrl, | 583 "file:2_file_resource_id", |
586 ClientContext(BACKGROUND), | 584 ClientContext(BACKGROUND), |
587 google_apis::test_util::CreateCopyResultCallback( | 585 google_apis::test_util::CreateCopyResultCallback( |
588 &download_error, &output_file_path), | 586 &download_error, &output_file_path), |
589 google_apis::GetContentCallback()); | 587 google_apis::GetContentCallback()); |
590 // Metadata should still work | 588 // Metadata should still work |
591 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; | 589 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; |
592 scoped_ptr<google_apis::AboutResource> about_resource; | 590 scoped_ptr<google_apis::AboutResource> about_resource; |
593 | 591 |
594 // Try to get the metadata | 592 // Try to get the metadata |
595 scheduler_->GetAboutResource( | 593 scheduler_->GetAboutResource( |
(...skipping 24 matching lines...) Expand all Loading... |
620 TEST_F(JobSchedulerTest, DownloadFileCellularEnabled) { | 618 TEST_F(JobSchedulerTest, DownloadFileCellularEnabled) { |
621 ConnectToCellular(); | 619 ConnectToCellular(); |
622 | 620 |
623 // Enable fetching over cellular network. | 621 // Enable fetching over cellular network. |
624 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, false); | 622 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, false); |
625 | 623 |
626 // Try to get a file in the background | 624 // Try to get a file in the background |
627 base::ScopedTempDir temp_dir; | 625 base::ScopedTempDir temp_dir; |
628 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 626 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
629 | 627 |
630 const GURL kContentUrl("https://file_content_url/"); | |
631 const base::FilePath kOutputFilePath = | 628 const base::FilePath kOutputFilePath = |
632 temp_dir.path().AppendASCII("whatever.txt"); | 629 temp_dir.path().AppendASCII("whatever.txt"); |
633 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; | 630 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; |
634 base::FilePath output_file_path; | 631 base::FilePath output_file_path; |
635 scheduler_->DownloadFile( | 632 scheduler_->DownloadFile( |
636 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path | 633 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path |
637 kOutputFilePath, | 634 kOutputFilePath, |
638 kContentUrl, | 635 "file:2_file_resource_id", |
639 ClientContext(BACKGROUND), | 636 ClientContext(BACKGROUND), |
640 google_apis::test_util::CreateCopyResultCallback( | 637 google_apis::test_util::CreateCopyResultCallback( |
641 &download_error, &output_file_path), | 638 &download_error, &output_file_path), |
642 google_apis::GetContentCallback()); | 639 google_apis::GetContentCallback()); |
643 // Metadata should still work | 640 // Metadata should still work |
644 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; | 641 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; |
645 scoped_ptr<google_apis::AboutResource> about_resource; | 642 scoped_ptr<google_apis::AboutResource> about_resource; |
646 | 643 |
647 // Try to get the metadata | 644 // Try to get the metadata |
648 scheduler_->GetAboutResource( | 645 scheduler_->GetAboutResource( |
(...skipping 16 matching lines...) Expand all Loading... |
665 TEST_F(JobSchedulerTest, DownloadFileWimaxEnabled) { | 662 TEST_F(JobSchedulerTest, DownloadFileWimaxEnabled) { |
666 ConnectToWimax(); | 663 ConnectToWimax(); |
667 | 664 |
668 // Enable fetching over cellular network. | 665 // Enable fetching over cellular network. |
669 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, false); | 666 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, false); |
670 | 667 |
671 // Try to get a file in the background | 668 // Try to get a file in the background |
672 base::ScopedTempDir temp_dir; | 669 base::ScopedTempDir temp_dir; |
673 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 670 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
674 | 671 |
675 const GURL kContentUrl("https://file_content_url/"); | |
676 const base::FilePath kOutputFilePath = | 672 const base::FilePath kOutputFilePath = |
677 temp_dir.path().AppendASCII("whatever.txt"); | 673 temp_dir.path().AppendASCII("whatever.txt"); |
678 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; | 674 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; |
679 base::FilePath output_file_path; | 675 base::FilePath output_file_path; |
680 scheduler_->DownloadFile( | 676 scheduler_->DownloadFile( |
681 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path | 677 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path |
682 kOutputFilePath, | 678 kOutputFilePath, |
683 kContentUrl, | 679 "file:2_file_resource_id", |
684 ClientContext(BACKGROUND), | 680 ClientContext(BACKGROUND), |
685 google_apis::test_util::CreateCopyResultCallback( | 681 google_apis::test_util::CreateCopyResultCallback( |
686 &download_error, &output_file_path), | 682 &download_error, &output_file_path), |
687 google_apis::GetContentCallback()); | 683 google_apis::GetContentCallback()); |
688 // Metadata should still work | 684 // Metadata should still work |
689 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; | 685 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; |
690 scoped_ptr<google_apis::AboutResource> about_resource; | 686 scoped_ptr<google_apis::AboutResource> about_resource; |
691 | 687 |
692 // Try to get the metadata | 688 // Try to get the metadata |
693 scheduler_->GetAboutResource( | 689 scheduler_->GetAboutResource( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 &error, &about_resource)); | 733 &error, &about_resource)); |
738 expected_types.insert(TYPE_RENAME_RESOURCE); | 734 expected_types.insert(TYPE_RENAME_RESOURCE); |
739 scheduler_->RenameResource( | 735 scheduler_->RenameResource( |
740 "file:2_file_resource_id", | 736 "file:2_file_resource_id", |
741 "New Name", | 737 "New Name", |
742 google_apis::test_util::CreateCopyResultCallback(&error)); | 738 google_apis::test_util::CreateCopyResultCallback(&error)); |
743 expected_types.insert(TYPE_DOWNLOAD_FILE); | 739 expected_types.insert(TYPE_DOWNLOAD_FILE); |
744 scheduler_->DownloadFile( | 740 scheduler_->DownloadFile( |
745 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path | 741 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path |
746 temp_dir.path().AppendASCII("whatever.txt"), | 742 temp_dir.path().AppendASCII("whatever.txt"), |
747 GURL("https://file_content_url/"), | 743 "file:2_file_resource_id", |
748 ClientContext(BACKGROUND), | 744 ClientContext(BACKGROUND), |
749 google_apis::test_util::CreateCopyResultCallback(&error, &path), | 745 google_apis::test_util::CreateCopyResultCallback(&error, &path), |
750 google_apis::GetContentCallback()); | 746 google_apis::GetContentCallback()); |
751 | 747 |
752 // The number of jobs queued so far. | 748 // The number of jobs queued so far. |
753 EXPECT_EQ(4U, scheduler_->GetJobInfoList().size()); | 749 EXPECT_EQ(4U, scheduler_->GetJobInfoList().size()); |
754 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_ADD_NEW_DIRECTORY)); | 750 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_ADD_NEW_DIRECTORY)); |
755 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_GET_ABOUT_RESOURCE)); | 751 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_GET_ABOUT_RESOURCE)); |
756 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_RENAME_RESOURCE)); | 752 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_RENAME_RESOURCE)); |
757 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_DOWNLOAD_FILE)); | 753 EXPECT_TRUE(logger.Has(JobListLogger::ADDED, TYPE_DOWNLOAD_FILE)); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 base::ScopedTempDir temp_dir; | 828 base::ScopedTempDir temp_dir; |
833 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 829 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
834 | 830 |
835 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 831 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
836 base::FilePath path; | 832 base::FilePath path; |
837 | 833 |
838 // Download job. | 834 // Download job. |
839 scheduler_->DownloadFile( | 835 scheduler_->DownloadFile( |
840 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path | 836 base::FilePath::FromUTF8Unsafe("drive/whatever.txt"), // virtual path |
841 temp_dir.path().AppendASCII("whatever.txt"), | 837 temp_dir.path().AppendASCII("whatever.txt"), |
842 GURL("https://file_content_url/"), | 838 "file:2_file_resource_id", |
843 ClientContext(BACKGROUND), | 839 ClientContext(BACKGROUND), |
844 google_apis::test_util::CreateCopyResultCallback(&error, &path), | 840 google_apis::test_util::CreateCopyResultCallback(&error, &path), |
845 google_apis::GetContentCallback()); | 841 google_apis::GetContentCallback()); |
846 base::RunLoop().RunUntilIdle(); | 842 base::RunLoop().RunUntilIdle(); |
847 | 843 |
848 std::vector<int64> download_progress; | 844 std::vector<int64> download_progress; |
849 logger.GetProgressInfo(TYPE_DOWNLOAD_FILE, &download_progress); | 845 logger.GetProgressInfo(TYPE_DOWNLOAD_FILE, &download_progress); |
850 ASSERT_TRUE(!download_progress.empty()); | 846 ASSERT_TRUE(!download_progress.empty()); |
851 EXPECT_TRUE(base::STLIsSorted(download_progress)); | 847 EXPECT_TRUE(base::STLIsSorted(download_progress)); |
852 EXPECT_GE(download_progress.front(), 0); | 848 EXPECT_GE(download_progress.front(), 0); |
(...skipping 18 matching lines...) Expand all Loading... |
871 | 867 |
872 std::vector<int64> upload_progress; | 868 std::vector<int64> upload_progress; |
873 logger.GetProgressInfo(TYPE_UPLOAD_NEW_FILE, &upload_progress); | 869 logger.GetProgressInfo(TYPE_UPLOAD_NEW_FILE, &upload_progress); |
874 ASSERT_TRUE(!upload_progress.empty()); | 870 ASSERT_TRUE(!upload_progress.empty()); |
875 EXPECT_TRUE(base::STLIsSorted(upload_progress)); | 871 EXPECT_TRUE(base::STLIsSorted(upload_progress)); |
876 EXPECT_GE(upload_progress.front(), 0); | 872 EXPECT_GE(upload_progress.front(), 0); |
877 EXPECT_LE(upload_progress.back(), 13); | 873 EXPECT_LE(upload_progress.back(), 13); |
878 } | 874 } |
879 | 875 |
880 } // namespace drive | 876 } // namespace drive |
OLD | NEW |