| 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/drive_scheduler.h" | 5 #include "chrome/browser/chromeos/drive/drive_scheduler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 ConnectToCellular(); | 396 ConnectToCellular(); |
| 397 | 397 |
| 398 // Disable fetching over cellular network. | 398 // Disable fetching over cellular network. |
| 399 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, true); | 399 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, true); |
| 400 | 400 |
| 401 // Try to get a file in the background | 401 // Try to get a file in the background |
| 402 base::ScopedTempDir temp_dir; | 402 base::ScopedTempDir temp_dir; |
| 403 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 403 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 404 | 404 |
| 405 const GURL kContentUrl("https://file_content_url/"); | 405 const GURL kContentUrl("https://file_content_url/"); |
| 406 const FilePath kOutputFilePath = temp_dir.path().AppendASCII("whatever.txt"); | 406 const base::FilePath kOutputFilePath = |
| 407 temp_dir.path().AppendASCII("whatever.txt"); |
| 407 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; | 408 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; |
| 408 FilePath output_file_path; | 409 base::FilePath output_file_path; |
| 409 scheduler_->DownloadFile( | 410 scheduler_->DownloadFile( |
| 410 FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path | 411 base::FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path |
| 411 kOutputFilePath, | 412 kOutputFilePath, |
| 412 kContentUrl, | 413 kContentUrl, |
| 413 DriveClientContext(BACKGROUND), | 414 DriveClientContext(BACKGROUND), |
| 414 base::Bind(&google_apis::test_util::CopyResultsFromDownloadActionCallback, | 415 base::Bind(&google_apis::test_util::CopyResultsFromDownloadActionCallback, |
| 415 &download_error, | 416 &download_error, |
| 416 &output_file_path), | 417 &output_file_path), |
| 417 google_apis::GetContentCallback()); | 418 google_apis::GetContentCallback()); |
| 418 // Metadata should still work | 419 // Metadata should still work |
| 419 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; | 420 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; |
| 420 scoped_ptr<google_apis::AccountMetadataFeed> account_metadata; | 421 scoped_ptr<google_apis::AccountMetadataFeed> account_metadata; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 ConnectToWimax(); | 454 ConnectToWimax(); |
| 454 | 455 |
| 455 // Disable fetching over cellular network. | 456 // Disable fetching over cellular network. |
| 456 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, true); | 457 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, true); |
| 457 | 458 |
| 458 // Try to get a file in the background | 459 // Try to get a file in the background |
| 459 base::ScopedTempDir temp_dir; | 460 base::ScopedTempDir temp_dir; |
| 460 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 461 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 461 | 462 |
| 462 const GURL kContentUrl("https://file_content_url/"); | 463 const GURL kContentUrl("https://file_content_url/"); |
| 463 const FilePath kOutputFilePath = temp_dir.path().AppendASCII("whatever.txt"); | 464 const base::FilePath kOutputFilePath = |
| 465 temp_dir.path().AppendASCII("whatever.txt"); |
| 464 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; | 466 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; |
| 465 FilePath output_file_path; | 467 base::FilePath output_file_path; |
| 466 scheduler_->DownloadFile( | 468 scheduler_->DownloadFile( |
| 467 FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path | 469 base::FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path |
| 468 kOutputFilePath, | 470 kOutputFilePath, |
| 469 kContentUrl, | 471 kContentUrl, |
| 470 DriveClientContext(BACKGROUND), | 472 DriveClientContext(BACKGROUND), |
| 471 base::Bind(&google_apis::test_util::CopyResultsFromDownloadActionCallback, | 473 base::Bind(&google_apis::test_util::CopyResultsFromDownloadActionCallback, |
| 472 &download_error, | 474 &download_error, |
| 473 &output_file_path), | 475 &output_file_path), |
| 474 google_apis::GetContentCallback()); | 476 google_apis::GetContentCallback()); |
| 475 // Metadata should still work | 477 // Metadata should still work |
| 476 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; | 478 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; |
| 477 scoped_ptr<google_apis::AccountMetadataFeed> account_metadata; | 479 scoped_ptr<google_apis::AccountMetadataFeed> account_metadata; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 ConnectToCellular(); | 512 ConnectToCellular(); |
| 511 | 513 |
| 512 // Enable fetching over cellular network. | 514 // Enable fetching over cellular network. |
| 513 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, false); | 515 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, false); |
| 514 | 516 |
| 515 // Try to get a file in the background | 517 // Try to get a file in the background |
| 516 base::ScopedTempDir temp_dir; | 518 base::ScopedTempDir temp_dir; |
| 517 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 519 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 518 | 520 |
| 519 const GURL kContentUrl("https://file_content_url/"); | 521 const GURL kContentUrl("https://file_content_url/"); |
| 520 const FilePath kOutputFilePath = temp_dir.path().AppendASCII("whatever.txt"); | 522 const base::FilePath kOutputFilePath = |
| 523 temp_dir.path().AppendASCII("whatever.txt"); |
| 521 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; | 524 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; |
| 522 FilePath output_file_path; | 525 base::FilePath output_file_path; |
| 523 scheduler_->DownloadFile( | 526 scheduler_->DownloadFile( |
| 524 FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path | 527 base::FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path |
| 525 kOutputFilePath, | 528 kOutputFilePath, |
| 526 kContentUrl, | 529 kContentUrl, |
| 527 DriveClientContext(BACKGROUND), | 530 DriveClientContext(BACKGROUND), |
| 528 base::Bind(&google_apis::test_util::CopyResultsFromDownloadActionCallback, | 531 base::Bind(&google_apis::test_util::CopyResultsFromDownloadActionCallback, |
| 529 &download_error, | 532 &download_error, |
| 530 &output_file_path), | 533 &output_file_path), |
| 531 google_apis::GetContentCallback()); | 534 google_apis::GetContentCallback()); |
| 532 // Metadata should still work | 535 // Metadata should still work |
| 533 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; | 536 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; |
| 534 scoped_ptr<google_apis::AccountMetadataFeed> account_metadata; | 537 scoped_ptr<google_apis::AccountMetadataFeed> account_metadata; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 559 ConnectToWimax(); | 562 ConnectToWimax(); |
| 560 | 563 |
| 561 // Enable fetching over cellular network. | 564 // Enable fetching over cellular network. |
| 562 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, false); | 565 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, false); |
| 563 | 566 |
| 564 // Try to get a file in the background | 567 // Try to get a file in the background |
| 565 base::ScopedTempDir temp_dir; | 568 base::ScopedTempDir temp_dir; |
| 566 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 569 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 567 | 570 |
| 568 const GURL kContentUrl("https://file_content_url/"); | 571 const GURL kContentUrl("https://file_content_url/"); |
| 569 const FilePath kOutputFilePath = temp_dir.path().AppendASCII("whatever.txt"); | 572 const base::FilePath kOutputFilePath = |
| 573 temp_dir.path().AppendASCII("whatever.txt"); |
| 570 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; | 574 google_apis::GDataErrorCode download_error = google_apis::GDATA_OTHER_ERROR; |
| 571 FilePath output_file_path; | 575 base::FilePath output_file_path; |
| 572 scheduler_->DownloadFile( | 576 scheduler_->DownloadFile( |
| 573 FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path | 577 base::FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path |
| 574 kOutputFilePath, | 578 kOutputFilePath, |
| 575 kContentUrl, | 579 kContentUrl, |
| 576 DriveClientContext(BACKGROUND), | 580 DriveClientContext(BACKGROUND), |
| 577 base::Bind(&google_apis::test_util::CopyResultsFromDownloadActionCallback, | 581 base::Bind(&google_apis::test_util::CopyResultsFromDownloadActionCallback, |
| 578 &download_error, | 582 &download_error, |
| 579 &output_file_path), | 583 &output_file_path), |
| 580 google_apis::GetContentCallback()); | 584 google_apis::GetContentCallback()); |
| 581 // Metadata should still work | 585 // Metadata should still work |
| 582 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; | 586 google_apis::GDataErrorCode metadata_error = google_apis::GDATA_OTHER_ERROR; |
| 583 scoped_ptr<google_apis::AccountMetadataFeed> account_metadata; | 587 scoped_ptr<google_apis::AccountMetadataFeed> account_metadata; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 598 // Check the download | 602 // Check the download |
| 599 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error); | 603 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error); |
| 600 std::string content; | 604 std::string content; |
| 601 EXPECT_EQ(output_file_path, kOutputFilePath); | 605 EXPECT_EQ(output_file_path, kOutputFilePath); |
| 602 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content)); | 606 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content)); |
| 603 // The content is "x"s of the file size specified in root_feed.json. | 607 // The content is "x"s of the file size specified in root_feed.json. |
| 604 EXPECT_EQ("xxxxxxxxxx", content); | 608 EXPECT_EQ("xxxxxxxxxx", content); |
| 605 } | 609 } |
| 606 | 610 |
| 607 } // namespace drive | 611 } // namespace drive |
| OLD | NEW |