| 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 <string> | 5 #include <string> |
| 6 #include <set> | 6 #include <set> |
| 7 | 7 |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/i18n/number_formatting.h" | 9 #include "base/i18n/number_formatting.h" |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 17 #include "chrome/browser/download/download_create_info.h" | 18 #include "chrome/browser/download/download_create_info.h" |
| 18 #include "chrome/browser/download/download_file.h" | 19 #include "chrome/browser/download/download_file.h" |
| 19 #include "chrome/browser/download/download_file_manager.h" | 20 #include "chrome/browser/download/download_file_manager.h" |
| 20 #include "chrome/browser/download/download_item.h" | 21 #include "chrome/browser/download/download_item.h" |
| 21 #include "chrome/browser/download/download_item_model.h" | 22 #include "chrome/browser/download/download_item_model.h" |
| 22 #include "chrome/browser/download/download_manager.h" | 23 #include "chrome/browser/download/download_manager.h" |
| 23 #include "chrome/browser/download/download_prefs.h" | 24 #include "chrome/browser/download/download_prefs.h" |
| 24 #include "chrome/browser/download/download_status_updater.h" | 25 #include "chrome/browser/download/download_status_updater.h" |
| 25 #include "chrome/browser/download/download_util.h" | 26 #include "chrome/browser/download/download_util.h" |
| 26 #include "chrome/browser/download/mock_download_manager.h" | 27 #include "chrome/browser/download/mock_download_manager.h" |
| 27 #include "chrome/browser/download/mock_download_manager_delegate.h" | |
| 28 #include "chrome/browser/prefs/pref_service.h" | 28 #include "chrome/browser/prefs/pref_service.h" |
| 29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/test/base/testing_browser_process_test.h" | 30 #include "chrome/test/base/testing_browser_process_test.h" |
| 31 #include "chrome/test/base/testing_profile.h" | 31 #include "chrome/test/base/testing_profile.h" |
| 32 #include "content/browser/browser_thread.h" | 32 #include "content/browser/browser_thread.h" |
| 33 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
| 34 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
| 35 #include "testing/gmock_mutant.h" | 35 #include "testing/gmock_mutant.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 37 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 38 #include "ui/base/text/bytes_formatting.h" | 38 #include "ui/base/text/bytes_formatting.h" |
| 39 | 39 |
| 40 class DownloadManagerTest : public TestingBrowserProcessTest { | 40 class DownloadManagerTest : public TestingBrowserProcessTest { |
| 41 public: | 41 public: |
| 42 static const char* kTestData; | 42 static const char* kTestData; |
| 43 static const size_t kTestDataLen; | 43 static const size_t kTestDataLen; |
| 44 | 44 |
| 45 DownloadManagerTest() | 45 DownloadManagerTest() |
| 46 : profile_(new TestingProfile()), | 46 : profile_(new TestingProfile()), |
| 47 download_manager_delegate_(new MockDownloadManagerDelegate()), | 47 download_manager_delegate_(new ChromeDownloadManagerDelegate()), |
| 48 download_manager_(new MockDownloadManager( | 48 download_manager_(new MockDownloadManager( |
| 49 download_manager_delegate_.get(), &download_status_updater_)), | 49 download_manager_delegate_, &download_status_updater_)), |
| 50 ui_thread_(BrowserThread::UI, &message_loop_), | 50 ui_thread_(BrowserThread::UI, &message_loop_), |
| 51 file_thread_(BrowserThread::FILE, &message_loop_) { | 51 file_thread_(BrowserThread::FILE, &message_loop_) { |
| 52 download_manager_delegate_->set_download_manager(download_manager_); |
| 52 download_manager_->Init(profile_.get()); | 53 download_manager_->Init(profile_.get()); |
| 53 } | 54 } |
| 54 | 55 |
| 55 ~DownloadManagerTest() { | 56 ~DownloadManagerTest() { |
| 56 download_manager_->Shutdown(); | 57 download_manager_->Shutdown(); |
| 57 // profile_ must outlive download_manager_, so we explicitly delete | 58 // profile_ must outlive download_manager_, so we explicitly delete |
| 58 // download_manager_ first. | 59 // download_manager_ first. |
| 59 download_manager_ = NULL; | 60 download_manager_ = NULL; |
| 60 profile_.reset(NULL); | 61 profile_.reset(NULL); |
| 61 message_loop_.RunAllPending(); | 62 message_loop_.RunAllPending(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 84 // Get the download item with ID |id|. | 85 // Get the download item with ID |id|. |
| 85 DownloadItem* GetActiveDownloadItem(int32 id) { | 86 DownloadItem* GetActiveDownloadItem(int32 id) { |
| 86 if (ContainsKey(download_manager_->active_downloads_, id)) | 87 if (ContainsKey(download_manager_->active_downloads_, id)) |
| 87 return download_manager_->active_downloads_[id]; | 88 return download_manager_->active_downloads_[id]; |
| 88 return NULL; | 89 return NULL; |
| 89 } | 90 } |
| 90 | 91 |
| 91 protected: | 92 protected: |
| 92 DownloadStatusUpdater download_status_updater_; | 93 DownloadStatusUpdater download_status_updater_; |
| 93 scoped_ptr<TestingProfile> profile_; | 94 scoped_ptr<TestingProfile> profile_; |
| 94 scoped_ptr<MockDownloadManagerDelegate> download_manager_delegate_; | 95 scoped_refptr<ChromeDownloadManagerDelegate> download_manager_delegate_; |
| 95 scoped_refptr<DownloadManager> download_manager_; | 96 scoped_refptr<DownloadManager> download_manager_; |
| 96 scoped_refptr<DownloadFileManager> file_manager_; | 97 scoped_refptr<DownloadFileManager> file_manager_; |
| 97 MessageLoopForUI message_loop_; | 98 MessageLoopForUI message_loop_; |
| 98 BrowserThread ui_thread_; | 99 BrowserThread ui_thread_; |
| 99 BrowserThread file_thread_; | 100 BrowserThread file_thread_; |
| 100 | 101 |
| 101 DownloadFileManager* file_manager() { | 102 DownloadFileManager* file_manager() { |
| 102 if (!file_manager_) { | 103 if (!file_manager_) { |
| 103 file_manager_ = new DownloadFileManager(NULL); | 104 file_manager_ = new DownloadFileManager(NULL); |
| 104 download_manager_->file_manager_ = file_manager_; | 105 download_manager_->file_manager_ = file_manager_; |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 714 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 714 EXPECT_TRUE(observer->was_updated()); | 715 EXPECT_TRUE(observer->was_updated()); |
| 715 EXPECT_FALSE(observer->was_opened()); | 716 EXPECT_FALSE(observer->was_opened()); |
| 716 EXPECT_TRUE(download->file_externally_removed()); | 717 EXPECT_TRUE(download->file_externally_removed()); |
| 717 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); | 718 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); |
| 718 EXPECT_EQ(download_item_model->GetStatusText(), | 719 EXPECT_EQ(download_item_model->GetStatusText(), |
| 719 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); | 720 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); |
| 720 | 721 |
| 721 EXPECT_FALSE(file_util::PathExists(new_path)); | 722 EXPECT_FALSE(file_util::PathExists(new_path)); |
| 722 } | 723 } |
| OLD | NEW |