| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 bool calculate_hash, | 97 bool calculate_hash, |
| 98 const net::BoundNetLog& bound_net_log) { | 98 const net::BoundNetLog& bound_net_log) { |
| 99 NOTREACHED(); | 99 NOTREACHED(); |
| 100 return NULL; | 100 return NULL; |
| 101 } | 101 } |
| 102 | 102 |
| 103 DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain"; | 103 DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain"; |
| 104 | 104 |
| 105 class TestDownloadManagerDelegate : public content::DownloadManagerDelegate { | 105 class TestDownloadManagerDelegate : public content::DownloadManagerDelegate { |
| 106 public: | 106 public: |
| 107 TestDownloadManagerDelegate() | 107 explicit TestDownloadManagerDelegate(content::DownloadManager* dm) |
| 108 : mark_content_dangerous_(false), | 108 : mark_content_dangerous_(false), |
| 109 prompt_user_for_save_location_(false), | 109 prompt_user_for_save_location_(false), |
| 110 should_complete_download_(true), | 110 should_complete_download_(true), |
| 111 download_manager_(NULL) { | 111 download_manager_(dm) { |
| 112 } | 112 } |
| 113 | 113 |
| 114 void set_download_directory(const FilePath& path) { | 114 void set_download_directory(const FilePath& path) { |
| 115 download_directory_ = path; | 115 download_directory_ = path; |
| 116 } | 116 } |
| 117 | 117 |
| 118 void set_download_manager(content::DownloadManager* dm) { | |
| 119 download_manager_ = dm; | |
| 120 } | |
| 121 | |
| 122 void set_prompt_user_for_save_location(bool value) { | 118 void set_prompt_user_for_save_location(bool value) { |
| 123 prompt_user_for_save_location_ = value; | 119 prompt_user_for_save_location_ = value; |
| 124 } | 120 } |
| 125 | 121 |
| 126 virtual bool ShouldStartDownload(int32 download_id) OVERRIDE { | 122 virtual bool ShouldStartDownload(int32 download_id) OVERRIDE { |
| 127 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); | 123 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); |
| 128 FilePath path = net::GenerateFileName(item->GetURL(), | 124 FilePath path = net::GenerateFileName(item->GetURL(), |
| 129 item->GetContentDisposition(), | 125 item->GetContentDisposition(), |
| 130 item->GetReferrerCharset(), | 126 item->GetReferrerCharset(), |
| 131 item->GetSuggestedFilename(), | 127 item->GetSuggestedFilename(), |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 251 |
| 256 } // namespace | 252 } // namespace |
| 257 | 253 |
| 258 class DownloadManagerTest : public testing::Test { | 254 class DownloadManagerTest : public testing::Test { |
| 259 public: | 255 public: |
| 260 static const char* kTestData; | 256 static const char* kTestData; |
| 261 static const size_t kTestDataLen; | 257 static const size_t kTestDataLen; |
| 262 | 258 |
| 263 DownloadManagerTest() | 259 DownloadManagerTest() |
| 264 : browser_context(new content::TestBrowserContext()), | 260 : browser_context(new content::TestBrowserContext()), |
| 265 download_manager_delegate_(new TestDownloadManagerDelegate()), | 261 download_manager_(new DownloadManagerImpl(NULL)), |
| 266 download_manager_(new DownloadManagerImpl( | |
| 267 download_manager_delegate_.get(), NULL)), | |
| 268 ui_thread_(BrowserThread::UI, &message_loop_), | 262 ui_thread_(BrowserThread::UI, &message_loop_), |
| 269 file_thread_(BrowserThread::FILE, &message_loop_) { | 263 file_thread_(BrowserThread::FILE, &message_loop_) { |
| 264 download_manager_delegate_.reset( |
| 265 new TestDownloadManagerDelegate(download_manager_.get())); |
| 266 download_manager_->SetDelegate(download_manager_delegate_.get()); |
| 270 download_manager_->Init(browser_context.get()); | 267 download_manager_->Init(browser_context.get()); |
| 271 download_manager_delegate_->set_download_manager(download_manager_); | |
| 272 } | 268 } |
| 273 | 269 |
| 274 ~DownloadManagerTest() { | 270 ~DownloadManagerTest() { |
| 275 download_manager_->Shutdown(); | 271 download_manager_->Shutdown(); |
| 276 // browser_context must outlive download_manager_, so we explicitly delete | 272 // browser_context must outlive download_manager_, so we explicitly delete |
| 277 // download_manager_ first. | 273 // download_manager_ first. |
| 278 download_manager_ = NULL; | 274 download_manager_ = NULL; |
| 279 download_manager_delegate_.reset(); | 275 download_manager_delegate_.reset(); |
| 280 browser_context.reset(NULL); | 276 browser_context.reset(NULL); |
| 281 message_loop_.RunAllPending(); | 277 message_loop_.RunAllPending(); |
| (...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1274 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); | 1270 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); |
| 1275 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); | 1271 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); |
| 1276 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 1272 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 1277 EXPECT_TRUE(observer->was_updated()); | 1273 EXPECT_TRUE(observer->was_updated()); |
| 1278 EXPECT_FALSE(observer->was_opened()); | 1274 EXPECT_FALSE(observer->was_opened()); |
| 1279 EXPECT_TRUE(download->GetFileExternallyRemoved()); | 1275 EXPECT_TRUE(download->GetFileExternallyRemoved()); |
| 1280 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); | 1276 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); |
| 1281 | 1277 |
| 1282 EXPECT_FALSE(file_util::PathExists(new_path)); | 1278 EXPECT_FALSE(file_util::PathExists(new_path)); |
| 1283 } | 1279 } |
| OLD | NEW |