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

Side by Side Diff: chrome/browser/download/download_browsertest.cc

Issue 8487002: Basic tests for DownloadUrl/DownloadUrlToFile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ifdef out breaking chromeos behavior with bug pointer. Created 9 years 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 | « no previous file | chrome/browser/download/download_test_observer.cc » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 // Returning false indicates a failure of the function, and should be asserted 460 // Returning false indicates a failure of the function, and should be asserted
461 // in the caller. 461 // in the caller.
462 bool CheckDownload(Browser* browser, 462 bool CheckDownload(Browser* browser,
463 const FilePath& downloaded_filename, 463 const FilePath& downloaded_filename,
464 const FilePath& origin_filename) { 464 const FilePath& origin_filename) {
465 // Find the path to which the data will be downloaded. 465 // Find the path to which the data will be downloaded.
466 FilePath downloaded_file(DestinationFile(browser, downloaded_filename)); 466 FilePath downloaded_file(DestinationFile(browser, downloaded_filename));
467 467
468 // Find the origin path (from which the data comes). 468 // Find the origin path (from which the data comes).
469 FilePath origin_file(OriginFile(origin_filename)); 469 FilePath origin_file(OriginFile(origin_filename));
470 return CheckDownloadFullPaths(browser, downloaded_file, origin_file);
471 }
472
473 // A version of CheckDownload that allows complete path specification.
474 bool CheckDownloadFullPaths(Browser* browser,
475 const FilePath& downloaded_file,
476 const FilePath& origin_file) {
470 bool origin_file_exists = file_util::PathExists(origin_file); 477 bool origin_file_exists = file_util::PathExists(origin_file);
471 EXPECT_TRUE(origin_file_exists); 478 EXPECT_TRUE(origin_file_exists);
472 if (!origin_file_exists) 479 if (!origin_file_exists)
473 return false; 480 return false;
474 481
475 // Confirm the downloaded data file exists. 482 // Confirm the downloaded data file exists.
476 bool downloaded_file_exists = file_util::PathExists(downloaded_file); 483 bool downloaded_file_exists = file_util::PathExists(downloaded_file);
477 EXPECT_TRUE(downloaded_file_exists); 484 EXPECT_TRUE(downloaded_file_exists);
478 if (!downloaded_file_exists) 485 if (!downloaded_file_exists)
479 return false; 486 return false;
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1663 search_results.clear(); 1670 search_results.clear();
1664 1671
1665 manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results); 1672 manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results);
1666 ASSERT_EQ(2u, search_results.size()); 1673 ASSERT_EQ(2u, search_results.size());
1667 std::sort(search_results.begin(), search_results.end(), 1674 std::sort(search_results.begin(), search_results.end(),
1668 DownloadItemSorter); 1675 DownloadItemSorter);
1669 EXPECT_EQ(2, search_results[0]->GetDbHandle()); 1676 EXPECT_EQ(2, search_results[0]->GetDbHandle());
1670 EXPECT_EQ(3, search_results[1]->GetDbHandle()); 1677 EXPECT_EQ(3, search_results[1]->GetDbHandle());
1671 search_results.clear(); 1678 search_results.clear();
1672 } 1679 }
1680
1681 // Tests for download initiation functions.
1682 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) {
1683 ASSERT_TRUE(InitialSetup(false));
1684 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1685 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1686
1687 // DownloadUrl always prompts; return acceptance of whatever it prompts.
1688 NullSelectFile(browser());
1689
1690 TabContents* tab_contents = browser()->GetSelectedTabContents();
1691 ASSERT_TRUE(tab_contents);
1692
1693 DownloadTestObserver* observer(
1694 new DownloadTestObserver(
1695 DownloadManagerForBrowser(browser()), 1,
1696 DownloadItem::COMPLETE, // Really done
1697 false, // Ignore select file.
1698 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1699 DownloadManagerForBrowser(browser())->DownloadUrl(
1700 url, GURL(""), "", tab_contents);
1701 observer->WaitForFinished();
1702 EXPECT_TRUE(observer->select_file_dialog_seen());
1703
1704 // Check state.
1705 EXPECT_EQ(1, browser()->tab_count());
1706 ASSERT_TRUE(CheckDownload(browser(), file, file));
1707 CheckDownloadUI(browser(), true, true, file);
1708 }
1709
1710 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToFile) {
1711 ASSERT_TRUE(InitialSetup(false));
1712 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1713 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1714
1715 TabContents* tab_contents = browser()->GetSelectedTabContents();
1716 ASSERT_TRUE(tab_contents);
1717
1718 ScopedTempDir other_directory;
1719 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
1720 FilePath target_file_full_path
1721 = other_directory.path().Append(file.BaseName());
1722 DownloadSaveInfo save_info;
1723 save_info.file_path = target_file_full_path;
1724
1725 DownloadTestObserver* observer(CreateWaiter(browser(), 1));
1726 DownloadManagerForBrowser(browser())->DownloadUrlToFile(
1727 url, GURL(""), "", save_info, tab_contents);
1728 observer->WaitForFinished();
1729
1730 // Check state.
1731 EXPECT_EQ(1, browser()->tab_count());
1732 ASSERT_TRUE(CheckDownloadFullPaths(browser(),
1733 target_file_full_path,
1734 OriginFile(file)));
1735 #if !defined(OS_CHROMEOS)
1736 // TODO(rdsmith/achuith): Re-enable on ChromeOS when
1737 // http://crbug.com/106856 is fixed.
1738
1739 // Temporary downloads won't be visible.
1740 CheckDownloadUI(browser(), false, false, file);
1741 #endif
1742 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_test_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698