Commit fdd2715c authored by rdsmith@chromium.org's avatar rdsmith@chromium.org

Basic tests for DownloadUrl/DownloadUrlToFile.


Review URL: http://codereview.chromium.org/8487002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113864 0039d316-1c4b-4281-b951-d872f2087c98
parent 5bee6a89
......@@ -467,6 +467,13 @@ class DownloadTest : public InProcessBrowserTest {
// Find the origin path (from which the data comes).
FilePath origin_file(OriginFile(origin_filename));
return CheckDownloadFullPaths(browser, downloaded_file, origin_file);
}
// A version of CheckDownload that allows complete path specification.
bool CheckDownloadFullPaths(Browser* browser,
const FilePath& downloaded_file,
const FilePath& origin_file) {
bool origin_file_exists = file_util::PathExists(origin_file);
EXPECT_TRUE(origin_file_exists);
if (!origin_file_exists)
......@@ -1670,3 +1677,66 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, SearchDownloads) {
EXPECT_EQ(3, search_results[1]->GetDbHandle());
search_results.clear();
}
// Tests for download initiation functions.
IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) {
ASSERT_TRUE(InitialSetup(false));
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
// DownloadUrl always prompts; return acceptance of whatever it prompts.
NullSelectFile(browser());
TabContents* tab_contents = browser()->GetSelectedTabContents();
ASSERT_TRUE(tab_contents);
DownloadTestObserver* observer(
new DownloadTestObserver(
DownloadManagerForBrowser(browser()), 1,
DownloadItem::COMPLETE, // Really done
false, // Ignore select file.
DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
DownloadManagerForBrowser(browser())->DownloadUrl(
url, GURL(""), "", tab_contents);
observer->WaitForFinished();
EXPECT_TRUE(observer->select_file_dialog_seen());
// Check state.
EXPECT_EQ(1, browser()->tab_count());
ASSERT_TRUE(CheckDownload(browser(), file, file));
CheckDownloadUI(browser(), true, true, file);
}
IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToFile) {
ASSERT_TRUE(InitialSetup(false));
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
TabContents* tab_contents = browser()->GetSelectedTabContents();
ASSERT_TRUE(tab_contents);
ScopedTempDir other_directory;
ASSERT_TRUE(other_directory.CreateUniqueTempDir());
FilePath target_file_full_path
= other_directory.path().Append(file.BaseName());
DownloadSaveInfo save_info;
save_info.file_path = target_file_full_path;
DownloadTestObserver* observer(CreateWaiter(browser(), 1));
DownloadManagerForBrowser(browser())->DownloadUrlToFile(
url, GURL(""), "", save_info, tab_contents);
observer->WaitForFinished();
// Check state.
EXPECT_EQ(1, browser()->tab_count());
ASSERT_TRUE(CheckDownloadFullPaths(browser(),
target_file_full_path,
OriginFile(file)));
#if !defined(OS_CHROMEOS)
// TODO(rdsmith/achuith): Re-enable on ChromeOS when
// http://crbug.com/106856 is fixed.
// Temporary downloads won't be visible.
CheckDownloadUI(browser(), false, false, file);
#endif
}
......@@ -142,6 +142,9 @@ void DownloadTestObserver::ModelChanged() {
// (done by |OnDownloadUpdated()|).
std::vector<DownloadItem*> downloads;
download_manager_->GetAllDownloads(FilePath(), &downloads);
// As a test class, we're generally interested in whatever's there,
// so we include temporary downloads.
download_manager_->GetTemporaryDownloads(FilePath(), &downloads);
for (std::vector<DownloadItem*>::iterator it = downloads.begin();
it != downloads.end(); ++it) {
......
......@@ -158,9 +158,6 @@ void DownloadFileManager::StartDownload(
return;
}
// TODO(phajdan.jr): fix the duplication of path info below.
info->path = info->save_info.file_path;
manager->CreateDownloadItem(info, request_handle);
bool hash_needed = manager->delegate()->GenerateFileHash();
......
......@@ -183,7 +183,7 @@ void DownloadManagerImpl::GetTemporaryDownloads(
for (DownloadMap::iterator it = history_downloads_.begin();
it != history_downloads_.end(); ++it) {
if (it->second->IsTemporary() &&
it->second->GetFullPath().DirName() == dir_path)
(dir_path.empty() || it->second->GetFullPath().DirName() == dir_path))
result->push_back(it->second);
}
}
......@@ -383,6 +383,7 @@ void DownloadManagerImpl::ContinueDownloadWithPath(
DCHECK(ContainsKey(active_downloads_, download_id));
// Make sure the initial file name is set only once.
DCHECK(download->GetFullPath().empty());
download->OnPathDetermined(chosen_file);
VLOG(20) << __FUNCTION__ << "()"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment