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

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: 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 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 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1546 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1540 1547
1541 // Download shelf should close. Download panel stays open on ChromeOS. 1548 // Download shelf should close. Download panel stays open on ChromeOS.
1542 CheckDownloadUI(browser(), false, true, FilePath()); 1549 CheckDownloadUI(browser(), false, true, FilePath());
1543 1550
1544 // Check that the extension was installed. 1551 // Check that the extension was installed.
1545 ExtensionService* extension_service = 1552 ExtensionService* extension_service =
1546 browser()->profile()->GetExtensionService(); 1553 browser()->profile()->GetExtensionService();
1547 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); 1554 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false));
1548 } 1555 }
1556
1557 // Tests for download initiation functions.
1558 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) {
1559 ASSERT_TRUE(InitialSetup(false));
1560 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1561 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1562
1563 // DownloadUrl always prompts; return acceptance of whatever it prompts.
1564 NullSelectFile(browser());
1565
1566 TabContents* tab_contents = browser()->GetSelectedTabContents();
1567 ASSERT_TRUE(tab_contents);
1568
1569 DownloadTestObserver* observer(
1570 new DownloadTestObserver(
1571 DownloadManagerForBrowser(browser()), 1,
1572 DownloadItem::COMPLETE, // Really done
1573 false, // Ignore select file.
1574 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1575 DownloadManagerForBrowser(browser())->DownloadUrl(
1576 url, GURL(""), "", tab_contents);
achuithb 2011/11/06 20:44:00 nit: shouldn't GURL() suffice?
1577 observer->WaitForFinished();
1578 EXPECT_TRUE(observer->select_file_dialog_seen());
1579
1580 // Check state.
1581 EXPECT_EQ(1, browser()->tab_count());
1582 ASSERT_TRUE(CheckDownload(browser(), file, file));
1583 CheckDownloadUI(browser(), true, true, file);
1584 }
1585
1586 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToFile) {
1587 ASSERT_TRUE(InitialSetup(false));
1588 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1589 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1590
1591 TabContents* tab_contents = browser()->GetSelectedTabContents();
1592 ASSERT_TRUE(tab_contents);
1593
1594 ScopedTempDir other_directory;
1595 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
1596 FilePath target_file_full_path
1597 = other_directory.path().Append(file.BaseName());
1598 DownloadSaveInfo save_info;
1599 save_info.file_path = target_file_full_path;
1600
1601 DownloadTestObserver* observer(CreateWaiter(browser(), 1));
1602 DownloadManagerForBrowser(browser())->DownloadUrlToFile(
1603 url, GURL(""), "", save_info, tab_contents);
achuithb 2011/11/06 20:44:00 nit: same
1604 observer->WaitForFinished();
1605
1606 // Check state.
1607 EXPECT_EQ(1, browser()->tab_count());
1608 ASSERT_TRUE(CheckDownloadFullPaths(browser(),
1609 target_file_full_path,
1610 OriginFile(file)));
1611 // Temporary downloads won't be visible.
1612 CheckDownloadUI(browser(), false, false, file);
1613 }
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