OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/download_handler.h" | 5 #include "chrome/browser/chromeos/drive/download_handler.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 // various responses from FileSystem. | 27 // various responses from FileSystem. |
28 class DownloadHandlerTestFileSystem : public DummyFileSystem { | 28 class DownloadHandlerTestFileSystem : public DummyFileSystem { |
29 public: | 29 public: |
30 DownloadHandlerTestFileSystem() : error_(FILE_ERROR_FAILED) {} | 30 DownloadHandlerTestFileSystem() : error_(FILE_ERROR_FAILED) {} |
31 | 31 |
32 void set_error(FileError error) { error_ = error; } | 32 void set_error(FileError error) { error_ = error; } |
33 | 33 |
34 // FileSystemInterface overrides. | 34 // FileSystemInterface overrides. |
35 void GetResourceEntry(const base::FilePath& file_path, | 35 void GetResourceEntry(const base::FilePath& file_path, |
36 const GetResourceEntryCallback& callback) override { | 36 const GetResourceEntryCallback& callback) override { |
37 callback.Run(error_, scoped_ptr<ResourceEntry>( | 37 callback.Run(error_, std::unique_ptr<ResourceEntry>(error_ == FILE_ERROR_OK |
38 error_ == FILE_ERROR_OK ? new ResourceEntry : NULL)); | 38 ? new ResourceEntry |
| 39 : NULL)); |
39 } | 40 } |
40 | 41 |
41 void CreateDirectory(const base::FilePath& directory_path, | 42 void CreateDirectory(const base::FilePath& directory_path, |
42 bool is_exclusive, | 43 bool is_exclusive, |
43 bool is_recursive, | 44 bool is_recursive, |
44 const FileOperationCallback& callback) override { | 45 const FileOperationCallback& callback) override { |
45 callback.Run(error_); | 46 callback.Run(error_); |
46 } | 47 } |
47 | 48 |
48 void FreeDiskSpaceIfNeededFor( | 49 void FreeDiskSpaceIfNeededFor( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 download_handler_.reset(new DownloadHandler(&test_file_system_)); | 101 download_handler_.reset(new DownloadHandler(&test_file_system_)); |
101 download_handler_->Initialize(download_manager_.get(), temp_dir_.path()); | 102 download_handler_->Initialize(download_manager_.get(), temp_dir_.path()); |
102 download_handler_->SetFreeDiskSpaceDelayForTesting( | 103 download_handler_->SetFreeDiskSpaceDelayForTesting( |
103 base::TimeDelta::FromMilliseconds(0)); | 104 base::TimeDelta::FromMilliseconds(0)); |
104 } | 105 } |
105 | 106 |
106 protected: | 107 protected: |
107 base::ScopedTempDir temp_dir_; | 108 base::ScopedTempDir temp_dir_; |
108 content::TestBrowserThreadBundle thread_bundle_; | 109 content::TestBrowserThreadBundle thread_bundle_; |
109 TestingProfile profile_; | 110 TestingProfile profile_; |
110 scoped_ptr<DownloadHandlerTestDownloadManager> download_manager_; | 111 std::unique_ptr<DownloadHandlerTestDownloadManager> download_manager_; |
111 scoped_ptr<DownloadHandlerTestDownloadManager> incognito_download_manager_; | 112 std::unique_ptr<DownloadHandlerTestDownloadManager> |
| 113 incognito_download_manager_; |
112 DownloadHandlerTestFileSystem test_file_system_; | 114 DownloadHandlerTestFileSystem test_file_system_; |
113 scoped_ptr<DownloadHandler> download_handler_; | 115 std::unique_ptr<DownloadHandler> download_handler_; |
114 content::MockDownloadItem download_item_; | 116 content::MockDownloadItem download_item_; |
115 }; | 117 }; |
116 | 118 |
117 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPathNonDrivePath) { | 119 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPathNonDrivePath) { |
118 const base::FilePath non_drive_path(FILE_PATH_LITERAL("/foo/bar")); | 120 const base::FilePath non_drive_path(FILE_PATH_LITERAL("/foo/bar")); |
119 ASSERT_FALSE(util::IsUnderDriveMountPoint(non_drive_path)); | 121 ASSERT_FALSE(util::IsUnderDriveMountPoint(non_drive_path)); |
120 | 122 |
121 // Call SubstituteDriveDownloadPath() | 123 // Call SubstituteDriveDownloadPath() |
122 base::FilePath substituted_path; | 124 base::FilePath substituted_path; |
123 download_handler_->SubstituteDriveDownloadPath( | 125 download_handler_->SubstituteDriveDownloadPath( |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 download_item_d.is_done_ = false; | 348 download_item_d.is_done_ = false; |
347 download_item_d.total_bytes_ = 0; | 349 download_item_d.total_bytes_ = 0; |
348 downloads.push_back(&download_item_d); | 350 downloads.push_back(&download_item_d); |
349 | 351 |
350 // Unknown size downloads should be counted as 0 byte. | 352 // Unknown size downloads should be counted as 0 byte. |
351 ASSERT_EQ(download_item_a.total_bytes_ - download_item_a.received_bytes_, | 353 ASSERT_EQ(download_item_a.total_bytes_ - download_item_a.received_bytes_, |
352 download_handler_->CalculateRequestSpace(downloads)); | 354 download_handler_->CalculateRequestSpace(downloads)); |
353 } | 355 } |
354 | 356 |
355 } // namespace drive | 357 } // namespace drive |
OLD | NEW |