| 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 FilePath GetTempDownloadPath(const FilePath& suggested_path) { | 68 FilePath GetTempDownloadPath(const FilePath& suggested_path) { |
| 69 return FilePath(suggested_path.value() + FILE_PATH_LITERAL(".temp")); | 69 return FilePath(suggested_path.value() + FILE_PATH_LITERAL(".temp")); |
| 70 } | 70 } |
| 71 | 71 |
| 72 class MockDownloadFileFactory | 72 class MockDownloadFileFactory |
| 73 : public DownloadFileManager::DownloadFileFactory { | 73 : public DownloadFileManager::DownloadFileFactory { |
| 74 public: | 74 public: |
| 75 MockDownloadFileFactory() {} | 75 MockDownloadFileFactory() {} |
| 76 | 76 |
| 77 virtual DownloadFile* CreateFile(DownloadCreateInfo* info, | 77 virtual DownloadFile* CreateFile( |
| 78 const DownloadRequestHandle& request_handle, | 78 DownloadCreateInfo* info, |
| 79 DownloadManager* download_manager, | 79 const DownloadRequestHandle& request_handle, |
| 80 bool calculate_hash) OVERRIDE; | 80 DownloadManager* download_manager, |
| 81 bool calculate_hash, |
| 82 const net::BoundNetLog& bound_net_log) OVERRIDE; |
| 81 }; | 83 }; |
| 82 | 84 |
| 83 DownloadFile* MockDownloadFileFactory::CreateFile( | 85 DownloadFile* MockDownloadFileFactory::CreateFile( |
| 84 DownloadCreateInfo* info, | 86 DownloadCreateInfo* info, |
| 85 const DownloadRequestHandle& request_handle, | 87 const DownloadRequestHandle& request_handle, |
| 86 DownloadManager* download_manager, | 88 DownloadManager* download_manager, |
| 87 bool calculate_hash) { | 89 bool calculate_hash, |
| 90 const net::BoundNetLog& bound_net_log) { |
| 88 NOTREACHED(); | 91 NOTREACHED(); |
| 89 return NULL; | 92 return NULL; |
| 90 } | 93 } |
| 91 | 94 |
| 92 DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain"; | 95 DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain"; |
| 93 | 96 |
| 94 class TestDownloadManagerDelegate : public content::DownloadManagerDelegate { | 97 class TestDownloadManagerDelegate : public content::DownloadManagerDelegate { |
| 95 public: | 98 public: |
| 96 TestDownloadManagerDelegate() | 99 TestDownloadManagerDelegate() |
| 97 : mark_content_dangerous_(false), | 100 : mark_content_dangerous_(false), |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 207 |
| 205 class DownloadManagerTest : public testing::Test { | 208 class DownloadManagerTest : public testing::Test { |
| 206 public: | 209 public: |
| 207 static const char* kTestData; | 210 static const char* kTestData; |
| 208 static const size_t kTestDataLen; | 211 static const size_t kTestDataLen; |
| 209 | 212 |
| 210 DownloadManagerTest() | 213 DownloadManagerTest() |
| 211 : browser_context(new TestBrowserContext()), | 214 : browser_context(new TestBrowserContext()), |
| 212 download_manager_delegate_(new TestDownloadManagerDelegate()), | 215 download_manager_delegate_(new TestDownloadManagerDelegate()), |
| 213 download_manager_(DownloadManager::Create( | 216 download_manager_(DownloadManager::Create( |
| 214 download_manager_delegate_.get())), | 217 download_manager_delegate_.get(), NULL)), |
| 215 ui_thread_(BrowserThread::UI, &message_loop_), | 218 ui_thread_(BrowserThread::UI, &message_loop_), |
| 216 file_thread_(BrowserThread::FILE, &message_loop_), | 219 file_thread_(BrowserThread::FILE, &message_loop_), |
| 217 download_buffer_(new content::DownloadBuffer) { | 220 download_buffer_(new content::DownloadBuffer) { |
| 218 download_manager_->Init(browser_context.get()); | 221 download_manager_->Init(browser_context.get()); |
| 219 download_manager_delegate_->set_download_manager(download_manager_); | 222 download_manager_delegate_->set_download_manager(download_manager_); |
| 220 } | 223 } |
| 221 | 224 |
| 222 ~DownloadManagerTest() { | 225 ~DownloadManagerTest() { |
| 223 download_manager_->Shutdown(); | 226 download_manager_->Shutdown(); |
| 224 // browser_context must outlive download_manager_, so we explicitly delete | 227 // browser_context must outlive download_manager_, so we explicitly delete |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 341 |
| 339 net::Error forced_error_; | 342 net::Error forced_error_; |
| 340 }; | 343 }; |
| 341 | 344 |
| 342 DownloadFileWithErrors::DownloadFileWithErrors(DownloadCreateInfo* info, | 345 DownloadFileWithErrors::DownloadFileWithErrors(DownloadCreateInfo* info, |
| 343 DownloadManager* manager, | 346 DownloadManager* manager, |
| 344 bool calculate_hash) | 347 bool calculate_hash) |
| 345 : DownloadFileImpl(info, | 348 : DownloadFileImpl(info, |
| 346 new DownloadRequestHandle(), | 349 new DownloadRequestHandle(), |
| 347 manager, | 350 manager, |
| 348 calculate_hash), | 351 calculate_hash, |
| 352 net::BoundNetLog()), |
| 349 forced_error_(net::OK) { | 353 forced_error_(net::OK) { |
| 350 } | 354 } |
| 351 | 355 |
| 352 net::Error DownloadFileWithErrors::Initialize() { | 356 net::Error DownloadFileWithErrors::Initialize() { |
| 353 return ReturnError(DownloadFileImpl::Initialize()); | 357 return ReturnError(DownloadFileImpl::Initialize()); |
| 354 } | 358 } |
| 355 | 359 |
| 356 net::Error DownloadFileWithErrors::AppendDataToFile(const char* data, | 360 net::Error DownloadFileWithErrors::AppendDataToFile(const char* data, |
| 357 size_t data_len) { | 361 size_t data_len) { |
| 358 return ReturnError(DownloadFileImpl::AppendDataToFile(data, data_len)); | 362 return ReturnError(DownloadFileImpl::AppendDataToFile(data, data_len)); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); | 532 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); |
| 529 const DownloadId id = DownloadId(kValidIdDomain, static_cast<int>(i)); | 533 const DownloadId id = DownloadId(kValidIdDomain, static_cast<int>(i)); |
| 530 info->download_id = id; | 534 info->download_id = id; |
| 531 info->prompt_user_for_save_location = kStartDownloadCases[i].save_as; | 535 info->prompt_user_for_save_location = kStartDownloadCases[i].save_as; |
| 532 info->url_chain.push_back(GURL(kStartDownloadCases[i].url)); | 536 info->url_chain.push_back(GURL(kStartDownloadCases[i].url)); |
| 533 info->mime_type = kStartDownloadCases[i].mime_type; | 537 info->mime_type = kStartDownloadCases[i].mime_type; |
| 534 download_manager_->CreateDownloadItem(info.get(), DownloadRequestHandle()); | 538 download_manager_->CreateDownloadItem(info.get(), DownloadRequestHandle()); |
| 535 | 539 |
| 536 DownloadFile* download_file( | 540 DownloadFile* download_file( |
| 537 new DownloadFileImpl(info.get(), new DownloadRequestHandle(), | 541 new DownloadFileImpl(info.get(), new DownloadRequestHandle(), |
| 538 download_manager_, false)); | 542 download_manager_, false, net::BoundNetLog())); |
| 539 AddDownloadToFileManager(info->download_id.local(), download_file); | 543 AddDownloadToFileManager(info->download_id.local(), download_file); |
| 540 download_file->Initialize(); | 544 download_file->Initialize(); |
| 541 download_manager_->StartDownload(info->download_id.local()); | 545 download_manager_->StartDownload(info->download_id.local()); |
| 542 message_loop_.RunAllPending(); | 546 message_loop_.RunAllPending(); |
| 543 | 547 |
| 544 // SelectFileObserver will have recorded any attempt to open the | 548 // SelectFileObserver will have recorded any attempt to open the |
| 545 // select file dialog. | 549 // select file dialog. |
| 546 // Note that DownloadManager::FileSelectionCanceled() is never called. | 550 // Note that DownloadManager::FileSelectionCanceled() is never called. |
| 547 EXPECT_EQ(kStartDownloadCases[i].expected_save_as, | 551 EXPECT_EQ(kStartDownloadCases[i].expected_save_as, |
| 548 observer.ShowedFileDialogForId(i)); | 552 observer.ShowedFileDialogForId(i)); |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 | 1183 |
| 1180 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->GetState()); | 1184 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->GetState()); |
| 1181 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); | 1185 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); |
| 1182 | 1186 |
| 1183 // Create and initialize the download file. We're bypassing the first part | 1187 // Create and initialize the download file. We're bypassing the first part |
| 1184 // of the download process and skipping to the part after the final file | 1188 // of the download process and skipping to the part after the final file |
| 1185 // name has been chosen, so we need to initialize the download file | 1189 // name has been chosen, so we need to initialize the download file |
| 1186 // properly. | 1190 // properly. |
| 1187 DownloadFile* download_file( | 1191 DownloadFile* download_file( |
| 1188 new DownloadFileImpl(info.get(), new DownloadRequestHandle(), | 1192 new DownloadFileImpl(info.get(), new DownloadRequestHandle(), |
| 1189 download_manager_, false)); | 1193 download_manager_, false, net::BoundNetLog())); |
| 1190 download_file->Rename(cr_path); | 1194 download_file->Rename(cr_path); |
| 1191 // This creates the .temp version of the file. | 1195 // This creates the .temp version of the file. |
| 1192 download_file->Initialize(); | 1196 download_file->Initialize(); |
| 1193 // |download_file| is owned by DownloadFileManager. | 1197 // |download_file| is owned by DownloadFileManager. |
| 1194 AddDownloadToFileManager(info->download_id.local(), download_file); | 1198 AddDownloadToFileManager(info->download_id.local(), download_file); |
| 1195 | 1199 |
| 1196 ContinueDownloadWithPath(download, new_path); | 1200 ContinueDownloadWithPath(download, new_path); |
| 1197 message_loop_.RunAllPending(); | 1201 message_loop_.RunAllPending(); |
| 1198 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | 1202 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
| 1199 | 1203 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1253 | 1257 |
| 1254 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->GetState()); | 1258 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->GetState()); |
| 1255 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); | 1259 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); |
| 1256 | 1260 |
| 1257 // Create and initialize the download file. We're bypassing the first part | 1261 // Create and initialize the download file. We're bypassing the first part |
| 1258 // of the download process and skipping to the part after the final file | 1262 // of the download process and skipping to the part after the final file |
| 1259 // name has been chosen, so we need to initialize the download file | 1263 // name has been chosen, so we need to initialize the download file |
| 1260 // properly. | 1264 // properly. |
| 1261 DownloadFile* download_file( | 1265 DownloadFile* download_file( |
| 1262 new DownloadFileImpl(info.get(), new DownloadRequestHandle(), | 1266 new DownloadFileImpl(info.get(), new DownloadRequestHandle(), |
| 1263 download_manager_, false)); | 1267 download_manager_, false, net::BoundNetLog())); |
| 1264 download_file->Rename(cr_path); | 1268 download_file->Rename(cr_path); |
| 1265 // This creates the .temp version of the file. | 1269 // This creates the .temp version of the file. |
| 1266 download_file->Initialize(); | 1270 download_file->Initialize(); |
| 1267 // |download_file| is owned by DownloadFileManager. | 1271 // |download_file| is owned by DownloadFileManager. |
| 1268 AddDownloadToFileManager(info->download_id.local(), download_file); | 1272 AddDownloadToFileManager(info->download_id.local(), download_file); |
| 1269 | 1273 |
| 1270 ContinueDownloadWithPath(download, new_path); | 1274 ContinueDownloadWithPath(download, new_path); |
| 1271 message_loop_.RunAllPending(); | 1275 message_loop_.RunAllPending(); |
| 1272 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | 1276 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
| 1273 | 1277 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1303 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); | 1307 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); |
| 1304 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); | 1308 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); |
| 1305 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 1309 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 1306 EXPECT_TRUE(observer->was_updated()); | 1310 EXPECT_TRUE(observer->was_updated()); |
| 1307 EXPECT_FALSE(observer->was_opened()); | 1311 EXPECT_FALSE(observer->was_opened()); |
| 1308 EXPECT_TRUE(download->GetFileExternallyRemoved()); | 1312 EXPECT_TRUE(download->GetFileExternallyRemoved()); |
| 1309 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); | 1313 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); |
| 1310 | 1314 |
| 1311 EXPECT_FALSE(file_util::PathExists(new_path)); | 1315 EXPECT_FALSE(file_util::PathExists(new_path)); |
| 1312 } | 1316 } |
| OLD | NEW |