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

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

Issue 11150027: Handle the case where IAttachmentExecute::Save() deletes a downloaded file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + Address comments + Update strings Created 8 years, 1 month 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_factory.h" 10 #include "content/browser/download/download_file_factory.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // EXPECT_CALL(download_file, Rename(_,_,_)) 71 // EXPECT_CALL(download_file, Rename(_,_,_))
72 // .WillOnce(ScheduleRenameCallback(new_path)); 72 // .WillOnce(ScheduleRenameCallback(new_path));
73 ACTION_P(ScheduleRenameCallback, new_path) { 73 ACTION_P(ScheduleRenameCallback, new_path) {
74 BrowserThread::PostTask( 74 BrowserThread::PostTask(
75 BrowserThread::UI, FROM_HERE, 75 BrowserThread::UI, FROM_HERE,
76 base::Bind(arg2, DOWNLOAD_INTERRUPT_REASON_NONE, new_path)); 76 base::Bind(arg2, DOWNLOAD_INTERRUPT_REASON_NONE, new_path));
77 } 77 }
78 78
79 // Schedules a task to invoke the input closure on 79 // Schedules a task to invoke the input closure on
80 // the UI thread. Should only be used as the action for 80 // the UI thread. Should only be used as the action for
81 // MockDownloadFile::Detach/Cancel as follows: 81 // MockDownloadFile::Detach as follows:
82 // EXPECT_CALL(download_file, Detach(_)) 82 // EXPECT_CALL(download_file, Detach(_))
83 // .WillOnce(ScheduleClosure())); 83 // .WillOnce(ScheduleDetachCallback()));
84 ACTION(ScheduleClosure) { 84 ACTION(ScheduleDetachCallback) {
85 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, arg0); 85 BrowserThread::PostTask(
86 } 86 BrowserThread::UI, FROM_HERE,
87 87 base::Bind(arg0, DOWNLOAD_INTERRUPT_REASON_NONE));
88 // Similarly for scheduling a completion callback.
89 ACTION(ScheduleCompleteCallback) {
90 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(arg1));
91 } 88 }
92 89
93 } // namespace 90 } // namespace
94 91
95 class DownloadItemTest : public testing::Test { 92 class DownloadItemTest : public testing::Test {
96 public: 93 public:
97 class MockObserver : public DownloadItem::Observer { 94 class MockObserver : public DownloadItem::Observer {
98 public: 95 public:
99 explicit MockObserver(DownloadItem* item) 96 explicit MockObserver(DownloadItem* item)
100 : item_(item), 97 : item_(item),
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 EXPECT_CALL(*mock_delegate(), 498 EXPECT_CALL(*mock_delegate(),
502 DownloadRenamedToFinalName( 499 DownloadRenamedToFinalName(
503 AllOf(item, 500 AllOf(item,
504 Property(&DownloadItem::GetFullPath, final_path), 501 Property(&DownloadItem::GetFullPath, final_path),
505 Property(&DownloadItem::GetTargetFilePath, 502 Property(&DownloadItem::GetTargetFilePath,
506 final_path)))); 503 final_path))));
507 EXPECT_CALL(*mock_delegate(), DownloadCompleted(item)); 504 EXPECT_CALL(*mock_delegate(), DownloadCompleted(item));
508 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item)) 505 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item))
509 .WillOnce(Return(true)); 506 .WillOnce(Return(true));
510 EXPECT_CALL(*download_file, Detach(_)) 507 EXPECT_CALL(*download_file, Detach(_))
511 .WillOnce(ScheduleClosure()); 508 .WillOnce(ScheduleDetachCallback());
512 item->SetIsPersisted(); 509 item->SetIsPersisted();
513 item->MaybeCompleteDownload(); 510 item->MaybeCompleteDownload();
514 RunAllPendingInMessageLoops(); 511 RunAllPendingInMessageLoops();
515 ::testing::Mock::VerifyAndClearExpectations(download_file); 512 ::testing::Mock::VerifyAndClearExpectations(download_file);
516 ::testing::Mock::VerifyAndClearExpectations(mock_delegate()); 513 ::testing::Mock::VerifyAndClearExpectations(mock_delegate());
517 } 514 }
518 515
519 TEST_F(DownloadItemTest, Interrupted) { 516 TEST_F(DownloadItemTest, Interrupted) {
520 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 517 DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
521 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item, NULL); 518 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item, NULL);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 EXPECT_EQ("livebeef", item->GetHash()); 630 EXPECT_EQ("livebeef", item->GetHash());
634 EXPECT_EQ("", item->GetHashState()); 631 EXPECT_EQ("", item->GetHashState());
635 EXPECT_TRUE(item->AllDataSaved()); 632 EXPECT_TRUE(item->AllDataSaved());
636 } 633 }
637 634
638 TEST(MockDownloadItem, Compiles) { 635 TEST(MockDownloadItem, Compiles) {
639 MockDownloadItem mock_item; 636 MockDownloadItem mock_item;
640 } 637 }
641 638
642 } // namespace content 639 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl.cc ('k') | content/browser/download/download_net_log_parameters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698