| 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/observer_list.h" | 8 #include "base/observer_list.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 const DownloadTargetDeterminerDelegate::ReservedPathCallback& callback); | 171 const DownloadTargetDeterminerDelegate::ReservedPathCallback& callback); |
| 172 static void NullPromptUser( | 172 static void NullPromptUser( |
| 173 DownloadItem* download, const base::FilePath& suggested_path, | 173 DownloadItem* download, const base::FilePath& suggested_path, |
| 174 const FileSelectedCallback& callback); | 174 const FileSelectedCallback& callback); |
| 175 static void NullDetermineLocalPath( | 175 static void NullDetermineLocalPath( |
| 176 DownloadItem* download, const base::FilePath& virtual_path, | 176 DownloadItem* download, const base::FilePath& virtual_path, |
| 177 const LocalPathCallback& callback); | 177 const LocalPathCallback& callback); |
| 178 }; | 178 }; |
| 179 | 179 |
| 180 class DownloadTargetDeterminerTest : public ChromeRenderViewHostTestHarness { | 180 class DownloadTargetDeterminerTest : public ChromeRenderViewHostTestHarness { |
| 181 public: | 181 protected: |
| 182 DownloadTargetDeterminerTest(); | |
| 183 | |
| 184 // ::testing::Test | 182 // ::testing::Test |
| 185 virtual void SetUp() OVERRIDE; | 183 virtual void SetUp() OVERRIDE; |
| 186 virtual void TearDown() OVERRIDE; | 184 virtual void TearDown() OVERRIDE; |
| 187 | 185 |
| 188 // Creates MockDownloadItem and sets up default expectations. | 186 // Creates MockDownloadItem and sets up default expectations. |
| 189 content::MockDownloadItem* CreateActiveDownloadItem( | 187 content::MockDownloadItem* CreateActiveDownloadItem( |
| 190 int32 id, | 188 int32 id, |
| 191 const DownloadTestCase& test_case); | 189 const DownloadTestCase& test_case); |
| 192 | 190 |
| 193 // Sets the AutoOpenBasedOnExtension user preference for |path|. | 191 // Sets the AutoOpenBasedOnExtension user preference for |path|. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 DownloadItem::TargetDisposition disposition, | 244 DownloadItem::TargetDisposition disposition, |
| 247 content::DownloadDangerType danger_type, | 245 content::DownloadDangerType danger_type, |
| 248 const base::FilePath& intermediate_path); | 246 const base::FilePath& intermediate_path); |
| 249 | 247 |
| 250 scoped_ptr<DownloadPrefs> download_prefs_; | 248 scoped_ptr<DownloadPrefs> download_prefs_; |
| 251 ::testing::NiceMock<MockDownloadTargetDeterminerDelegate> delegate_; | 249 ::testing::NiceMock<MockDownloadTargetDeterminerDelegate> delegate_; |
| 252 NullWebContentsDelegate web_contents_delegate_; | 250 NullWebContentsDelegate web_contents_delegate_; |
| 253 base::ScopedTempDir test_download_dir_; | 251 base::ScopedTempDir test_download_dir_; |
| 254 base::FilePath test_virtual_dir_; | 252 base::FilePath test_virtual_dir_; |
| 255 base::FilePath last_selected_directory_; | 253 base::FilePath last_selected_directory_; |
| 256 content::TestBrowserThread ui_thread_; | |
| 257 content::TestBrowserThread file_thread_; | |
| 258 }; | 254 }; |
| 259 | 255 |
| 260 DownloadTargetDeterminerTest::DownloadTargetDeterminerTest() | |
| 261 : ChromeRenderViewHostTestHarness(), | |
| 262 ui_thread_(content::BrowserThread::UI, &message_loop_), | |
| 263 file_thread_(content::BrowserThread::FILE, &message_loop_) { | |
| 264 } | |
| 265 | |
| 266 void DownloadTargetDeterminerTest::SetUp() { | 256 void DownloadTargetDeterminerTest::SetUp() { |
| 267 ChromeRenderViewHostTestHarness::SetUp(); | 257 ChromeRenderViewHostTestHarness::SetUp(); |
| 268 CHECK(profile()); | 258 CHECK(profile()); |
| 269 download_prefs_.reset(new DownloadPrefs(profile())); | 259 download_prefs_.reset(new DownloadPrefs(profile())); |
| 270 web_contents()->SetDelegate(&web_contents_delegate_); | 260 web_contents()->SetDelegate(&web_contents_delegate_); |
| 271 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); | 261 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); |
| 272 test_virtual_dir_ = test_download_dir().Append(FILE_PATH_LITERAL("virtual")); | 262 test_virtual_dir_ = test_download_dir().Append(FILE_PATH_LITERAL("virtual")); |
| 273 SetDefaultDownloadPath(test_download_dir()); | 263 SetDefaultDownloadPath(test_download_dir()); |
| 274 delegate_.SetupDefaults(); | 264 delegate_.SetupDefaults(); |
| 275 } | 265 } |
| 276 | 266 |
| 277 void DownloadTargetDeterminerTest::TearDown() { | 267 void DownloadTargetDeterminerTest::TearDown() { |
| 278 download_prefs_.reset(); | 268 download_prefs_.reset(); |
| 279 message_loop_.RunUntilIdle(); | |
| 280 ChromeRenderViewHostTestHarness::TearDown(); | 269 ChromeRenderViewHostTestHarness::TearDown(); |
| 281 } | 270 } |
| 282 | 271 |
| 283 content::MockDownloadItem* | 272 content::MockDownloadItem* |
| 284 DownloadTargetDeterminerTest::CreateActiveDownloadItem( | 273 DownloadTargetDeterminerTest::CreateActiveDownloadItem( |
| 285 int32 id, | 274 int32 id, |
| 286 const DownloadTestCase& test_case) { | 275 const DownloadTestCase& test_case) { |
| 287 content::MockDownloadItem* item = | 276 content::MockDownloadItem* item = |
| 288 new ::testing::NiceMock<content::MockDownloadItem>(); | 277 new ::testing::NiceMock<content::MockDownloadItem>(); |
| 289 GURL download_url(test_case.url); | 278 GURL download_url(test_case.url); |
| (...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1472 .WillOnce(WithArg<2>( | 1461 .WillOnce(WithArg<2>( |
| 1473 ScheduleCallback2(overridden_path, | 1462 ScheduleCallback2(overridden_path, |
| 1474 DownloadPathReservationTracker::UNIQUIFY))); | 1463 DownloadPathReservationTracker::UNIQUIFY))); |
| 1475 EXPECT_CALL(*delegate(), | 1464 EXPECT_CALL(*delegate(), |
| 1476 PromptUserForDownloadPath(_, full_overridden_path, _)) | 1465 PromptUserForDownloadPath(_, full_overridden_path, _)) |
| 1477 .WillOnce(WithArg<2>( | 1466 .WillOnce(WithArg<2>( |
| 1478 ScheduleCallback(full_overridden_path))); | 1467 ScheduleCallback(full_overridden_path))); |
| 1479 RunTestCase(test_case, item.get()); | 1468 RunTestCase(test_case, item.get()); |
| 1480 } | 1469 } |
| 1481 } // namespace | 1470 } // namespace |
| OLD | NEW |