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

Unified 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: Fixed typos. Created 9 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/download/download_test_observer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/download_browsertest.cc
diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc
index d1876ebce586d1fa7719e96159f032b3779b4f4c..dac0006dc84e42da39101aaead05058bb053ca0e 100644
--- a/chrome/browser/download/download_browsertest.cc
+++ b/chrome/browser/download/download_browsertest.cc
@@ -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)
@@ -1546,3 +1553,61 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) {
browser()->profile()->GetExtensionService();
ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false));
}
+
+// 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);
achuithb 2011/11/06 20:44:00 nit: shouldn't GURL() suffice?
+ 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);
achuithb 2011/11/06 20:44:00 nit: same
+ observer->WaitForFinished();
+
+ // Check state.
+ EXPECT_EQ(1, browser()->tab_count());
+ ASSERT_TRUE(CheckDownloadFullPaths(browser(),
+ target_file_full_path,
+ OriginFile(file)));
+ // Temporary downloads won't be visible.
+ CheckDownloadUI(browser(), false, false, file);
+}
« 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