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 void* data, size_t length) { | |
cbentzel
2011/08/29 15:05:27
Should |data| be const char* to be consistent with
ahendrickson
2011/08/29 16:30:53
I don't have a strong opinion about this.
Changed
| |
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 io_buffer is not a |scoped_refptr|, and we | |
cbentzel
2011/08/29 15:05:27
This comment isn't quite correct. If io_buffer wer
ahendrickson
2011/08/29 16:30:53
Yeah, it's funky.
Changed.
| |
89 // will do a |Release()| in |UpdateDownload()|. | |
90 io_buffer->AddRef(); | |
91 memcpy(io_buffer->data(), data, length); | |
92 | |
93 { | |
94 base::AutoLock auto_lock(download_buffer_.lock); | |
cbentzel
2011/08/29 15:05:27
This is kinda gross, although it already existed.
ahendrickson
2011/08/29 16:30:53
I think that's outside the scope of this CL.
Randy Smith (Not in Mondays)
2011/08/29 16:57:57
Agreed with both points (suggested refactor, and t
| |
95 | |
96 download_buffer_.contents.push_back( | |
97 std::make_pair(io_buffer, length)); | |
98 } | |
99 | |
100 BrowserThread::PostTask( | |
101 BrowserThread::FILE, FROM_HERE, | |
102 NewRunnableMethod(file_manager_.get(), | |
103 &DownloadFileManager::UpdateDownload, | |
104 id, | |
105 &download_buffer_)); | |
106 | |
107 message_loop_.RunAllPending(); | |
cbentzel
2011/08/29 15:05:27
Why do you need to do this inside of UpdateData?
ahendrickson
2011/08/29 16:30:53
For other operations. Most tests don't need to us
| |
108 } | |
109 | |
82 void OnDownloadError(int32 download_id, int64 size, int os_error) { | 110 void OnDownloadError(int32 download_id, int64 size, int os_error) { |
83 download_manager_->OnDownloadError(download_id, size, os_error); | 111 download_manager_->OnDownloadError(download_id, size, os_error); |
84 } | 112 } |
85 | 113 |
86 // Get the download item with ID |id|. | 114 // Get the download item with ID |id|. |
87 DownloadItem* GetActiveDownloadItem(int32 id) { | 115 DownloadItem* GetActiveDownloadItem(int32 id) { |
88 if (ContainsKey(download_manager_->active_downloads_, id)) | 116 if (ContainsKey(download_manager_->active_downloads_, id)) |
89 return download_manager_->active_downloads_[id]; | 117 return download_manager_->active_downloads_[id]; |
90 return NULL; | 118 return NULL; |
91 } | 119 } |
92 | 120 |
93 protected: | 121 protected: |
94 DownloadStatusUpdater download_status_updater_; | 122 DownloadStatusUpdater download_status_updater_; |
95 scoped_ptr<TestingProfile> profile_; | 123 scoped_ptr<TestingProfile> profile_; |
96 scoped_refptr<ChromeDownloadManagerDelegate> download_manager_delegate_; | 124 scoped_refptr<ChromeDownloadManagerDelegate> download_manager_delegate_; |
97 scoped_refptr<DownloadManager> download_manager_; | 125 scoped_refptr<DownloadManager> download_manager_; |
98 scoped_refptr<DownloadFileManager> file_manager_; | 126 scoped_refptr<DownloadFileManager> file_manager_; |
99 MessageLoopForUI message_loop_; | 127 MessageLoopForUI message_loop_; |
100 BrowserThread ui_thread_; | 128 BrowserThread ui_thread_; |
101 BrowserThread file_thread_; | 129 BrowserThread file_thread_; |
130 DownloadBuffer download_buffer_; | |
102 | 131 |
103 DownloadFileManager* file_manager() { | 132 DownloadFileManager* file_manager() { |
104 if (!file_manager_) { | 133 if (!file_manager_) { |
105 file_manager_ = new DownloadFileManager(NULL); | 134 file_manager_ = new DownloadFileManager(NULL); |
106 download_manager_->file_manager_ = file_manager_; | 135 download_manager_->file_manager_ = file_manager_; |
107 } | 136 } |
108 return file_manager_; | 137 return file_manager_; |
109 } | 138 } |
110 | 139 |
111 // Make sure download item |id| was set with correct safety state for | 140 // Make sure download item |id| was set with correct safety state for |
112 // given |is_dangerous_file| and |is_dangerous_url|. | 141 // given |is_dangerous_file| and |is_dangerous_url|. |
113 bool VerifySafetyState(bool is_dangerous_file, | 142 bool VerifySafetyState(bool is_dangerous_file, |
114 bool is_dangerous_url, | 143 bool is_dangerous_url, |
115 int id) { | 144 int id) { |
116 DownloadItem::SafetyState safety_state = | 145 DownloadItem::SafetyState safety_state = |
117 download_manager_->GetDownloadItem(id)->safety_state(); | 146 download_manager_->GetDownloadItem(id)->safety_state(); |
118 return (is_dangerous_file || is_dangerous_url) ? | 147 return (is_dangerous_file || is_dangerous_url) ? |
119 safety_state != DownloadItem::SAFE : safety_state == DownloadItem::SAFE; | 148 safety_state != DownloadItem::SAFE : safety_state == DownloadItem::SAFE; |
120 } | 149 } |
121 | 150 |
122 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); | 151 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); |
123 }; | 152 }; |
124 | 153 |
125 const char* DownloadManagerTest::kTestData = "a;sdlfalsdfjalsdkfjad"; | 154 const char* DownloadManagerTest::kTestData = "a;sdlfalsdfjalsdkfjad"; |
126 const size_t DownloadManagerTest::kTestDataLen = | 155 const size_t DownloadManagerTest::kTestDataLen = |
127 strlen(DownloadManagerTest::kTestData); | 156 strlen(DownloadManagerTest::kTestData); |
128 | 157 |
158 // A DownloadFile that we can inject errors into. Uses MockFileStream. | |
159 // Note: This can't be in an anonymous namespace because it must be declared | |
160 // as a friend of |DownloadFile| in order to access its private members. | |
cbentzel
2011/08/29 15:05:27
Could you just add a DownloadFile constructor whic
ahendrickson
2011/08/29 16:30:53
It needs more information than just the file strea
| |
161 class DownloadFileWithMockStream : public DownloadFile { | |
162 public: | |
163 DownloadFileWithMockStream(DownloadCreateInfo* info, | |
164 DownloadManager* manager, | |
165 testing::MockFileStream* stream) | |
166 : DownloadFile(info, manager) { | |
167 DCHECK(file_stream_ == NULL); | |
168 file_stream_.reset(stream); | |
169 } | |
170 virtual ~DownloadFileWithMockStream() { | |
171 } | |
172 | |
173 void SetForcedError(int error) | |
174 { | |
175 testing::MockFileStream* mock_stream = | |
Randy Smith (Not in Mondays)
2011/08/28 22:14:03
Please put in a comment as to why the upcast is ok
ahendrickson
2011/08/29 16:30:53
Done.
| |
176 static_cast<testing::MockFileStream *>(file_stream_.get()); | |
177 mock_stream->set_forced_error(error); | |
178 } | |
179 | |
180 protected: | |
181 // This version creates a |MockFileStream| instead of a |FileStream|. | |
182 virtual void CreateFileStream() { | |
cbentzel
2011/08/29 15:05:27
OVERRIDE
cbentzel
2011/08/29 15:05:27
Is this expected to be called?
ahendrickson
2011/08/29 16:30:53
Yes, from Open().
ahendrickson
2011/08/29 16:30:53
Done.
cbentzel
2011/08/29 17:27:55
Well, it could be called from Open(), but that onl
ahendrickson
2011/08/29 17:51:37
No, the rename operation does a Close() (which res
| |
183 file_stream_.reset(new testing::MockFileStream); | |
184 } | |
185 }; | |
186 | |
129 namespace { | 187 namespace { |
130 | 188 |
131 const struct { | 189 const struct { |
132 const char* url; | 190 const char* url; |
133 const char* mime_type; | 191 const char* mime_type; |
134 bool save_as; | 192 bool save_as; |
135 bool prompt_for_download; | 193 bool prompt_for_download; |
136 bool expected_save_as; | 194 bool expected_save_as; |
137 } kStartDownloadCases[] = { | 195 } kStartDownloadCases[] = { |
138 { "http://www.foo.com/dont-open.html", | 196 { "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); | 435 DownloadItem* download = GetActiveDownloadItem(i); |
378 ASSERT_TRUE(download != NULL); | 436 ASSERT_TRUE(download != NULL); |
379 if (kDownloadRenameCases[i].is_dangerous_file) | 437 if (kDownloadRenameCases[i].is_dangerous_file) |
380 download->MarkFileDangerous(); | 438 download->MarkFileDangerous(); |
381 if (kDownloadRenameCases[i].is_dangerous_url) | 439 if (kDownloadRenameCases[i].is_dangerous_url) |
382 download->MarkUrlDangerous(); | 440 download->MarkUrlDangerous(); |
383 | 441 |
384 int32* id_ptr = new int32; | 442 int32* id_ptr = new int32; |
385 *id_ptr = i; // Deleted in FileSelected(). | 443 *id_ptr = i; // Deleted in FileSelected(). |
386 if (kDownloadRenameCases[i].finish_before_rename) { | 444 if (kDownloadRenameCases[i].finish_before_rename) { |
387 OnAllDataSaved(i, 1024, std::string("fake_hash")); | 445 OnResponseCompleted(i, 1024, std::string("fake_hash")); |
388 message_loop_.RunAllPending(); | 446 message_loop_.RunAllPending(); |
389 FileSelected(new_path, id_ptr); | 447 FileSelected(new_path, id_ptr); |
390 } else { | 448 } else { |
391 FileSelected(new_path, id_ptr); | 449 FileSelected(new_path, id_ptr); |
392 message_loop_.RunAllPending(); | 450 message_loop_.RunAllPending(); |
393 OnAllDataSaved(i, 1024, std::string("fake_hash")); | 451 OnResponseCompleted(i, 1024, std::string("fake_hash")); |
394 } | 452 } |
395 | 453 |
396 message_loop_.RunAllPending(); | 454 message_loop_.RunAllPending(); |
397 EXPECT_TRUE(VerifySafetyState(kDownloadRenameCases[i].is_dangerous_file, | 455 EXPECT_TRUE(VerifySafetyState(kDownloadRenameCases[i].is_dangerous_file, |
398 kDownloadRenameCases[i].is_dangerous_url, | 456 kDownloadRenameCases[i].is_dangerous_url, |
399 i)); | 457 i)); |
400 } | 458 } |
401 } | 459 } |
402 | 460 |
403 TEST_F(DownloadManagerTest, DownloadInterruptTest) { | 461 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)); | 533 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); |
476 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 534 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
477 EXPECT_TRUE(observer->was_updated()); | 535 EXPECT_TRUE(observer->was_updated()); |
478 EXPECT_FALSE(observer->was_opened()); | 536 EXPECT_FALSE(observer->was_opened()); |
479 EXPECT_FALSE(download->file_externally_removed()); | 537 EXPECT_FALSE(download->file_externally_removed()); |
480 EXPECT_EQ(DownloadItem::INTERRUPTED, download->state()); | 538 EXPECT_EQ(DownloadItem::INTERRUPTED, download->state()); |
481 EXPECT_EQ(download->received_bytes(), error_size); | 539 EXPECT_EQ(download->received_bytes(), error_size); |
482 EXPECT_EQ(download->total_bytes(), static_cast<int64>(kTestDataLen)); | 540 EXPECT_EQ(download->total_bytes(), static_cast<int64>(kTestDataLen)); |
483 } | 541 } |
484 | 542 |
543 // Test the behavior of DownloadFileManager and DownloadManager in the event | |
544 // of a file error while writing the download to disk. | |
545 TEST_F(DownloadManagerTest, DownloadFileErrorTest) { | |
546 // Create a temporary file and a mock stream. | |
547 FilePath path; | |
548 ASSERT_TRUE(file_util::CreateTemporaryFile(&path)); | |
549 | |
550 // This file stream will be used, until the first rename occurs. | |
551 testing::MockFileStream* mock_stream = new testing::MockFileStream; | |
552 ASSERT_EQ(0, mock_stream->Open( | |
553 path, | |
554 base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE)); | |
555 | |
556 // Normally, the download system takes ownership of info, and is | |
557 // responsible for deleting it. In these unit tests, however, we | |
558 // don't call the function that deletes it, so we can use a stack variable. | |
cbentzel
2011/08/29 15:05:27
Looks like other tests use scoped_ptr. I'd either
ahendrickson
2011/08/29 16:30:53
DownloadFileManager::CreateDownloadFile() normally
Randy Smith (Not in Mondays)
2011/08/29 16:57:57
I'm cool with shifting back to scoped_ptr; I agree
ahendrickson
2011/08/29 17:51:37
Done.
| |
559 DownloadCreateInfo info; | |
560 int32 id = 0; | |
561 info.download_id = id; | |
562 info.prompt_user_for_save_location = false; | |
563 info.url_chain.push_back(GURL()); | |
564 info.total_bytes = static_cast<int64>(kTestDataLen * 3); | |
565 info.save_info.file_path = path; | |
566 | |
567 // Create a download file that we can insert errors into. | |
568 DownloadFileWithMockStream* download_file(new DownloadFileWithMockStream( | |
569 &info, download_manager_, mock_stream)); | |
570 AddDownloadToFileManager(id, download_file); | |
571 | |
572 // |download_file| is owned by DownloadFileManager. | |
573 ::testing::Mock::AllowLeak(download_file); | |
Randy Smith (Not in Mondays)
2011/08/28 22:14:03
Why does the leak occur? Shouldn't it be cleaned
ahendrickson
2011/08/29 16:30:53
Hmm, thinking about it, due to recent refactorings
| |
574 download_manager_->CreateDownloadItem(&info); | |
575 | |
576 DownloadItem* download = GetActiveDownloadItem(0); | |
577 ASSERT_TRUE(download != NULL); | |
578 // This will keep track of what should be displayed on the shelf. | |
579 scoped_ptr<DownloadItemModel> download_item_model( | |
580 new DownloadItemModel(download)); | |
581 | |
582 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); | |
583 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); | |
584 | |
585 // Add some data before finalizing the file name. | |
586 UpdateData(id, kTestData, kTestDataLen); | |
587 | |
588 // Finalize the file name. | |
589 ContinueDownloadWithPath(download, path); | |
590 message_loop_.RunAllPending(); | |
591 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | |
592 | |
593 // Add more data. | |
594 UpdateData(id, kTestData, kTestDataLen); | |
595 | |
596 // Add more data, but an error occurs. | |
597 download_file->SetForcedError(net::ERR_FAILED); | |
598 UpdateData(id, kTestData, kTestDataLen); | |
599 | |
600 // Check the state. The download should have been interrupted. | |
601 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); | |
602 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); | |
603 EXPECT_TRUE(observer->hit_state(DownloadItem::INTERRUPTED)); | |
604 EXPECT_FALSE(observer->hit_state(DownloadItem::COMPLETE)); | |
605 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); | |
606 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | |
607 EXPECT_TRUE(observer->was_updated()); | |
608 EXPECT_FALSE(observer->was_opened()); | |
609 EXPECT_FALSE(download->file_externally_removed()); | |
610 EXPECT_EQ(DownloadItem::INTERRUPTED, download->state()); | |
611 | |
612 // Check the download shelf's information. | |
613 size_t error_size = kTestDataLen * 3; | |
614 ui::DataUnits amount_units = ui::GetByteDisplayUnits(kTestDataLen); | |
615 string16 simple_size = | |
616 ui::FormatBytesWithUnits(error_size, amount_units, false); | |
617 string16 simple_total = base::i18n::GetDisplayStringInLTRDirectionality( | |
618 ui::FormatBytesWithUnits(error_size, amount_units, true)); | |
619 EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_INTERRUPTED, | |
620 simple_size, | |
621 simple_total), | |
622 download_item_model->GetStatusText()); | |
623 | |
624 // Clean up. | |
625 download->Cancel(true); | |
626 } | |
627 | |
485 TEST_F(DownloadManagerTest, DownloadCancelTest) { | 628 TEST_F(DownloadManagerTest, DownloadCancelTest) { |
486 using ::testing::_; | 629 using ::testing::_; |
487 using ::testing::CreateFunctor; | 630 using ::testing::CreateFunctor; |
488 using ::testing::Invoke; | 631 using ::testing::Invoke; |
489 using ::testing::Return; | 632 using ::testing::Return; |
490 | 633 |
491 // Normally, the download system takes ownership of info, and is | 634 // Normally, the download system takes ownership of info, and is |
492 // responsible for deleting it. In these unit tests, however, we | 635 // responsible for deleting it. In these unit tests, however, we |
493 // don't call the function that deletes it, so we do so ourselves. | 636 // don't call the function that deletes it, so we do so ourselves. |
494 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); | 637 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. | 745 // |download_file| is owned by DownloadFileManager. |
603 AddDownloadToFileManager(info->download_id, download_file); | 746 AddDownloadToFileManager(info->download_id, download_file); |
604 | 747 |
605 ContinueDownloadWithPath(download, new_path); | 748 ContinueDownloadWithPath(download, new_path); |
606 message_loop_.RunAllPending(); | 749 message_loop_.RunAllPending(); |
607 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | 750 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
608 | 751 |
609 download_file->AppendDataToFile(kTestData, kTestDataLen); | 752 download_file->AppendDataToFile(kTestData, kTestDataLen); |
610 | 753 |
611 // Finish the download. | 754 // Finish the download. |
612 OnAllDataSaved(0, kTestDataLen, ""); | 755 OnResponseCompleted(0, kTestDataLen, ""); |
613 message_loop_.RunAllPending(); | 756 message_loop_.RunAllPending(); |
614 | 757 |
615 // Download is complete. | 758 // Download is complete. |
616 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); | 759 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); |
617 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); | 760 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); |
618 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); | 761 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); |
619 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); | 762 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); |
620 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); | 763 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); |
621 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 764 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
622 EXPECT_TRUE(observer->was_updated()); | 765 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. | 821 // |download_file| is owned by DownloadFileManager. |
679 AddDownloadToFileManager(info->download_id, download_file); | 822 AddDownloadToFileManager(info->download_id, download_file); |
680 | 823 |
681 ContinueDownloadWithPath(download, new_path); | 824 ContinueDownloadWithPath(download, new_path); |
682 message_loop_.RunAllPending(); | 825 message_loop_.RunAllPending(); |
683 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | 826 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
684 | 827 |
685 download_file->AppendDataToFile(kTestData, kTestDataLen); | 828 download_file->AppendDataToFile(kTestData, kTestDataLen); |
686 | 829 |
687 // Finish the download. | 830 // Finish the download. |
688 OnAllDataSaved(0, kTestDataLen, ""); | 831 OnResponseCompleted(0, kTestDataLen, ""); |
689 message_loop_.RunAllPending(); | 832 message_loop_.RunAllPending(); |
690 | 833 |
691 // Download is complete. | 834 // Download is complete. |
692 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); | 835 EXPECT_TRUE(GetActiveDownloadItem(0) == NULL); |
693 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); | 836 EXPECT_TRUE(observer->hit_state(DownloadItem::IN_PROGRESS)); |
694 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); | 837 EXPECT_FALSE(observer->hit_state(DownloadItem::CANCELLED)); |
695 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); | 838 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); |
696 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); | 839 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); |
697 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 840 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
698 EXPECT_TRUE(observer->was_updated()); | 841 EXPECT_TRUE(observer->was_updated()); |
(...skipping 18 matching lines...) Expand all Loading... | |
717 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 860 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
718 EXPECT_TRUE(observer->was_updated()); | 861 EXPECT_TRUE(observer->was_updated()); |
719 EXPECT_FALSE(observer->was_opened()); | 862 EXPECT_FALSE(observer->was_opened()); |
720 EXPECT_TRUE(download->file_externally_removed()); | 863 EXPECT_TRUE(download->file_externally_removed()); |
721 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); | 864 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); |
722 EXPECT_EQ(download_item_model->GetStatusText(), | 865 EXPECT_EQ(download_item_model->GetStatusText(), |
723 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); | 866 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); |
724 | 867 |
725 EXPECT_FALSE(file_util::PathExists(new_path)); | 868 EXPECT_FALSE(file_util::PathExists(new_path)); |
726 } | 869 } |
OLD | NEW |