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/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/observer_list.h" | 8 #include "base/observer_list.h" |
9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } | 296 } |
297 | 297 |
298 void ChromeDownloadManagerDelegateTest::SetUp() { | 298 void ChromeDownloadManagerDelegateTest::SetUp() { |
299 ChromeRenderViewHostTestHarness::SetUp(); | 299 ChromeRenderViewHostTestHarness::SetUp(); |
300 | 300 |
301 CHECK(profile()); | 301 CHECK(profile()); |
302 delegate_ = new TestChromeDownloadManagerDelegate(profile()); | 302 delegate_ = new TestChromeDownloadManagerDelegate(profile()); |
| 303 EXPECT_CALL(*download_manager_.get(), GetAllDownloads(_)) |
| 304 .WillRepeatedly(Return()); |
| 305 EXPECT_CALL(*download_manager_.get(), AddObserver(_)) |
| 306 .WillRepeatedly(Return()); |
303 delegate_->SetDownloadManager(download_manager_.get()); | 307 delegate_->SetDownloadManager(download_manager_.get()); |
304 pref_service_ = profile()->GetTestingPrefService(); | 308 pref_service_ = profile()->GetTestingPrefService(); |
305 contents()->SetDelegate(&web_contents_delegate_); | 309 contents()->SetDelegate(&web_contents_delegate_); |
306 | 310 |
307 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); | 311 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); |
308 SetDefaultDownloadPath(test_download_dir_.path()); | 312 SetDefaultDownloadPath(test_download_dir_.path()); |
309 } | 313 } |
310 | 314 |
311 void ChromeDownloadManagerDelegateTest::TearDown() { | 315 void ChromeDownloadManagerDelegateTest::TearDown() { |
312 message_loop_.RunAllPending(); | 316 message_loop_.RunAllPending(); |
313 delegate_->Shutdown(); | 317 delegate_->Shutdown(); |
314 ChromeRenderViewHostTestHarness::TearDown(); | 318 ChromeRenderViewHostTestHarness::TearDown(); |
315 } | 319 } |
316 | 320 |
317 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() { | 321 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() { |
318 ::testing::Mock::VerifyAndClearExpectations(delegate_); | 322 ::testing::Mock::VerifyAndClearExpectations(delegate_); |
319 ::testing::Mock::VerifyAndClearExpectations(download_manager_); | 323 ::testing::Mock::VerifyAndClearExpectations(download_manager_); |
| 324 EXPECT_CALL(*download_manager_.get(), RemoveObserver(_)) |
| 325 .WillRepeatedly(Return()); |
320 } | 326 } |
321 | 327 |
322 content::MockDownloadItem* | 328 content::MockDownloadItem* |
323 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32 id) { | 329 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32 id) { |
324 content::MockDownloadItem* item = | 330 content::MockDownloadItem* item = |
325 new ::testing::NiceMock<content::MockDownloadItem>(); | 331 new ::testing::NiceMock<content::MockDownloadItem>(); |
| 332 EXPECT_CALL(*item, GetState()) |
| 333 .WillRepeatedly(Return(DownloadItem::IN_PROGRESS)); |
| 334 EXPECT_CALL(*item, AddObserver(_)) |
| 335 .WillRepeatedly(Return()); |
| 336 EXPECT_CALL(*item, RemoveObserver(_)) |
| 337 .WillRepeatedly(Return()); |
326 ON_CALL(*item, GetFullPath()) | 338 ON_CALL(*item, GetFullPath()) |
327 .WillByDefault(ReturnRefOfCopy(FilePath())); | 339 .WillByDefault(ReturnRefOfCopy(FilePath())); |
328 ON_CALL(*item, GetHash()) | 340 ON_CALL(*item, GetHash()) |
329 .WillByDefault(ReturnRefOfCopy(std::string())); | 341 .WillByDefault(ReturnRefOfCopy(std::string())); |
330 ON_CALL(*item, GetReferrerUrl()) | 342 ON_CALL(*item, GetReferrerUrl()) |
331 .WillByDefault(ReturnRefOfCopy(GURL())); | 343 .WillByDefault(ReturnRefOfCopy(GURL())); |
332 ON_CALL(*item, GetTransitionType()) | 344 ON_CALL(*item, GetTransitionType()) |
333 .WillByDefault(Return(content::PAGE_TRANSITION_LINK)); | 345 .WillByDefault(Return(content::PAGE_TRANSITION_LINK)); |
334 ON_CALL(*item, HasUserGesture()) | 346 ON_CALL(*item, HasUserGesture()) |
335 .WillByDefault(Return(false)); | 347 .WillByDefault(Return(false)); |
336 ON_CALL(*item, IsDangerous()) | 348 ON_CALL(*item, IsDangerous()) |
337 .WillByDefault(Return(false)); | 349 .WillByDefault(Return(false)); |
338 ON_CALL(*item, IsTemporary()) | 350 ON_CALL(*item, IsTemporary()) |
339 .WillByDefault(Return(false)); | 351 .WillByDefault(Return(false)); |
340 ON_CALL(*item, GetWebContents()) | 352 ON_CALL(*item, GetWebContents()) |
341 .WillByDefault(Return(contents())); | 353 .WillByDefault(Return(contents())); |
342 EXPECT_CALL(*item, GetId()) | 354 EXPECT_CALL(*item, GetId()) |
343 .WillRepeatedly(Return(id)); | 355 .WillRepeatedly(Return(id)); |
| 356 EXPECT_CALL(*download_manager_, GetDownload(id)) |
| 357 .WillRepeatedly(Return(item)); |
344 EXPECT_CALL(*download_manager_, GetActiveDownloadItem(id)) | 358 EXPECT_CALL(*download_manager_, GetActiveDownloadItem(id)) |
345 .WillRepeatedly(Return(item)); | 359 .WillRepeatedly(Return(item)); |
346 return item; | 360 return item; |
347 } | 361 } |
348 | 362 |
349 void ChromeDownloadManagerDelegateTest::EnableAutoOpenBasedOnExtension( | 363 void ChromeDownloadManagerDelegateTest::EnableAutoOpenBasedOnExtension( |
350 const FilePath& path) { | 364 const FilePath& path) { |
351 EXPECT_TRUE( | 365 EXPECT_TRUE( |
352 delegate_->download_prefs()->EnableAutoOpenBasedOnExtension(path)); | 366 delegate_->download_prefs()->EnableAutoOpenBasedOnExtension(path)); |
353 } | 367 } |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 }; | 944 }; |
931 | 945 |
932 RunTestCases(kWebIntentsTestCases, arraysize(kWebIntentsTestCases)); | 946 RunTestCases(kWebIntentsTestCases, arraysize(kWebIntentsTestCases)); |
933 } | 947 } |
934 | 948 |
935 // TODO(asanka): Add more tests. | 949 // TODO(asanka): Add more tests. |
936 // * Default download path is not writable. | 950 // * Default download path is not writable. |
937 // * Download path doesn't exist. | 951 // * Download path doesn't exist. |
938 // * IsDangerousFile(). | 952 // * IsDangerousFile(). |
939 // * Filename generation. | 953 // * Filename generation. |
OLD | NEW |