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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 const base::FilePath& local_path, | 236 const base::FilePath& local_path, |
239 DownloadItem::TargetDisposition disposition, | 237 DownloadItem::TargetDisposition disposition, |
240 content::DownloadDangerType danger_type, | 238 content::DownloadDangerType danger_type, |
241 const base::FilePath& intermediate_path); | 239 const base::FilePath& intermediate_path); |
242 | 240 |
243 scoped_ptr<DownloadPrefs> download_prefs_; | 241 scoped_ptr<DownloadPrefs> download_prefs_; |
244 ::testing::NiceMock<MockDownloadTargetDeterminerDelegate> delegate_; | 242 ::testing::NiceMock<MockDownloadTargetDeterminerDelegate> delegate_; |
245 NullWebContentsDelegate web_contents_delegate_; | 243 NullWebContentsDelegate web_contents_delegate_; |
246 base::ScopedTempDir test_download_dir_; | 244 base::ScopedTempDir test_download_dir_; |
247 base::FilePath test_virtual_dir_; | 245 base::FilePath test_virtual_dir_; |
248 content::TestBrowserThread ui_thread_; | |
249 content::TestBrowserThread file_thread_; | |
250 }; | 246 }; |
251 | 247 |
252 DownloadTargetDeterminerTest::DownloadTargetDeterminerTest() | |
253 : ChromeRenderViewHostTestHarness(), | |
254 ui_thread_(content::BrowserThread::UI, &message_loop_), | |
255 file_thread_(content::BrowserThread::FILE, &message_loop_) { | |
256 } | |
257 | |
258 void DownloadTargetDeterminerTest::SetUp() { | 248 void DownloadTargetDeterminerTest::SetUp() { |
259 ChromeRenderViewHostTestHarness::SetUp(); | 249 ChromeRenderViewHostTestHarness::SetUp(); |
260 CHECK(profile()); | 250 CHECK(profile()); |
261 download_prefs_.reset(new DownloadPrefs(profile())); | 251 download_prefs_.reset(new DownloadPrefs(profile())); |
262 web_contents()->SetDelegate(&web_contents_delegate_); | 252 web_contents()->SetDelegate(&web_contents_delegate_); |
263 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); | 253 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); |
264 test_virtual_dir_ = test_download_dir().Append(FILE_PATH_LITERAL("virtual")); | 254 test_virtual_dir_ = test_download_dir().Append(FILE_PATH_LITERAL("virtual")); |
265 download_prefs_->SetDownloadPath(test_download_dir()); | 255 download_prefs_->SetDownloadPath(test_download_dir()); |
266 delegate_.SetupDefaults(); | 256 delegate_.SetupDefaults(); |
267 } | 257 } |
268 | 258 |
269 void DownloadTargetDeterminerTest::TearDown() { | 259 void DownloadTargetDeterminerTest::TearDown() { |
270 download_prefs_.reset(); | 260 download_prefs_.reset(); |
271 message_loop_.RunUntilIdle(); | |
272 ChromeRenderViewHostTestHarness::TearDown(); | 261 ChromeRenderViewHostTestHarness::TearDown(); |
273 } | 262 } |
274 | 263 |
275 content::MockDownloadItem* | 264 content::MockDownloadItem* |
276 DownloadTargetDeterminerTest::CreateActiveDownloadItem( | 265 DownloadTargetDeterminerTest::CreateActiveDownloadItem( |
277 int32 id, | 266 int32 id, |
278 const DownloadTestCase& test_case) { | 267 const DownloadTestCase& test_case) { |
279 content::MockDownloadItem* item = | 268 content::MockDownloadItem* item = |
280 new ::testing::NiceMock<content::MockDownloadItem>(); | 269 new ::testing::NiceMock<content::MockDownloadItem>(); |
281 GURL download_url(test_case.url); | 270 GURL download_url(test_case.url); |
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 .WillOnce(WithArg<2>( | 1443 .WillOnce(WithArg<2>( |
1455 ScheduleCallback2(overridden_path, | 1444 ScheduleCallback2(overridden_path, |
1456 DownloadPathReservationTracker::UNIQUIFY))); | 1445 DownloadPathReservationTracker::UNIQUIFY))); |
1457 EXPECT_CALL(*delegate(), | 1446 EXPECT_CALL(*delegate(), |
1458 PromptUserForDownloadPath(_, full_overridden_path, _)) | 1447 PromptUserForDownloadPath(_, full_overridden_path, _)) |
1459 .WillOnce(WithArg<2>( | 1448 .WillOnce(WithArg<2>( |
1460 ScheduleCallback(full_overridden_path))); | 1449 ScheduleCallback(full_overridden_path))); |
1461 RunTestCase(test_case, item.get()); | 1450 RunTestCase(test_case, item.get()); |
1462 } | 1451 } |
1463 } // namespace | 1452 } // namespace |
OLD | NEW |