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

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

Issue 1522893004: [Downloads] Use final URL for resumption. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@download-browsertest-cleanup
Patch Set: Created 5 years 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
« no previous file with comments | « content/browser/download/download_item_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 209a3c15bda3d3a79924c618337c4b8871bade69..4e482bd1db8cae669226acd705b49bcca51a5b1e 100644
--- a/content/browser/download/download_item_impl_unittest.cc
+++ b/content/browser/download/download_item_impl_unittest.cc
@@ -203,21 +203,22 @@ class DownloadItemTest : public testing::Test {
// be torn down at the end of the test unless DestroyDownloadItem is
// called.
DownloadItemImpl* CreateDownloadItem() {
- // Normally, the download system takes ownership of info, and is
- // responsible for deleting it. In these unit tests, however, we
- // don't call the function that deletes it, so we do so ourselves.
- scoped_ptr<DownloadCreateInfo> info_;
+ scoped_ptr<DownloadCreateInfo> info;
- info_.reset(new DownloadCreateInfo());
+ info.reset(new DownloadCreateInfo());
+ info->save_info = scoped_ptr<DownloadSaveInfo>(new DownloadSaveInfo());
+ info->save_info->prompt_for_save_location = false;
+ info->url_chain.push_back(GURL());
+ info->etag = "SomethingToSatisfyResumption";
+
+ return CreateDownloadItemWithCreateInfo(info.Pass());
+ }
+
+ DownloadItemImpl* CreateDownloadItemWithCreateInfo(
+ scoped_ptr<DownloadCreateInfo> info) {
static uint32 next_id = DownloadItem::kInvalidId + 1;
svaldez 2015/12/15 15:11:50 nit: Possibly move this out of the CreateDownload
asanka 2015/12/15 17:32:27 Done.
- info_->save_info = scoped_ptr<DownloadSaveInfo>(new DownloadSaveInfo());
- info_->save_info->prompt_for_save_location = false;
- info_->url_chain.push_back(GURL());
- info_->etag = "SomethingToSatisfyResumption";
-
- DownloadItemImpl* download =
- new DownloadItemImpl(
- &delegate_, next_id++, *(info_.get()), net::BoundNetLog());
+ DownloadItemImpl* download = new DownloadItemImpl(
+ &delegate_, next_id++, *(info.get()), net::BoundNetLog());
allocated_downloads_.insert(download);
return download;
}
@@ -404,7 +405,6 @@ TEST_F(DownloadItemTest, ContinueAfterInterrupted) {
TestBrowserContext test_browser_context;
DownloadItemImpl* item = CreateDownloadItem();
TestDownloadItemObserver observer(item);
- DownloadItemImplDelegate::DownloadTargetCallback callback;
MockDownloadFile* download_file =
DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
@@ -437,7 +437,6 @@ TEST_F(DownloadItemTest, RestartAfterInterrupted) {
DownloadItemImpl* item = CreateDownloadItem();
TestDownloadItemObserver observer(item);
- DownloadItemImplDelegate::DownloadTargetCallback callback;
MockDownloadFile* download_file =
DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
@@ -461,7 +460,6 @@ TEST_F(DownloadItemTest, UnresumableInterrupt) {
DownloadItemImpl* item = CreateDownloadItem();
TestDownloadItemObserver observer(item);
- DownloadItemImplDelegate::DownloadTargetCallback callback;
MockDownloadFile* download_file =
DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
@@ -546,6 +544,50 @@ TEST_F(DownloadItemTest, LimitRestartsAfterInterrupted) {
CleanupItem(item, mock_download_file, DownloadItem::INTERRUPTED);
}
+// Test that resumption uses the final URL in a URL chain when resuming.
+TEST_F(DownloadItemTest, ResumeUsingFinalURL) {
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableDownloadResumption);
+
+ TestBrowserContext test_browser_context;
+ scoped_ptr<DownloadCreateInfo> create_info(new DownloadCreateInfo);
+ create_info->save_info = scoped_ptr<DownloadSaveInfo>(new DownloadSaveInfo());
+ create_info->save_info->prompt_for_save_location = false;
+ create_info->etag = "SomethingToSatisfyResumption";
+ create_info->url_chain.push_back(GURL("http://example.com/a"));
+ create_info->url_chain.push_back(GURL("http://example.com/b"));
+ create_info->url_chain.push_back(GURL("http://example.com/c"));
+
+ DownloadItemImpl* item = CreateDownloadItemWithCreateInfo(create_info.Pass());
+ TestDownloadItemObserver observer(item);
+ MockDownloadFile* download_file =
+ DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
+
+ // Interrupt the download, using a continuable interrupt.
+ EXPECT_CALL(*download_file, FullPath()).WillOnce(Return(base::FilePath()));
+ EXPECT_CALL(*download_file, Detach());
+ EXPECT_CALL(*mock_delegate(), GetBrowserContext())
+ .WillRepeatedly(Return(&test_browser_context));
+ EXPECT_CALL(*mock_delegate(), MockResumeInterruptedDownload(
+ Property(&DownloadUrlParameters::url,
+ GURL("http://example.com/c")),
+ _))
+ .Times(1);
+ item->DestinationObserverAsWeakPtr()->DestinationError(
+ DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR);
+ ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
+ ASSERT_EQ(1, observer.interrupt_count());
+
+ // Test expectations verify that ResumeInterruptedDownload() is called (by way
+ // of MockResumeInterruptedDownload) after the download is interrupted. But
+ // the mock doesn't follow through with the resumption.
+ // ResumeInterruptedDownload() being called is sufficient for verifying that
+ // the resumption was triggered.
+ RunAllPendingInMessageLoops();
+
+ CleanupItem(item, download_file, DownloadItem::INTERRUPTED);
+}
+
TEST_F(DownloadItemTest, NotificationAfterRemove) {
DownloadItemImpl* item = CreateDownloadItem();
MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item, NULL);
« no previous file with comments | « content/browser/download/download_item_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698