| 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 10 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 161 |
| 162 private: | 162 private: |
| 163 void OnDownloadTargetDone(DownloadTarget* result, | 163 void OnDownloadTargetDone(DownloadTarget* result, |
| 164 const base::FilePath& target_path, | 164 const base::FilePath& target_path, |
| 165 DownloadItem::TargetDisposition disposition, | 165 DownloadItem::TargetDisposition disposition, |
| 166 content::DownloadDangerType danger_type, | 166 content::DownloadDangerType danger_type, |
| 167 const base::FilePath& intermediate_path); | 167 const base::FilePath& intermediate_path); |
| 168 | 168 |
| 169 TestingPrefServiceSyncable* pref_service_; | 169 TestingPrefServiceSyncable* pref_service_; |
| 170 base::ScopedTempDir test_download_dir_; | 170 base::ScopedTempDir test_download_dir_; |
| 171 content::TestBrowserThread ui_thread_; | |
| 172 content::TestBrowserThread file_thread_; | |
| 173 scoped_ptr<content::MockDownloadManager> download_manager_; | 171 scoped_ptr<content::MockDownloadManager> download_manager_; |
| 174 scoped_refptr<TestChromeDownloadManagerDelegate> delegate_; | 172 scoped_refptr<TestChromeDownloadManagerDelegate> delegate_; |
| 175 MockWebContentsDelegate web_contents_delegate_; | 173 MockWebContentsDelegate web_contents_delegate_; |
| 176 }; | 174 }; |
| 177 | 175 |
| 178 ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest() | 176 ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest() |
| 179 : ChromeRenderViewHostTestHarness(), | 177 : download_manager_(new ::testing::NiceMock<content::MockDownloadManager>) { |
| 180 ui_thread_(content::BrowserThread::UI, &message_loop_), | |
| 181 file_thread_(content::BrowserThread::FILE, &message_loop_), | |
| 182 download_manager_(new ::testing::NiceMock<content::MockDownloadManager>) { | |
| 183 } | 178 } |
| 184 | 179 |
| 185 void ChromeDownloadManagerDelegateTest::SetUp() { | 180 void ChromeDownloadManagerDelegateTest::SetUp() { |
| 186 ChromeRenderViewHostTestHarness::SetUp(); | 181 ChromeRenderViewHostTestHarness::SetUp(); |
| 187 | 182 |
| 188 CHECK(profile()); | 183 CHECK(profile()); |
| 189 delegate_ = new TestChromeDownloadManagerDelegate(profile()); | 184 delegate_ = new TestChromeDownloadManagerDelegate(profile()); |
| 190 delegate_->SetDownloadManager(download_manager_.get()); | 185 delegate_->SetDownloadManager(download_manager_.get()); |
| 191 pref_service_ = profile()->GetTestingPrefService(); | 186 pref_service_ = profile()->GetTestingPrefService(); |
| 192 web_contents()->SetDelegate(&web_contents_delegate_); | 187 web_contents()->SetDelegate(&web_contents_delegate_); |
| 193 | 188 |
| 194 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); | 189 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); |
| 195 SetDefaultDownloadPath(test_download_dir_.path()); | 190 SetDefaultDownloadPath(test_download_dir_.path()); |
| 196 } | 191 } |
| 197 | 192 |
| 198 void ChromeDownloadManagerDelegateTest::TearDown() { | 193 void ChromeDownloadManagerDelegateTest::TearDown() { |
| 199 message_loop_.RunUntilIdle(); | 194 base::RunLoop().RunUntilIdle(); |
| 200 delegate_->Shutdown(); | 195 delegate_->Shutdown(); |
| 201 ChromeRenderViewHostTestHarness::TearDown(); | 196 ChromeRenderViewHostTestHarness::TearDown(); |
| 202 } | 197 } |
| 203 | 198 |
| 204 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() { | 199 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() { |
| 205 ::testing::Mock::VerifyAndClearExpectations(delegate_.get()); | 200 ::testing::Mock::VerifyAndClearExpectations(delegate_.get()); |
| 206 } | 201 } |
| 207 | 202 |
| 208 content::MockDownloadItem* | 203 content::MockDownloadItem* |
| 209 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32 id) { | 204 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32 id) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 DownloadTarget result; | 362 DownloadTarget result; |
| 368 base::FilePath expected_prompt_path(GetPathInDownloadDir("foo.txt")); | 363 base::FilePath expected_prompt_path(GetPathInDownloadDir("foo.txt")); |
| 369 EXPECT_CALL(*delegate(), | 364 EXPECT_CALL(*delegate(), |
| 370 MockPromptUserForDownloadPath(save_as_download.get(), | 365 MockPromptUserForDownloadPath(save_as_download.get(), |
| 371 expected_prompt_path, _)) | 366 expected_prompt_path, _)) |
| 372 .WillOnce(Return(base::FilePath())); | 367 .WillOnce(Return(base::FilePath())); |
| 373 DetermineDownloadTarget(save_as_download.get(), &result); | 368 DetermineDownloadTarget(save_as_download.get(), &result); |
| 374 VerifyAndClearExpectations(); | 369 VerifyAndClearExpectations(); |
| 375 } | 370 } |
| 376 } | 371 } |
| OLD | NEW |