| OLD | NEW |
| 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 <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "chrome/common/chrome_notification_types.h" | 41 #include "chrome/common/chrome_notification_types.h" |
| 42 #include "chrome/common/chrome_paths.h" | 42 #include "chrome/common/chrome_paths.h" |
| 43 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
| 44 #include "chrome/common/url_constants.h" | 44 #include "chrome/common/url_constants.h" |
| 45 #include "chrome/test/base/in_process_browser_test.h" | 45 #include "chrome/test/base/in_process_browser_test.h" |
| 46 #include "chrome/test/base/ui_test_utils.h" | 46 #include "chrome/test/base/ui_test_utils.h" |
| 47 #include "content/public/browser/download_item.h" | 47 #include "content/public/browser/download_item.h" |
| 48 #include "content/public/browser/download_manager.h" | 48 #include "content/public/browser/download_manager.h" |
| 49 #include "content/public/browser/download_persistent_store_info.h" | 49 #include "content/public/browser/download_persistent_store_info.h" |
| 50 #include "content/public/browser/download_save_info.h" | 50 #include "content/public/browser/download_save_info.h" |
| 51 #include "content/public/browser/download_url_parameters.h" |
| 51 #include "content/public/browser/notification_source.h" | 52 #include "content/public/browser/notification_source.h" |
| 52 #include "content/public/browser/render_view_host.h" | 53 #include "content/public/browser/render_view_host.h" |
| 53 #include "content/public/browser/resource_context.h" | 54 #include "content/public/browser/resource_context.h" |
| 54 #include "content/public/browser/web_contents.h" | 55 #include "content/public/browser/web_contents.h" |
| 55 #include "content/public/common/context_menu_params.h" | 56 #include "content/public/common/context_menu_params.h" |
| 56 #include "content/public/common/page_transition_types.h" | 57 #include "content/public/common/page_transition_types.h" |
| 57 #include "content/test/net/url_request_mock_http_job.h" | 58 #include "content/test/net/url_request_mock_http_job.h" |
| 58 #include "content/test/net/url_request_slow_download_job.h" | 59 #include "content/test/net/url_request_slow_download_job.h" |
| 59 #include "content/test/test_file_error_injector.h" | 60 #include "content/test/test_file_error_injector.h" |
| 60 #include "content/test/test_navigation_observer.h" | 61 #include "content/test/test_navigation_observer.h" |
| 61 #include "net/base/net_util.h" | 62 #include "net/base/net_util.h" |
| 62 #include "net/test/test_server.h" | 63 #include "net/test/test_server.h" |
| 63 #include "testing/gtest/include/gtest/gtest.h" | 64 #include "testing/gtest/include/gtest/gtest.h" |
| 64 | 65 |
| 65 using content::BrowserThread; | 66 using content::BrowserThread; |
| 66 using content::DownloadItem; | 67 using content::DownloadItem; |
| 67 using content::DownloadManager; | 68 using content::DownloadManager; |
| 68 using content::DownloadPersistentStoreInfo; | 69 using content::DownloadPersistentStoreInfo; |
| 70 using content::DownloadUrlParameters; |
| 69 using content::WebContents; | 71 using content::WebContents; |
| 70 | 72 |
| 71 namespace { | 73 namespace { |
| 72 | 74 |
| 73 // IDs and paths of CRX files used in tests. | 75 // IDs and paths of CRX files used in tests. |
| 74 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 76 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 75 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); | 77 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); |
| 76 | 78 |
| 77 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; | 79 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
| 78 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); | 80 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 | 663 |
| 662 if (download_info.download_method == DOWNLOAD_DIRECT) { | 664 if (download_info.download_method == DOWNLOAD_DIRECT) { |
| 663 // Go directly to download. Don't wait for navigation. | 665 // Go directly to download. Don't wait for navigation. |
| 664 content::DownloadSaveInfo save_info; | 666 content::DownloadSaveInfo save_info; |
| 665 // NOTE: |prompt_for_save_location| may change during the download. | 667 // NOTE: |prompt_for_save_location| may change during the download. |
| 666 save_info.prompt_for_save_location = false; | 668 save_info.prompt_for_save_location = false; |
| 667 | 669 |
| 668 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( | 670 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( |
| 669 new DownloadTestItemCreationObserver); | 671 new DownloadTestItemCreationObserver); |
| 670 | 672 |
| 671 DownloadManagerForBrowser(browser())->DownloadUrl( | 673 DownloadUrlParameters* params = DownloadUrlParameters::FromWebContents( |
| 672 url, GURL(""), "", false, -1, save_info, web_contents, | 674 web_contents, url, save_info); |
| 673 creation_observer->callback()); | 675 params->set_callback(creation_observer->callback()); |
| 676 DownloadManagerForBrowser(browser())->DownloadUrl(params); |
| 674 | 677 |
| 675 // Wait until the item is created, or we have determined that it | 678 // Wait until the item is created, or we have determined that it |
| 676 // won't be. | 679 // won't be. |
| 677 creation_observer->WaitForDownloadItemCreation(); | 680 creation_observer->WaitForDownloadItemCreation(); |
| 678 | 681 |
| 679 int32 invalid_id = content::DownloadId::Invalid().local(); | 682 int32 invalid_id = content::DownloadId::Invalid().local(); |
| 680 EXPECT_EQ(download_info.show_download_item, | 683 EXPECT_EQ(download_info.show_download_item, |
| 681 creation_observer->succeeded()); | 684 creation_observer->succeeded()); |
| 682 if (download_info.show_download_item) { | 685 if (download_info.show_download_item) { |
| 683 EXPECT_EQ(net::OK, creation_observer->error()); | 686 EXPECT_EQ(net::OK, creation_observer->error()); |
| (...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1962 ASSERT_TRUE(web_contents); | 1965 ASSERT_TRUE(web_contents); |
| 1963 | 1966 |
| 1964 DownloadTestObserver* observer( | 1967 DownloadTestObserver* observer( |
| 1965 new DownloadTestObserverTerminal( | 1968 new DownloadTestObserverTerminal( |
| 1966 DownloadManagerForBrowser(browser()), 1, | 1969 DownloadManagerForBrowser(browser()), 1, |
| 1967 false, // Ignore select file. | 1970 false, // Ignore select file. |
| 1968 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1971 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1969 content::DownloadSaveInfo save_info; | 1972 content::DownloadSaveInfo save_info; |
| 1970 save_info.prompt_for_save_location = true; | 1973 save_info.prompt_for_save_location = true; |
| 1971 DownloadManagerForBrowser(browser())->DownloadUrl( | 1974 DownloadManagerForBrowser(browser())->DownloadUrl( |
| 1972 url, GURL(""), "", false, -1, save_info, web_contents, | 1975 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); |
| 1973 DownloadManager::OnStartedCallback()); | |
| 1974 observer->WaitForFinished(); | 1976 observer->WaitForFinished(); |
| 1975 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1977 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1976 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1978 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1977 EXPECT_TRUE(observer->select_file_dialog_seen()); | 1979 EXPECT_TRUE(observer->select_file_dialog_seen()); |
| 1978 | 1980 |
| 1979 // Check state. | 1981 // Check state. |
| 1980 EXPECT_EQ(1, browser()->tab_count()); | 1982 EXPECT_EQ(1, browser()->tab_count()); |
| 1981 ASSERT_TRUE(CheckDownload(browser(), file, file)); | 1983 ASSERT_TRUE(CheckDownload(browser(), file, file)); |
| 1982 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1984 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1983 } | 1985 } |
| 1984 | 1986 |
| 1985 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { | 1987 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { |
| 1986 ASSERT_TRUE(InitialSetup(false)); | 1988 ASSERT_TRUE(InitialSetup(false)); |
| 1987 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1989 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1988 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1990 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1989 | 1991 |
| 1990 WebContents* web_contents = browser()->GetSelectedWebContents(); | 1992 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 1991 ASSERT_TRUE(web_contents); | 1993 ASSERT_TRUE(web_contents); |
| 1992 | 1994 |
| 1993 ScopedTempDir other_directory; | 1995 ScopedTempDir other_directory; |
| 1994 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); | 1996 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); |
| 1995 FilePath target_file_full_path | 1997 FilePath target_file_full_path |
| 1996 = other_directory.path().Append(file.BaseName()); | 1998 = other_directory.path().Append(file.BaseName()); |
| 1997 content::DownloadSaveInfo save_info; | 1999 content::DownloadSaveInfo save_info; |
| 1998 save_info.file_path = target_file_full_path; | 2000 save_info.file_path = target_file_full_path; |
| 1999 | 2001 |
| 2000 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); | 2002 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); |
| 2001 DownloadManagerForBrowser(browser())->DownloadUrl( | 2003 DownloadManagerForBrowser(browser())->DownloadUrl( |
| 2002 url, GURL(""), "", false, -1, save_info, web_contents, | 2004 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); |
| 2003 DownloadManager::OnStartedCallback()); | |
| 2004 observer->WaitForFinished(); | 2005 observer->WaitForFinished(); |
| 2005 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 2006 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 2006 | 2007 |
| 2007 // Check state. | 2008 // Check state. |
| 2008 EXPECT_EQ(1, browser()->tab_count()); | 2009 EXPECT_EQ(1, browser()->tab_count()); |
| 2009 ASSERT_TRUE(CheckDownloadFullPaths(browser(), | 2010 ASSERT_TRUE(CheckDownloadFullPaths(browser(), |
| 2010 target_file_full_path, | 2011 target_file_full_path, |
| 2011 OriginFile(file))); | 2012 OriginFile(file))); |
| 2012 | 2013 |
| 2013 // Temporary downloads won't be visible. | 2014 // Temporary downloads won't be visible. |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2432 GURL url(test_server()->GetURL(path)); | 2433 GURL url(test_server()->GetURL(path)); |
| 2433 | 2434 |
| 2434 DownloadTestObserver* observer(DangerousDownloadWaiter( | 2435 DownloadTestObserver* observer(DangerousDownloadWaiter( |
| 2435 browser(), 1, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 2436 browser(), 1, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 2436 ui_test_utils::NavigateToURL(browser(), url); | 2437 ui_test_utils::NavigateToURL(browser(), url); |
| 2437 observer->WaitForFinished(); | 2438 observer->WaitForFinished(); |
| 2438 | 2439 |
| 2439 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 2440 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 2440 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 2441 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 2441 } | 2442 } |
| OLD | NEW |