OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
6 #include <set> | 6 #include <set> |
7 | 7 |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/i18n/number_formatting.h" |
| 10 #include "base/i18n/rtl.h" |
9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util-inl.h" | 12 #include "base/stl_util-inl.h" |
11 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/string16.h" |
| 15 #include "base/utf_string_conversions.h" |
12 #include "build/build_config.h" | 16 #include "build/build_config.h" |
13 #include "chrome/browser/download/download_create_info.h" | 17 #include "chrome/browser/download/download_create_info.h" |
14 #include "chrome/browser/download/download_file.h" | 18 #include "chrome/browser/download/download_file.h" |
15 #include "chrome/browser/download/download_file_manager.h" | 19 #include "chrome/browser/download/download_file_manager.h" |
16 #include "chrome/browser/download/download_item.h" | 20 #include "chrome/browser/download/download_item.h" |
| 21 #include "chrome/browser/download/download_item_model.h" |
17 #include "chrome/browser/download/download_manager.h" | 22 #include "chrome/browser/download/download_manager.h" |
18 #include "chrome/browser/download/download_prefs.h" | 23 #include "chrome/browser/download/download_prefs.h" |
19 #include "chrome/browser/download/download_status_updater.h" | 24 #include "chrome/browser/download/download_status_updater.h" |
20 #include "chrome/browser/download/download_util.h" | 25 #include "chrome/browser/download/download_util.h" |
21 #include "chrome/browser/download/mock_download_manager.h" | 26 #include "chrome/browser/download/mock_download_manager.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
24 #include "chrome/test/testing_profile.h" | 29 #include "chrome/test/testing_profile.h" |
25 #include "content/browser/browser_thread.h" | 30 #include "content/browser/browser_thread.h" |
| 31 #include "grit/generated_resources.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
27 #include "testing/gmock_mutant.h" | 33 #include "testing/gmock_mutant.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #include "ui/base/l10n/l10n_util.h" |
29 | 36 |
30 class DownloadManagerTest : public testing::Test { | 37 class DownloadManagerTest : public testing::Test { |
31 public: | 38 public: |
32 static const char* kTestData; | 39 static const char* kTestData; |
33 static const size_t kTestDataLen; | 40 static const size_t kTestDataLen; |
34 | 41 |
35 DownloadManagerTest() | 42 DownloadManagerTest() |
36 : profile_(new TestingProfile()), | 43 : profile_(new TestingProfile()), |
37 download_manager_(new MockDownloadManager(&download_status_updater_)), | 44 download_manager_(new MockDownloadManager(&download_status_updater_)), |
38 ui_thread_(BrowserThread::UI, &message_loop_), | 45 ui_thread_(BrowserThread::UI, &message_loop_), |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 using ::testing::Invoke; | 396 using ::testing::Invoke; |
390 using ::testing::Return; | 397 using ::testing::Return; |
391 | 398 |
392 // Normally, the download system takes ownership of info, and is | 399 // Normally, the download system takes ownership of info, and is |
393 // responsible for deleting it. In these unit tests, however, we | 400 // responsible for deleting it. In these unit tests, however, we |
394 // don't call the function that deletes it, so we do so ourselves. | 401 // don't call the function that deletes it, so we do so ourselves. |
395 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); | 402 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); |
396 info->download_id = static_cast<int>(0); | 403 info->download_id = static_cast<int>(0); |
397 info->prompt_user_for_save_location = false; | 404 info->prompt_user_for_save_location = false; |
398 info->url_chain.push_back(GURL()); | 405 info->url_chain.push_back(GURL()); |
| 406 info->total_bytes = static_cast<int64>(kTestDataLen); |
399 const FilePath new_path(FILE_PATH_LITERAL("foo.zip")); | 407 const FilePath new_path(FILE_PATH_LITERAL("foo.zip")); |
400 const FilePath cr_path(download_util::GetCrDownloadPath(new_path)); | 408 const FilePath cr_path(download_util::GetCrDownloadPath(new_path)); |
401 | 409 |
402 MockDownloadFile* download_file( | 410 MockDownloadFile* download_file( |
403 new MockDownloadFile(info.get(), download_manager_)); | 411 new MockDownloadFile(info.get(), download_manager_)); |
404 AddDownloadToFileManager(info->download_id, download_file); | 412 AddDownloadToFileManager(info->download_id, download_file); |
405 | 413 |
406 // |download_file| is owned by DownloadFileManager. | 414 // |download_file| is owned by DownloadFileManager. |
407 ::testing::Mock::AllowLeak(download_file); | 415 ::testing::Mock::AllowLeak(download_file); |
408 EXPECT_CALL(*download_file, Destructed()).Times(1); | 416 EXPECT_CALL(*download_file, Destructed()).Times(1); |
409 | 417 |
410 EXPECT_CALL(*download_file, Rename(cr_path)).WillOnce(Return(true)); | 418 EXPECT_CALL(*download_file, Rename(cr_path)).WillOnce(Return(true)); |
411 | 419 |
412 download_manager_->CreateDownloadItem(info.get()); | 420 download_manager_->CreateDownloadItem(info.get()); |
413 | 421 |
414 DownloadItem* download = GetActiveDownloadItem(0); | 422 DownloadItem* download = GetActiveDownloadItem(0); |
415 ASSERT_TRUE(download != NULL); | 423 ASSERT_TRUE(download != NULL); |
| 424 scoped_ptr<DownloadItemModel> download_item_model( |
| 425 new DownloadItemModel(download)); |
416 | 426 |
417 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); | 427 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); |
418 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); | 428 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); |
419 | 429 |
420 download_file->AppendDataToFile(kTestData, kTestDataLen); | 430 download_file->AppendDataToFile(kTestData, kTestDataLen); |
421 | 431 |
422 ContinueDownloadWithPath(download, new_path); | 432 ContinueDownloadWithPath(download, new_path); |
423 message_loop_.RunAllPending(); | 433 message_loop_.RunAllPending(); |
424 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | 434 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
425 | 435 |
426 OnDownloadError(0, 1024, -6); | 436 int64 error_size = 3; |
| 437 OnDownloadError(0, error_size, -6); |
427 message_loop_.RunAllPending(); | 438 message_loop_.RunAllPending(); |
428 | 439 |
429 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); | 440 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); |
430 EXPECT_EQ(DownloadItem::INTERRUPTED, download->state()); | |
431 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); | 441 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); |
432 EXPECT_TRUE(observer->hit_state(DownloadItem::INTERRUPTED)); | 442 EXPECT_TRUE(observer->hit_state(DownloadItem::INTERRUPTED)); |
433 EXPECT_FALSE(observer->hit_state(DownloadItem::COMPLETE)); | 443 EXPECT_FALSE(observer->hit_state(DownloadItem::COMPLETE)); |
434 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); | 444 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); |
435 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 445 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
436 EXPECT_TRUE(observer->was_updated()); | 446 EXPECT_TRUE(observer->was_updated()); |
437 EXPECT_FALSE(observer->was_opened()); | 447 EXPECT_FALSE(observer->was_opened()); |
| 448 EXPECT_FALSE(download->file_externally_removed()); |
| 449 EXPECT_EQ(DownloadItem::INTERRUPTED, download->state()); |
| 450 DataUnits amount_units = GetByteDisplayUnits(kTestDataLen); |
| 451 const string16 simple_size = FormatBytes(error_size, amount_units, false); |
| 452 string16 simple_total = base::i18n::GetDisplayStringInLTRDirectionality( |
| 453 FormatBytes(kTestDataLen, amount_units, true)); |
| 454 EXPECT_EQ(download_item_model->GetStatusText(), |
| 455 l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_INTERRUPTED, |
| 456 simple_size, |
| 457 simple_total)); |
438 | 458 |
439 download->Cancel(true); | 459 download->Cancel(true); |
440 | 460 |
441 EXPECT_EQ(DownloadItem::INTERRUPTED, download->state()); | |
442 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); | 461 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); |
443 EXPECT_TRUE(observer->hit_state(DownloadItem::INTERRUPTED)); | 462 EXPECT_TRUE(observer->hit_state(DownloadItem::INTERRUPTED)); |
444 EXPECT_FALSE(observer->hit_state(DownloadItem::COMPLETE)); | 463 EXPECT_FALSE(observer->hit_state(DownloadItem::COMPLETE)); |
445 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); | 464 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); |
446 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 465 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
447 EXPECT_TRUE(observer->was_updated()); | 466 EXPECT_TRUE(observer->was_updated()); |
448 EXPECT_FALSE(observer->was_opened()); | 467 EXPECT_FALSE(observer->was_opened()); |
| 468 EXPECT_FALSE(download->file_externally_removed()); |
| 469 EXPECT_EQ(DownloadItem::INTERRUPTED, download->state()); |
| 470 EXPECT_EQ(download->received_bytes(), error_size); |
| 471 EXPECT_EQ(download->total_bytes(), static_cast<int64>(kTestDataLen)); |
449 } | 472 } |
450 | 473 |
451 TEST_F(DownloadManagerTest, DownloadCancelTest) { | 474 TEST_F(DownloadManagerTest, DownloadCancelTest) { |
452 using ::testing::_; | 475 using ::testing::_; |
453 using ::testing::CreateFunctor; | 476 using ::testing::CreateFunctor; |
454 using ::testing::Invoke; | 477 using ::testing::Invoke; |
455 using ::testing::Return; | 478 using ::testing::Return; |
456 | 479 |
457 // Normally, the download system takes ownership of info, and is | 480 // Normally, the download system takes ownership of info, and is |
458 // responsible for deleting it. In these unit tests, however, we | 481 // responsible for deleting it. In these unit tests, however, we |
(...skipping 12 matching lines...) Expand all Loading... |
471 // |download_file| is owned by DownloadFileManager. | 494 // |download_file| is owned by DownloadFileManager. |
472 ::testing::Mock::AllowLeak(download_file); | 495 ::testing::Mock::AllowLeak(download_file); |
473 EXPECT_CALL(*download_file, Destructed()).Times(1); | 496 EXPECT_CALL(*download_file, Destructed()).Times(1); |
474 | 497 |
475 EXPECT_CALL(*download_file, Rename(cr_path)).WillOnce(Return(true)); | 498 EXPECT_CALL(*download_file, Rename(cr_path)).WillOnce(Return(true)); |
476 | 499 |
477 download_manager_->CreateDownloadItem(info.get()); | 500 download_manager_->CreateDownloadItem(info.get()); |
478 | 501 |
479 DownloadItem* download = GetActiveDownloadItem(0); | 502 DownloadItem* download = GetActiveDownloadItem(0); |
480 ASSERT_TRUE(download != NULL); | 503 ASSERT_TRUE(download != NULL); |
| 504 scoped_ptr<DownloadItemModel> download_item_model( |
| 505 new DownloadItemModel(download)); |
481 | 506 |
482 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); | 507 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); |
483 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); | 508 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); |
484 | 509 |
485 ContinueDownloadWithPath(download, new_path); | 510 ContinueDownloadWithPath(download, new_path); |
486 message_loop_.RunAllPending(); | 511 message_loop_.RunAllPending(); |
487 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | 512 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
488 | 513 |
489 download_file->AppendDataToFile(kTestData, kTestDataLen); | 514 download_file->AppendDataToFile(kTestData, kTestDataLen); |
490 | 515 |
491 download->Cancel(false); | 516 download->Cancel(false); |
492 message_loop_.RunAllPending(); | 517 message_loop_.RunAllPending(); |
493 | 518 |
494 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | 519 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
495 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); | 520 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); |
496 EXPECT_TRUE(observer->hit_state(DownloadItem::CANCELLED)); | 521 EXPECT_TRUE(observer->hit_state(DownloadItem::CANCELLED)); |
497 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); | 522 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); |
498 EXPECT_FALSE(observer->hit_state(DownloadItem::COMPLETE)); | 523 EXPECT_FALSE(observer->hit_state(DownloadItem::COMPLETE)); |
499 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 524 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
500 EXPECT_TRUE(observer->was_updated()); | 525 EXPECT_TRUE(observer->was_updated()); |
501 EXPECT_FALSE(observer->was_opened()); | 526 EXPECT_FALSE(observer->was_opened()); |
| 527 EXPECT_FALSE(download->file_externally_removed()); |
| 528 EXPECT_EQ(DownloadItem::CANCELLED, download->state()); |
| 529 EXPECT_EQ(download_item_model->GetStatusText(), |
| 530 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_CANCELED)); |
502 | 531 |
503 EXPECT_FALSE(file_util::PathExists(new_path)); | 532 EXPECT_FALSE(file_util::PathExists(new_path)); |
504 EXPECT_FALSE(file_util::PathExists(cr_path)); | 533 EXPECT_FALSE(file_util::PathExists(cr_path)); |
505 } | 534 } |
506 | 535 |
507 TEST_F(DownloadManagerTest, DownloadOverwriteTest) { | 536 TEST_F(DownloadManagerTest, DownloadOverwriteTest) { |
508 using ::testing::_; | 537 using ::testing::_; |
509 using ::testing::CreateFunctor; | 538 using ::testing::CreateFunctor; |
510 using ::testing::Invoke; | 539 using ::testing::Invoke; |
511 using ::testing::Return; | 540 using ::testing::Return; |
(...skipping 25 matching lines...) Expand all Loading... |
537 // don't call the function that deletes it, so we do so ourselves. | 566 // don't call the function that deletes it, so we do so ourselves. |
538 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); | 567 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); |
539 info->download_id = static_cast<int>(0); | 568 info->download_id = static_cast<int>(0); |
540 info->prompt_user_for_save_location = true; | 569 info->prompt_user_for_save_location = true; |
541 info->url_chain.push_back(GURL()); | 570 info->url_chain.push_back(GURL()); |
542 | 571 |
543 download_manager_->CreateDownloadItem(info.get()); | 572 download_manager_->CreateDownloadItem(info.get()); |
544 | 573 |
545 DownloadItem* download = GetActiveDownloadItem(0); | 574 DownloadItem* download = GetActiveDownloadItem(0); |
546 ASSERT_TRUE(download != NULL); | 575 ASSERT_TRUE(download != NULL); |
| 576 scoped_ptr<DownloadItemModel> download_item_model( |
| 577 new DownloadItemModel(download)); |
547 | 578 |
548 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); | 579 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); |
549 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); | 580 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); |
550 | 581 |
551 // Create and initialize the download file. We're bypassing the first part | 582 // Create and initialize the download file. We're bypassing the first part |
552 // of the download process and skipping to the part after the final file | 583 // of the download process and skipping to the part after the final file |
553 // name has been chosen, so we need to initialize the download file | 584 // name has been chosen, so we need to initialize the download file |
554 // properly. | 585 // properly. |
555 DownloadFile* download_file( | 586 DownloadFile* download_file( |
556 new DownloadFile(info.get(), download_manager_)); | 587 new DownloadFile(info.get(), download_manager_)); |
(...skipping 15 matching lines...) Expand all Loading... |
572 | 603 |
573 // Download is complete. | 604 // Download is complete. |
574 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); | 605 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); |
575 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); | 606 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); |
576 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); | 607 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); |
577 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); | 608 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); |
578 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); | 609 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); |
579 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 610 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
580 EXPECT_TRUE(observer->was_updated()); | 611 EXPECT_TRUE(observer->was_updated()); |
581 EXPECT_FALSE(observer->was_opened()); | 612 EXPECT_FALSE(observer->was_opened()); |
| 613 EXPECT_FALSE(download->file_externally_removed()); |
582 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); | 614 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); |
| 615 EXPECT_EQ(download_item_model->GetStatusText(), ASCIIToUTF16("")); |
583 | 616 |
584 EXPECT_TRUE(file_util::PathExists(new_path)); | 617 EXPECT_TRUE(file_util::PathExists(new_path)); |
585 EXPECT_FALSE(file_util::PathExists(cr_path)); | 618 EXPECT_FALSE(file_util::PathExists(cr_path)); |
586 EXPECT_FALSE(file_util::PathExists(unique_new_path)); | 619 EXPECT_FALSE(file_util::PathExists(unique_new_path)); |
587 std::string file_contents; | 620 std::string file_contents; |
588 EXPECT_TRUE(file_util::ReadFileToString(new_path, &file_contents)); | 621 EXPECT_TRUE(file_util::ReadFileToString(new_path, &file_contents)); |
589 EXPECT_EQ(std::string(kTestData), file_contents); | 622 EXPECT_EQ(std::string(kTestData), file_contents); |
590 } | 623 } |
| 624 |
| 625 TEST_F(DownloadManagerTest, DownloadRemoveTest) { |
| 626 using ::testing::_; |
| 627 using ::testing::CreateFunctor; |
| 628 using ::testing::Invoke; |
| 629 using ::testing::Return; |
| 630 |
| 631 // Create a temporary directory. |
| 632 ScopedTempDir temp_dir_; |
| 633 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 634 |
| 635 // File names we're using. |
| 636 const FilePath new_path(temp_dir_.path().AppendASCII("foo.txt")); |
| 637 const FilePath cr_path(download_util::GetCrDownloadPath(new_path)); |
| 638 EXPECT_FALSE(file_util::PathExists(new_path)); |
| 639 |
| 640 // Normally, the download system takes ownership of info, and is |
| 641 // responsible for deleting it. In these unit tests, however, we |
| 642 // don't call the function that deletes it, so we do so ourselves. |
| 643 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); |
| 644 info->download_id = static_cast<int>(0); |
| 645 info->prompt_user_for_save_location = true; |
| 646 info->url_chain.push_back(GURL()); |
| 647 |
| 648 download_manager_->CreateDownloadItem(info.get()); |
| 649 |
| 650 DownloadItem* download = GetActiveDownloadItem(0); |
| 651 ASSERT_TRUE(download != NULL); |
| 652 scoped_ptr<DownloadItemModel> download_item_model( |
| 653 new DownloadItemModel(download)); |
| 654 |
| 655 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); |
| 656 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); |
| 657 |
| 658 // Create and initialize the download file. We're bypassing the first part |
| 659 // of the download process and skipping to the part after the final file |
| 660 // name has been chosen, so we need to initialize the download file |
| 661 // properly. |
| 662 DownloadFile* download_file( |
| 663 new DownloadFile(info.get(), download_manager_)); |
| 664 download_file->Rename(cr_path); |
| 665 // This creates the .crdownload version of the file. |
| 666 download_file->Initialize(false); |
| 667 // |download_file| is owned by DownloadFileManager. |
| 668 AddDownloadToFileManager(info->download_id, download_file); |
| 669 |
| 670 ContinueDownloadWithPath(download, new_path); |
| 671 message_loop_.RunAllPending(); |
| 672 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
| 673 |
| 674 download_file->AppendDataToFile(kTestData, kTestDataLen); |
| 675 |
| 676 // Finish the download. |
| 677 OnAllDataSaved(0, kTestDataLen, ""); |
| 678 message_loop_.RunAllPending(); |
| 679 |
| 680 // Download is complete. |
| 681 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); |
| 682 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); |
| 683 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); |
| 684 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); |
| 685 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); |
| 686 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 687 EXPECT_TRUE(observer->was_updated()); |
| 688 EXPECT_FALSE(observer->was_opened()); |
| 689 EXPECT_FALSE(download->file_externally_removed()); |
| 690 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); |
| 691 EXPECT_EQ(download_item_model->GetStatusText(), ASCIIToUTF16("")); |
| 692 |
| 693 EXPECT_TRUE(file_util::PathExists(new_path)); |
| 694 EXPECT_FALSE(file_util::PathExists(cr_path)); |
| 695 |
| 696 // Remove the downloaded file. |
| 697 ASSERT_TRUE(file_util::Delete(new_path, false)); |
| 698 download->OnDownloadedFileRemoved(); |
| 699 message_loop_.RunAllPending(); |
| 700 |
| 701 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); |
| 702 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); |
| 703 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); |
| 704 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); |
| 705 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); |
| 706 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 707 EXPECT_TRUE(observer->was_updated()); |
| 708 EXPECT_FALSE(observer->was_opened()); |
| 709 EXPECT_TRUE(download->file_externally_removed()); |
| 710 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); |
| 711 EXPECT_EQ(download_item_model->GetStatusText(), |
| 712 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); |
| 713 |
| 714 EXPECT_FALSE(file_util::PathExists(new_path)); |
| 715 } |
OLD | NEW |