| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 void SetFileSelectionExpectation(const FilePath& suggested_path, | 170 void SetFileSelectionExpectation(const FilePath& suggested_path, |
| 171 const FilePath& response) { | 171 const FilePath& response) { |
| 172 expected_suggested_path_ = suggested_path; | 172 expected_suggested_path_ = suggested_path; |
| 173 file_selection_response_ = response; | 173 file_selection_response_ = response; |
| 174 } | 174 } |
| 175 | 175 |
| 176 void SetMarkContentsDangerous(bool dangerous) { | 176 void SetMarkContentsDangerous(bool dangerous) { |
| 177 mark_content_dangerous_ = dangerous; | 177 mark_content_dangerous_ = dangerous; |
| 178 } | 178 } |
| 179 | 179 |
| 180 virtual bool ShouldCompleteDownload(DownloadItem* item) { | 180 virtual bool ShouldCompleteDownload( |
| 181 DownloadItem* item, |
| 182 const base::Closure& complete_callback) { |
| 181 if (mark_content_dangerous_) { | 183 if (mark_content_dangerous_) { |
| 184 CHECK(!complete_callback.is_null()); |
| 182 BrowserThread::PostTask( | 185 BrowserThread::PostTask( |
| 183 BrowserThread::UI, FROM_HERE, | 186 BrowserThread::UI, FROM_HERE, |
| 184 base::Bind(&TestDownloadManagerDelegate::MarkContentDangerous, | 187 base::Bind(&TestDownloadManagerDelegate::MarkContentDangerous, |
| 185 base::Unretained(this), item->GetId())); | 188 base::Unretained(this), item->GetId(), complete_callback)); |
| 186 mark_content_dangerous_ = false; | 189 mark_content_dangerous_ = false; |
| 187 return false; | 190 return false; |
| 188 } else { | 191 } else { |
| 189 return true; | 192 return true; |
| 190 } | 193 } |
| 191 } | 194 } |
| 192 | 195 |
| 193 private: | 196 private: |
| 194 void MarkContentDangerous(int32 download_id) { | 197 void MarkContentDangerous( |
| 198 int32 download_id, |
| 199 const base::Closure& complete_callback) { |
| 195 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); | 200 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); |
| 196 if (!item) | 201 if (!item) |
| 197 return; | 202 return; |
| 198 item->SetDangerType(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT); | 203 item->SetDangerType(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT); |
| 199 item->MaybeCompleteDownload(); | 204 complete_callback.Run(); |
| 200 } | 205 } |
| 201 | 206 |
| 202 FilePath expected_suggested_path_; | 207 FilePath expected_suggested_path_; |
| 203 FilePath file_selection_response_; | 208 FilePath file_selection_response_; |
| 204 bool mark_content_dangerous_; | 209 bool mark_content_dangerous_; |
| 205 bool prompt_user_for_save_location_; | 210 bool prompt_user_for_save_location_; |
| 206 DownloadManager* download_manager_; | 211 DownloadManager* download_manager_; |
| 212 |
| 213 DISALLOW_COPY_AND_ASSIGN(TestDownloadManagerDelegate); |
| 207 }; | 214 }; |
| 208 | 215 |
| 209 } // namespace | 216 } // namespace |
| 210 | 217 |
| 211 class DownloadManagerTest : public testing::Test { | 218 class DownloadManagerTest : public testing::Test { |
| 212 public: | 219 public: |
| 213 static const char* kTestData; | 220 static const char* kTestData; |
| 214 static const size_t kTestDataLen; | 221 static const size_t kTestDataLen; |
| 215 | 222 |
| 216 DownloadManagerTest() | 223 DownloadManagerTest() |
| (...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1310 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); | 1317 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); |
| 1311 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); | 1318 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); |
| 1312 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 1319 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 1313 EXPECT_TRUE(observer->was_updated()); | 1320 EXPECT_TRUE(observer->was_updated()); |
| 1314 EXPECT_FALSE(observer->was_opened()); | 1321 EXPECT_FALSE(observer->was_opened()); |
| 1315 EXPECT_TRUE(download->GetFileExternallyRemoved()); | 1322 EXPECT_TRUE(download->GetFileExternallyRemoved()); |
| 1316 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); | 1323 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); |
| 1317 | 1324 |
| 1318 EXPECT_FALSE(file_util::PathExists(new_path)); | 1325 EXPECT_FALSE(file_util::PathExists(new_path)); |
| 1319 } | 1326 } |
| OLD | NEW |