Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: content/browser/download/download_item_impl_unittest.cc

Issue 10344024: Rewrite download manager unit to be actual unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Modified creation comment. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/stl_util.h" 6 #include "base/stl_util.h"
7 #include "base/threading/thread.h" 7 #include "base/threading/thread.h"
8 #include "content/browser/download/byte_stream.h" 8 #include "content/browser/download/byte_stream.h"
9 #include "content/browser/download/download_create_info.h" 9 #include "content/browser/download/download_create_info.h"
10 #include "content/browser/download/download_file_manager.h" 10 #include "content/browser/download/download_file_manager.h"
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 AllOf(item, 543 AllOf(item,
544 Property(&DownloadItem::GetFullPath, final_path), 544 Property(&DownloadItem::GetFullPath, final_path),
545 Property(&DownloadItem::GetTargetFilePath, 545 Property(&DownloadItem::GetTargetFilePath,
546 final_path)))); 546 final_path))));
547 item->OnDownloadCompleting(file_manager.get()); 547 item->OnDownloadCompleting(file_manager.get());
548 RunAllPendingInMessageLoops(); 548 RunAllPendingInMessageLoops();
549 ::testing::Mock::VerifyAndClearExpectations(file_manager.get()); 549 ::testing::Mock::VerifyAndClearExpectations(file_manager.get());
550 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); 550 ::testing::Mock::VerifyAndClearExpectations(mock_delegate());
551 } 551 }
552 552
553 TEST_F(DownloadItemTest, Interrupted) {
554 DownloadItem* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
555
556 int64 size = 1022;
557 const std::string hash_state("Live beef");
558 const content::DownloadInterruptReason reason(
559 content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED);
560
561 // Confirm interrupt sets state properly.
562 item->Interrupted(size, hash_state, reason);
563 EXPECT_EQ(size, item->GetReceivedBytes());
564 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState());
565 EXPECT_EQ(hash_state, item->GetHashState());
566 EXPECT_EQ(reason, item->GetLastReason());
567
568 // Cancel should result in no change.
569 item->Cancel(true);
570 EXPECT_EQ(size, item->GetReceivedBytes());
571 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState());
572 EXPECT_EQ(hash_state, item->GetHashState());
573 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED,
574 item->GetLastReason());
575 }
576
577 TEST_F(DownloadItemTest, Canceled) {
578 DownloadItem* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
579
580 // Confirm cancel sets state properly.
581 EXPECT_CALL(*mock_delegate(), DownloadCancelled(item));
582 item->Cancel(true);
583 EXPECT_EQ(DownloadItem::CANCELLED, item->GetState());
584 }
585
586 TEST_F(DownloadItemTest, FileRemoved) {
587 DownloadItem* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
588
589 EXPECT_EQ(false, item->GetFileExternallyRemoved());
590 item->OnDownloadedFileRemoved();
591 EXPECT_EQ(true, item->GetFileExternallyRemoved());
592 }
593
553 TEST(MockDownloadItem, Compiles) { 594 TEST(MockDownloadItem, Compiles) {
554 MockDownloadItem mock_item; 595 MockDownloadItem mock_item;
555 } 596 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/download/download_manager_impl.h » ('j') | content/browser/download/download_manager_impl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698