Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: content/browser/download/download_manager_impl_unittest.cc

Issue 9316004: Move common file path related methods between chrome & content to file_util. I reduced the 4 meth... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: remove includes Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/download/download_item_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 FilePath(suggested_path.value() + FILE_PATH_LITERAL(".temp"));
71 suggested_path, FILE_PATH_LITERAL(".temp"));
72 } 71 }
73 72
74 class MockDownloadFileFactory 73 class MockDownloadFileFactory
75 : public DownloadFileManager::DownloadFileFactory { 74 : public DownloadFileManager::DownloadFileFactory {
76 public: 75 public:
77 MockDownloadFileFactory() {} 76 MockDownloadFileFactory() {}
78 77
79 virtual DownloadFile* CreateFile(DownloadCreateInfo* info, 78 virtual DownloadFile* CreateFile(DownloadCreateInfo* info,
80 const DownloadRequestHandle& request_handle, 79 const DownloadRequestHandle& request_handle,
81 DownloadManager* download_manager, 80 DownloadManager* download_manager,
(...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 EXPECT_FALSE(file_util::PathExists(new_path)); 1151 EXPECT_FALSE(file_util::PathExists(new_path));
1153 1152
1154 // Create the file that we will overwrite. Will be automatically cleaned 1153 // Create the file that we will overwrite. Will be automatically cleaned
1155 // up when temp_dir_ is destroyed. 1154 // up when temp_dir_ is destroyed.
1156 FILE* fp = file_util::OpenFile(new_path, "w"); 1155 FILE* fp = file_util::OpenFile(new_path, "w");
1157 file_util::CloseFile(fp); 1156 file_util::CloseFile(fp);
1158 EXPECT_TRUE(file_util::PathExists(new_path)); 1157 EXPECT_TRUE(file_util::PathExists(new_path));
1159 1158
1160 // Construct the unique file name that normally would be created, but 1159 // Construct the unique file name that normally would be created, but
1161 // which we will override. 1160 // which we will override.
1162 int uniquifier = DownloadFile::GetUniquePathNumber(new_path); 1161 int uniquifier =
1162 file_util::GetUniquePathNumber(new_path, FILE_PATH_LITERAL(""));
1163 FilePath unique_new_path = new_path; 1163 FilePath unique_new_path = new_path;
1164 EXPECT_NE(0, uniquifier); 1164 EXPECT_NE(0, uniquifier);
1165 DownloadFile::AppendNumberToPath(&unique_new_path, uniquifier); 1165 unique_new_path = unique_new_path.InsertBeforeExtensionASCII(
1166 StringPrintf(" (%d)", 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
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 }
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698