| 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/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/i18n/number_formatting.h" | 10 #include "base/i18n/number_formatting.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 169 |
| 170 protected: | 170 protected: |
| 171 // This version creates a |MockFileStream| instead of a |FileStream|. | 171 // This version creates a |MockFileStream| instead of a |FileStream|. |
| 172 virtual void CreateFileStream() OVERRIDE; | 172 virtual void CreateFileStream() OVERRIDE; |
| 173 }; | 173 }; |
| 174 | 174 |
| 175 DownloadFileWithMockStream::DownloadFileWithMockStream( | 175 DownloadFileWithMockStream::DownloadFileWithMockStream( |
| 176 DownloadCreateInfo* info, | 176 DownloadCreateInfo* info, |
| 177 DownloadManager* manager, | 177 DownloadManager* manager, |
| 178 net::testing::MockFileStream* stream) | 178 net::testing::MockFileStream* stream) |
| 179 : DownloadFile(info, DownloadRequestHandle(), manager) { | 179 : DownloadFile(info, new DownloadRequestHandle(), manager) { |
| 180 DCHECK(file_stream_ == NULL); | 180 DCHECK(file_stream_ == NULL); |
| 181 file_stream_.reset(stream); | 181 file_stream_.reset(stream); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void DownloadFileWithMockStream::SetForcedError(int error) | 184 void DownloadFileWithMockStream::SetForcedError(int error) |
| 185 { | 185 { |
| 186 // |file_stream_| can only be set in the constructor and in | 186 // |file_stream_| can only be set in the constructor and in |
| 187 // CreateFileStream(), both of which insure that it is a |MockFileStream|. | 187 // CreateFileStream(), both of which insure that it is a |MockFileStream|. |
| 188 net::testing::MockFileStream* mock_stream = | 188 net::testing::MockFileStream* mock_stream = |
| 189 static_cast<net::testing::MockFileStream *>(file_stream_.get()); | 189 static_cast<net::testing::MockFileStream *>(file_stream_.get()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // Dangerous download, download finishes AFTER file name determined. | 267 // Dangerous download, download finishes AFTER file name determined. |
| 268 // Needs to be renamed only once. | 268 // Needs to be renamed only once. |
| 269 { FILE_PATH_LITERAL("Unconfirmed xxx.crdownload"), true, false, false, 1, }, | 269 { FILE_PATH_LITERAL("Unconfirmed xxx.crdownload"), true, false, false, 1, }, |
| 270 { FILE_PATH_LITERAL("Unconfirmed xxx.crdownload"), false, true, false, 1, }, | 270 { FILE_PATH_LITERAL("Unconfirmed xxx.crdownload"), false, true, false, 1, }, |
| 271 { FILE_PATH_LITERAL("Unconfirmed xxx.crdownload"), true, true, false, 1, }, | 271 { FILE_PATH_LITERAL("Unconfirmed xxx.crdownload"), true, true, false, 1, }, |
| 272 }; | 272 }; |
| 273 | 273 |
| 274 class MockDownloadFile : public DownloadFile { | 274 class MockDownloadFile : public DownloadFile { |
| 275 public: | 275 public: |
| 276 MockDownloadFile(DownloadCreateInfo* info, DownloadManager* manager) | 276 MockDownloadFile(DownloadCreateInfo* info, DownloadManager* manager) |
| 277 : DownloadFile(info, DownloadRequestHandle(), manager), | 277 : DownloadFile(info, new DownloadRequestHandle(), manager), |
| 278 renamed_count_(0) { } | 278 renamed_count_(0) { } |
| 279 virtual ~MockDownloadFile() { Destructed(); } | 279 virtual ~MockDownloadFile() { Destructed(); } |
| 280 MOCK_METHOD1(Rename, net::Error(const FilePath&)); | 280 MOCK_METHOD1(Rename, net::Error(const FilePath&)); |
| 281 MOCK_METHOD0(Destructed, void()); | 281 MOCK_METHOD0(Destructed, void()); |
| 282 | 282 |
| 283 net::Error TestMultipleRename( | 283 net::Error TestMultipleRename( |
| 284 int expected_count, const FilePath& expected, | 284 int expected_count, const FilePath& expected, |
| 285 const FilePath& path) { | 285 const FilePath& path) { |
| 286 ++renamed_count_; | 286 ++renamed_count_; |
| 287 EXPECT_EQ(expected_count, renamed_count_); | 287 EXPECT_EQ(expected_count, renamed_count_); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 // responsible for deleting it. In these unit tests, however, we | 383 // responsible for deleting it. In these unit tests, however, we |
| 384 // don't call the function that deletes it, so we do so ourselves. | 384 // don't call the function that deletes it, so we do so ourselves. |
| 385 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); | 385 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); |
| 386 info->download_id = static_cast<int>(i); | 386 info->download_id = static_cast<int>(i); |
| 387 info->prompt_user_for_save_location = kStartDownloadCases[i].save_as; | 387 info->prompt_user_for_save_location = kStartDownloadCases[i].save_as; |
| 388 info->url_chain.push_back(GURL(kStartDownloadCases[i].url)); | 388 info->url_chain.push_back(GURL(kStartDownloadCases[i].url)); |
| 389 info->mime_type = kStartDownloadCases[i].mime_type; | 389 info->mime_type = kStartDownloadCases[i].mime_type; |
| 390 download_manager_->CreateDownloadItem(info.get(), DownloadRequestHandle()); | 390 download_manager_->CreateDownloadItem(info.get(), DownloadRequestHandle()); |
| 391 | 391 |
| 392 DownloadFile* download_file( | 392 DownloadFile* download_file( |
| 393 new DownloadFile(info.get(), DownloadRequestHandle(), | 393 new DownloadFile(info.get(), new DownloadRequestHandle(), |
| 394 download_manager_)); | 394 download_manager_)); |
| 395 AddDownloadToFileManager(info->download_id, download_file); | 395 AddDownloadToFileManager(info->download_id, download_file); |
| 396 download_file->Initialize(false); | 396 download_file->Initialize(false); |
| 397 download_manager_->StartDownload(info->download_id); | 397 download_manager_->StartDownload(info->download_id); |
| 398 message_loop_.RunAllPending(); | 398 message_loop_.RunAllPending(); |
| 399 | 399 |
| 400 // SelectFileObserver will have recorded any attempt to open the | 400 // SelectFileObserver will have recorded any attempt to open the |
| 401 // select file dialog. | 401 // select file dialog. |
| 402 // Note that DownloadManager::FileSelectionCanceled() is never called. | 402 // Note that DownloadManager::FileSelectionCanceled() is never called. |
| 403 EXPECT_EQ(kStartDownloadCases[i].expected_save_as, | 403 EXPECT_EQ(kStartDownloadCases[i].expected_save_as, |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 new DownloadItemModel(download)); | 744 new DownloadItemModel(download)); |
| 745 | 745 |
| 746 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); | 746 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); |
| 747 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); | 747 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); |
| 748 | 748 |
| 749 // Create and initialize the download file. We're bypassing the first part | 749 // Create and initialize the download file. We're bypassing the first part |
| 750 // of the download process and skipping to the part after the final file | 750 // of the download process and skipping to the part after the final file |
| 751 // name has been chosen, so we need to initialize the download file | 751 // name has been chosen, so we need to initialize the download file |
| 752 // properly. | 752 // properly. |
| 753 DownloadFile* download_file( | 753 DownloadFile* download_file( |
| 754 new DownloadFile(info.get(), DownloadRequestHandle(), download_manager_)); | 754 new DownloadFile(info.get(), new DownloadRequestHandle(), |
| 755 download_manager_)); |
| 755 download_file->Rename(cr_path); | 756 download_file->Rename(cr_path); |
| 756 // This creates the .crdownload version of the file. | 757 // This creates the .crdownload version of the file. |
| 757 download_file->Initialize(false); | 758 download_file->Initialize(false); |
| 758 // |download_file| is owned by DownloadFileManager. | 759 // |download_file| is owned by DownloadFileManager. |
| 759 AddDownloadToFileManager(info->download_id, download_file); | 760 AddDownloadToFileManager(info->download_id, download_file); |
| 760 | 761 |
| 761 ContinueDownloadWithPath(download, new_path); | 762 ContinueDownloadWithPath(download, new_path); |
| 762 message_loop_.RunAllPending(); | 763 message_loop_.RunAllPending(); |
| 763 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | 764 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
| 764 | 765 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 new DownloadItemModel(download)); | 821 new DownloadItemModel(download)); |
| 821 | 822 |
| 822 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); | 823 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); |
| 823 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); | 824 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); |
| 824 | 825 |
| 825 // Create and initialize the download file. We're bypassing the first part | 826 // Create and initialize the download file. We're bypassing the first part |
| 826 // of the download process and skipping to the part after the final file | 827 // of the download process and skipping to the part after the final file |
| 827 // name has been chosen, so we need to initialize the download file | 828 // name has been chosen, so we need to initialize the download file |
| 828 // properly. | 829 // properly. |
| 829 DownloadFile* download_file( | 830 DownloadFile* download_file( |
| 830 new DownloadFile(info.get(), DownloadRequestHandle(), download_manager_)); | 831 new DownloadFile(info.get(), new DownloadRequestHandle(), |
| 832 download_manager_)); |
| 831 download_file->Rename(cr_path); | 833 download_file->Rename(cr_path); |
| 832 // This creates the .crdownload version of the file. | 834 // This creates the .crdownload version of the file. |
| 833 download_file->Initialize(false); | 835 download_file->Initialize(false); |
| 834 // |download_file| is owned by DownloadFileManager. | 836 // |download_file| is owned by DownloadFileManager. |
| 835 AddDownloadToFileManager(info->download_id, download_file); | 837 AddDownloadToFileManager(info->download_id, download_file); |
| 836 | 838 |
| 837 ContinueDownloadWithPath(download, new_path); | 839 ContinueDownloadWithPath(download, new_path); |
| 838 message_loop_.RunAllPending(); | 840 message_loop_.RunAllPending(); |
| 839 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); | 841 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); |
| 840 | 842 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 875 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 874 EXPECT_TRUE(observer->was_updated()); | 876 EXPECT_TRUE(observer->was_updated()); |
| 875 EXPECT_FALSE(observer->was_opened()); | 877 EXPECT_FALSE(observer->was_opened()); |
| 876 EXPECT_TRUE(download->file_externally_removed()); | 878 EXPECT_TRUE(download->file_externally_removed()); |
| 877 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); | 879 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); |
| 878 EXPECT_EQ(download_item_model->GetStatusText(), | 880 EXPECT_EQ(download_item_model->GetStatusText(), |
| 879 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); | 881 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); |
| 880 | 882 |
| 881 EXPECT_FALSE(file_util::PathExists(new_path)); | 883 EXPECT_FALSE(file_util::PathExists(new_path)); |
| 882 } | 884 } |
| OLD | NEW |