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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 void(DownloadItem*, const FilePath&)); | 187 void(DownloadItem*, const FilePath&)); |
188 MOCK_METHOD1(RemoveItemFromPersistentStore, void(DownloadItem*)); | 188 MOCK_METHOD1(RemoveItemFromPersistentStore, void(DownloadItem*)); |
189 MOCK_METHOD2(RemoveItemsFromPersistentStoreBetween, void( | 189 MOCK_METHOD2(RemoveItemsFromPersistentStoreBetween, void( |
190 base::Time remove_begin, base::Time remove_end)); | 190 base::Time remove_begin, base::Time remove_end)); |
191 MOCK_METHOD4(GetSaveDir, void(WebContents*, FilePath*, FilePath*, bool*)); | 191 MOCK_METHOD4(GetSaveDir, void(WebContents*, FilePath*, FilePath*, bool*)); |
192 MOCK_METHOD5(ChooseSavePath, void( | 192 MOCK_METHOD5(ChooseSavePath, void( |
193 WebContents*, const FilePath&, const FilePath::StringType&, | 193 WebContents*, const FilePath&, const FilePath::StringType&, |
194 bool, const content::SavePackagePathPickedCallback&)); | 194 bool, const content::SavePackagePathPickedCallback&)); |
195 }; | 195 }; |
196 | 196 |
197 MockDownloadManagerDelegate::MockDownloadManagerDelegate() { } | 197 MockDownloadManagerDelegate::MockDownloadManagerDelegate() {} |
198 | 198 |
199 MockDownloadManagerDelegate::~MockDownloadManagerDelegate() { } | 199 MockDownloadManagerDelegate::~MockDownloadManagerDelegate() {} |
200 | 200 |
201 class MockDownloadFileManager : public DownloadFileManager { | 201 class MockDownloadFileManager : public DownloadFileManager { |
202 public: | 202 public: |
203 MockDownloadFileManager(); | 203 MockDownloadFileManager(); |
204 | 204 |
205 void CreateDownloadFile( | 205 void CreateDownloadFile( |
206 scoped_ptr<DownloadCreateInfo> info, | 206 scoped_ptr<DownloadCreateInfo> info, |
207 scoped_ptr<content::ByteStreamReader> stream, | 207 scoped_ptr<content::ByteStreamReader> stream, |
208 scoped_refptr<content::DownloadManager> download_manager, | 208 scoped_refptr<content::DownloadManager> download_manager, |
209 bool hash_needed, | 209 bool hash_needed, |
(...skipping 23 matching lines...) Expand all Loading... |
233 MOCK_METHOD4(RenameDownloadFile, void(content::DownloadId, | 233 MOCK_METHOD4(RenameDownloadFile, void(content::DownloadId, |
234 const FilePath&, | 234 const FilePath&, |
235 bool, | 235 bool, |
236 const RenameCompletionCallback&)); | 236 const RenameCompletionCallback&)); |
237 MOCK_CONST_METHOD0(NumberOfActiveDownloads, int()); | 237 MOCK_CONST_METHOD0(NumberOfActiveDownloads, int()); |
238 protected: | 238 protected: |
239 virtual ~MockDownloadFileManager(); | 239 virtual ~MockDownloadFileManager(); |
240 }; | 240 }; |
241 | 241 |
242 MockDownloadFileManager::MockDownloadFileManager() | 242 MockDownloadFileManager::MockDownloadFileManager() |
243 : DownloadFileManager(NULL) { } | 243 : DownloadFileManager(NULL) {} |
244 | 244 |
245 MockDownloadFileManager::~MockDownloadFileManager() { } | 245 MockDownloadFileManager::~MockDownloadFileManager() {} |
246 | 246 |
247 class MockDownloadItemFactory | 247 class MockDownloadItemFactory |
248 : public content::DownloadItemFactory, | 248 : public content::DownloadItemFactory, |
249 public base::SupportsWeakPtr<MockDownloadItemFactory> { | 249 public base::SupportsWeakPtr<MockDownloadItemFactory> { |
250 public: | 250 public: |
251 MockDownloadItemFactory(); | 251 MockDownloadItemFactory(); |
252 virtual ~MockDownloadItemFactory(); | 252 virtual ~MockDownloadItemFactory(); |
253 | 253 |
254 // Access to map of created items. | 254 // Access to map of created items. |
255 // TODO(rdsmith): Could add type (save page, persisted, etc.) | 255 // TODO(rdsmith): Could add type (save page, persisted, etc.) |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 new StrictMock<MockDownloadItemImpl>(&item_delegate_); | 370 new StrictMock<MockDownloadItemImpl>(&item_delegate_); |
371 EXPECT_CALL(*result, GetId()) | 371 EXPECT_CALL(*result, GetId()) |
372 .WillRepeatedly(Return(local_id)); | 372 .WillRepeatedly(Return(local_id)); |
373 items_[local_id] = result; | 373 items_[local_id] = result; |
374 | 374 |
375 return result; | 375 return result; |
376 } | 376 } |
377 | 377 |
378 class MockBrowserContext : public content::BrowserContext { | 378 class MockBrowserContext : public content::BrowserContext { |
379 public: | 379 public: |
380 MockBrowserContext() { } | 380 MockBrowserContext() {} |
381 ~MockBrowserContext() { } | 381 ~MockBrowserContext() {} |
382 | 382 |
383 MOCK_METHOD0(GetPath, FilePath()); | 383 MOCK_METHOD0(GetPath, FilePath()); |
384 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); | 384 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); |
385 MOCK_METHOD0(GetRequestContext, net::URLRequestContextGetter*()); | 385 MOCK_METHOD0(GetRequestContext, net::URLRequestContextGetter*()); |
386 MOCK_METHOD1(GetRequestContextForRenderProcess, | 386 MOCK_METHOD1(GetRequestContextForRenderProcess, |
387 net::URLRequestContextGetter*(int renderer_child_id)); | 387 net::URLRequestContextGetter*(int renderer_child_id)); |
388 MOCK_METHOD0(GetRequestContextForMedia, net::URLRequestContextGetter*()); | 388 MOCK_METHOD0(GetRequestContextForMedia, net::URLRequestContextGetter*()); |
389 MOCK_METHOD0(GetResourceContext, content::ResourceContext*()); | 389 MOCK_METHOD0(GetResourceContext, content::ResourceContext*()); |
390 MOCK_METHOD0(GetDownloadManagerDelegate, content::DownloadManagerDelegate*()); | 390 MOCK_METHOD0(GetDownloadManagerDelegate, content::DownloadManagerDelegate*()); |
391 MOCK_METHOD0(GetGeolocationPermissionContext, | 391 MOCK_METHOD0(GetGeolocationPermissionContext, |
392 content::GeolocationPermissionContext* ()); | 392 content::GeolocationPermissionContext* ()); |
393 MOCK_METHOD0(GetSpeechRecognitionPreferences, | 393 MOCK_METHOD0(GetSpeechRecognitionPreferences, |
394 content::SpeechRecognitionPreferences* ()); | 394 content::SpeechRecognitionPreferences* ()); |
395 MOCK_METHOD0(DidLastSessionExitCleanly, bool()); | 395 MOCK_METHOD0(DidLastSessionExitCleanly, bool()); |
396 MOCK_METHOD0(GetSpecialStoragePolicy, quota::SpecialStoragePolicy*()); | 396 MOCK_METHOD0(GetSpecialStoragePolicy, quota::SpecialStoragePolicy*()); |
397 }; | 397 }; |
398 | 398 |
| 399 class MockDownloadManagerObserver : public content::DownloadManager::Observer { |
| 400 public: |
| 401 MockDownloadManagerObserver() {} |
| 402 ~MockDownloadManagerObserver() {} |
| 403 MOCK_METHOD2(OnDownloadCreated, void( |
| 404 content::DownloadManager*, content::DownloadItem*)); |
| 405 MOCK_METHOD1(ModelChanged, void(content::DownloadManager*)); |
| 406 MOCK_METHOD1(ManagerGoingDown, void(content::DownloadManager*)); |
| 407 MOCK_METHOD2(SelectFileDialogDisplayed, void( |
| 408 content::DownloadManager*, int32)); |
| 409 }; |
| 410 |
399 } // namespace | 411 } // namespace |
400 | 412 |
401 class DownloadManagerTest : public testing::Test { | 413 class DownloadManagerTest : public testing::Test { |
402 public: | 414 public: |
403 static const char* kTestData; | 415 static const char* kTestData; |
404 static const size_t kTestDataLen; | 416 static const size_t kTestDataLen; |
405 | 417 |
406 DownloadManagerTest() | 418 DownloadManagerTest() |
407 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 419 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
408 file_thread_(content::BrowserThread::FILE, &message_loop_), | 420 file_thread_(content::BrowserThread::FILE, &message_loop_), |
(...skipping 18 matching lines...) Expand all Loading... |
427 EXPECT_CALL(*mock_download_file_manager_.get(), | 439 EXPECT_CALL(*mock_download_file_manager_.get(), |
428 OnDownloadManagerShutdown(_)); | 440 OnDownloadManagerShutdown(_)); |
429 mock_browser_context_.reset(new StrictMock<MockBrowserContext>); | 441 mock_browser_context_.reset(new StrictMock<MockBrowserContext>); |
430 EXPECT_CALL(*mock_browser_context_.get(), IsOffTheRecord()) | 442 EXPECT_CALL(*mock_browser_context_.get(), IsOffTheRecord()) |
431 .WillRepeatedly(Return(false)); | 443 .WillRepeatedly(Return(false)); |
432 | 444 |
433 download_manager_ = new DownloadManagerImpl( | 445 download_manager_ = new DownloadManagerImpl( |
434 mock_download_file_manager_.get(), | 446 mock_download_file_manager_.get(), |
435 scoped_ptr<content::DownloadItemFactory>( | 447 scoped_ptr<content::DownloadItemFactory>( |
436 mock_download_item_factory_.get()).Pass(), NULL); | 448 mock_download_item_factory_.get()).Pass(), NULL); |
| 449 observer_.reset(new MockDownloadManagerObserver()); |
| 450 EXPECT_CALL(GetMockObserver(), ModelChanged(download_manager_.get())) |
| 451 .WillOnce(Return()); |
| 452 download_manager_->AddObserver(observer_.get()); |
437 download_manager_->SetDelegate(mock_download_manager_delegate_.get()); | 453 download_manager_->SetDelegate(mock_download_manager_delegate_.get()); |
438 download_manager_->Init(mock_browser_context_.get()); | 454 download_manager_->Init(mock_browser_context_.get()); |
439 } | 455 } |
440 | 456 |
441 virtual void TearDown() { | 457 virtual void TearDown() { |
442 while (MockDownloadItemImpl* | 458 while (MockDownloadItemImpl* |
443 item = mock_download_item_factory_->PopItem()) { | 459 item = mock_download_item_factory_->PopItem()) { |
444 EXPECT_CALL(*item, GetSafetyState()) | 460 EXPECT_CALL(*item, GetSafetyState()) |
445 .WillOnce(Return(content::DownloadItem::SAFE)); | 461 .WillOnce(Return(content::DownloadItem::SAFE)); |
446 EXPECT_CALL(*item, IsPartialDownload()) | 462 EXPECT_CALL(*item, IsPartialDownload()) |
447 .WillOnce(Return(false)); | 463 .WillOnce(Return(false)); |
448 } | 464 } |
| 465 EXPECT_CALL(GetMockObserver(), ManagerGoingDown(download_manager_.get())) |
| 466 .WillOnce(Return()); |
449 | 467 |
450 download_manager_->Shutdown(); | 468 download_manager_->Shutdown(); |
451 download_manager_ = NULL; | 469 download_manager_ = NULL; |
452 message_loop_.RunAllPending(); | 470 message_loop_.RunAllPending(); |
453 ASSERT_EQ(NULL, mock_download_item_factory_.get()); | 471 ASSERT_EQ(NULL, mock_download_item_factory_.get()); |
454 message_loop_.RunAllPending(); | 472 message_loop_.RunAllPending(); |
455 mock_download_manager_delegate_.reset(); | 473 mock_download_manager_delegate_.reset(); |
456 mock_download_file_manager_ = NULL; | 474 mock_download_file_manager_ = NULL; |
457 mock_browser_context_.reset(); | 475 mock_browser_context_.reset(); |
458 } | 476 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 } | 510 } |
493 | 511 |
494 MockDownloadManagerDelegate& GetMockDownloadManagerDelegate() { | 512 MockDownloadManagerDelegate& GetMockDownloadManagerDelegate() { |
495 return *mock_download_manager_delegate_; | 513 return *mock_download_manager_delegate_; |
496 } | 514 } |
497 | 515 |
498 MockDownloadFileManager& GetMockDownloadFileManager() { | 516 MockDownloadFileManager& GetMockDownloadFileManager() { |
499 return *mock_download_file_manager_; | 517 return *mock_download_file_manager_; |
500 } | 518 } |
501 | 519 |
| 520 MockDownloadManagerObserver& GetMockObserver() { |
| 521 return *observer_; |
| 522 } |
| 523 |
502 // Probe at private internals. | 524 // Probe at private internals. |
503 void DownloadStopped(DownloadItemImpl* item) { | 525 void DownloadStopped(DownloadItemImpl* item) { |
504 download_manager_->DownloadStopped(item); | 526 download_manager_->DownloadStopped(item); |
505 } | 527 } |
506 | 528 |
507 void AddItemToHistory(MockDownloadItemImpl& item, int64 db_handle) { | 529 void AddItemToHistory(MockDownloadItemImpl& item, int64 db_handle) { |
508 // For DCHECK in AddDownloadItemToHistory. Don't want to use | 530 // For DCHECK in AddDownloadItemToHistory. Don't want to use |
509 // WillRepeatedly as it may have to return true after this. | 531 // WillRepeatedly as it may have to return true after this. |
510 if (DCHECK_IS_ON()) | 532 if (DCHECK_IS_ON()) |
511 EXPECT_CALL(item, IsPersisted()) | 533 EXPECT_CALL(item, IsPersisted()) |
(...skipping 26 matching lines...) Expand all Loading... |
538 scoped_refptr<DownloadManagerImpl> download_manager_; | 560 scoped_refptr<DownloadManagerImpl> download_manager_; |
539 | 561 |
540 private: | 562 private: |
541 MessageLoopForUI message_loop_; | 563 MessageLoopForUI message_loop_; |
542 content::TestBrowserThread ui_thread_; | 564 content::TestBrowserThread ui_thread_; |
543 content::TestBrowserThread file_thread_; | 565 content::TestBrowserThread file_thread_; |
544 base::WeakPtr<MockDownloadItemFactory> mock_download_item_factory_; | 566 base::WeakPtr<MockDownloadItemFactory> mock_download_item_factory_; |
545 scoped_ptr<MockDownloadManagerDelegate> mock_download_manager_delegate_; | 567 scoped_ptr<MockDownloadManagerDelegate> mock_download_manager_delegate_; |
546 scoped_refptr<MockDownloadFileManager> mock_download_file_manager_; | 568 scoped_refptr<MockDownloadFileManager> mock_download_file_manager_; |
547 scoped_ptr<MockBrowserContext> mock_browser_context_; | 569 scoped_ptr<MockBrowserContext> mock_browser_context_; |
| 570 scoped_ptr<MockDownloadManagerObserver> observer_; |
548 int next_download_id_; | 571 int next_download_id_; |
549 | 572 |
550 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); | 573 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); |
551 }; | 574 }; |
552 | 575 |
553 // Confirm the appropriate invocations occur when you start a download. | 576 // Confirm the appropriate invocations occur when you start a download. |
554 TEST_F(DownloadManagerTest, StartDownload) { | 577 TEST_F(DownloadManagerTest, StartDownload) { |
555 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); | 578 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); |
556 scoped_ptr<content::ByteStreamReader> stream; | 579 scoped_ptr<content::ByteStreamReader> stream; |
557 int32 local_id(5); // Random value | 580 int32 local_id(5); // Random value |
558 | 581 |
559 EXPECT_FALSE(download_manager_->GetActiveDownloadItem(local_id)); | 582 EXPECT_FALSE(download_manager_->GetActiveDownloadItem(local_id)); |
560 | 583 |
| 584 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
| 585 .WillOnce(Return()); |
561 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId()) | 586 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId()) |
562 .WillOnce(Return(content::DownloadId(this, local_id))); | 587 .WillOnce(Return(content::DownloadId(this, local_id))); |
563 EXPECT_CALL(GetMockDownloadManagerDelegate(), GenerateFileHash()) | 588 EXPECT_CALL(GetMockDownloadManagerDelegate(), GenerateFileHash()) |
564 .WillOnce(Return(true)); | 589 .WillOnce(Return(true)); |
565 EXPECT_CALL(GetMockDownloadFileManager(), MockCreateDownloadFile( | 590 EXPECT_CALL(GetMockDownloadFileManager(), MockCreateDownloadFile( |
566 info.get(), static_cast<content::ByteStreamReader*>(NULL), | 591 info.get(), static_cast<content::ByteStreamReader*>(NULL), |
567 download_manager_.get(), true, _, _)); | 592 download_manager_.get(), true, _, _)); |
568 | 593 |
569 download_manager_->StartDownload(info.Pass(), stream.Pass()); | 594 download_manager_->StartDownload(info.Pass(), stream.Pass()); |
570 EXPECT_TRUE(download_manager_->GetActiveDownloadItem(local_id)); | 595 EXPECT_TRUE(download_manager_->GetActiveDownloadItem(local_id)); |
571 } | 596 } |
572 | 597 |
573 // Does the DownloadManager prompt when requested? | 598 // Does the DownloadManager prompt when requested? |
574 TEST_F(DownloadManagerTest, RestartDownload) { | 599 TEST_F(DownloadManagerTest, RestartDownload) { |
| 600 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
| 601 .WillOnce(Return()); |
| 602 EXPECT_CALL(GetMockObserver(), SelectFileDialogDisplayed( |
| 603 download_manager_.get(), 0)).WillOnce(Return()); |
575 // Put a mock we have a handle to on the download manager. | 604 // Put a mock we have a handle to on the download manager. |
576 MockDownloadItemImpl& item(AddItemToManager()); | 605 MockDownloadItemImpl& item(AddItemToManager()); |
577 int download_id = item.GetId(); | 606 int download_id = item.GetId(); |
578 | 607 |
579 // Confirm we're internally consistent. | 608 // Confirm we're internally consistent. |
580 EXPECT_EQ(&item, download_manager_->GetActiveDownloadItem(download_id)); | 609 EXPECT_EQ(&item, download_manager_->GetActiveDownloadItem(download_id)); |
581 | 610 |
582 ScopedTempDir download_dir; | 611 ScopedTempDir download_dir; |
583 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); | 612 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); |
584 FilePath expected_path(download_dir.path().Append( | 613 FilePath expected_path(download_dir.path().Append( |
585 FILE_PATH_LITERAL("location"))); | 614 FILE_PATH_LITERAL("location"))); |
586 | 615 |
587 EXPECT_CALL(item, GetTargetDisposition()) | 616 EXPECT_CALL(item, GetTargetDisposition()) |
588 .WillOnce(Return(DownloadItem::TARGET_DISPOSITION_PROMPT)); | 617 .WillOnce(Return(DownloadItem::TARGET_DISPOSITION_PROMPT)); |
589 EXPECT_CALL(GetMockDownloadManagerDelegate(), ChooseDownloadPath(&item)); | 618 EXPECT_CALL(GetMockDownloadManagerDelegate(), ChooseDownloadPath(&item)); |
590 download_manager_->RestartDownload(download_id); | 619 download_manager_->RestartDownload(download_id); |
591 | 620 |
592 // The alternative pathway goes straight to OnTargetPathAvailable, | 621 // The alternative pathway goes straight to OnTargetPathAvailable, |
593 // so it more naturally belongs below. | 622 // so it more naturally belongs below. |
594 } | 623 } |
595 | 624 |
596 // Do the results of GetIntermediatePath get passed through to the | 625 // Do the results of GetIntermediatePath get passed through to the |
597 // download? Note that this path is tested from RestartDownload | 626 // download? Note that this path is tested from RestartDownload |
598 // to test the non-prompting path in RestartDownload as well. | 627 // to test the non-prompting path in RestartDownload as well. |
599 TEST_F(DownloadManagerTest, OnTargetPathAvailable) { | 628 TEST_F(DownloadManagerTest, OnTargetPathAvailable) { |
| 629 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
| 630 .WillOnce(Return()); |
600 // Put a mock we have a handle to on the download manager. | 631 // Put a mock we have a handle to on the download manager. |
601 MockDownloadItemImpl& item(AddItemToManager()); | 632 MockDownloadItemImpl& item(AddItemToManager()); |
602 | 633 |
603 ScopedTempDir download_dir; | 634 ScopedTempDir download_dir; |
604 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); | 635 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); |
605 FilePath target_path(download_dir.path().Append( | 636 FilePath target_path(download_dir.path().Append( |
606 FILE_PATH_LITERAL("location"))); | 637 FILE_PATH_LITERAL("location"))); |
607 FilePath intermediate_path(download_dir.path().Append( | 638 FilePath intermediate_path(download_dir.path().Append( |
608 FILE_PATH_LITERAL("location.crdownload"))); | 639 FILE_PATH_LITERAL("location.crdownload"))); |
609 | 640 |
610 EXPECT_CALL(item, GetTargetDisposition()) | 641 EXPECT_CALL(item, GetTargetDisposition()) |
611 .WillOnce(Return(DownloadItem::TARGET_DISPOSITION_OVERWRITE)); | 642 .WillOnce(Return(DownloadItem::TARGET_DISPOSITION_OVERWRITE)); |
612 EXPECT_CALL(GetMockDownloadManagerDelegate(), | 643 EXPECT_CALL(GetMockDownloadManagerDelegate(), |
613 GetIntermediatePath(Ref(item))) | 644 GetIntermediatePath(Ref(item))) |
614 .WillOnce(Return(intermediate_path)); | 645 .WillOnce(Return(intermediate_path)); |
615 // Finesse DCHECK with WillRepeatedly. | 646 // Finesse DCHECK with WillRepeatedly. |
616 EXPECT_CALL(item, GetTargetFilePath()) | 647 EXPECT_CALL(item, GetTargetFilePath()) |
617 .WillRepeatedly(ReturnRef(target_path)); | 648 .WillRepeatedly(ReturnRef(target_path)); |
618 EXPECT_CALL(item, OnIntermediatePathDetermined( | 649 EXPECT_CALL(item, OnIntermediatePathDetermined( |
619 &GetMockDownloadFileManager(), intermediate_path)); | 650 &GetMockDownloadFileManager(), intermediate_path)); |
620 download_manager_->RestartDownload(item.GetId()); | 651 download_manager_->RestartDownload(item.GetId()); |
621 } | 652 } |
622 | 653 |
623 // Do the results of an OnDownloadInterrupted get passed through properly | 654 // Do the results of an OnDownloadInterrupted get passed through properly |
624 // to the DownloadItem? | 655 // to the DownloadItem? |
625 TEST_F(DownloadManagerTest, OnDownloadInterrupted) { | 656 TEST_F(DownloadManagerTest, OnDownloadInterrupted) { |
| 657 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
| 658 .WillOnce(Return()); |
626 // Put a mock we have a handle to on the download manager. | 659 // Put a mock we have a handle to on the download manager. |
627 MockDownloadItemImpl& item(AddItemToManager()); | 660 MockDownloadItemImpl& item(AddItemToManager()); |
628 int download_id = item.GetId(); | 661 int download_id = item.GetId(); |
629 | 662 |
630 content::DownloadInterruptReason reason( | 663 content::DownloadInterruptReason reason( |
631 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); | 664 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); |
632 | 665 |
633 EXPECT_CALL(item, Interrupt(reason)); | 666 EXPECT_CALL(item, Interrupt(reason)); |
634 download_manager_->OnDownloadInterrupted(download_id, reason); | 667 download_manager_->OnDownloadInterrupted(download_id, reason); |
635 EXPECT_EQ(&item, download_manager_->GetActiveDownloadItem(download_id)); | 668 EXPECT_EQ(&item, download_manager_->GetActiveDownloadItem(download_id)); |
636 } | 669 } |
637 | 670 |
638 // Does DownloadStopped remove Download from appropriate queues? | 671 // Does DownloadStopped remove Download from appropriate queues? |
639 // This test tests non-persisted downloads. | 672 // This test tests non-persisted downloads. |
640 TEST_F(DownloadManagerTest, OnDownloadStopped_NonPersisted) { | 673 TEST_F(DownloadManagerTest, OnDownloadStopped_NonPersisted) { |
| 674 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
| 675 .WillOnce(Return()); |
641 // Put a mock we have a handle to on the download manager. | 676 // Put a mock we have a handle to on the download manager. |
642 MockDownloadItemImpl& item(AddItemToManager()); | 677 MockDownloadItemImpl& item(AddItemToManager()); |
643 | 678 |
644 EXPECT_CALL(item, IsPersisted()) | 679 EXPECT_CALL(item, IsPersisted()) |
645 .WillRepeatedly(Return(false)); | 680 .WillRepeatedly(Return(false)); |
646 EXPECT_CALL(item, GetState()) | 681 EXPECT_CALL(item, GetState()) |
647 .WillRepeatedly(Return(DownloadItem::CANCELLED)); | 682 .WillRepeatedly(Return(DownloadItem::CANCELLED)); |
648 EXPECT_CALL(item, GetDbHandle()) | 683 EXPECT_CALL(item, GetDbHandle()) |
649 .WillRepeatedly(Return(DownloadItem::kUninitializedHandle)); | 684 .WillRepeatedly(Return(DownloadItem::kUninitializedHandle)); |
650 | 685 |
651 EXPECT_CALL(item, OffThreadCancel(&GetMockDownloadFileManager())); | 686 EXPECT_CALL(item, OffThreadCancel(&GetMockDownloadFileManager())); |
652 DownloadStopped(&item); | 687 DownloadStopped(&item); |
653 // TODO(rdsmith): Confirm that the download item is no longer on the | 688 // TODO(rdsmith): Confirm that the download item is no longer on the |
654 // active list by calling download_manager_->GetActiveDownloadItem(id). | 689 // active list by calling download_manager_->GetActiveDownloadItem(id). |
655 // Currently, the item is left on the active list for rendez-vous with | 690 // Currently, the item is left on the active list for rendez-vous with |
656 // the history system :-{. | 691 // the history system :-{. |
657 } | 692 } |
658 | 693 |
659 // Does DownloadStopped remove Download from appropriate queues? | 694 // Does DownloadStopped remove Download from appropriate queues? |
660 // This test tests persisted downloads. | 695 // This test tests persisted downloads. |
661 TEST_F(DownloadManagerTest, OnDownloadStopped_Persisted) { | 696 TEST_F(DownloadManagerTest, OnDownloadStopped_Persisted) { |
| 697 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) |
| 698 .WillOnce(Return()); |
662 // Put a mock we have a handle to on the download manager. | 699 // Put a mock we have a handle to on the download manager. |
663 MockDownloadItemImpl& item(AddItemToManager()); | 700 MockDownloadItemImpl& item(AddItemToManager()); |
664 int download_id = item.GetId(); | 701 int download_id = item.GetId(); |
665 int64 db_handle = 0x7; | 702 int64 db_handle = 0x7; |
666 EXPECT_CALL(item, GetExternalData(_)) | 703 EXPECT_CALL(item, GetExternalData(_)) |
667 .WillOnce(Return(static_cast<DownloadItem::ExternalData*>(NULL))); | 704 .WillOnce(Return(static_cast<DownloadItem::ExternalData*>(NULL))); |
| 705 EXPECT_CALL(GetMockObserver(), ModelChanged(download_manager_.get())) |
| 706 .WillOnce(Return()); |
668 AddItemToHistory(item, db_handle); | 707 AddItemToHistory(item, db_handle); |
669 | 708 |
670 EXPECT_CALL(item, IsPersisted()) | 709 EXPECT_CALL(item, IsPersisted()) |
671 .WillRepeatedly(Return(true)); | 710 .WillRepeatedly(Return(true)); |
672 EXPECT_CALL(GetMockDownloadManagerDelegate(), | 711 EXPECT_CALL(GetMockDownloadManagerDelegate(), |
673 UpdateItemInPersistentStore(&item)); | 712 UpdateItemInPersistentStore(&item)); |
674 EXPECT_CALL(item, GetState()) | 713 EXPECT_CALL(item, GetState()) |
675 .WillRepeatedly(Return(DownloadItem::CANCELLED)); | 714 .WillRepeatedly(Return(DownloadItem::CANCELLED)); |
676 EXPECT_CALL(item, GetDbHandle()) | 715 EXPECT_CALL(item, GetDbHandle()) |
677 .WillRepeatedly(Return(db_handle)); | 716 .WillRepeatedly(Return(db_handle)); |
678 | 717 |
679 EXPECT_CALL(item, OffThreadCancel(&GetMockDownloadFileManager())); | 718 EXPECT_CALL(item, OffThreadCancel(&GetMockDownloadFileManager())); |
680 DownloadStopped(&item); | 719 DownloadStopped(&item); |
681 EXPECT_EQ(NULL, download_manager_->GetActiveDownloadItem(download_id)); | 720 EXPECT_EQ(NULL, download_manager_->GetActiveDownloadItem(download_id)); |
682 } | 721 } |
OLD | NEW |