Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/i18n/number_formatting.h" | 10 #include "base/i18n/number_formatting.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 class DownloadManagerTest : public testing::Test { | 50 class DownloadManagerTest : public testing::Test { |
| 51 public: | 51 public: |
| 52 static const char* kTestData; | 52 static const char* kTestData; |
| 53 static const size_t kTestDataLen; | 53 static const size_t kTestDataLen; |
| 54 | 54 |
| 55 DownloadManagerTest() | 55 DownloadManagerTest() |
| 56 : profile_(new TestingProfile()), | 56 : profile_(new TestingProfile()), |
| 57 download_manager_delegate_(new ChromeDownloadManagerDelegate( | 57 download_manager_delegate_(new ChromeDownloadManagerDelegate( |
| 58 profile_.get())), | 58 profile_.get())), |
| 59 id_factory_(new DownloadIdFactory(kValidIdDomain)), | 59 id_factory_(new DownloadIdFactory(kValidIdDomain)), |
| 60 download_manager_(new MockDownloadManager( | 60 download_manager_(new DownloadManagerImpl( |
|
Randy Smith (Not in Mondays)
2011/11/08 22:10:51
Why this change?
ahendrickson
2011/11/09 17:09:02
A) This is a test for DownloadManager.
B) The old
Randy Smith (Not in Mondays)
2011/11/09 19:06:34
Sounds good.
| |
| 61 download_manager_delegate_, | 61 download_manager_delegate_, |
| 62 id_factory_, | 62 id_factory_, |
| 63 &download_status_updater_)), | 63 &download_status_updater_)), |
| 64 ui_thread_(BrowserThread::UI, &message_loop_), | 64 ui_thread_(BrowserThread::UI, &message_loop_), |
| 65 file_thread_(BrowserThread::FILE, &message_loop_), | 65 file_thread_(BrowserThread::FILE, &message_loop_), |
| 66 download_buffer_(new content::DownloadBuffer) { | 66 download_buffer_(new content::DownloadBuffer) { |
| 67 download_manager_->Init(profile_.get()); | 67 download_manager_->Init(profile_.get()); |
| 68 download_manager_delegate_->SetDownloadManager(download_manager_); | 68 download_manager_delegate_->SetDownloadManager(download_manager_); |
| 69 } | 69 } |
| 70 | 70 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 message_loop_.RunAllPending(); | 113 message_loop_.RunAllPending(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void OnDownloadInterrupted(int32 download_id, int64 size, | 116 void OnDownloadInterrupted(int32 download_id, int64 size, |
| 117 InterruptReason reason) { | 117 InterruptReason reason) { |
| 118 download_manager_->OnDownloadInterrupted(download_id, size, reason); | 118 download_manager_->OnDownloadInterrupted(download_id, size, reason); |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Get the download item with ID |id|. | 121 // Get the download item with ID |id|. |
| 122 DownloadItem* GetActiveDownloadItem(int32 id) { | 122 DownloadItem* GetActiveDownloadItem(int32 id) { |
| 123 if (ContainsKey(download_manager_->active_downloads_, id)) | 123 return download_manager_->GetActiveDownload(id); |
| 124 return download_manager_->active_downloads_[id]; | |
| 125 return NULL; | |
| 126 } | 124 } |
| 127 | 125 |
| 128 protected: | 126 protected: |
| 129 DownloadStatusUpdater download_status_updater_; | 127 DownloadStatusUpdater download_status_updater_; |
| 130 scoped_ptr<TestingProfile> profile_; | 128 scoped_ptr<TestingProfile> profile_; |
| 131 scoped_refptr<ChromeDownloadManagerDelegate> download_manager_delegate_; | 129 scoped_refptr<ChromeDownloadManagerDelegate> download_manager_delegate_; |
| 132 scoped_refptr<DownloadIdFactory> id_factory_; | 130 scoped_refptr<DownloadIdFactory> id_factory_; |
| 133 scoped_refptr<DownloadManager> download_manager_; | 131 scoped_refptr<DownloadManager> download_manager_; |
| 134 scoped_refptr<DownloadFileManager> file_manager_; | 132 scoped_refptr<DownloadFileManager> file_manager_; |
| 135 MessageLoopForUI message_loop_; | 133 MessageLoopForUI message_loop_; |
| 136 content::TestBrowserThread ui_thread_; | 134 content::TestBrowserThread ui_thread_; |
| 137 content::TestBrowserThread file_thread_; | 135 content::TestBrowserThread file_thread_; |
| 138 scoped_refptr<content::DownloadBuffer> download_buffer_; | 136 scoped_refptr<content::DownloadBuffer> download_buffer_; |
| 139 | 137 |
| 140 DownloadFileManager* file_manager() { | 138 DownloadFileManager* file_manager() { |
| 141 if (!file_manager_) { | 139 if (!file_manager_) { |
| 142 file_manager_ = new DownloadFileManager(NULL); | 140 file_manager_ = new DownloadFileManager(NULL); |
| 143 download_manager_->file_manager_ = file_manager_; | 141 download_manager_->SetFileManager(file_manager_); |
| 144 } | 142 } |
| 145 return file_manager_; | 143 return file_manager_; |
| 146 } | 144 } |
| 147 | 145 |
| 148 // Make sure download item |id| was set with correct safety state for | 146 // Make sure download item |id| was set with correct safety state for |
| 149 // given |is_dangerous_file| and |is_dangerous_url|. | 147 // given |is_dangerous_file| and |is_dangerous_url|. |
| 150 bool VerifySafetyState(bool is_dangerous_file, | 148 bool VerifySafetyState(bool is_dangerous_file, |
| 151 bool is_dangerous_url, | 149 bool is_dangerous_url, |
| 152 int id) { | 150 int id) { |
| 153 DownloadItem::SafetyState safety_state = | 151 DownloadItem::SafetyState safety_state = |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 884 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 882 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 885 EXPECT_TRUE(observer->was_updated()); | 883 EXPECT_TRUE(observer->was_updated()); |
| 886 EXPECT_FALSE(observer->was_opened()); | 884 EXPECT_FALSE(observer->was_opened()); |
| 887 EXPECT_TRUE(download->file_externally_removed()); | 885 EXPECT_TRUE(download->file_externally_removed()); |
| 888 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); | 886 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); |
| 889 EXPECT_EQ(download_item_model->GetStatusText(), | 887 EXPECT_EQ(download_item_model->GetStatusText(), |
| 890 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); | 888 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); |
| 891 | 889 |
| 892 EXPECT_FALSE(file_util::PathExists(new_path)); | 890 EXPECT_FALSE(file_util::PathExists(new_path)); |
| 893 } | 891 } |
| OLD | NEW |