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

Unified Diff: content/browser/download/download_item_impl_unittest.cc

Issue 10831302: Download resumption - Preliminary (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed content unit tests. Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/download/download_item_impl_unittest.cc
diff --git a/content/browser/download/download_item_impl_unittest.cc b/content/browser/download/download_item_impl_unittest.cc
index 7a186af7659e9d242a7d1985e78fc8fd8b211a68..3915474bfde5f08d426d2574d41524474f431915 100644
--- a/content/browser/download/download_item_impl_unittest.cc
+++ b/content/browser/download/download_item_impl_unittest.cc
@@ -13,6 +13,7 @@
#include "content/browser/download/download_request_handle.h"
#include "content/public/browser/download_id.h"
#include "content/public/browser/download_interrupt_reasons.h"
+#include "content/public/browser/download_url_parameters.h"
#include "content/public/test/mock_download_item.h"
#include "content/public/test/test_browser_thread.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -40,7 +41,10 @@ class MockDelegate : public DownloadItemImplDelegate {
MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const FilePath& path));
MOCK_METHOD1(ShouldOpenDownload, bool(DownloadItemImpl* download));
MOCK_METHOD1(CheckForFileRemoval, void(DownloadItemImpl* download));
- MOCK_METHOD1(MaybeCompleteDownload, void(DownloadItemImpl* download));
+ MOCK_METHOD1(MaybeCompleteDownload, void(int32 download_id));
+ MOCK_METHOD2(RestartInterruptedDownload,
+ void(DownloadItemImpl* download,
+ const content::DownloadUrlParameters::OnStartedCallback&));
MOCK_CONST_METHOD0(GetBrowserContext, content::BrowserContext*());
MOCK_METHOD1(DownloadStopped, void(DownloadItemImpl* download));
MOCK_METHOD1(DownloadCompleted, void(DownloadItemImpl* download));
@@ -64,6 +68,8 @@ class MockRequestHandle : public DownloadRequestHandleInterface {
MOCK_CONST_METHOD0(PauseRequest, void());
MOCK_CONST_METHOD0(ResumeRequest, void());
MOCK_CONST_METHOD0(CancelRequest, void());
+ MOCK_METHOD1(SetRequestId, void(int new_request_id));
+ MOCK_CONST_METHOD0(RequestId, int());
MOCK_CONST_METHOD0(DebugString, std::string());
};
@@ -219,8 +225,8 @@ class DownloadItemTest : public testing::Test {
scoped_ptr<DownloadRequestHandleInterface> request_handle(
new testing::NiceMock<MockRequestHandle>);
DownloadItemImpl* download =
- new DownloadItemImpl(&delegate_, *(info_.get()),
- request_handle.Pass(), net::BoundNetLog());
+ new DownloadItemImpl(&delegate_, *(info_.get()), net::BoundNetLog());
+ download->SetRequest(request_handle.Pass());
allocated_downloads_.insert(download);
return download;
}
@@ -317,6 +323,9 @@ TEST_F(DownloadItemTest, NotificationAfterInterrupted) {
DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
MockObserver observer(item);
+ EXPECT_CALL(*mock_delegate(), RestartInterruptedDownload(_,_))
+ .Times(0);
+
item->Interrupt(content::DOWNLOAD_INTERRUPT_REASON_NONE);
ASSERT_TRUE(observer.CheckUpdated());
}
@@ -337,6 +346,45 @@ TEST_F(DownloadItemTest, NotificationAfterDestroyed) {
ASSERT_TRUE(observer.CheckDestroyed());
}
+TEST_F(DownloadItemTest, RestartAfterInterrupted) {
+ DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
+ MockObserver observer(item);
+ // Pretend we've recorded it in the history DB, to allow restart.
+ item->SetDbHandle(DownloadItem::kUninitializedHandle);
+ item->SetIsPersisted();
+
+ EXPECT_CALL(*mock_delegate(), RestartInterruptedDownload(item,_))
+ .Times(1);
+
+//EXPECT_CALL(item, IsInterrupted())
+// .Times(1)
+// .WillOnce(Return(true));
+
+ item->Interrupt(content::DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR);
+ ASSERT_TRUE(observer.CheckUpdated());
+}
+
+TEST_F(DownloadItemTest, LimitRestartsAfterInterrupted) {
+ DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
+ MockObserver observer(item);
+ // Pretend we've recorded it in the history DB, to allow restart.
+ item->SetDbHandle(DownloadItem::kUninitializedHandle);
+ item->SetIsPersisted();
+
+ EXPECT_CALL(*mock_delegate(), RestartInterruptedDownload(item,_))
+ .Times(DownloadItemImpl::kMaxAutoResumeAttempts);
+
+ scoped_ptr<DownloadRequestHandleInterface> request_handle(
+ new testing::NiceMock<MockRequestHandle>);
+
+ for (int i = 0; i < (DownloadItemImpl::kMaxAutoResumeAttempts + 2); ++i) {
+ item->Interrupt(content::DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR);
+ // Should call delegate->RestartInterruptedDownload() here, up to
+ // kMaxAutoResumeAttempts times.
+ item->Resume(request_handle.Pass());
+ }
+}
+
TEST_F(DownloadItemTest, NotificationAfterRemove) {
DownloadItemImpl* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
MockObserver observer(item);
@@ -512,9 +560,9 @@ TEST_F(DownloadItemTest, Interrupted) {
EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState());
EXPECT_EQ(reason, item->GetLastReason());
- // Cancel should result in no change.
+ // Cancel should kill it.
item->Cancel(true);
- EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState());
+ EXPECT_EQ(DownloadItem::CANCELLED, item->GetState());
EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED,
item->GetLastReason());
}

Powered by Google App Engine
This is Rietveld 408576698