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 10 matching lines...) Expand all Loading... |
21 #include "chrome/browser/download/download_util.h" | 21 #include "chrome/browser/download/download_util.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
24 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
25 #include "content/browser/download/download_buffer.h" | 25 #include "content/browser/download/download_buffer.h" |
26 #include "content/browser/download/download_create_info.h" | 26 #include "content/browser/download/download_create_info.h" |
27 #include "content/browser/download/download_file_impl.h" | 27 #include "content/browser/download/download_file_impl.h" |
28 #include "content/browser/download/download_file_manager.h" | 28 #include "content/browser/download/download_file_manager.h" |
29 #include "content/browser/download/download_id_factory.h" | 29 #include "content/browser/download/download_id_factory.h" |
30 #include "content/browser/download/download_item.h" | 30 #include "content/browser/download/download_item.h" |
31 #include "content/browser/download/download_manager.h" | 31 #include "content/browser/download/download_manager_impl.h" |
32 #include "content/browser/download/download_request_handle.h" | 32 #include "content/browser/download/download_request_handle.h" |
33 #include "content/browser/download/download_status_updater.h" | 33 #include "content/browser/download/download_status_updater.h" |
34 #include "content/browser/download/interrupt_reasons.h" | 34 #include "content/browser/download/interrupt_reasons.h" |
35 #include "content/browser/download/mock_download_file.h" | 35 #include "content/browser/download/mock_download_file.h" |
36 #include "content/browser/download/mock_download_manager.h" | 36 #include "content/browser/download/mock_download_manager.h" |
37 #include "content/test/test_browser_thread.h" | 37 #include "content/test/test_browser_thread.h" |
38 #include "grit/generated_resources.h" | 38 #include "grit/generated_resources.h" |
39 #include "net/base/io_buffer.h" | 39 #include "net/base/io_buffer.h" |
40 #include "testing/gmock/include/gmock/gmock.h" | 40 #include "testing/gmock/include/gmock/gmock.h" |
41 #include "testing/gmock_mutant.h" | 41 #include "testing/gmock_mutant.h" |
42 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
43 #include "ui/base/l10n/l10n_util.h" | 43 #include "ui/base/l10n/l10n_util.h" |
44 #include "ui/base/text/bytes_formatting.h" | 44 #include "ui/base/text/bytes_formatting.h" |
45 | 45 |
46 using content::BrowserThread; | 46 using content::BrowserThread; |
47 | 47 |
48 DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain"; | 48 DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain"; |
49 | 49 |
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( |
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 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 872 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
875 EXPECT_TRUE(observer->was_updated()); | 873 EXPECT_TRUE(observer->was_updated()); |
876 EXPECT_FALSE(observer->was_opened()); | 874 EXPECT_FALSE(observer->was_opened()); |
877 EXPECT_TRUE(download->file_externally_removed()); | 875 EXPECT_TRUE(download->file_externally_removed()); |
878 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); | 876 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); |
879 EXPECT_EQ(download_item_model->GetStatusText(), | 877 EXPECT_EQ(download_item_model->GetStatusText(), |
880 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); | 878 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); |
881 | 879 |
882 EXPECT_FALSE(file_util::PathExists(new_path)); | 880 EXPECT_FALSE(file_util::PathExists(new_path)); |
883 } | 881 } |
OLD | NEW |