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

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

Issue 9570005: Added callback to DownloadUrl() so we can find download failures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with parent. Created 8 years, 9 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 return true; 695 return true;
696 } 696 }
697 697
698 // Attempts to download a file, based on information in |download_info|. 698 // Attempts to download a file, based on information in |download_info|.
699 void DownloadFileCheckErrors(const DownloadInfo& download_info) { 699 void DownloadFileCheckErrors(const DownloadInfo& download_info) {
700 ASSERT_TRUE(test_server()->Start()); 700 ASSERT_TRUE(test_server()->Start());
701 std::vector<DownloadItem*> download_items; 701 std::vector<DownloadItem*> download_items;
702 GetDownloads(browser(), &download_items); 702 GetDownloads(browser(), &download_items);
703 ASSERT_TRUE(download_items.empty()); 703 ASSERT_TRUE(download_items.empty());
704 704
705 NullSelectFile(browser());
706
705 std::string server_path = "files/downloads/"; 707 std::string server_path = "files/downloads/";
706 server_path += download_info.url_name; 708 server_path += download_info.url_name;
707 GURL url = test_server()->GetURL(server_path); 709 GURL url = test_server()->GetURL(server_path);
708 ASSERT_TRUE(url.is_valid()); 710 ASSERT_TRUE(url.is_valid());
709 711
710 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); 712 DownloadManager* download_manager = DownloadManagerForBrowser(browser());
711 scoped_ptr<DownloadTestObserver> observer( 713 scoped_ptr<DownloadTestObserver> observer(
712 new DownloadTestObserverTerminal( 714 new DownloadTestObserverTerminal(
713 download_manager, 715 download_manager,
714 1, 716 1,
715 true, // Bail on select file 717 false, // Don't bail on select file.
716 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 718 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
717 719
718 if (download_info.download_method == DOWNLOAD_DIRECT) { 720 if (download_info.download_method == DOWNLOAD_DIRECT) {
719 // Go directly to download. 721 // Go directly to download.
720 WebContents* web_contents = browser()->GetSelectedWebContents(); 722 WebContents* web_contents = browser()->GetSelectedWebContents();
721 ASSERT_TRUE(web_contents); 723 ASSERT_TRUE(web_contents);
722 DownloadSaveInfo save_info; 724 DownloadSaveInfo save_info;
723 save_info.prompt_for_save_location = false; 725 save_info.prompt_for_save_location = false;
724 726
727 scoped_refptr<DownloadTestItemCreationObserver> creation_observer(
728 new DownloadTestItemCreationObserver);
729
725 DownloadManagerForBrowser(browser())->DownloadUrl( 730 DownloadManagerForBrowser(browser())->DownloadUrl(
726 url, GURL(""), "", false, -1, save_info, web_contents); 731 url, GURL(""), "", false, -1, save_info, web_contents,
732 creation_observer->callback());
733
734 // Wait until the item is created, or we have determined that it
735 // won't be.
736 creation_observer->WaitForDownloadItemCreation();
737
738 int32 invalid_id = content::DownloadId::Invalid().local();
739 EXPECT_EQ(download_info.show_download_item,
740 creation_observer->succeeded());
741 if (download_info.show_download_item) {
742 EXPECT_EQ(net::OK, creation_observer->error());
743 EXPECT_NE(invalid_id, creation_observer->download_id().local());
744 } else {
745 EXPECT_NE(net::OK, creation_observer->error());
746 EXPECT_EQ(invalid_id, creation_observer->download_id().local());
747 }
727 } else { 748 } else {
728 // Navigate to URL normally, wait until done. 749 // Navigate to URL normally, wait until done.
729 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), 750 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
730 url, 751 url,
731 1); 752 1);
732 } 753 }
733 754
734 if (download_info.show_download_item) { 755 if (download_info.show_download_item) {
735 observer->WaitForFinished(); 756 observer->WaitForFinished();
736 DownloadItem::DownloadState final_state = 757 DownloadItem::DownloadState final_state =
(...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1856 ASSERT_TRUE(web_contents); 1877 ASSERT_TRUE(web_contents);
1857 1878
1858 DownloadTestObserver* observer( 1879 DownloadTestObserver* observer(
1859 new DownloadTestObserverTerminal( 1880 new DownloadTestObserverTerminal(
1860 DownloadManagerForBrowser(browser()), 1, 1881 DownloadManagerForBrowser(browser()), 1,
1861 false, // Ignore select file. 1882 false, // Ignore select file.
1862 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 1883 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1863 DownloadSaveInfo save_info; 1884 DownloadSaveInfo save_info;
1864 save_info.prompt_for_save_location = true; 1885 save_info.prompt_for_save_location = true;
1865 DownloadManagerForBrowser(browser())->DownloadUrl( 1886 DownloadManagerForBrowser(browser())->DownloadUrl(
1866 url, GURL(""), "", false, -1, save_info, web_contents); 1887 url, GURL(""), "", false, -1, save_info, web_contents,
1888 DownloadManager::OnStartedCallback());
1867 observer->WaitForFinished(); 1889 observer->WaitForFinished();
1868 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1890 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1869 CheckDownloadStates(1, DownloadItem::COMPLETE); 1891 CheckDownloadStates(1, DownloadItem::COMPLETE);
1870 EXPECT_TRUE(observer->select_file_dialog_seen()); 1892 EXPECT_TRUE(observer->select_file_dialog_seen());
1871 1893
1872 // Check state. 1894 // Check state.
1873 EXPECT_EQ(1, browser()->tab_count()); 1895 EXPECT_EQ(1, browser()->tab_count());
1874 ASSERT_TRUE(CheckDownload(browser(), file, file)); 1896 ASSERT_TRUE(CheckDownload(browser(), file, file));
1875 CheckDownloadUI(browser(), true, true, file); 1897 CheckDownloadUI(browser(), true, true, file);
1876 } 1898 }
1877 1899
1878 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { 1900 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) {
1879 ASSERT_TRUE(InitialSetup(false)); 1901 ASSERT_TRUE(InitialSetup(false));
1880 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1902 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1881 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1903 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1882 1904
1883 WebContents* web_contents = browser()->GetSelectedWebContents(); 1905 WebContents* web_contents = browser()->GetSelectedWebContents();
1884 ASSERT_TRUE(web_contents); 1906 ASSERT_TRUE(web_contents);
1885 1907
1886 ScopedTempDir other_directory; 1908 ScopedTempDir other_directory;
1887 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); 1909 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
1888 FilePath target_file_full_path 1910 FilePath target_file_full_path
1889 = other_directory.path().Append(file.BaseName()); 1911 = other_directory.path().Append(file.BaseName());
1890 DownloadSaveInfo save_info; 1912 DownloadSaveInfo save_info;
1891 save_info.file_path = target_file_full_path; 1913 save_info.file_path = target_file_full_path;
1892 1914
1893 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); 1915 DownloadTestObserver* observer(CreateWaiter(browser(), 1));
1894 DownloadManagerForBrowser(browser())->DownloadUrl( 1916 DownloadManagerForBrowser(browser())->DownloadUrl(
1895 url, GURL(""), "", false, -1, save_info, web_contents); 1917 url, GURL(""), "", false, -1, save_info, web_contents,
1918 DownloadManager::OnStartedCallback());
1896 observer->WaitForFinished(); 1919 observer->WaitForFinished();
1897 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1920 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1898 1921
1899 // Check state. 1922 // Check state.
1900 EXPECT_EQ(1, browser()->tab_count()); 1923 EXPECT_EQ(1, browser()->tab_count());
1901 ASSERT_TRUE(CheckDownloadFullPaths(browser(), 1924 ASSERT_TRUE(CheckDownloadFullPaths(browser(),
1902 target_file_full_path, 1925 target_file_full_path,
1903 OriginFile(file))); 1926 OriginFile(file)));
1904 1927
1905 // Temporary downloads won't be visible. 1928 // Temporary downloads won't be visible.
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
2117 "zip_file_not_found.zip", 2140 "zip_file_not_found.zip",
2118 DOWNLOAD_NAVIGATE, 2141 DOWNLOAD_NAVIGATE,
2119 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, 2142 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2120 false 2143 false
2121 }; 2144 };
2122 2145
2123 // Do initial setup. 2146 // Do initial setup.
2124 ASSERT_TRUE(InitialSetup(false)); 2147 ASSERT_TRUE(InitialSetup(false));
2125 DownloadFileCheckErrors(download_info); 2148 DownloadFileCheckErrors(download_info);
2126 } 2149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698