diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-19 15:57:18 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-19 15:57:18 +0000 |
commit | 1da813714de79af80d4790b7797ea6788822c9be (patch) | |
tree | e649ca9a0a9eaee8aa81d2affeea49267a88a049 /chrome/browser/download | |
parent | 63c7e0afd187c8d771b70b2752ff88bbd135a0ba (diff) | |
download | chromium_src-1da813714de79af80d4790b7797ea6788822c9be.zip chromium_src-1da813714de79af80d4790b7797ea6788822c9be.tar.gz chromium_src-1da813714de79af80d4790b7797ea6788822c9be.tar.bz2 |
Revert 118297 since it caused component build failure:
"""
Created DownloadFileManager unit test.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/8978001
TBR=ahendrickson@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9150034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118300 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r-- | chrome/browser/download/download_manager_unittest.cc | 109 |
1 files changed, 48 insertions, 61 deletions
diff --git a/chrome/browser/download/download_manager_unittest.cc b/chrome/browser/download/download_manager_unittest.cc index 2ab9057..3f2c669 100644 --- a/chrome/browser/download/download_manager_unittest.cc +++ b/chrome/browser/download/download_manager_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -60,8 +60,6 @@ using content::BrowserThread; using content::DownloadFile; using content::DownloadItem; using content::DownloadManager; -using ::testing::ReturnRef; -using ::testing::Return; using content::WebContents; namespace { @@ -195,12 +193,6 @@ class DownloadManagerTest : public testing::Test { download_file; } - void AddMockDownloadToFileManager(int id, MockDownloadFile* download_file) { - AddDownloadToFileManager(id, download_file); - ON_CALL(*download_file, GetDownloadManager()) - .WillByDefault(Return(download_manager_)); - } - void OnResponseCompleted(int32 download_id, int64 size, const std::string& hash) { download_manager_->OnResponseCompleted(download_id, size, hash); @@ -493,8 +485,7 @@ TEST_F(DownloadManagerTest, MAYBE_StartDownload) { // responsible for deleting it. In these unit tests, however, we // don't call the function that deletes it, so we do so ourselves. scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); - const DownloadId id = DownloadId(kValidIdDomain, static_cast<int>(i)); - info->download_id = id; + info->download_id = DownloadId(kValidIdDomain, static_cast<int>(i)); info->prompt_user_for_save_location = kStartDownloadCases[i].save_as; info->url_chain.push_back(GURL(kStartDownloadCases[i].url)); info->mime_type = kStartDownloadCases[i].mime_type; @@ -513,8 +504,6 @@ TEST_F(DownloadManagerTest, MAYBE_StartDownload) { // Note that DownloadManager::FileSelectionCanceled() is never called. EXPECT_EQ(kStartDownloadCases[i].expected_save_as, observer.ShowedFileDialogForId(i)); - - file_manager()->CancelDownload(id); } } @@ -771,7 +760,9 @@ TEST_F(DownloadManagerTest, DownloadFilenameTest) { info->download_id = DownloadId(kValidIdDomain, i); info->url_chain.push_back(GURL()); - MockDownloadFile* download_file(new MockDownloadFile()); + MockDownloadFile::StatisticsRecorder recorder; + MockDownloadFile* download_file(new MockDownloadFile( + info.get(), DownloadRequestHandle(), download_manager_, &recorder)); FilePath suggested_path(ExpandFilenameTestPath( kDownloadFilenameTestCases[i].suggested_path, downloads_dir, alternate_dir)); @@ -784,18 +775,15 @@ TEST_F(DownloadManagerTest, DownloadFilenameTest) { FilePath final_path(ExpandFilenameTestPath( kDownloadFilenameTestCases[i].final_path, downloads_dir, alternate_dir)); + // If |final_path| is empty, its a signal that the download doesn't + // complete. Therefore it will only go through a single rename. + int expected_rename_count = (final_path.empty() ? 1 : 2); - AddMockDownloadToFileManager(info->download_id.local(), download_file); - - EXPECT_CALL(*download_file, Rename(intermediate_path)) - .WillOnce(Return(net::OK)); + AddDownloadToFileManager(info->download_id.local(), download_file); - if (!final_path.empty()) { - // If |final_path| is empty, its a signal that the download doesn't - // complete. Therefore it will only go through a single rename. - EXPECT_CALL(*download_file, Rename(final_path)) - .WillOnce(Return(net::OK)); - } + download_file->SetExpectedPath(0, intermediate_path); + if (!final_path.empty()) + download_file->SetExpectedPath(1, final_path); download_manager_->CreateDownloadItem(info.get(), DownloadRequestHandle()); DownloadItem* download = GetActiveDownloadItem(i); @@ -830,6 +818,11 @@ TEST_F(DownloadManagerTest, DownloadFilenameTest) { message_loop_.RunAllPending(); // |download| might be deleted when we get here. } + + EXPECT_EQ( + expected_rename_count, + recorder.Count(MockDownloadFile::StatisticsRecorder::STAT_RENAME)) + << "For test run " << i; } } @@ -849,27 +842,22 @@ TEST_F(DownloadManagerTest, DownloadRenameTest) { info->url_chain.push_back(GURL()); const FilePath new_path(kDownloadRenameCases[i].suggested_path); - MockDownloadFile* download_file(new MockDownloadFile()); - const DownloadId id = info->download_id; - ON_CALL(*download_file, GlobalId()) - .WillByDefault(ReturnRef(id)); - - AddMockDownloadToFileManager(info->download_id.local(), download_file); + MockDownloadFile::StatisticsRecorder recorder; + MockDownloadFile* download_file( + new MockDownloadFile(info.get(), + DownloadRequestHandle(), + download_manager_, + &recorder)); + AddDownloadToFileManager(info->download_id.local(), download_file); // |download_file| is owned by DownloadFileManager. if (kDownloadRenameCases[i].expected_rename_count == 1) { - EXPECT_CALL(*download_file, Rename(new_path)) - .Times(1) - .WillOnce(Return(net::OK)); + download_file->SetExpectedPath(0, new_path); } else { ASSERT_EQ(2, kDownloadRenameCases[i].expected_rename_count); FilePath crdownload(download_util::GetCrDownloadPath(new_path)); - EXPECT_CALL(*download_file, Rename(crdownload)) - .Times(1) - .WillOnce(Return(net::OK)); - EXPECT_CALL(*download_file, Rename(new_path)) - .Times(1) - .WillOnce(Return(net::OK)); + download_file->SetExpectedPath(0, crdownload); + download_file->SetExpectedPath(1, new_path); } download_manager_->CreateDownloadItem(info.get(), DownloadRequestHandle()); DownloadItem* download = GetActiveDownloadItem(i); @@ -889,10 +877,10 @@ TEST_F(DownloadManagerTest, DownloadRenameTest) { message_loop_.RunAllPending(); OnResponseCompleted(i, 1024, std::string("fake_hash")); } - // Validating the download item, so it will complete. - if (state.danger == DownloadStateInfo::DANGEROUS_FILE) - download->DangerousDownloadValidated(); message_loop_.RunAllPending(); + EXPECT_EQ( + kDownloadRenameCases[i].expected_rename_count, + recorder.Count(MockDownloadFile::StatisticsRecorder::STAT_RENAME)); } } @@ -913,16 +901,16 @@ TEST_F(DownloadManagerTest, DownloadInterruptTest) { const FilePath new_path(FILE_PATH_LITERAL("foo.zip")); const FilePath cr_path(download_util::GetCrDownloadPath(new_path)); - MockDownloadFile* download_file(new MockDownloadFile()); - ON_CALL(*download_file, AppendDataToFile(_, _)) - .WillByDefault(Return(net::OK)); + MockDownloadFile::StatisticsRecorder recorder; + MockDownloadFile* download_file( + new MockDownloadFile(info.get(), + DownloadRequestHandle(), + download_manager_, + &recorder)); + AddDownloadToFileManager(info->download_id.local(), download_file); // |download_file| is owned by DownloadFileManager. - AddMockDownloadToFileManager(info->download_id.local(), download_file); - - EXPECT_CALL(*download_file, Rename(cr_path)) - .Times(1) - .WillOnce(Return(net::OK)); + download_file->SetExpectedPath(0, cr_path); download_manager_->CreateDownloadItem(info.get(), DownloadRequestHandle()); @@ -938,6 +926,8 @@ TEST_F(DownloadManagerTest, DownloadInterruptTest) { ContinueDownloadWithPath(download, new_path); message_loop_.RunAllPending(); + EXPECT_EQ(1, + recorder.Count(MockDownloadFile::StatisticsRecorder::STAT_RENAME)); EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); int64 error_size = 3; @@ -1078,22 +1068,21 @@ TEST_F(DownloadManagerTest, DownloadCancelTest) { // responsible for deleting it. In these unit tests, however, we // don't call the function that deletes it, so we do so ourselves. scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); - DownloadId id = DownloadId(kValidIdDomain, 0); - info->download_id = id; + info->download_id = DownloadId(kValidIdDomain, 0); info->prompt_user_for_save_location = false; info->url_chain.push_back(GURL()); const FilePath new_path(FILE_PATH_LITERAL("foo.zip")); const FilePath cr_path(download_util::GetCrDownloadPath(new_path)); - MockDownloadFile* download_file(new MockDownloadFile()); - ON_CALL(*download_file, AppendDataToFile(_, _)) - .WillByDefault(Return(net::OK)); - AddMockDownloadToFileManager(info->download_id.local(), download_file); + MockDownloadFile* download_file( + new MockDownloadFile(info.get(), + DownloadRequestHandle(), + download_manager_, + NULL)); + AddDownloadToFileManager(info->download_id.local(), download_file); // |download_file| is owned by DownloadFileManager. - EXPECT_CALL(*download_file, Rename(cr_path)) - .Times(1) - .WillOnce(Return(net::OK)); + download_file->SetExpectedPath(0, cr_path); download_manager_->CreateDownloadItem(info.get(), DownloadRequestHandle()); @@ -1127,8 +1116,6 @@ TEST_F(DownloadManagerTest, DownloadCancelTest) { EXPECT_EQ(download_item_model->GetStatusText(), l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_CANCELED)); - file_manager()->CancelDownload(id); - EXPECT_FALSE(file_util::PathExists(new_path)); EXPECT_FALSE(file_util::PathExists(cr_path)); } |