Chromium Code Reviews| 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/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 | 272 |
| 273 private: | 273 private: |
| 274 // Verifies that |target_path|, |disposition|, |danger_type| and | 274 // Verifies that |target_path|, |disposition|, |danger_type| and |
| 275 // |intermediate_path| matches the expectations of |test_case|. | 275 // |intermediate_path| matches the expectations of |test_case|. |
| 276 void DownloadTargetVerifier(const DownloadTestCase* test_case, | 276 void DownloadTargetVerifier(const DownloadTestCase* test_case, |
| 277 const FilePath& target_path, | 277 const FilePath& target_path, |
| 278 DownloadItem::TargetDisposition disposition, | 278 DownloadItem::TargetDisposition disposition, |
| 279 content::DownloadDangerType danger_type, | 279 content::DownloadDangerType danger_type, |
| 280 const FilePath& intermediate_path); | 280 const FilePath& intermediate_path); |
| 281 | 281 |
| 282 TestingPrefService* pref_service_; | 282 TestingPrefServiceSyncable* pref_service_; |
| 283 base::ScopedTempDir test_download_dir_; | 283 base::ScopedTempDir test_download_dir_; |
| 284 content::TestBrowserThread ui_thread_; | 284 content::TestBrowserThread ui_thread_; |
| 285 content::TestBrowserThread file_thread_; | 285 content::TestBrowserThread file_thread_; |
| 286 scoped_refptr<content::MockDownloadManager> download_manager_; | 286 scoped_refptr<content::MockDownloadManager> download_manager_; |
| 287 scoped_refptr<TestChromeDownloadManagerDelegate> delegate_; | 287 scoped_refptr<TestChromeDownloadManagerDelegate> delegate_; |
| 288 MockWebContentsDelegate web_contents_delegate_; | 288 MockWebContentsDelegate web_contents_delegate_; |
| 289 }; | 289 }; |
| 290 | 290 |
| 291 ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest() | 291 ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest() |
| 292 : ChromeRenderViewHostTestHarness(), | 292 : ChromeRenderViewHostTestHarness(), |
| 293 ui_thread_(content::BrowserThread::UI, &message_loop_), | 293 ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 294 file_thread_(content::BrowserThread::FILE, &message_loop_), | 294 file_thread_(content::BrowserThread::FILE, &message_loop_), |
| 295 download_manager_(new content::MockDownloadManager) { | 295 download_manager_(new content::MockDownloadManager) { |
| 296 EXPECT_CALL(*download_manager_, GetAllDownloads(_)).WillRepeatedly(Return()); | 296 EXPECT_CALL(*download_manager_, GetAllDownloads(_)).WillRepeatedly(Return()); |
| 297 EXPECT_CALL(*download_manager_, AddObserver(_)).WillRepeatedly(Return()); | 297 EXPECT_CALL(*download_manager_, AddObserver(_)).WillRepeatedly(Return()); |
| 298 EXPECT_CALL(*download_manager_, RemoveObserver(_)).WillRepeatedly(Return()); | 298 EXPECT_CALL(*download_manager_, RemoveObserver(_)).WillRepeatedly(Return()); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void ChromeDownloadManagerDelegateTest::SetUp() { | 301 void ChromeDownloadManagerDelegateTest::SetUp() { |
| 302 ChromeRenderViewHostTestHarness::SetUp(); | 302 ChromeRenderViewHostTestHarness::SetUp(); |
| 303 | 303 |
| 304 CHECK(profile()); | 304 CHECK(profile()); |
| 305 delegate_ = new TestChromeDownloadManagerDelegate(profile()); | 305 delegate_ = new TestChromeDownloadManagerDelegate(profile()); |
| 306 EXPECT_CALL(*download_manager_.get(), GetAllDownloads(_)) | 306 EXPECT_CALL(*download_manager_.get(), GetAllDownloads(_)) |
| 307 .WillRepeatedly(Return()); | 307 .WillRepeatedly(Return()); |
| 308 EXPECT_CALL(*download_manager_.get(), AddObserver(_)) | 308 EXPECT_CALL(*download_manager_.get(), AddObserver(_)) |
| 309 .WillRepeatedly(Return()); | 309 .WillRepeatedly(Return()); |
| 310 delegate_->SetDownloadManager(download_manager_.get()); | 310 delegate_->SetDownloadManager(download_manager_.get()); |
| 311 pref_service_ = profile()->GetTestingPrefService(); | 311 pref_service_ = profile()->GetTestingPrefService(); |
|
Mattias Nissler (ping if slow)
2012/12/19 19:50:22
used?
Jói
2012/12/20 16:30:31
Yes, from SetDefaultDownloadPath, SetManagedDownlo
| |
| 312 web_contents()->SetDelegate(&web_contents_delegate_); | 312 web_contents()->SetDelegate(&web_contents_delegate_); |
| 313 | 313 |
| 314 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); | 314 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); |
| 315 SetDefaultDownloadPath(test_download_dir_.path()); | 315 SetDefaultDownloadPath(test_download_dir_.path()); |
| 316 } | 316 } |
| 317 | 317 |
| 318 void ChromeDownloadManagerDelegateTest::TearDown() { | 318 void ChromeDownloadManagerDelegateTest::TearDown() { |
| 319 message_loop_.RunUntilIdle(); | 319 message_loop_.RunUntilIdle(); |
| 320 delegate_->Shutdown(); | 320 delegate_->Shutdown(); |
| 321 ChromeRenderViewHostTestHarness::TearDown(); | 321 ChromeRenderViewHostTestHarness::TearDown(); |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 912 // Run the first test case again. Since the last download path was cleared, | 912 // Run the first test case again. Since the last download path was cleared, |
| 913 // this test case should behave identically to the first time it was run. | 913 // this test case should behave identically to the first time it was run. |
| 914 RunTestCases(kLastSavePathTestCases, 1); | 914 RunTestCases(kLastSavePathTestCases, 1); |
| 915 } | 915 } |
| 916 | 916 |
| 917 // TODO(asanka): Add more tests. | 917 // TODO(asanka): Add more tests. |
| 918 // * Default download path is not writable. | 918 // * Default download path is not writable. |
| 919 // * Download path doesn't exist. | 919 // * Download path doesn't exist. |
| 920 // * IsDangerousFile(). | 920 // * IsDangerousFile(). |
| 921 // * Filename generation. | 921 // * Filename generation. |
| OLD | NEW |