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 net::testing::MockFileStream* stream); |
| 165 |
| 166 virtual ~DownloadFileWithMockStream() {} |
| 167 |
| 168 void SetForcedError(int error); |
| 169 |
| 170 protected: |
| 171 // This version creates a |MockFileStream| instead of a |FileStream|. |
| 172 virtual void CreateFileStream() OVERRIDE; |
| 173 }; |
| 174 |
| 175 DownloadFileWithMockStream::DownloadFileWithMockStream( |
| 176 DownloadCreateInfo* info, |
| 177 DownloadManager* manager, |
| 178 net::testing::MockFileStream* stream) |
| 179 : DownloadFile(info, manager) { |
| 180 DCHECK(file_stream_ == NULL); |
| 181 file_stream_.reset(stream); |
| 182 } |
| 183 |
| 184 void DownloadFileWithMockStream::SetForcedError(int error) |
| 185 { |
| 186 // |file_stream_| can only be set in the constructor and in |
| 187 // CreateFileStream(), both of which insure that it is a |MockFileStream|. |
| 188 net::testing::MockFileStream* mock_stream = |
| 189 static_cast<net::testing::MockFileStream *>(file_stream_.get()); |
| 190 mock_stream->set_forced_error(error); |
| 191 } |
| 192 void DownloadFileWithMockStream::CreateFileStream() { |
| 193 file_stream_.reset(new net::testing::MockFileStream); |
| 194 } |
| 195 |
129 namespace { | 196 namespace { |
130 | 197 |
131 const struct { | 198 const struct { |
132 const char* url; | 199 const char* url; |
133 const char* mime_type; | 200 const char* mime_type; |
134 bool save_as; | 201 bool save_as; |
135 bool prompt_for_download; | 202 bool prompt_for_download; |
136 bool expected_save_as; | 203 bool expected_save_as; |
137 } kStartDownloadCases[] = { | 204 } kStartDownloadCases[] = { |
138 { "http://www.foo.com/dont-open.html", | 205 { "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); | 444 DownloadItem* download = GetActiveDownloadItem(i); |
378 ASSERT_TRUE(download != NULL); | 445 ASSERT_TRUE(download != NULL); |
379 if (kDownloadRenameCases[i].is_dangerous_file) | 446 if (kDownloadRenameCases[i].is_dangerous_file) |
380 download->MarkFileDangerous(); | 447 download->MarkFileDangerous(); |
381 if (kDownloadRenameCases[i].is_dangerous_url) | 448 if (kDownloadRenameCases[i].is_dangerous_url) |
382 download->MarkUrlDangerous(); | 449 download->MarkUrlDangerous(); |
383 | 450 |
384 int32* id_ptr = new int32; | 451 int32* id_ptr = new int32; |
385 *id_ptr = i; // Deleted in FileSelected(). | 452 *id_ptr = i; // Deleted in FileSelected(). |
386 if (kDownloadRenameCases[i].finish_before_rename) { | 453 if (kDownloadRenameCases[i].finish_before_rename) { |
387 OnAllDataSaved(i, 1024, std::string("fake_hash")); | 454 OnResponseCompleted(i, 1024, std::string("fake_hash")); |
388 message_loop_.RunAllPending(); | 455 message_loop_.RunAllPending(); |
389 FileSelected(new_path, id_ptr); | 456 FileSelected(new_path, id_ptr); |
390 } else { | 457 } else { |
391 FileSelected(new_path, id_ptr); | 458 FileSelected(new_path, id_ptr); |
392 message_loop_.RunAllPending(); | 459 message_loop_.RunAllPending(); |
393 OnAllDataSaved(i, 1024, std::string("fake_hash")); | 460 OnResponseCompleted(i, 1024, std::string("fake_hash")); |
394 } | 461 } |
395 | 462 |
396 message_loop_.RunAllPending(); | 463 message_loop_.RunAllPending(); |
397 EXPECT_TRUE(VerifySafetyState(kDownloadRenameCases[i].is_dangerous_file, | 464 EXPECT_TRUE(VerifySafetyState(kDownloadRenameCases[i].is_dangerous_file, |
398 kDownloadRenameCases[i].is_dangerous_url, | 465 kDownloadRenameCases[i].is_dangerous_url, |
399 i)); | 466 i)); |
400 } | 467 } |
401 } | 468 } |
402 | 469 |
403 TEST_F(DownloadManagerTest, DownloadInterruptTest) { | 470 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)); | 542 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); |
476 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 543 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
477 EXPECT_TRUE(observer->was_updated()); | 544 EXPECT_TRUE(observer->was_updated()); |
478 EXPECT_FALSE(observer->was_opened()); | 545 EXPECT_FALSE(observer->was_opened()); |
479 EXPECT_FALSE(download->file_externally_removed()); | 546 EXPECT_FALSE(download->file_externally_removed()); |
480 EXPECT_EQ(DownloadItem::INTERRUPTED, download->state()); | 547 EXPECT_EQ(DownloadItem::INTERRUPTED, download->state()); |
481 EXPECT_EQ(download->received_bytes(), error_size); | 548 EXPECT_EQ(download->received_bytes(), error_size); |
482 EXPECT_EQ(download->total_bytes(), static_cast<int64>(kTestDataLen)); | 549 EXPECT_EQ(download->total_bytes(), static_cast<int64>(kTestDataLen)); |
483 } | 550 } |
484 | 551 |
| 552 // Test the behavior of DownloadFileManager and DownloadManager in the event |
| 553 // of a file error while writing the download to disk. |
| 554 TEST_F(DownloadManagerTest, DownloadFileErrorTest) { |
| 555 // Create a temporary file and a mock stream. |
| 556 FilePath path; |
| 557 ASSERT_TRUE(file_util::CreateTemporaryFile(&path)); |
| 558 |
| 559 // This file stream will be used, until the first rename occurs. |
| 560 net::testing::MockFileStream* mock_stream = new net::testing::MockFileStream; |
| 561 ASSERT_EQ(0, mock_stream->Open( |
| 562 path, |
| 563 base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE)); |
| 564 |
| 565 // Normally, the download system takes ownership of info, and is |
| 566 // responsible for deleting it. In these unit tests, however, we |
| 567 // don't call the function that deletes it, so we do so ourselves. |
| 568 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); |
| 569 int32 id = 0; |
| 570 info->download_id = id; |
| 571 info->prompt_user_for_save_location = false; |
| 572 info->url_chain.push_back(GURL()); |
| 573 info->total_bytes = static_cast<int64>(kTestDataLen * 3); |
| 574 info->save_info.file_path = path; |
| 575 |
| 576 // Create a download file that we can insert errors into. |
| 577 DownloadFileWithMockStream* download_file(new DownloadFileWithMockStream( |
| 578 info.get(), download_manager_, mock_stream)); |
| 579 AddDownloadToFileManager(id, download_file); |
| 580 |
| 581 // |download_file| is owned by DownloadFileManager. |
| 582 download_manager_->CreateDownloadItem(info.get()); |
| 583 |
| 584 DownloadItem* download = GetActiveDownloadItem(0); |
| 585 ASSERT_TRUE(download != NULL); |
| 586 // This will keep track of what should be displayed on the shelf. |
| 587 scoped_ptr<DownloadItemModel> download_item_model( |
| 588 new DownloadItemModel(download)); |
| 589 |
| 590 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); |
| 591 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); |
| 592 |
| 593 // Add some data before finalizing the file name. |
| 594 UpdateData(id, kTestData, kTestDataLen); |
| 595 |
| 596 // Finalize the file name. |
| 597 ContinueDownloadWithPath(download, path); |
| 598 message_loop_.RunAllPending(); |
| 599 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
| 600 |
| 601 // Add more data. |
| 602 UpdateData(id, kTestData, kTestDataLen); |
| 603 |
| 604 // Add more data, but an error occurs. |
| 605 download_file->SetForcedError(net::ERR_FAILED); |
| 606 UpdateData(id, kTestData, kTestDataLen); |
| 607 |
| 608 // Check the state. The download should have been interrupted. |
| 609 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); |
| 610 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); |
| 611 EXPECT_TRUE(observer->hit_state(DownloadItem::INTERRUPTED)); |
| 612 EXPECT_FALSE(observer->hit_state(DownloadItem::COMPLETE)); |
| 613 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); |
| 614 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 615 EXPECT_TRUE(observer->was_updated()); |
| 616 EXPECT_FALSE(observer->was_opened()); |
| 617 EXPECT_FALSE(download->file_externally_removed()); |
| 618 EXPECT_EQ(DownloadItem::INTERRUPTED, download->state()); |
| 619 |
| 620 // Check the download shelf's information. |
| 621 size_t error_size = kTestDataLen * 3; |
| 622 ui::DataUnits amount_units = ui::GetByteDisplayUnits(kTestDataLen); |
| 623 string16 simple_size = |
| 624 ui::FormatBytesWithUnits(error_size, amount_units, false); |
| 625 string16 simple_total = base::i18n::GetDisplayStringInLTRDirectionality( |
| 626 ui::FormatBytesWithUnits(error_size, amount_units, true)); |
| 627 EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_INTERRUPTED, |
| 628 simple_size, |
| 629 simple_total), |
| 630 download_item_model->GetStatusText()); |
| 631 |
| 632 // Clean up. |
| 633 download->Cancel(true); |
| 634 message_loop_.RunAllPending(); |
| 635 } |
| 636 |
485 TEST_F(DownloadManagerTest, DownloadCancelTest) { | 637 TEST_F(DownloadManagerTest, DownloadCancelTest) { |
486 using ::testing::_; | 638 using ::testing::_; |
487 using ::testing::CreateFunctor; | 639 using ::testing::CreateFunctor; |
488 using ::testing::Invoke; | 640 using ::testing::Invoke; |
489 using ::testing::Return; | 641 using ::testing::Return; |
490 | 642 |
491 // Normally, the download system takes ownership of info, and is | 643 // Normally, the download system takes ownership of info, and is |
492 // responsible for deleting it. In these unit tests, however, we | 644 // responsible for deleting it. In these unit tests, however, we |
493 // don't call the function that deletes it, so we do so ourselves. | 645 // don't call the function that deletes it, so we do so ourselves. |
494 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); | 646 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. | 754 // |download_file| is owned by DownloadFileManager. |
603 AddDownloadToFileManager(info->download_id, download_file); | 755 AddDownloadToFileManager(info->download_id, download_file); |
604 | 756 |
605 ContinueDownloadWithPath(download, new_path); | 757 ContinueDownloadWithPath(download, new_path); |
606 message_loop_.RunAllPending(); | 758 message_loop_.RunAllPending(); |
607 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | 759 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
608 | 760 |
609 download_file->AppendDataToFile(kTestData, kTestDataLen); | 761 download_file->AppendDataToFile(kTestData, kTestDataLen); |
610 | 762 |
611 // Finish the download. | 763 // Finish the download. |
612 OnAllDataSaved(0, kTestDataLen, ""); | 764 OnResponseCompleted(0, kTestDataLen, ""); |
613 message_loop_.RunAllPending(); | 765 message_loop_.RunAllPending(); |
614 | 766 |
615 // Download is complete. | 767 // Download is complete. |
616 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); | 768 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); |
617 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); | 769 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); |
618 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); | 770 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); |
619 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); | 771 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); |
620 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); | 772 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); |
621 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 773 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
622 EXPECT_TRUE(observer->was_updated()); | 774 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. | 830 // |download_file| is owned by DownloadFileManager. |
679 AddDownloadToFileManager(info->download_id, download_file); | 831 AddDownloadToFileManager(info->download_id, download_file); |
680 | 832 |
681 ContinueDownloadWithPath(download, new_path); | 833 ContinueDownloadWithPath(download, new_path); |
682 message_loop_.RunAllPending(); | 834 message_loop_.RunAllPending(); |
683 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | 835 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
684 | 836 |
685 download_file->AppendDataToFile(kTestData, kTestDataLen); | 837 download_file->AppendDataToFile(kTestData, kTestDataLen); |
686 | 838 |
687 // Finish the download. | 839 // Finish the download. |
688 OnAllDataSaved(0, kTestDataLen, ""); | 840 OnResponseCompleted(0, kTestDataLen, ""); |
689 message_loop_.RunAllPending(); | 841 message_loop_.RunAllPending(); |
690 | 842 |
691 // Download is complete. | 843 // Download is complete. |
692 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); | 844 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); |
693 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); | 845 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); |
694 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); | 846 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); |
695 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); | 847 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); |
696 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); | 848 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); |
697 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 849 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
698 EXPECT_TRUE(observer->was_updated()); | 850 EXPECT_TRUE(observer->was_updated()); |
(...skipping 18 matching lines...) Expand all Loading... |
717 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 869 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
718 EXPECT_TRUE(observer->was_updated()); | 870 EXPECT_TRUE(observer->was_updated()); |
719 EXPECT_FALSE(observer->was_opened()); | 871 EXPECT_FALSE(observer->was_opened()); |
720 EXPECT_TRUE(download->file_externally_removed()); | 872 EXPECT_TRUE(download->file_externally_removed()); |
721 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); | 873 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); |
722 EXPECT_EQ(download_item_model->GetStatusText(), | 874 EXPECT_EQ(download_item_model->GetStatusText(), |
723 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); | 875 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); |
724 | 876 |
725 EXPECT_FALSE(file_util::PathExists(new_path)); | 877 EXPECT_FALSE(file_util::PathExists(new_path)); |
726 } | 878 } |
OLD | NEW |