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

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

Issue 1538933002: Enable download resumption by default. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Forgot ChromeOS 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 unified diff | Download patch
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/callback.h" 5 #include "base/callback.h"
6 #include "base/command_line.h" 6 #include "base/feature_list.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 #include "content/browser/byte_stream.h" 10 #include "content/browser/byte_stream.h"
11 #include "content/browser/download/download_create_info.h" 11 #include "content/browser/download/download_create_info.h"
12 #include "content/browser/download/download_file_factory.h" 12 #include "content/browser/download/download_file_factory.h"
13 #include "content/browser/download/download_item_impl.h" 13 #include "content/browser/download/download_item_impl.h"
14 #include "content/browser/download/download_item_impl_delegate.h" 14 #include "content/browser/download/download_item_impl_delegate.h"
15 #include "content/browser/download/download_request_handle.h" 15 #include "content/browser/download/download_request_handle.h"
16 #include "content/browser/download/mock_download_file.h" 16 #include "content/browser/download/mock_download_file.h"
17 #include "content/public/browser/download_destination_observer.h" 17 #include "content/public/browser/download_destination_observer.h"
18 #include "content/public/browser/download_interrupt_reasons.h" 18 #include "content/public/browser/download_interrupt_reasons.h"
19 #include "content/public/browser/download_url_parameters.h" 19 #include "content/public/browser/download_url_parameters.h"
20 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_features.h"
21 #include "content/public/test/mock_download_item.h" 21 #include "content/public/test/mock_download_item.h"
22 #include "content/public/test/test_browser_context.h" 22 #include "content/public/test/test_browser_context.h"
23 #include "content/public/test/test_browser_thread.h" 23 #include "content/public/test/test_browser_thread.h"
24 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 26
27 using ::testing::_; 27 using ::testing::_;
28 using ::testing::NiceMock; 28 using ::testing::NiceMock;
29 using ::testing::Property; 29 using ::testing::Property;
30 using ::testing::Return; 30 using ::testing::Return;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 DownloadItemTest() 185 DownloadItemTest()
186 : ui_thread_(BrowserThread::UI, &loop_), 186 : ui_thread_(BrowserThread::UI, &loop_),
187 file_thread_(BrowserThread::FILE, &loop_), 187 file_thread_(BrowserThread::FILE, &loop_),
188 delegate_() { 188 delegate_() {
189 } 189 }
190 190
191 ~DownloadItemTest() { 191 ~DownloadItemTest() {
192 } 192 }
193 193
194 virtual void SetUp() { 194 virtual void SetUp() {
195 base::FeatureList::ClearInstanceForTesting();
196 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList);
197 feature_list->InitializeFromCommandLine(features::kDownloadResumption.name,
198 std::string());
199 base::FeatureList::SetInstance(std::move(feature_list));
195 } 200 }
196 201
197 virtual void TearDown() { 202 virtual void TearDown() {
198 ui_thread_.DeprecatedGetThreadObject()->message_loop()->RunUntilIdle(); 203 ui_thread_.DeprecatedGetThreadObject()->message_loop()->RunUntilIdle();
199 STLDeleteElements(&allocated_downloads_); 204 STLDeleteElements(&allocated_downloads_);
200 } 205 }
201 206
202 // This class keeps ownership of the created download item; it will 207 // This class keeps ownership of the created download item; it will
203 // be torn down at the end of the test unless DestroyDownloadItem is 208 // be torn down at the end of the test unless DestroyDownloadItem is
204 // called. 209 // called.
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 397
393 TEST_F(DownloadItemTest, NotificationAfterDestroyed) { 398 TEST_F(DownloadItemTest, NotificationAfterDestroyed) {
394 DownloadItemImpl* item = CreateDownloadItem(); 399 DownloadItemImpl* item = CreateDownloadItem();
395 TestDownloadItemObserver observer(item); 400 TestDownloadItemObserver observer(item);
396 401
397 DestroyDownloadItem(item); 402 DestroyDownloadItem(item);
398 ASSERT_TRUE(observer.download_destroyed()); 403 ASSERT_TRUE(observer.download_destroyed());
399 } 404 }
400 405
401 TEST_F(DownloadItemTest, ContinueAfterInterrupted) { 406 TEST_F(DownloadItemTest, ContinueAfterInterrupted) {
402 base::CommandLine::ForCurrentProcess()->AppendSwitch(
403 switches::kEnableDownloadResumption);
404
405 TestBrowserContext test_browser_context; 407 TestBrowserContext test_browser_context;
406 DownloadItemImpl* item = CreateDownloadItem(); 408 DownloadItemImpl* item = CreateDownloadItem();
407 TestDownloadItemObserver observer(item); 409 TestDownloadItemObserver observer(item);
408 MockDownloadFile* download_file = 410 MockDownloadFile* download_file =
409 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 411 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
410 412
411 // Interrupt the download, using a continuable interrupt. 413 // Interrupt the download, using a continuable interrupt.
412 EXPECT_CALL(*download_file, FullPath()) 414 EXPECT_CALL(*download_file, FullPath())
413 .WillOnce(Return(base::FilePath())); 415 .WillOnce(Return(base::FilePath()));
414 EXPECT_CALL(*download_file, Detach()); 416 EXPECT_CALL(*download_file, Detach());
(...skipping 10 matching lines...) Expand all
425 // the mock doesn't follow through with the resumption. 427 // the mock doesn't follow through with the resumption.
426 // ResumeInterruptedDownload() being called is sufficient for verifying that 428 // ResumeInterruptedDownload() being called is sufficient for verifying that
427 // the automatic resumption was triggered. 429 // the automatic resumption was triggered.
428 RunAllPendingInMessageLoops(); 430 RunAllPendingInMessageLoops();
429 431
430 CleanupItem(item, download_file, DownloadItem::INTERRUPTED); 432 CleanupItem(item, download_file, DownloadItem::INTERRUPTED);
431 } 433 }
432 434
433 // Same as above, but with a non-continuable interrupt. 435 // Same as above, but with a non-continuable interrupt.
434 TEST_F(DownloadItemTest, RestartAfterInterrupted) { 436 TEST_F(DownloadItemTest, RestartAfterInterrupted) {
435 base::CommandLine::ForCurrentProcess()->AppendSwitch(
436 switches::kEnableDownloadResumption);
437
438 DownloadItemImpl* item = CreateDownloadItem(); 437 DownloadItemImpl* item = CreateDownloadItem();
439 TestDownloadItemObserver observer(item); 438 TestDownloadItemObserver observer(item);
440 MockDownloadFile* download_file = 439 MockDownloadFile* download_file =
441 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 440 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
442 441
443 // Interrupt the download, using a restartable interrupt. 442 // Interrupt the download, using a restartable interrupt.
444 EXPECT_CALL(*download_file, Cancel()); 443 EXPECT_CALL(*download_file, Cancel());
445 item->DestinationObserverAsWeakPtr()->DestinationError( 444 item->DestinationObserverAsWeakPtr()->DestinationError(
446 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); 445 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED);
447 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated()); 446 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
448 // Should not try to auto-resume. 447 // Should not try to auto-resume.
449 ASSERT_EQ(1, observer.interrupt_count()); 448 ASSERT_EQ(1, observer.interrupt_count());
450 ASSERT_EQ(0, observer.resume_count()); 449 ASSERT_EQ(0, observer.resume_count());
451 RunAllPendingInMessageLoops(); 450 RunAllPendingInMessageLoops();
452 451
453 CleanupItem(item, download_file, DownloadItem::INTERRUPTED); 452 CleanupItem(item, download_file, DownloadItem::INTERRUPTED);
454 } 453 }
455 454
456 // Check we do correct cleanup for RESUME_MODE_INVALID interrupts. 455 // Check we do correct cleanup for RESUME_MODE_INVALID interrupts.
457 TEST_F(DownloadItemTest, UnresumableInterrupt) { 456 TEST_F(DownloadItemTest, UnresumableInterrupt) {
458 base::CommandLine::ForCurrentProcess()->AppendSwitch(
459 switches::kEnableDownloadResumption);
460
461 DownloadItemImpl* item = CreateDownloadItem(); 457 DownloadItemImpl* item = CreateDownloadItem();
462 TestDownloadItemObserver observer(item); 458 TestDownloadItemObserver observer(item);
463 MockDownloadFile* download_file = 459 MockDownloadFile* download_file =
464 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 460 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
465 461
466 // Fail final rename with unresumable reason. 462 // Fail final rename with unresumable reason.
467 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) 463 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _))
468 .WillOnce(Return(true)); 464 .WillOnce(Return(true));
469 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) 465 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _))
470 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED, 466 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED,
471 base::FilePath(kDummyPath))); 467 base::FilePath(kDummyPath)));
472 EXPECT_CALL(*download_file, Cancel()); 468 EXPECT_CALL(*download_file, Cancel());
473 469
474 // Complete download to trigger final rename. 470 // Complete download to trigger final rename.
475 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); 471 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string());
476 RunAllPendingInMessageLoops(); 472 RunAllPendingInMessageLoops();
477 473
478 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated()); 474 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
479 // Should not try to auto-resume. 475 // Should not try to auto-resume.
480 ASSERT_EQ(1, observer.interrupt_count()); 476 ASSERT_EQ(1, observer.interrupt_count());
481 ASSERT_EQ(0, observer.resume_count()); 477 ASSERT_EQ(0, observer.resume_count());
482 478
483 CleanupItem(item, download_file, DownloadItem::INTERRUPTED); 479 CleanupItem(item, download_file, DownloadItem::INTERRUPTED);
484 } 480 }
485 481
486 TEST_F(DownloadItemTest, LimitRestartsAfterInterrupted) { 482 TEST_F(DownloadItemTest, LimitRestartsAfterInterrupted) {
487 base::CommandLine::ForCurrentProcess()->AppendSwitch(
488 switches::kEnableDownloadResumption);
489
490 TestBrowserContext test_browser_context; 483 TestBrowserContext test_browser_context;
491 DownloadItemImpl* item = CreateDownloadItem(); 484 DownloadItemImpl* item = CreateDownloadItem();
492 base::WeakPtr<DownloadDestinationObserver> as_observer( 485 base::WeakPtr<DownloadDestinationObserver> as_observer(
493 item->DestinationObserverAsWeakPtr()); 486 item->DestinationObserverAsWeakPtr());
494 TestDownloadItemObserver observer(item); 487 TestDownloadItemObserver observer(item);
495 MockDownloadFile* mock_download_file(NULL); 488 MockDownloadFile* mock_download_file(NULL);
496 scoped_ptr<DownloadFile> download_file; 489 scoped_ptr<DownloadFile> download_file;
497 MockRequestHandle* mock_request_handle(NULL); 490 MockRequestHandle* mock_request_handle(NULL);
498 scoped_ptr<DownloadRequestHandleInterface> request_handle; 491 scoped_ptr<DownloadRequestHandleInterface> request_handle;
499 DownloadItemImplDelegate::DownloadTargetCallback callback; 492 DownloadItemImplDelegate::DownloadTargetCallback callback;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 532
540 ASSERT_EQ(i + 1, observer.interrupt_count()); 533 ASSERT_EQ(i + 1, observer.interrupt_count());
541 ::testing::Mock::VerifyAndClearExpectations(mock_download_file); 534 ::testing::Mock::VerifyAndClearExpectations(mock_download_file);
542 } 535 }
543 536
544 CleanupItem(item, mock_download_file, DownloadItem::INTERRUPTED); 537 CleanupItem(item, mock_download_file, DownloadItem::INTERRUPTED);
545 } 538 }
546 539
547 // Test that resumption uses the final URL in a URL chain when resuming. 540 // Test that resumption uses the final URL in a URL chain when resuming.
548 TEST_F(DownloadItemTest, ResumeUsingFinalURL) { 541 TEST_F(DownloadItemTest, ResumeUsingFinalURL) {
549 base::CommandLine::ForCurrentProcess()->AppendSwitch(
550 switches::kEnableDownloadResumption);
551
552 TestBrowserContext test_browser_context; 542 TestBrowserContext test_browser_context;
553 scoped_ptr<DownloadCreateInfo> create_info(new DownloadCreateInfo); 543 scoped_ptr<DownloadCreateInfo> create_info(new DownloadCreateInfo);
554 create_info->save_info = scoped_ptr<DownloadSaveInfo>(new DownloadSaveInfo()); 544 create_info->save_info = scoped_ptr<DownloadSaveInfo>(new DownloadSaveInfo());
555 create_info->save_info->prompt_for_save_location = false; 545 create_info->save_info->prompt_for_save_location = false;
556 create_info->etag = "SomethingToSatisfyResumption"; 546 create_info->etag = "SomethingToSatisfyResumption";
557 create_info->url_chain.push_back(GURL("http://example.com/a")); 547 create_info->url_chain.push_back(GURL("http://example.com/a"));
558 create_info->url_chain.push_back(GURL("http://example.com/b")); 548 create_info->url_chain.push_back(GURL("http://example.com/b"));
559 create_info->url_chain.push_back(GURL("http://example.com/c")); 549 create_info->url_chain.push_back(GURL("http://example.com/c"));
560 550
561 DownloadItemImpl* item = CreateDownloadItemWithCreateInfo(create_info.Pass()); 551 DownloadItemImpl* item = CreateDownloadItemWithCreateInfo(create_info.Pass());
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 mock_delegate()->VerifyAndClearExpectations(); 830 mock_delegate()->VerifyAndClearExpectations();
841 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); 831 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState());
842 EXPECT_TRUE(item->GetFullPath().empty()); 832 EXPECT_TRUE(item->GetFullPath().empty());
843 EXPECT_EQ(final_path, item->GetTargetFilePath()); 833 EXPECT_EQ(final_path, item->GetTargetFilePath());
844 } 834 }
845 835
846 // As above. But if the download can be resumed by continuing, then the 836 // As above. But if the download can be resumed by continuing, then the
847 // intermediate path should be retained when the download is interrupted after 837 // intermediate path should be retained when the download is interrupted after
848 // the intermediate rename succeeds. 838 // the intermediate rename succeeds.
849 TEST_F(DownloadItemTest, InterruptedBeforeIntermediateRename_Continue) { 839 TEST_F(DownloadItemTest, InterruptedBeforeIntermediateRename_Continue) {
850 base::CommandLine::ForCurrentProcess()->AppendSwitch(
851 switches::kEnableDownloadResumption);
852 DownloadItemImpl* item = CreateDownloadItem(); 840 DownloadItemImpl* item = CreateDownloadItem();
853 DownloadItemImplDelegate::DownloadTargetCallback callback; 841 DownloadItemImplDelegate::DownloadTargetCallback callback;
854 MockDownloadFile* download_file = 842 MockDownloadFile* download_file =
855 AddDownloadFileToDownloadItem(item, &callback); 843 AddDownloadFileToDownloadItem(item, &callback);
856 item->DestinationObserverAsWeakPtr()->DestinationError( 844 item->DestinationObserverAsWeakPtr()->DestinationError(
857 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED); 845 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED);
858 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 846 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
859 847
860 base::FilePath final_path(base::FilePath(kDummyPath).AppendASCII("foo.bar")); 848 base::FilePath final_path(base::FilePath(kDummyPath).AppendASCII("foo.bar"));
861 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); 849 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x"));
(...skipping 13 matching lines...) Expand all
875 ::testing::Mock::VerifyAndClearExpectations(download_file); 863 ::testing::Mock::VerifyAndClearExpectations(download_file);
876 mock_delegate()->VerifyAndClearExpectations(); 864 mock_delegate()->VerifyAndClearExpectations();
877 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); 865 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState());
878 EXPECT_EQ(new_intermediate_path, item->GetFullPath()); 866 EXPECT_EQ(new_intermediate_path, item->GetFullPath());
879 EXPECT_EQ(final_path, item->GetTargetFilePath()); 867 EXPECT_EQ(final_path, item->GetTargetFilePath());
880 } 868 }
881 869
882 // As above. If the intermediate rename fails, then the interrupt reason should 870 // As above. If the intermediate rename fails, then the interrupt reason should
883 // be set to the destination error and the intermediate path should be empty. 871 // be set to the destination error and the intermediate path should be empty.
884 TEST_F(DownloadItemTest, InterruptedBeforeIntermediateRename_Failed) { 872 TEST_F(DownloadItemTest, InterruptedBeforeIntermediateRename_Failed) {
885 base::CommandLine::ForCurrentProcess()->AppendSwitch(
886 switches::kEnableDownloadResumption);
887 DownloadItemImpl* item = CreateDownloadItem(); 873 DownloadItemImpl* item = CreateDownloadItem();
888 DownloadItemImplDelegate::DownloadTargetCallback callback; 874 DownloadItemImplDelegate::DownloadTargetCallback callback;
889 MockDownloadFile* download_file = 875 MockDownloadFile* download_file =
890 AddDownloadFileToDownloadItem(item, &callback); 876 AddDownloadFileToDownloadItem(item, &callback);
891 item->DestinationObserverAsWeakPtr()->DestinationError( 877 item->DestinationObserverAsWeakPtr()->DestinationError(
892 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED); 878 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED);
893 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 879 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
894 880
895 base::FilePath final_path(base::FilePath(kDummyPath).AppendASCII("foo.bar")); 881 base::FilePath final_path(base::FilePath(kDummyPath).AppendASCII("foo.bar"));
896 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); 882 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x"));
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this); 1261 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this);
1276 item->StealDangerousDownload( 1262 item->StealDangerousDownload(
1277 base::Bind(&DownloadItemTest::OnDownloadFileAcquired, 1263 base::Bind(&DownloadItemTest::OnDownloadFileAcquired,
1278 weak_ptr_factory.GetWeakPtr(), 1264 weak_ptr_factory.GetWeakPtr(),
1279 base::Unretained(&returned_path))); 1265 base::Unretained(&returned_path)));
1280 RunAllPendingInMessageLoops(); 1266 RunAllPendingInMessageLoops();
1281 EXPECT_EQ(full_path, returned_path); 1267 EXPECT_EQ(full_path, returned_path);
1282 } 1268 }
1283 1269
1284 TEST_F(DownloadItemTest, StealInterruptedDangerousDownload) { 1270 TEST_F(DownloadItemTest, StealInterruptedDangerousDownload) {
1285 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1286 switches::kEnableDownloadResumption);
1287 base::FilePath returned_path; 1271 base::FilePath returned_path;
1288 DownloadItemImpl* item = CreateDownloadItem(); 1272 DownloadItemImpl* item = CreateDownloadItem();
1289 MockDownloadFile* download_file = 1273 MockDownloadFile* download_file =
1290 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); 1274 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE);
1291 base::FilePath full_path = item->GetFullPath(); 1275 base::FilePath full_path = item->GetFullPath();
1292 EXPECT_FALSE(full_path.empty()); 1276 EXPECT_FALSE(full_path.empty());
1293 EXPECT_CALL(*download_file, FullPath()) 1277 EXPECT_CALL(*download_file, FullPath())
1294 .WillOnce(Return(full_path)); 1278 .WillOnce(Return(full_path));
1295 EXPECT_CALL(*download_file, Detach()); 1279 EXPECT_CALL(*download_file, Detach());
1296 item->DestinationObserverAsWeakPtr()->DestinationError( 1280 item->DestinationObserverAsWeakPtr()->DestinationError(
1297 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED); 1281 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED);
1298 ASSERT_TRUE(item->IsDangerous()); 1282 ASSERT_TRUE(item->IsDangerous());
1299 1283
1300 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_)); 1284 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_));
1301 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this); 1285 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this);
1302 item->StealDangerousDownload( 1286 item->StealDangerousDownload(
1303 base::Bind(&DownloadItemTest::OnDownloadFileAcquired, 1287 base::Bind(&DownloadItemTest::OnDownloadFileAcquired,
1304 weak_ptr_factory.GetWeakPtr(), 1288 weak_ptr_factory.GetWeakPtr(),
1305 base::Unretained(&returned_path))); 1289 base::Unretained(&returned_path)));
1306 RunAllPendingInMessageLoops(); 1290 RunAllPendingInMessageLoops();
1307 EXPECT_EQ(full_path, returned_path); 1291 EXPECT_EQ(full_path, returned_path);
1308 } 1292 }
1309 1293
1310 TEST_F(DownloadItemTest, StealInterruptedNonResumableDangerousDownload) { 1294 TEST_F(DownloadItemTest, StealInterruptedNonResumableDangerousDownload) {
1311 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1312 switches::kEnableDownloadResumption);
1313 base::FilePath returned_path; 1295 base::FilePath returned_path;
1314 DownloadItemImpl* item = CreateDownloadItem(); 1296 DownloadItemImpl* item = CreateDownloadItem();
1315 MockDownloadFile* download_file = 1297 MockDownloadFile* download_file =
1316 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); 1298 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE);
1317 EXPECT_CALL(*download_file, Cancel()); 1299 EXPECT_CALL(*download_file, Cancel());
1318 item->DestinationObserverAsWeakPtr()->DestinationError( 1300 item->DestinationObserverAsWeakPtr()->DestinationError(
1319 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); 1301 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED);
1320 ASSERT_TRUE(item->IsDangerous()); 1302 ASSERT_TRUE(item->IsDangerous());
1321 1303
1322 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_)); 1304 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_));
1323 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this); 1305 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this);
1324 item->StealDangerousDownload( 1306 item->StealDangerousDownload(
1325 base::Bind(&DownloadItemTest::OnDownloadFileAcquired, 1307 base::Bind(&DownloadItemTest::OnDownloadFileAcquired,
1326 weak_ptr_factory.GetWeakPtr(), 1308 weak_ptr_factory.GetWeakPtr(),
1327 base::Unretained(&returned_path))); 1309 base::Unretained(&returned_path)));
1328 RunAllPendingInMessageLoops(); 1310 RunAllPendingInMessageLoops();
1329 EXPECT_TRUE(returned_path.empty()); 1311 EXPECT_TRUE(returned_path.empty());
1330 } 1312 }
1331 1313
1332 TEST(MockDownloadItem, Compiles) { 1314 TEST(MockDownloadItem, Compiles) {
1333 MockDownloadItem mock_item; 1315 MockDownloadItem mock_item;
1334 } 1316 }
1335 1317
1336 } // namespace content 1318 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl.cc ('k') | content/public/common/content_features.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698