OLD | NEW |
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/command_line.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" |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); | 452 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); |
453 ASSERT_TRUE(observer.CheckUpdated()); | 453 ASSERT_TRUE(observer.CheckUpdated()); |
454 // Should not try to auto-resume. | 454 // Should not try to auto-resume. |
455 ASSERT_EQ(1, observer.GetInterruptCount()); | 455 ASSERT_EQ(1, observer.GetInterruptCount()); |
456 ASSERT_EQ(0, observer.GetResumeCount()); | 456 ASSERT_EQ(0, observer.GetResumeCount()); |
457 RunAllPendingInMessageLoops(); | 457 RunAllPendingInMessageLoops(); |
458 | 458 |
459 CleanupItem(item, download_file, DownloadItem::INTERRUPTED); | 459 CleanupItem(item, download_file, DownloadItem::INTERRUPTED); |
460 } | 460 } |
461 | 461 |
| 462 // Check we do correct cleanup for RESUME_MODE_INVALID interrupts. |
| 463 TEST_F(DownloadItemTest, UnresumableInterrupt) { |
| 464 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 465 switches::kEnableDownloadResumption); |
| 466 |
| 467 DownloadItemImpl* item = CreateDownloadItem(); |
| 468 MockObserver observer(item); |
| 469 DownloadItemImplDelegate::DownloadTargetCallback callback; |
| 470 MockDownloadFile* download_file = |
| 471 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
| 472 |
| 473 // Fail final rename with unresumable reason. |
| 474 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) |
| 475 .WillOnce(Return(true)); |
| 476 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) |
| 477 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED, |
| 478 base::FilePath(kDummyPath))); |
| 479 EXPECT_CALL(*download_file, Cancel()); |
| 480 |
| 481 // Complete download to trigger final rename. |
| 482 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); |
| 483 RunAllPendingInMessageLoops(); |
| 484 |
| 485 ASSERT_TRUE(observer.CheckUpdated()); |
| 486 // Should not try to auto-resume. |
| 487 ASSERT_EQ(1, observer.GetInterruptCount()); |
| 488 ASSERT_EQ(0, observer.GetResumeCount()); |
| 489 |
| 490 CleanupItem(item, download_file, DownloadItem::INTERRUPTED); |
| 491 } |
| 492 |
462 TEST_F(DownloadItemTest, LimitRestartsAfterInterrupted) { | 493 TEST_F(DownloadItemTest, LimitRestartsAfterInterrupted) { |
463 CommandLine::ForCurrentProcess()->AppendSwitch( | 494 CommandLine::ForCurrentProcess()->AppendSwitch( |
464 switches::kEnableDownloadResumption); | 495 switches::kEnableDownloadResumption); |
465 | 496 |
466 DownloadItemImpl* item = CreateDownloadItem(); | 497 DownloadItemImpl* item = CreateDownloadItem(); |
467 base::WeakPtr<DownloadDestinationObserver> as_observer( | 498 base::WeakPtr<DownloadDestinationObserver> as_observer( |
468 item->DestinationObserverAsWeakPtr()); | 499 item->DestinationObserverAsWeakPtr()); |
469 MockObserver observer(item); | 500 MockObserver observer(item); |
470 MockDownloadFile* mock_download_file(NULL); | 501 MockDownloadFile* mock_download_file(NULL); |
471 scoped_ptr<DownloadFile> download_file; | 502 scoped_ptr<DownloadFile> download_file; |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 base::Unretained(&returned_path))); | 1293 base::Unretained(&returned_path))); |
1263 RunAllPendingInMessageLoops(); | 1294 RunAllPendingInMessageLoops(); |
1264 EXPECT_TRUE(returned_path.empty()); | 1295 EXPECT_TRUE(returned_path.empty()); |
1265 } | 1296 } |
1266 | 1297 |
1267 TEST(MockDownloadItem, Compiles) { | 1298 TEST(MockDownloadItem, Compiles) { |
1268 MockDownloadItem mock_item; | 1299 MockDownloadItem mock_item; |
1269 } | 1300 } |
1270 | 1301 |
1271 } // namespace content | 1302 } // namespace content |
OLD | NEW |