Chromium Code Reviews| 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" | 9 #include "base/i18n/number_formatting.h" |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
| 24 #include "content/browser/browser_thread.h" | 24 #include "content/browser/browser_thread.h" |
| 25 #include "content/browser/download/download_create_info.h" | 25 #include "content/browser/download/download_create_info.h" |
| 26 #include "content/browser/download/download_file.h" | 26 #include "content/browser/download/download_file.h" |
| 27 #include "content/browser/download/download_file_manager.h" | 27 #include "content/browser/download/download_file_manager.h" |
| 28 #include "content/browser/download/download_item.h" | 28 #include "content/browser/download/download_item.h" |
| 29 #include "content/browser/download/download_manager.h" | 29 #include "content/browser/download/download_manager.h" |
| 30 #include "content/browser/download/download_status_updater.h" | 30 #include "content/browser/download/download_status_updater.h" |
| 31 #include "content/browser/download/mock_download_manager.h" | 31 #include "content/browser/download/mock_download_manager.h" |
| 32 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
| 33 #include "net/base/io_buffer.h" | |
| 34 #include "net/base/mock_file_stream.h" | |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "testing/gmock_mutant.h" | 36 #include "testing/gmock_mutant.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
| 37 #include "ui/base/text/bytes_formatting.h" | 39 #include "ui/base/text/bytes_formatting.h" |
| 38 | 40 |
| 39 class DownloadManagerTest : public testing::Test { | 41 class DownloadManagerTest : public testing::Test { |
| 40 public: | 42 public: |
| 41 static const char* kTestData; | 43 static const char* kTestData; |
| 42 static const size_t kTestDataLen; | 44 static const size_t kTestDataLen; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 60 download_manager_ = NULL; | 62 download_manager_ = NULL; |
| 61 download_manager_delegate_ = NULL; | 63 download_manager_delegate_ = NULL; |
| 62 profile_.reset(NULL); | 64 profile_.reset(NULL); |
| 63 message_loop_.RunAllPending(); | 65 message_loop_.RunAllPending(); |
| 64 } | 66 } |
| 65 | 67 |
| 66 void AddDownloadToFileManager(int id, DownloadFile* download_file) { | 68 void AddDownloadToFileManager(int id, DownloadFile* download_file) { |
| 67 file_manager()->downloads_[id] = download_file; | 69 file_manager()->downloads_[id] = download_file; |
| 68 } | 70 } |
| 69 | 71 |
| 70 void OnAllDataSaved(int32 download_id, int64 size, const std::string& hash) { | 72 void OnResponseCompleted(int32 download_id, int64 size, |
| 71 download_manager_->OnAllDataSaved(download_id, size, hash); | 73 const std::string& hash) { |
| 74 download_manager_->OnResponseCompleted(download_id, size, hash); | |
| 72 } | 75 } |
| 73 | 76 |
| 74 void FileSelected(const FilePath& path, void* params) { | 77 void FileSelected(const FilePath& path, void* params) { |
| 75 download_manager_->FileSelected(path, params); | 78 download_manager_->FileSelected(path, params); |
| 76 } | 79 } |
| 77 | 80 |
| 78 void ContinueDownloadWithPath(DownloadItem* download, const FilePath& path) { | 81 void ContinueDownloadWithPath(DownloadItem* download, const FilePath& path) { |
| 79 download_manager_->ContinueDownloadWithPath(download, path); | 82 download_manager_->ContinueDownloadWithPath(download, path); |
| 80 } | 83 } |
| 81 | 84 |
| 85 void UpdateData(int32 id, const char* data, size_t length) { | |
| 86 // We are passing ownership of this buffer to the download file manager. | |
| 87 net::IOBuffer* io_buffer = new net::IOBuffer(length); | |
| 88 // We need |AddRef()| because we do a |Release()| in |UpdateDownload()|. | |
| 89 io_buffer->AddRef(); | |
| 90 memcpy(io_buffer->data(), data, length); | |
| 91 | |
| 92 { | |
| 93 base::AutoLock auto_lock(download_buffer_.lock); | |
| 94 | |
| 95 download_buffer_.contents.push_back( | |
| 96 std::make_pair(io_buffer, length)); | |
| 97 } | |
| 98 | |
| 99 BrowserThread::PostTask( | |
| 100 BrowserThread::FILE, FROM_HERE, | |
| 101 NewRunnableMethod(file_manager_.get(), | |
| 102 &DownloadFileManager::UpdateDownload, | |
| 103 id, | |
| 104 &download_buffer_)); | |
| 105 | |
| 106 message_loop_.RunAllPending(); | |
| 107 } | |
| 108 | |
| 82 void OnDownloadError(int32 download_id, int64 size, int os_error) { | 109 void OnDownloadError(int32 download_id, int64 size, int os_error) { |
| 83 download_manager_->OnDownloadError(download_id, size, os_error); | 110 download_manager_->OnDownloadError(download_id, size, os_error); |
| 84 } | 111 } |
| 85 | 112 |
| 86 // Get the download item with ID |id|. | 113 // Get the download item with ID |id|. |
| 87 DownloadItem* GetActiveDownloadItem(int32 id) { | 114 DownloadItem* GetActiveDownloadItem(int32 id) { |
| 88 if (ContainsKey(download_manager_->active_downloads_, id)) | 115 if (ContainsKey(download_manager_->active_downloads_, id)) |
| 89 return download_manager_->active_downloads_[id]; | 116 return download_manager_->active_downloads_[id]; |
| 90 return NULL; | 117 return NULL; |
| 91 } | 118 } |
| 92 | 119 |
| 93 protected: | 120 protected: |
| 94 DownloadStatusUpdater download_status_updater_; | 121 DownloadStatusUpdater download_status_updater_; |
| 95 scoped_ptr<TestingProfile> profile_; | 122 scoped_ptr<TestingProfile> profile_; |
| 96 scoped_refptr<ChromeDownloadManagerDelegate> download_manager_delegate_; | 123 scoped_refptr<ChromeDownloadManagerDelegate> download_manager_delegate_; |
| 97 scoped_refptr<DownloadManager> download_manager_; | 124 scoped_refptr<DownloadManager> download_manager_; |
| 98 scoped_refptr<DownloadFileManager> file_manager_; | 125 scoped_refptr<DownloadFileManager> file_manager_; |
| 99 MessageLoopForUI message_loop_; | 126 MessageLoopForUI message_loop_; |
| 100 BrowserThread ui_thread_; | 127 BrowserThread ui_thread_; |
| 101 BrowserThread file_thread_; | 128 BrowserThread file_thread_; |
| 129 DownloadBuffer download_buffer_; | |
| 102 | 130 |
| 103 DownloadFileManager* file_manager() { | 131 DownloadFileManager* file_manager() { |
| 104 if (!file_manager_) { | 132 if (!file_manager_) { |
| 105 file_manager_ = new DownloadFileManager(NULL); | 133 file_manager_ = new DownloadFileManager(NULL); |
| 106 download_manager_->file_manager_ = file_manager_; | 134 download_manager_->file_manager_ = file_manager_; |
| 107 } | 135 } |
| 108 return file_manager_; | 136 return file_manager_; |
| 109 } | 137 } |
| 110 | 138 |
| 111 // Make sure download item |id| was set with correct safety state for | 139 // Make sure download item |id| was set with correct safety state for |
| 112 // given |is_dangerous_file| and |is_dangerous_url|. | 140 // given |is_dangerous_file| and |is_dangerous_url|. |
| 113 bool VerifySafetyState(bool is_dangerous_file, | 141 bool VerifySafetyState(bool is_dangerous_file, |
| 114 bool is_dangerous_url, | 142 bool is_dangerous_url, |
| 115 int id) { | 143 int id) { |
| 116 DownloadItem::SafetyState safety_state = | 144 DownloadItem::SafetyState safety_state = |
| 117 download_manager_->GetDownloadItem(id)->safety_state(); | 145 download_manager_->GetDownloadItem(id)->safety_state(); |
| 118 return (is_dangerous_file || is_dangerous_url) ? | 146 return (is_dangerous_file || is_dangerous_url) ? |
| 119 safety_state != DownloadItem::SAFE : safety_state == DownloadItem::SAFE; | 147 safety_state != DownloadItem::SAFE : safety_state == DownloadItem::SAFE; |
| 120 } | 148 } |
| 121 | 149 |
| 122 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); | 150 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); |
| 123 }; | 151 }; |
| 124 | 152 |
| 125 const char* DownloadManagerTest::kTestData = "a;sdlfalsdfjalsdkfjad"; | 153 const char* DownloadManagerTest::kTestData = "a;sdlfalsdfjalsdkfjad"; |
| 126 const size_t DownloadManagerTest::kTestDataLen = | 154 const size_t DownloadManagerTest::kTestDataLen = |
| 127 strlen(DownloadManagerTest::kTestData); | 155 strlen(DownloadManagerTest::kTestData); |
| 128 | 156 |
| 157 // A DownloadFile that we can inject errors into. Uses MockFileStream. | |
| 158 // Note: This can't be in an anonymous namespace because it must be declared | |
| 159 // as a friend of |DownloadFile| in order to access its private members. | |
| 160 class DownloadFileWithMockStream : public DownloadFile { | |
| 161 public: | |
| 162 DownloadFileWithMockStream(DownloadCreateInfo* info, | |
| 163 DownloadManager* manager, | |
| 164 testing::MockFileStream* stream) | |
| 165 : DownloadFile(info, manager) { | |
| 166 DCHECK(file_stream_ == NULL); | |
| 167 file_stream_.reset(stream); | |
| 168 } | |
| 169 virtual ~DownloadFileWithMockStream() { | |
| 170 } | |
| 171 | |
| 172 void SetForcedError(int error) | |
| 173 { | |
| 174 // |file_stream_| can only be set in the constructor and in | |
| 175 // CreateFileStream(), both of which insure that it is a |MockFileStream|. | |
| 176 testing::MockFileStream* mock_stream = | |
| 177 static_cast<testing::MockFileStream *>(file_stream_.get()); | |
| 178 mock_stream->set_forced_error(error); | |
| 179 } | |
| 180 | |
| 181 protected: | |
| 182 // This version creates a |MockFileStream| instead of a |FileStream|. | |
| 183 virtual void CreateFileStream() OVERRIDE; | |
| 184 }; | |
| 185 | |
| 186 void DownloadFileWithMockStream::CreateFileStream() { | |
|
Randy Smith (Not in Mondays)
2011/08/29 17:02:07
nit: I'd like to see the class written consistentl
ahendrickson
2011/08/29 17:51:38
Done.
| |
| 187 file_stream_.reset(new testing::MockFileStream); | |
| 188 } | |
| 189 | |
| 129 namespace { | 190 namespace { |
| 130 | 191 |
| 131 const struct { | 192 const struct { |
| 132 const char* url; | 193 const char* url; |
| 133 const char* mime_type; | 194 const char* mime_type; |
| 134 bool save_as; | 195 bool save_as; |
| 135 bool prompt_for_download; | 196 bool prompt_for_download; |
| 136 bool expected_save_as; | 197 bool expected_save_as; |
| 137 } kStartDownloadCases[] = { | 198 } kStartDownloadCases[] = { |
| 138 { "http://www.foo.com/dont-open.html", | 199 { "http://www.foo.com/dont-open.html", |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 DownloadItem* download = GetActiveDownloadItem(i); | 438 DownloadItem* download = GetActiveDownloadItem(i); |
| 378 ASSERT_TRUE(download != NULL); | 439 ASSERT_TRUE(download != NULL); |
| 379 if (kDownloadRenameCases[i].is_dangerous_file) | 440 if (kDownloadRenameCases[i].is_dangerous_file) |
| 380 download->MarkFileDangerous(); | 441 download->MarkFileDangerous(); |
| 381 if (kDownloadRenameCases[i].is_dangerous_url) | 442 if (kDownloadRenameCases[i].is_dangerous_url) |
| 382 download->MarkUrlDangerous(); | 443 download->MarkUrlDangerous(); |
| 383 | 444 |
| 384 int32* id_ptr = new int32; | 445 int32* id_ptr = new int32; |
| 385 *id_ptr = i; // Deleted in FileSelected(). | 446 *id_ptr = i; // Deleted in FileSelected(). |
| 386 if (kDownloadRenameCases[i].finish_before_rename) { | 447 if (kDownloadRenameCases[i].finish_before_rename) { |
| 387 OnAllDataSaved(i, 1024, std::string("fake_hash")); | 448 OnResponseCompleted(i, 1024, std::string("fake_hash")); |
| 388 message_loop_.RunAllPending(); | 449 message_loop_.RunAllPending(); |
| 389 FileSelected(new_path, id_ptr); | 450 FileSelected(new_path, id_ptr); |
| 390 } else { | 451 } else { |
| 391 FileSelected(new_path, id_ptr); | 452 FileSelected(new_path, id_ptr); |
| 392 message_loop_.RunAllPending(); | 453 message_loop_.RunAllPending(); |
| 393 OnAllDataSaved(i, 1024, std::string("fake_hash")); | 454 OnResponseCompleted(i, 1024, std::string("fake_hash")); |
| 394 } | 455 } |
| 395 | 456 |
| 396 message_loop_.RunAllPending(); | 457 message_loop_.RunAllPending(); |
| 397 EXPECT_TRUE(VerifySafetyState(kDownloadRenameCases[i].is_dangerous_file, | 458 EXPECT_TRUE(VerifySafetyState(kDownloadRenameCases[i].is_dangerous_file, |
| 398 kDownloadRenameCases[i].is_dangerous_url, | 459 kDownloadRenameCases[i].is_dangerous_url, |
| 399 i)); | 460 i)); |
| 400 } | 461 } |
| 401 } | 462 } |
| 402 | 463 |
| 403 TEST_F(DownloadManagerTest, DownloadInterruptTest) { | 464 TEST_F(DownloadManagerTest, DownloadInterruptTest) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); | 536 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); |
| 476 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 537 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 477 EXPECT_TRUE(observer->was_updated()); | 538 EXPECT_TRUE(observer->was_updated()); |
| 478 EXPECT_FALSE(observer->was_opened()); | 539 EXPECT_FALSE(observer->was_opened()); |
| 479 EXPECT_FALSE(download->file_externally_removed()); | 540 EXPECT_FALSE(download->file_externally_removed()); |
| 480 EXPECT_EQ(DownloadItem::INTERRUPTED, download->state()); | 541 EXPECT_EQ(DownloadItem::INTERRUPTED, download->state()); |
| 481 EXPECT_EQ(download->received_bytes(), error_size); | 542 EXPECT_EQ(download->received_bytes(), error_size); |
| 482 EXPECT_EQ(download->total_bytes(), static_cast<int64>(kTestDataLen)); | 543 EXPECT_EQ(download->total_bytes(), static_cast<int64>(kTestDataLen)); |
| 483 } | 544 } |
| 484 | 545 |
| 546 // Test the behavior of DownloadFileManager and DownloadManager in the event | |
| 547 // of a file error while writing the download to disk. | |
| 548 TEST_F(DownloadManagerTest, DownloadFileErrorTest) { | |
| 549 // Create a temporary file and a mock stream. | |
| 550 FilePath path; | |
| 551 ASSERT_TRUE(file_util::CreateTemporaryFile(&path)); | |
| 552 | |
| 553 // This file stream will be used, until the first rename occurs. | |
| 554 testing::MockFileStream* mock_stream = new testing::MockFileStream; | |
| 555 ASSERT_EQ(0, mock_stream->Open( | |
| 556 path, | |
| 557 base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE)); | |
| 558 | |
| 559 // Normally, the download system takes ownership of info, and is | |
| 560 // responsible for deleting it. In these unit tests, however, we | |
| 561 // don't call the function that deletes it, so we can use a stack variable. | |
| 562 DownloadCreateInfo info; | |
| 563 int32 id = 0; | |
| 564 info.download_id = id; | |
| 565 info.prompt_user_for_save_location = false; | |
| 566 info.url_chain.push_back(GURL()); | |
| 567 info.total_bytes = static_cast<int64>(kTestDataLen * 3); | |
| 568 info.save_info.file_path = path; | |
| 569 | |
| 570 // Create a download file that we can insert errors into. | |
| 571 DownloadFileWithMockStream* download_file(new DownloadFileWithMockStream( | |
| 572 &info, download_manager_, mock_stream)); | |
| 573 AddDownloadToFileManager(id, download_file); | |
| 574 | |
| 575 // |download_file| is owned by DownloadFileManager. | |
| 576 download_manager_->CreateDownloadItem(&info); | |
| 577 | |
| 578 DownloadItem* download = GetActiveDownloadItem(0); | |
| 579 ASSERT_TRUE(download != NULL); | |
| 580 // This will keep track of what should be displayed on the shelf. | |
| 581 scoped_ptr<DownloadItemModel> download_item_model( | |
| 582 new DownloadItemModel(download)); | |
| 583 | |
| 584 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); | |
| 585 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); | |
| 586 | |
| 587 // Add some data before finalizing the file name. | |
| 588 UpdateData(id, kTestData, kTestDataLen); | |
| 589 | |
| 590 // Finalize the file name. | |
| 591 ContinueDownloadWithPath(download, path); | |
| 592 message_loop_.RunAllPending(); | |
| 593 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | |
| 594 | |
| 595 // Add more data. | |
| 596 UpdateData(id, kTestData, kTestDataLen); | |
| 597 | |
| 598 // Add more data, but an error occurs. | |
| 599 download_file->SetForcedError(net::ERR_FAILED); | |
| 600 UpdateData(id, kTestData, kTestDataLen); | |
| 601 | |
| 602 // Check the state. The download should have been interrupted. | |
| 603 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); | |
| 604 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); | |
| 605 EXPECT_TRUE(observer->hit_state(DownloadItem::INTERRUPTED)); | |
| 606 EXPECT_FALSE(observer->hit_state(DownloadItem::COMPLETE)); | |
| 607 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); | |
| 608 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | |
| 609 EXPECT_TRUE(observer->was_updated()); | |
| 610 EXPECT_FALSE(observer->was_opened()); | |
| 611 EXPECT_FALSE(download->file_externally_removed()); | |
| 612 EXPECT_EQ(DownloadItem::INTERRUPTED, download->state()); | |
| 613 | |
| 614 // Check the download shelf's information. | |
| 615 size_t error_size = kTestDataLen * 3; | |
| 616 ui::DataUnits amount_units = ui::GetByteDisplayUnits(kTestDataLen); | |
| 617 string16 simple_size = | |
| 618 ui::FormatBytesWithUnits(error_size, amount_units, false); | |
| 619 string16 simple_total = base::i18n::GetDisplayStringInLTRDirectionality( | |
| 620 ui::FormatBytesWithUnits(error_size, amount_units, true)); | |
| 621 EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_INTERRUPTED, | |
| 622 simple_size, | |
| 623 simple_total), | |
| 624 download_item_model->GetStatusText()); | |
| 625 | |
| 626 // Clean up. | |
| 627 download->Cancel(true); | |
| 628 message_loop_.RunAllPending(); | |
| 629 } | |
| 630 | |
| 485 TEST_F(DownloadManagerTest, DownloadCancelTest) { | 631 TEST_F(DownloadManagerTest, DownloadCancelTest) { |
| 486 using ::testing::_; | 632 using ::testing::_; |
| 487 using ::testing::CreateFunctor; | 633 using ::testing::CreateFunctor; |
| 488 using ::testing::Invoke; | 634 using ::testing::Invoke; |
| 489 using ::testing::Return; | 635 using ::testing::Return; |
| 490 | 636 |
| 491 // Normally, the download system takes ownership of info, and is | 637 // Normally, the download system takes ownership of info, and is |
| 492 // responsible for deleting it. In these unit tests, however, we | 638 // responsible for deleting it. In these unit tests, however, we |
| 493 // don't call the function that deletes it, so we do so ourselves. | 639 // don't call the function that deletes it, so we do so ourselves. |
| 494 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); | 640 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 // |download_file| is owned by DownloadFileManager. | 748 // |download_file| is owned by DownloadFileManager. |
| 603 AddDownloadToFileManager(info->download_id, download_file); | 749 AddDownloadToFileManager(info->download_id, download_file); |
| 604 | 750 |
| 605 ContinueDownloadWithPath(download, new_path); | 751 ContinueDownloadWithPath(download, new_path); |
| 606 message_loop_.RunAllPending(); | 752 message_loop_.RunAllPending(); |
| 607 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | 753 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
| 608 | 754 |
| 609 download_file->AppendDataToFile(kTestData, kTestDataLen); | 755 download_file->AppendDataToFile(kTestData, kTestDataLen); |
| 610 | 756 |
| 611 // Finish the download. | 757 // Finish the download. |
| 612 OnAllDataSaved(0, kTestDataLen, ""); | 758 OnResponseCompleted(0, kTestDataLen, ""); |
| 613 message_loop_.RunAllPending(); | 759 message_loop_.RunAllPending(); |
| 614 | 760 |
| 615 // Download is complete. | 761 // Download is complete. |
| 616 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); | 762 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); |
| 617 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); | 763 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); |
| 618 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); | 764 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); |
| 619 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); | 765 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); |
| 620 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); | 766 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); |
| 621 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 767 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 622 EXPECT_TRUE(observer->was_updated()); | 768 EXPECT_TRUE(observer->was_updated()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 // |download_file| is owned by DownloadFileManager. | 824 // |download_file| is owned by DownloadFileManager. |
| 679 AddDownloadToFileManager(info->download_id, download_file); | 825 AddDownloadToFileManager(info->download_id, download_file); |
| 680 | 826 |
| 681 ContinueDownloadWithPath(download, new_path); | 827 ContinueDownloadWithPath(download, new_path); |
| 682 message_loop_.RunAllPending(); | 828 message_loop_.RunAllPending(); |
| 683 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | 829 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
| 684 | 830 |
| 685 download_file->AppendDataToFile(kTestData, kTestDataLen); | 831 download_file->AppendDataToFile(kTestData, kTestDataLen); |
| 686 | 832 |
| 687 // Finish the download. | 833 // Finish the download. |
| 688 OnAllDataSaved(0, kTestDataLen, ""); | 834 OnResponseCompleted(0, kTestDataLen, ""); |
| 689 message_loop_.RunAllPending(); | 835 message_loop_.RunAllPending(); |
| 690 | 836 |
| 691 // Download is complete. | 837 // Download is complete. |
| 692 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); | 838 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); |
| 693 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); | 839 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); |
| 694 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); | 840 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); |
| 695 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); | 841 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); |
| 696 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); | 842 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); |
| 697 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 843 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 698 EXPECT_TRUE(observer->was_updated()); | 844 EXPECT_TRUE(observer->was_updated()); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 717 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 863 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 718 EXPECT_TRUE(observer->was_updated()); | 864 EXPECT_TRUE(observer->was_updated()); |
| 719 EXPECT_FALSE(observer->was_opened()); | 865 EXPECT_FALSE(observer->was_opened()); |
| 720 EXPECT_TRUE(download->file_externally_removed()); | 866 EXPECT_TRUE(download->file_externally_removed()); |
| 721 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); | 867 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); |
| 722 EXPECT_EQ(download_item_model->GetStatusText(), | 868 EXPECT_EQ(download_item_model->GetStatusText(), |
| 723 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); | 869 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); |
| 724 | 870 |
| 725 EXPECT_FALSE(file_util::PathExists(new_path)); | 871 EXPECT_FALSE(file_util::PathExists(new_path)); |
| 726 } | 872 } |
| OLD | NEW |