| 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" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/scoped_temp_dir.h" | 12 #include "base/scoped_temp_dir.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "content/browser/download/download_buffer.h" | 18 #include "content/browser/download/download_buffer.h" |
| 19 #include "content/browser/download/download_create_info.h" | 19 #include "content/browser/download/download_create_info.h" |
| 20 #include "content/browser/download/download_file_impl.h" | 20 #include "content/browser/download/download_file_impl.h" |
| 21 #include "content/browser/download/download_file_manager.h" | 21 #include "content/browser/download/download_file_manager.h" |
| 22 #include "content/browser/download/download_manager_impl.h" | 22 #include "content/browser/download/download_manager_impl.h" |
| 23 #include "content/browser/download/download_request_handle.h" | 23 #include "content/browser/download/download_request_handle.h" |
| 24 #include "content/browser/download/interrupt_reasons.h" | |
| 25 #include "content/browser/download/mock_download_file.h" | 24 #include "content/browser/download/mock_download_file.h" |
| 25 #include "content/public/browser/download_interrupt_reasons.h" |
| 26 #include "content/public/browser/download_item.h" | 26 #include "content/public/browser/download_item.h" |
| 27 #include "content/public/browser/download_manager_delegate.h" | 27 #include "content/public/browser/download_manager_delegate.h" |
| 28 #include "content/test/mock_download_manager.h" | 28 #include "content/test/mock_download_manager.h" |
| 29 #include "content/test/test_browser_context.h" | 29 #include "content/test/test_browser_context.h" |
| 30 #include "content/test/test_browser_thread.h" | 30 #include "content/test/test_browser_thread.h" |
| 31 #include "net/base/io_buffer.h" | 31 #include "net/base/io_buffer.h" |
| 32 #include "net/base/net_util.h" | 32 #include "net/base/net_util.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "testing/gmock_mutant.h" | 34 #include "testing/gmock_mutant.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 BrowserThread::PostTask( | 268 BrowserThread::PostTask( |
| 269 BrowserThread::FILE, FROM_HERE, | 269 BrowserThread::FILE, FROM_HERE, |
| 270 base::Bind(&DownloadFileManager::UpdateDownload, file_manager_.get(), | 270 base::Bind(&DownloadFileManager::UpdateDownload, file_manager_.get(), |
| 271 DownloadId(kValidIdDomain, id), download_buffer_)); | 271 DownloadId(kValidIdDomain, id), download_buffer_)); |
| 272 | 272 |
| 273 message_loop_.RunAllPending(); | 273 message_loop_.RunAllPending(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void OnDownloadInterrupted(int32 download_id, int64 size, | 276 void OnDownloadInterrupted(int32 download_id, int64 size, |
| 277 const std::string& hash_state, | 277 const std::string& hash_state, |
| 278 InterruptReason reason) { | 278 content::DownloadInterruptReason reason) { |
| 279 download_manager_->OnDownloadInterrupted(download_id, size, | 279 download_manager_->OnDownloadInterrupted(download_id, size, |
| 280 hash_state, reason); | 280 hash_state, reason); |
| 281 } | 281 } |
| 282 | 282 |
| 283 // Get the download item with ID |id|. | 283 // Get the download item with ID |id|. |
| 284 DownloadItem* GetActiveDownloadItem(int32 id) { | 284 DownloadItem* GetActiveDownloadItem(int32 id) { |
| 285 return download_manager_->GetActiveDownload(id); | 285 return download_manager_->GetActiveDownload(id); |
| 286 } | 286 } |
| 287 | 287 |
| 288 protected: | 288 protected: |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); | 963 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); |
| 964 | 964 |
| 965 download_file->AppendDataToFile(kTestData, kTestDataLen); | 965 download_file->AppendDataToFile(kTestData, kTestDataLen); |
| 966 | 966 |
| 967 ContinueDownloadWithPath(download, new_path); | 967 ContinueDownloadWithPath(download, new_path); |
| 968 message_loop_.RunAllPending(); | 968 message_loop_.RunAllPending(); |
| 969 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | 969 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
| 970 | 970 |
| 971 int64 error_size = 3; | 971 int64 error_size = 3; |
| 972 OnDownloadInterrupted(0, error_size, "", | 972 OnDownloadInterrupted(0, error_size, "", |
| 973 DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED); | 973 content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED); |
| 974 message_loop_.RunAllPending(); | 974 message_loop_.RunAllPending(); |
| 975 | 975 |
| 976 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); | 976 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); |
| 977 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); | 977 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); |
| 978 EXPECT_TRUE(observer->hit_state(DownloadItem::INTERRUPTED)); | 978 EXPECT_TRUE(observer->hit_state(DownloadItem::INTERRUPTED)); |
| 979 EXPECT_FALSE(observer->hit_state(DownloadItem::COMPLETE)); | 979 EXPECT_FALSE(observer->hit_state(DownloadItem::COMPLETE)); |
| 980 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); | 980 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); |
| 981 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 981 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 982 EXPECT_TRUE(observer->was_updated()); | 982 EXPECT_TRUE(observer->was_updated()); |
| 983 EXPECT_FALSE(observer->was_opened()); | 983 EXPECT_FALSE(observer->was_opened()); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1301 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); | 1301 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); |
| 1302 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); | 1302 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); |
| 1303 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 1303 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 1304 EXPECT_TRUE(observer->was_updated()); | 1304 EXPECT_TRUE(observer->was_updated()); |
| 1305 EXPECT_FALSE(observer->was_opened()); | 1305 EXPECT_FALSE(observer->was_opened()); |
| 1306 EXPECT_TRUE(download->GetFileExternallyRemoved()); | 1306 EXPECT_TRUE(download->GetFileExternallyRemoved()); |
| 1307 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); | 1307 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); |
| 1308 | 1308 |
| 1309 EXPECT_FALSE(file_util::PathExists(new_path)); | 1309 EXPECT_FALSE(file_util::PathExists(new_path)); |
| 1310 } | 1310 } |
| OLD | NEW |