| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 using content::DownloadId; | 60 using content::DownloadId; |
| 61 using content::DownloadItem; | 61 using content::DownloadItem; |
| 62 using content::DownloadManager; | 62 using content::DownloadManager; |
| 63 using content::WebContents; | 63 using content::WebContents; |
| 64 using ::testing::ReturnRef; | 64 using ::testing::ReturnRef; |
| 65 using ::testing::Return; | 65 using ::testing::Return; |
| 66 | 66 |
| 67 namespace { | 67 namespace { |
| 68 | 68 |
| 69 FilePath GetTempDownloadPath(const FilePath& suggested_path) { | 69 FilePath GetTempDownloadPath(const FilePath& suggested_path) { |
| 70 return DownloadFile::AppendSuffixToPath( | 70 return file_util::AppendSuffixToPath( |
| 71 suggested_path, FILE_PATH_LITERAL(".temp")); | 71 suggested_path, FILE_PATH_LITERAL(".temp")); |
| 72 } | 72 } |
| 73 | 73 |
| 74 class MockDownloadFileFactory | 74 class MockDownloadFileFactory |
| 75 : public DownloadFileManager::DownloadFileFactory { | 75 : public DownloadFileManager::DownloadFileFactory { |
| 76 public: | 76 public: |
| 77 MockDownloadFileFactory() {} | 77 MockDownloadFileFactory() {} |
| 78 | 78 |
| 79 virtual DownloadFile* CreateFile(DownloadCreateInfo* info, | 79 virtual DownloadFile* CreateFile(DownloadCreateInfo* info, |
| 80 const DownloadRequestHandle& request_handle, | 80 const DownloadRequestHandle& request_handle, |
| (...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 EXPECT_FALSE(file_util::PathExists(new_path)); | 1152 EXPECT_FALSE(file_util::PathExists(new_path)); |
| 1153 | 1153 |
| 1154 // Create the file that we will overwrite. Will be automatically cleaned | 1154 // Create the file that we will overwrite. Will be automatically cleaned |
| 1155 // up when temp_dir_ is destroyed. | 1155 // up when temp_dir_ is destroyed. |
| 1156 FILE* fp = file_util::OpenFile(new_path, "w"); | 1156 FILE* fp = file_util::OpenFile(new_path, "w"); |
| 1157 file_util::CloseFile(fp); | 1157 file_util::CloseFile(fp); |
| 1158 EXPECT_TRUE(file_util::PathExists(new_path)); | 1158 EXPECT_TRUE(file_util::PathExists(new_path)); |
| 1159 | 1159 |
| 1160 // Construct the unique file name that normally would be created, but | 1160 // Construct the unique file name that normally would be created, but |
| 1161 // which we will override. | 1161 // which we will override. |
| 1162 int uniquifier = DownloadFile::GetUniquePathNumber(new_path); | 1162 int uniquifier = |
| 1163 file_util::GetUniquePathNumber(new_path, FILE_PATH_LITERAL("")); |
| 1163 FilePath unique_new_path = new_path; | 1164 FilePath unique_new_path = new_path; |
| 1164 EXPECT_NE(0, uniquifier); | 1165 EXPECT_NE(0, uniquifier); |
| 1165 DownloadFile::AppendNumberToPath(&unique_new_path, uniquifier); | 1166 file_util::AppendNumberToPath(&unique_new_path, uniquifier); |
| 1166 | 1167 |
| 1167 // Normally, the download system takes ownership of info, and is | 1168 // Normally, the download system takes ownership of info, and is |
| 1168 // responsible for deleting it. In these unit tests, however, we | 1169 // responsible for deleting it. In these unit tests, however, we |
| 1169 // don't call the function that deletes it, so we do so ourselves. | 1170 // don't call the function that deletes it, so we do so ourselves. |
| 1170 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); | 1171 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); |
| 1171 info->download_id = DownloadId(kValidIdDomain, 0); | 1172 info->download_id = DownloadId(kValidIdDomain, 0); |
| 1172 info->prompt_user_for_save_location = true; | 1173 info->prompt_user_for_save_location = true; |
| 1173 info->url_chain.push_back(GURL()); | 1174 info->url_chain.push_back(GURL()); |
| 1174 | 1175 |
| 1175 download_manager_->CreateDownloadItem(info.get(), DownloadRequestHandle()); | 1176 download_manager_->CreateDownloadItem(info.get(), DownloadRequestHandle()); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); | 1304 EXPECT_FALSE(observer->hit_state(DownloadItem::INTERRUPTED)); |
| 1304 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); | 1305 EXPECT_TRUE(observer->hit_state(DownloadItem::COMPLETE)); |
| 1305 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 1306 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 1306 EXPECT_TRUE(observer->was_updated()); | 1307 EXPECT_TRUE(observer->was_updated()); |
| 1307 EXPECT_FALSE(observer->was_opened()); | 1308 EXPECT_FALSE(observer->was_opened()); |
| 1308 EXPECT_TRUE(download->GetFileExternallyRemoved()); | 1309 EXPECT_TRUE(download->GetFileExternallyRemoved()); |
| 1309 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); | 1310 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); |
| 1310 | 1311 |
| 1311 EXPECT_FALSE(file_util::PathExists(new_path)); | 1312 EXPECT_FALSE(file_util::PathExists(new_path)); |
| 1312 } | 1313 } |
| OLD | NEW |