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

Unified Diff: content/browser/download/download_file_manager_unittest.cc

Issue 10689093: Move Rename functionality from DownloadFileManager to DownloadFileImple. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'd to TOT to avoid showing already committed changes in Rietveld. Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/download/download_file_manager_unittest.cc
diff --git a/content/browser/download/download_file_manager_unittest.cc b/content/browser/download/download_file_manager_unittest.cc
index 04290d4378b8d3df78fedf2763f88b60f8eae1a6..b53090c7e4079fac694472aac04beb621ce1c367 100644
--- a/content/browser/download/download_file_manager_unittest.cc
+++ b/content/browser/download/download_file_manager_unittest.cc
@@ -31,6 +31,7 @@ using ::testing::_;
using ::testing::AtLeast;
using ::testing::Mock;
using ::testing::Return;
+using ::testing::SaveArg;
using ::testing::StrictMock;
using ::testing::StrEq;
@@ -39,8 +40,10 @@ namespace {
// MockDownloadManager with the addition of a mock callback used for testing.
class TestDownloadManager : public MockDownloadManager {
public:
- MOCK_METHOD2(OnDownloadRenamed,
- void(int download_id, const FilePath& full_path));
+ MOCK_METHOD3(OnDownloadRenamed,
+ void(int download_id,
+ content::DownloadInterruptReason reason,
+ const FilePath& full_path));
private:
~TestDownloadManager() {}
};
@@ -218,42 +221,19 @@ class DownloadFileManagerTest : public testing::Test {
RenameFileOverwrite should_overwrite) {
MockDownloadFile* file = download_file_factory_->GetExistingFile(id);
ASSERT_TRUE(file != NULL);
+ content::DownloadFile::RenameCompletionCallback rename_callback;
- EXPECT_CALL(*file, Rename(unique_path))
- .Times(1)
- .WillOnce(Return(rename_error));
+ EXPECT_CALL(*file, Rename(unique_path, (should_overwrite == OVERWRITE), _))
asanka 2012/07/05 18:47:21 Should be expecting Rename(new_path,...) since uni
Randy Smith (Not in Mondays) 2012/07/09 20:35:51 Done.
+ .WillOnce(SaveArg<2>(&rename_callback));
- if (rename_error != content::DOWNLOAD_INTERRUPT_REASON_NONE) {
- EXPECT_CALL(*file, BytesSoFar())
- .Times(AtLeast(1))
- .WillRepeatedly(Return(byte_count_[id]));
- EXPECT_CALL(*file, GetHashState())
- .Times(AtLeast(1));
- EXPECT_CALL(*file, GetDownloadManager())
- .Times(AtLeast(1));
- }
-
- download_file_manager_->RenameDownloadFile(
- id, new_path, (should_overwrite == OVERWRITE),
+ content::DownloadFile::RenameCompletionCallback passed_callback(
base::Bind(&TestDownloadManager::OnDownloadRenamed,
download_manager_, id.local()));
- if (rename_error != content::DOWNLOAD_INTERRUPT_REASON_NONE) {
- EXPECT_CALL(*download_manager_,
- OnDownloadInterrupted(
- id.local(),
- byte_count_[id],
- "",
- rename_error));
- EXPECT_CALL(*download_manager_,
- OnDownloadRenamed(id.local(), FilePath()));
- ProcessAllPendingMessages();
- ++error_count_[id];
- } else {
- EXPECT_CALL(*download_manager_,
- OnDownloadRenamed(id.local(), unique_path));
- ProcessAllPendingMessages();
- }
+ download_file_manager_->RenameDownloadFile(
+ id, new_path, (should_overwrite == OVERWRITE), passed_callback);
+
+ EXPECT_TRUE(rename_callback.Equals(passed_callback));
}
void Complete(DownloadId id) {
@@ -361,25 +341,6 @@ TEST_F(DownloadFileManagerTest, RenameInProgress) {
CleanUp(dummy_id);
}
-TEST_F(DownloadFileManagerTest, RenameInProgressWithUniquification) {
- scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
- DownloadId dummy_id(download_manager_.get(), kDummyDownloadId);
- info->download_id = dummy_id;
- ScopedTempDir download_dir;
- ASSERT_TRUE(download_dir.CreateUniqueTempDir());
-
- CreateDownloadFile(info.Pass());
-
- FilePath foo(download_dir.path().Append(FILE_PATH_LITERAL("foo.txt")));
- FilePath unique_foo(foo.InsertBeforeExtension(FILE_PATH_LITERAL(" (1)")));
- ASSERT_EQ(0, file_util::WriteFile(foo, "", 0));
- RenameFile(dummy_id, foo, unique_foo,
- content::DOWNLOAD_INTERRUPT_REASON_NONE, IN_PROGRESS,
- DONT_OVERWRITE);
-
- CleanUp(dummy_id);
-}
-
TEST_F(DownloadFileManagerTest, RenameInProgressWithError) {
asanka 2012/07/05 18:47:21 This can't be tested here anymore. See suggestion
Randy Smith (Not in Mondays) 2012/07/09 20:35:51 Done.
scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
DownloadId dummy_id(download_manager_.get(), kDummyDownloadId);
@@ -397,27 +358,6 @@ TEST_F(DownloadFileManagerTest, RenameInProgressWithError) {
CleanUp(dummy_id);
}
-TEST_F(DownloadFileManagerTest, RenameWithUniquification) {
- scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
- DownloadId dummy_id(download_manager_.get(), kDummyDownloadId);
- info->download_id = dummy_id;
- ScopedTempDir download_dir;
- ASSERT_TRUE(download_dir.CreateUniqueTempDir());
-
- CreateDownloadFile(info.Pass());
-
- FilePath foo(download_dir.path().Append(FILE_PATH_LITERAL("foo.txt")));
- FilePath unique_foo(foo.InsertBeforeExtension(FILE_PATH_LITERAL(" (1)")));
- // Create a file at |foo|. Since we are specifying DONT_OVERWRITE,
- // RenameDownloadFile() should pick "foo (1).txt" instead of
- // overwriting this file.
- ASSERT_EQ(0, file_util::WriteFile(foo, "", 0));
- RenameFile(dummy_id, foo, unique_foo,
- content::DOWNLOAD_INTERRUPT_REASON_NONE, COMPLETE, DONT_OVERWRITE);
-
- CleanUp(dummy_id);
-}
-
TEST_F(DownloadFileManagerTest, RenameTwice) {
scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
DownloadId dummy_id(download_manager_.get(), kDummyDownloadId);

Powered by Google App Engine
This is Rietveld 408576698