| 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 }; | 266 }; |
| 267 | 267 |
| 268 DownloadTest() { | 268 DownloadTest() { |
| 269 EnableDOMAutomation(); | 269 EnableDOMAutomation(); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void SetUpOnMainThread() OVERRIDE { | 272 void SetUpOnMainThread() OVERRIDE { |
| 273 BrowserThread::PostTask( | 273 BrowserThread::PostTask( |
| 274 BrowserThread::IO, FROM_HERE, | 274 BrowserThread::IO, FROM_HERE, |
| 275 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 275 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
| 276 ASSERT_TRUE(InitialSetup()); |
| 276 } | 277 } |
| 277 | 278 |
| 278 // Returning false indicates a failure of the setup, and should be asserted | 279 // Returning false indicates a failure of the setup, and should be asserted |
| 279 // in the caller. | 280 // in the caller. |
| 280 virtual bool InitialSetup(bool prompt_for_download) { | 281 virtual bool InitialSetup() { |
| 281 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_); | 282 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_); |
| 282 EXPECT_TRUE(have_test_dir); | 283 EXPECT_TRUE(have_test_dir); |
| 283 if (!have_test_dir) | 284 if (!have_test_dir) |
| 284 return false; | 285 return false; |
| 285 | 286 |
| 286 // Sanity check default values for window / tab count and shelf visibility. | 287 // Sanity check default values for window / tab count and shelf visibility. |
| 287 int window_count = BrowserList::size(); | 288 int window_count = BrowserList::size(); |
| 288 EXPECT_EQ(1, window_count); | 289 EXPECT_EQ(1, window_count); |
| 289 EXPECT_EQ(1, browser()->tab_count()); | 290 EXPECT_EQ(1, browser()->tab_count()); |
| 290 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 291 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 291 | 292 |
| 292 // Set up the temporary download folder. | 293 // Set up the temporary download folder. |
| 293 bool created_downloads_dir = CreateAndSetDownloadsDirectory(browser()); | 294 bool created_downloads_dir = CreateAndSetDownloadsDirectory(browser()); |
| 294 EXPECT_TRUE(created_downloads_dir); | 295 EXPECT_TRUE(created_downloads_dir); |
| 295 if (!created_downloads_dir) | 296 if (!created_downloads_dir) |
| 296 return false; | 297 return false; |
| 297 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, | 298 browser()->profile()->GetPrefs()->SetBoolean( |
| 298 prompt_for_download); | 299 prefs::kPromptForDownload, false); |
| 299 | 300 |
| 300 DownloadManager* manager = DownloadManagerForBrowser(browser()); | 301 DownloadManager* manager = DownloadManagerForBrowser(browser()); |
| 301 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); | 302 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); |
| 302 manager->RemoveAllDownloads(); | 303 manager->RemoveAllDownloads(); |
| 303 | 304 |
| 304 return true; | 305 return true; |
| 305 } | 306 } |
| 306 | 307 |
| 307 protected: | 308 protected: |
| 308 | 309 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 bool downloaded_file_deleted = | 486 bool downloaded_file_deleted = |
| 486 file_util::DieFileDie(downloaded_file, false); | 487 file_util::DieFileDie(downloaded_file, false); |
| 487 EXPECT_TRUE(downloaded_file_deleted); | 488 EXPECT_TRUE(downloaded_file_deleted); |
| 488 return downloaded_file_deleted; | 489 return downloaded_file_deleted; |
| 489 } | 490 } |
| 490 | 491 |
| 491 bool RunSizeTest(Browser* browser, | 492 bool RunSizeTest(Browser* browser, |
| 492 SizeTestType type, | 493 SizeTestType type, |
| 493 const std::string& partial_indication, | 494 const std::string& partial_indication, |
| 494 const std::string& total_indication) { | 495 const std::string& total_indication) { |
| 495 if (!InitialSetup(false)) | |
| 496 return false; | |
| 497 | |
| 498 EXPECT_TRUE(type == SIZE_TEST_TYPE_UNKNOWN || type == SIZE_TEST_TYPE_KNOWN); | 496 EXPECT_TRUE(type == SIZE_TEST_TYPE_UNKNOWN || type == SIZE_TEST_TYPE_KNOWN); |
| 499 if (type != SIZE_TEST_TYPE_KNOWN && type != SIZE_TEST_TYPE_UNKNOWN) | 497 if (type != SIZE_TEST_TYPE_KNOWN && type != SIZE_TEST_TYPE_UNKNOWN) |
| 500 return false; | 498 return false; |
| 501 GURL url(type == SIZE_TEST_TYPE_KNOWN ? | 499 GURL url(type == SIZE_TEST_TYPE_KNOWN ? |
| 502 URLRequestSlowDownloadJob::kKnownSizeUrl : | 500 URLRequestSlowDownloadJob::kKnownSizeUrl : |
| 503 URLRequestSlowDownloadJob::kUnknownSizeUrl); | 501 URLRequestSlowDownloadJob::kUnknownSizeUrl); |
| 504 | 502 |
| 505 // TODO(ahendrickson) -- |expected_title_in_progress| and | 503 // TODO(ahendrickson) -- |expected_title_in_progress| and |
| 506 // |expected_title_finished| need to be checked. | 504 // |expected_title_finished| need to be checked. |
| 507 FilePath filename; | 505 FilePath filename; |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 info[i].error_info.url = url.spec(); | 804 info[i].error_info.url = url.spec(); |
| 807 | 805 |
| 808 DownloadInsertFilesErrorCheckErrorsLoopBody(injector, info[i], i); | 806 DownloadInsertFilesErrorCheckErrorsLoopBody(injector, info[i], i); |
| 809 } | 807 } |
| 810 } | 808 } |
| 811 | 809 |
| 812 // Attempts to download a file to a read-only folder, based on information | 810 // Attempts to download a file to a read-only folder, based on information |
| 813 // in |download_info|. | 811 // in |download_info|. |
| 814 void DownloadFilesToReadonlyFolder(size_t count, | 812 void DownloadFilesToReadonlyFolder(size_t count, |
| 815 DownloadInfo* download_info) { | 813 DownloadInfo* download_info) { |
| 816 ASSERT_TRUE(InitialSetup(false)); // Creates temporary download folder. | |
| 817 | |
| 818 DownloadFilesCheckErrorsSetup(); | 814 DownloadFilesCheckErrorsSetup(); |
| 819 | 815 |
| 820 // Make the test folder unwritable. | 816 // Make the test folder unwritable. |
| 821 FilePath destination_folder = GetDownloadDirectory(browser()); | 817 FilePath destination_folder = GetDownloadDirectory(browser()); |
| 822 DVLOG(1) << " " << __FUNCTION__ << "()" | 818 DVLOG(1) << " " << __FUNCTION__ << "()" |
| 823 << " folder = '" << destination_folder.value() << "'"; | 819 << " folder = '" << destination_folder.value() << "'"; |
| 824 file_util::PermissionRestorer permission_restorer(destination_folder); | 820 file_util::PermissionRestorer permission_restorer(destination_folder); |
| 825 EXPECT_TRUE(file_util::MakeFileUnwritable(destination_folder)); | 821 EXPECT_TRUE(file_util::MakeFileUnwritable(destination_folder)); |
| 826 | 822 |
| 827 for (size_t i = 0; i < count; ++i) { | 823 for (size_t i = 0; i < count; ++i) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 854 }; | 850 }; |
| 855 | 851 |
| 856 // NOTES: | 852 // NOTES: |
| 857 // | 853 // |
| 858 // Files for these tests are found in DIR_TEST_DATA (currently | 854 // Files for these tests are found in DIR_TEST_DATA (currently |
| 859 // "chrome\test\data\", see chrome_paths.cc). | 855 // "chrome\test\data\", see chrome_paths.cc). |
| 860 // Mock responses have extension .mock-http-headers appended to the file name. | 856 // Mock responses have extension .mock-http-headers appended to the file name. |
| 861 | 857 |
| 862 // Download a file due to the associated MIME type. | 858 // Download a file due to the associated MIME type. |
| 863 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { | 859 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { |
| 864 ASSERT_TRUE(InitialSetup(false)); | |
| 865 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 860 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 866 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 861 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 867 | 862 |
| 868 // Download the file and wait. We do not expect the Select File dialog. | 863 // Download the file and wait. We do not expect the Select File dialog. |
| 869 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 864 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); |
| 870 | 865 |
| 871 // Check state. | 866 // Check state. |
| 872 EXPECT_EQ(1, browser()->tab_count()); | 867 EXPECT_EQ(1, browser()->tab_count()); |
| 873 CheckDownload(browser(), file, file); | 868 CheckDownload(browser(), file, file); |
| 874 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 869 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 875 } | 870 } |
| 876 | 871 |
| 877 #if defined(OS_WIN) | 872 #if defined(OS_WIN) |
| 878 // Download a file and confirm that the zone identifier (on windows) | 873 // Download a file and confirm that the zone identifier (on windows) |
| 879 // is set to internet. | 874 // is set to internet. |
| 880 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { | 875 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { |
| 881 ASSERT_TRUE(InitialSetup(false)); | |
| 882 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 876 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 883 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 877 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 884 | 878 |
| 885 // Download the file and wait. We do not expect the Select File dialog. | 879 // Download the file and wait. We do not expect the Select File dialog. |
| 886 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 880 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); |
| 887 | 881 |
| 888 // Check state. Special file state must be checked before CheckDownload, | 882 // Check state. Special file state must be checked before CheckDownload, |
| 889 // as CheckDownload will delete the output file. | 883 // as CheckDownload will delete the output file. |
| 890 EXPECT_EQ(1, browser()->tab_count()); | 884 EXPECT_EQ(1, browser()->tab_count()); |
| 891 FilePath downloaded_file(DestinationFile(browser(), file)); | 885 FilePath downloaded_file(DestinationFile(browser(), file)); |
| 892 if (file_util::VolumeSupportsADS(downloaded_file)) | 886 if (file_util::VolumeSupportsADS(downloaded_file)) |
| 893 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); | 887 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); |
| 894 CheckDownload(browser(), file, file); | 888 CheckDownload(browser(), file, file); |
| 895 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 889 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 896 } | 890 } |
| 897 #endif | 891 #endif |
| 898 | 892 |
| 899 // Put up a Select File dialog when the file is downloaded, due to | 893 // Put up a Select File dialog when the file is downloaded, due to |
| 900 // downloads preferences settings. | 894 // downloads preferences settings. |
| 901 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { | 895 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { |
| 902 ASSERT_TRUE(InitialSetup(true)); | 896 // Re-enable prompting. |
| 897 browser()->profile()->GetPrefs()->SetBoolean( |
| 898 prefs::kPromptForDownload, true); |
| 903 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 899 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 904 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 900 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 905 | 901 |
| 906 NullSelectFile(browser()); | 902 NullSelectFile(browser()); |
| 907 | 903 |
| 908 // Download the file and wait. We expect the Select File dialog to appear | 904 // Download the file and wait. We expect the Select File dialog to appear |
| 909 // due to the MIME type, but we still wait until the download completes. | 905 // due to the MIME type, but we still wait until the download completes. |
| 910 scoped_ptr<DownloadTestObserver> observer( | 906 scoped_ptr<DownloadTestObserver> observer( |
| 911 new DownloadTestObserverTerminal( | 907 new DownloadTestObserverTerminal( |
| 912 DownloadManagerForBrowser(browser()), | 908 DownloadManagerForBrowser(browser()), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 923 | 919 |
| 924 // Check state. | 920 // Check state. |
| 925 EXPECT_EQ(1, browser()->tab_count()); | 921 EXPECT_EQ(1, browser()->tab_count()); |
| 926 CheckDownload(browser(), file, file); | 922 CheckDownload(browser(), file, file); |
| 927 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 923 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 928 } | 924 } |
| 929 | 925 |
| 930 // Access a file with a viewable mime-type, verify that a download | 926 // Access a file with a viewable mime-type, verify that a download |
| 931 // did not initiate. | 927 // did not initiate. |
| 932 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { | 928 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { |
| 933 ASSERT_TRUE(InitialSetup(false)); | |
| 934 FilePath file(FILE_PATH_LITERAL("download-test2.html")); | 929 FilePath file(FILE_PATH_LITERAL("download-test2.html")); |
| 935 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 930 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 936 FilePath file_path(DestinationFile(browser(), file)); | 931 FilePath file_path(DestinationFile(browser(), file)); |
| 937 | 932 |
| 938 // Open a web page and wait. | 933 // Open a web page and wait. |
| 939 ui_test_utils::NavigateToURL(browser(), url); | 934 ui_test_utils::NavigateToURL(browser(), url); |
| 940 | 935 |
| 941 // Check that we did not download the web page. | 936 // Check that we did not download the web page. |
| 942 EXPECT_FALSE(file_util::PathExists(file_path)); | 937 EXPECT_FALSE(file_util::PathExists(file_path)); |
| 943 | 938 |
| 944 // Check state. | 939 // Check state. |
| 945 EXPECT_EQ(1, browser()->tab_count()); | 940 EXPECT_EQ(1, browser()->tab_count()); |
| 946 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 941 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 947 } | 942 } |
| 948 | 943 |
| 949 // Verify that when the DownloadResourceThrottle cancels a download, the | 944 // Verify that when the DownloadResourceThrottle cancels a download, the |
| 950 // download never makes it to the downloads system. | 945 // download never makes it to the downloads system. |
| 951 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadResourceThrottleCancels) { | 946 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadResourceThrottleCancels) { |
| 952 ASSERT_TRUE(InitialSetup(false)); | |
| 953 | |
| 954 // Navigate to a page with the same domain as the file to download. We can't | 947 // Navigate to a page with the same domain as the file to download. We can't |
| 955 // navigate directly to the file we don't want to download because cross-site | 948 // navigate directly to the file we don't want to download because cross-site |
| 956 // navigations reset the TabDownloadState. | 949 // navigations reset the TabDownloadState. |
| 957 FilePath same_site_path(FILE_PATH_LITERAL("download_script.html")); | 950 FilePath same_site_path(FILE_PATH_LITERAL("download_script.html")); |
| 958 GURL same_site_url(URLRequestMockHTTPJob::GetMockUrl(same_site_path)); | 951 GURL same_site_url(URLRequestMockHTTPJob::GetMockUrl(same_site_path)); |
| 959 ui_test_utils::NavigateToURL(browser(), same_site_url); | 952 ui_test_utils::NavigateToURL(browser(), same_site_url); |
| 960 | 953 |
| 961 // Make sure the initial navigation didn't trigger a download. | 954 // Make sure the initial navigation didn't trigger a download. |
| 962 EXPECT_TRUE(EnsureNoPendingDownloads()); | 955 EXPECT_TRUE(EnsureNoPendingDownloads()); |
| 963 | 956 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 | 995 |
| 1003 // Verify that there's no pending download. | 996 // Verify that there's no pending download. |
| 1004 EXPECT_TRUE(EnsureNoPendingDownloads()); | 997 EXPECT_TRUE(EnsureNoPendingDownloads()); |
| 1005 } | 998 } |
| 1006 | 999 |
| 1007 // Download a 0-size file with a content-disposition header, verify that the | 1000 // Download a 0-size file with a content-disposition header, verify that the |
| 1008 // download tab opened and the file exists as the filename specified in the | 1001 // download tab opened and the file exists as the filename specified in the |
| 1009 // header. This also ensures we properly handle empty file downloads. | 1002 // header. This also ensures we properly handle empty file downloads. |
| 1010 // The download shelf should be visible in the current tab. | 1003 // The download shelf should be visible in the current tab. |
| 1011 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { | 1004 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { |
| 1012 ASSERT_TRUE(InitialSetup(false)); | |
| 1013 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 1005 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
| 1014 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1006 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1015 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); | 1007 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
| 1016 | 1008 |
| 1017 // Download a file and wait. | 1009 // Download a file and wait. |
| 1018 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1010 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); |
| 1019 | 1011 |
| 1020 CheckDownload(browser(), download_file, file); | 1012 CheckDownload(browser(), download_file, file); |
| 1021 | 1013 |
| 1022 // Check state. | 1014 // Check state. |
| 1023 EXPECT_EQ(1, browser()->tab_count()); | 1015 EXPECT_EQ(1, browser()->tab_count()); |
| 1024 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1016 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1025 } | 1017 } |
| 1026 | 1018 |
| 1027 // Test that the download shelf is per-window by starting a download in one | 1019 // Test that the download shelf is per-window by starting a download in one |
| 1028 // tab, opening a second tab, closing the shelf, going back to the first tab, | 1020 // tab, opening a second tab, closing the shelf, going back to the first tab, |
| 1029 // and checking that the shelf is closed. | 1021 // and checking that the shelf is closed. |
| 1030 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { | 1022 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { |
| 1031 ASSERT_TRUE(InitialSetup(false)); | |
| 1032 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 1023 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
| 1033 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1024 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1034 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); | 1025 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
| 1035 | 1026 |
| 1036 // Download a file and wait. | 1027 // Download a file and wait. |
| 1037 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1028 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); |
| 1038 | 1029 |
| 1039 CheckDownload(browser(), download_file, file); | 1030 CheckDownload(browser(), download_file, file); |
| 1040 | 1031 |
| 1041 // Check state. | 1032 // Check state. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1057 browser()->ActivateTabAt(0, true); | 1048 browser()->ActivateTabAt(0, true); |
| 1058 EXPECT_EQ(2, browser()->tab_count()); | 1049 EXPECT_EQ(2, browser()->tab_count()); |
| 1059 | 1050 |
| 1060 // The download shelf should not be visible. | 1051 // The download shelf should not be visible. |
| 1061 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1052 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1062 } | 1053 } |
| 1063 | 1054 |
| 1064 // Check whether the downloads shelf is closed when the downloads tab is | 1055 // Check whether the downloads shelf is closed when the downloads tab is |
| 1065 // invoked. | 1056 // invoked. |
| 1066 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseShelfOnDownloadsTab) { | 1057 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseShelfOnDownloadsTab) { |
| 1067 ASSERT_TRUE(InitialSetup(false)); | |
| 1068 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1058 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1069 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1059 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1070 | 1060 |
| 1071 // Download the file and wait. We do not expect the Select File dialog. | 1061 // Download the file and wait. We do not expect the Select File dialog. |
| 1072 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1062 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); |
| 1073 | 1063 |
| 1074 // Check state. | 1064 // Check state. |
| 1075 EXPECT_EQ(1, browser()->tab_count()); | 1065 EXPECT_EQ(1, browser()->tab_count()); |
| 1076 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1066 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1077 | 1067 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1097 IN_PROC_BROWSER_TEST_F(DownloadTest, KnownSize) { | 1087 IN_PROC_BROWSER_TEST_F(DownloadTest, KnownSize) { |
| 1098 ASSERT_TRUE(RunSizeTest(browser(), SIZE_TEST_TYPE_KNOWN, | 1088 ASSERT_TRUE(RunSizeTest(browser(), SIZE_TEST_TYPE_KNOWN, |
| 1099 "71% - ", "100% - ")); | 1089 "71% - ", "100% - ")); |
| 1100 } | 1090 } |
| 1101 | 1091 |
| 1102 // Test that when downloading an item in Incognito mode, we don't crash when | 1092 // Test that when downloading an item in Incognito mode, we don't crash when |
| 1103 // closing the last Incognito window (http://crbug.com/13983). | 1093 // closing the last Incognito window (http://crbug.com/13983). |
| 1104 // Also check that the download shelf is not visible after closing the | 1094 // Also check that the download shelf is not visible after closing the |
| 1105 // Incognito window. | 1095 // Incognito window. |
| 1106 IN_PROC_BROWSER_TEST_F(DownloadTest, IncognitoDownload) { | 1096 IN_PROC_BROWSER_TEST_F(DownloadTest, IncognitoDownload) { |
| 1107 ASSERT_TRUE(InitialSetup(false)); | |
| 1108 // Open an Incognito window. | 1097 // Open an Incognito window. |
| 1109 Browser* incognito = CreateIncognitoBrowser(); // Waits. | 1098 Browser* incognito = CreateIncognitoBrowser(); // Waits. |
| 1110 ASSERT_TRUE(incognito); | 1099 ASSERT_TRUE(incognito); |
| 1111 int window_count = BrowserList::size(); | 1100 int window_count = BrowserList::size(); |
| 1112 EXPECT_EQ(2, window_count); | 1101 EXPECT_EQ(2, window_count); |
| 1113 | 1102 |
| 1114 // Download a file in the Incognito window and wait. | 1103 // Download a file in the Incognito window and wait. |
| 1115 CreateAndSetDownloadsDirectory(incognito); | 1104 CreateAndSetDownloadsDirectory(incognito); |
| 1116 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1105 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1117 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1106 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1147 // On ChromeOS, the download panel is common to both profiles, so | 1136 // On ChromeOS, the download panel is common to both profiles, so |
| 1148 // it is still visible. | 1137 // it is still visible. |
| 1149 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1138 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1150 | 1139 |
| 1151 CheckDownload(browser(), file, file); | 1140 CheckDownload(browser(), file, file); |
| 1152 } | 1141 } |
| 1153 | 1142 |
| 1154 // Navigate to a new background page, but don't download. Confirm that the | 1143 // Navigate to a new background page, but don't download. Confirm that the |
| 1155 // download shelf is not visible and that we have two tabs. | 1144 // download shelf is not visible and that we have two tabs. |
| 1156 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) { | 1145 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) { |
| 1157 ASSERT_TRUE(InitialSetup(false)); | |
| 1158 // Because it's an HTML link, it should open a web page rather than | 1146 // Because it's an HTML link, it should open a web page rather than |
| 1159 // downloading. | 1147 // downloading. |
| 1160 FilePath file1(FILE_PATH_LITERAL("download-test2.html")); | 1148 FilePath file1(FILE_PATH_LITERAL("download-test2.html")); |
| 1161 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); | 1149 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); |
| 1162 | 1150 |
| 1163 // Open a web page and wait. | 1151 // Open a web page and wait. |
| 1164 ui_test_utils::NavigateToURLWithDisposition( | 1152 ui_test_utils::NavigateToURLWithDisposition( |
| 1165 browser(), | 1153 browser(), |
| 1166 url, | 1154 url, |
| 1167 NEW_BACKGROUND_TAB, | 1155 NEW_BACKGROUND_TAB, |
| 1168 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1156 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1169 | 1157 |
| 1170 // We should have two tabs now. | 1158 // We should have two tabs now. |
| 1171 EXPECT_EQ(2, browser()->tab_count()); | 1159 EXPECT_EQ(2, browser()->tab_count()); |
| 1172 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1160 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1173 } | 1161 } |
| 1174 | 1162 |
| 1175 // Download a file in a background tab. Verify that the tab is closed | 1163 // Download a file in a background tab. Verify that the tab is closed |
| 1176 // automatically, and that the download shelf is visible in the current tab. | 1164 // automatically, and that the download shelf is visible in the current tab. |
| 1177 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab1) { | 1165 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab1) { |
| 1178 ASSERT_TRUE(InitialSetup(false)); | |
| 1179 | |
| 1180 // Download a file in a new background tab and wait. The tab is automatically | 1166 // Download a file in a new background tab and wait. The tab is automatically |
| 1181 // closed when the download begins. | 1167 // closed when the download begins. |
| 1182 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1168 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1183 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1169 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1184 DownloadAndWaitWithDisposition( | 1170 DownloadAndWaitWithDisposition( |
| 1185 browser(), | 1171 browser(), |
| 1186 url, | 1172 url, |
| 1187 NEW_BACKGROUND_TAB, | 1173 NEW_BACKGROUND_TAB, |
| 1188 EXPECT_NO_SELECT_DIALOG, | 1174 EXPECT_NO_SELECT_DIALOG, |
| 1189 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1175 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1190 | 1176 |
| 1191 // When the download finishes, we should still have one tab. | 1177 // When the download finishes, we should still have one tab. |
| 1192 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1178 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1193 EXPECT_EQ(1, browser()->tab_count()); | 1179 EXPECT_EQ(1, browser()->tab_count()); |
| 1194 | 1180 |
| 1195 CheckDownload(browser(), file, file); | 1181 CheckDownload(browser(), file, file); |
| 1196 } | 1182 } |
| 1197 | 1183 |
| 1198 // Open a web page in the current tab, then download a file in another tab via | 1184 // Open a web page in the current tab, then download a file in another tab via |
| 1199 // a Javascript call. | 1185 // a Javascript call. |
| 1200 // Verify that we have 2 tabs, and the download shelf is visible in the current | 1186 // Verify that we have 2 tabs, and the download shelf is visible in the current |
| 1201 // tab. | 1187 // tab. |
| 1202 // | 1188 // |
| 1203 // The download_page1.html page contains an openNew() function that opens a | 1189 // The download_page1.html page contains an openNew() function that opens a |
| 1204 // tab and then downloads download-test1.lib. | 1190 // tab and then downloads download-test1.lib. |
| 1205 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab2) { | 1191 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab2) { |
| 1206 ASSERT_TRUE(InitialSetup(false)); | |
| 1207 // Because it's an HTML link, it should open a web page rather than | 1192 // Because it's an HTML link, it should open a web page rather than |
| 1208 // downloading. | 1193 // downloading. |
| 1209 FilePath file1(FILE_PATH_LITERAL("download_page1.html")); | 1194 FilePath file1(FILE_PATH_LITERAL("download_page1.html")); |
| 1210 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); | 1195 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); |
| 1211 | 1196 |
| 1212 // Open a web page and wait. | 1197 // Open a web page and wait. |
| 1213 ui_test_utils::NavigateToURL(browser(), url); | 1198 ui_test_utils::NavigateToURL(browser(), url); |
| 1214 | 1199 |
| 1215 // Download a file in a new tab and wait (via Javascript). | 1200 // Download a file in a new tab and wait (via Javascript). |
| 1216 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1201 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1228 } | 1213 } |
| 1229 | 1214 |
| 1230 // Open a web page in the current tab, open another tab via a Javascript call, | 1215 // Open a web page in the current tab, open another tab via a Javascript call, |
| 1231 // then download a file in the new tab. | 1216 // then download a file in the new tab. |
| 1232 // Verify that we have 2 tabs, and the download shelf is visible in the current | 1217 // Verify that we have 2 tabs, and the download shelf is visible in the current |
| 1233 // tab. | 1218 // tab. |
| 1234 // | 1219 // |
| 1235 // The download_page2.html page contains an openNew() function that opens a | 1220 // The download_page2.html page contains an openNew() function that opens a |
| 1236 // tab. | 1221 // tab. |
| 1237 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab3) { | 1222 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab3) { |
| 1238 ASSERT_TRUE(InitialSetup(false)); | |
| 1239 // Because it's an HTML link, it should open a web page rather than | 1223 // Because it's an HTML link, it should open a web page rather than |
| 1240 // downloading. | 1224 // downloading. |
| 1241 FilePath file1(FILE_PATH_LITERAL("download_page2.html")); | 1225 FilePath file1(FILE_PATH_LITERAL("download_page2.html")); |
| 1242 GURL url1(URLRequestMockHTTPJob::GetMockUrl(file1)); | 1226 GURL url1(URLRequestMockHTTPJob::GetMockUrl(file1)); |
| 1243 | 1227 |
| 1244 // Open a web page and wait. | 1228 // Open a web page and wait. |
| 1245 ui_test_utils::NavigateToURL(browser(), url1); | 1229 ui_test_utils::NavigateToURL(browser(), url1); |
| 1246 | 1230 |
| 1247 // Open a new tab and wait. | 1231 // Open a new tab and wait. |
| 1248 ui_test_utils::NavigateToURLWithDisposition( | 1232 ui_test_utils::NavigateToURLWithDisposition( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1270 } | 1254 } |
| 1271 | 1255 |
| 1272 // Open a web page in the current tab, then download a file via Javascript, | 1256 // Open a web page in the current tab, then download a file via Javascript, |
| 1273 // which will do so in a temporary tab. | 1257 // which will do so in a temporary tab. |
| 1274 // Verify that we have 1 tab, and the download shelf is visible. | 1258 // Verify that we have 1 tab, and the download shelf is visible. |
| 1275 // | 1259 // |
| 1276 // The download_page3.html page contains an openNew() function that opens a | 1260 // The download_page3.html page contains an openNew() function that opens a |
| 1277 // tab with download-test1.lib in the URL. When the URL is determined to be | 1261 // tab with download-test1.lib in the URL. When the URL is determined to be |
| 1278 // a download, the tab is closed automatically. | 1262 // a download, the tab is closed automatically. |
| 1279 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab2) { | 1263 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab2) { |
| 1280 ASSERT_TRUE(InitialSetup(false)); | |
| 1281 // Because it's an HTML link, it should open a web page rather than | 1264 // Because it's an HTML link, it should open a web page rather than |
| 1282 // downloading. | 1265 // downloading. |
| 1283 FilePath file1(FILE_PATH_LITERAL("download_page3.html")); | 1266 FilePath file1(FILE_PATH_LITERAL("download_page3.html")); |
| 1284 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); | 1267 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); |
| 1285 | 1268 |
| 1286 // Open a web page and wait. | 1269 // Open a web page and wait. |
| 1287 ui_test_utils::NavigateToURL(browser(), url); | 1270 ui_test_utils::NavigateToURL(browser(), url); |
| 1288 | 1271 |
| 1289 // Download a file and wait. | 1272 // Download a file and wait. |
| 1290 // The file to download is "download-test1.lib". | 1273 // The file to download is "download-test1.lib". |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1303 } | 1286 } |
| 1304 | 1287 |
| 1305 // Open a web page in the current tab, then call Javascript via a button to | 1288 // Open a web page in the current tab, then call Javascript via a button to |
| 1306 // download a file in a new tab, which is closed automatically when the | 1289 // download a file in a new tab, which is closed automatically when the |
| 1307 // download begins. | 1290 // download begins. |
| 1308 // Verify that we have 1 tab, and the download shelf is visible. | 1291 // Verify that we have 1 tab, and the download shelf is visible. |
| 1309 // | 1292 // |
| 1310 // The download_page4.html page contains a form with download-test1.lib as the | 1293 // The download_page4.html page contains a form with download-test1.lib as the |
| 1311 // action. | 1294 // action. |
| 1312 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab3) { | 1295 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab3) { |
| 1313 ASSERT_TRUE(InitialSetup(false)); | |
| 1314 // Because it's an HTML link, it should open a web page rather than | 1296 // Because it's an HTML link, it should open a web page rather than |
| 1315 // downloading. | 1297 // downloading. |
| 1316 FilePath file1(FILE_PATH_LITERAL("download_page4.html")); | 1298 FilePath file1(FILE_PATH_LITERAL("download_page4.html")); |
| 1317 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); | 1299 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); |
| 1318 | 1300 |
| 1319 // Open a web page and wait. | 1301 // Open a web page and wait. |
| 1320 ui_test_utils::NavigateToURL(browser(), url); | 1302 ui_test_utils::NavigateToURL(browser(), url); |
| 1321 | 1303 |
| 1322 // Download a file in a new tab and wait. The tab will automatically close | 1304 // Download a file in a new tab and wait. The tab will automatically close |
| 1323 // when the download begins. | 1305 // when the download begins. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1338 } | 1320 } |
| 1339 | 1321 |
| 1340 // Download a file in a new window. | 1322 // Download a file in a new window. |
| 1341 // Verify that we have 2 windows, and the download shelf is not visible in the | 1323 // Verify that we have 2 windows, and the download shelf is not visible in the |
| 1342 // first window, but is visible in the second window. | 1324 // first window, but is visible in the second window. |
| 1343 // Close the new window. | 1325 // Close the new window. |
| 1344 // Verify that we have 1 window, and the download shelf is not visible. | 1326 // Verify that we have 1 window, and the download shelf is not visible. |
| 1345 // | 1327 // |
| 1346 // Regression test for http://crbug.com/44454 | 1328 // Regression test for http://crbug.com/44454 |
| 1347 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { | 1329 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { |
| 1348 ASSERT_TRUE(InitialSetup(false)); | |
| 1349 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1330 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1350 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1331 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1351 #if !defined(OS_MACOSX) | 1332 #if !defined(OS_MACOSX) |
| 1352 // See below. | 1333 // See below. |
| 1353 Browser* first_browser = browser(); | 1334 Browser* first_browser = browser(); |
| 1354 #endif | 1335 #endif |
| 1355 | 1336 |
| 1356 // Download a file in a new window and wait. | 1337 // Download a file in a new window and wait. |
| 1357 DownloadAndWaitWithDisposition(browser(), | 1338 DownloadAndWaitWithDisposition(browser(), |
| 1358 url, | 1339 url, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1398 EXPECT_EQ(1, browser()->tab_count()); | 1379 EXPECT_EQ(1, browser()->tab_count()); |
| 1399 // Download shelf should close. Download panel stays open on ChromeOS. | 1380 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1400 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1381 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1401 | 1382 |
| 1402 CheckDownload(browser(), file, file); | 1383 CheckDownload(browser(), file, file); |
| 1403 } | 1384 } |
| 1404 | 1385 |
| 1405 // Check that downloading multiple (in this case, 2) files does not result in | 1386 // Check that downloading multiple (in this case, 2) files does not result in |
| 1406 // corrupted files. | 1387 // corrupted files. |
| 1407 IN_PROC_BROWSER_TEST_F(DownloadTest, MultiDownload) { | 1388 IN_PROC_BROWSER_TEST_F(DownloadTest, MultiDownload) { |
| 1408 ASSERT_TRUE(InitialSetup(false)); | |
| 1409 EXPECT_EQ(1, browser()->tab_count()); | 1389 EXPECT_EQ(1, browser()->tab_count()); |
| 1410 | 1390 |
| 1411 // Create a download, wait until it's started, and confirm | 1391 // Create a download, wait until it's started, and confirm |
| 1412 // we're in the expected state. | 1392 // we're in the expected state. |
| 1413 scoped_ptr<DownloadTestObserver> observer1( | 1393 scoped_ptr<DownloadTestObserver> observer1( |
| 1414 CreateInProgressWaiter(browser(), 1)); | 1394 CreateInProgressWaiter(browser(), 1)); |
| 1415 ui_test_utils::NavigateToURL( | 1395 ui_test_utils::NavigateToURL( |
| 1416 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 1396 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
| 1417 observer1->WaitForFinished(); | 1397 observer1->WaitForFinished(); |
| 1418 | 1398 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 size_t file_size1 = URLRequestSlowDownloadJob::kFirstDownloadSize + | 1448 size_t file_size1 = URLRequestSlowDownloadJob::kFirstDownloadSize + |
| 1469 URLRequestSlowDownloadJob::kSecondDownloadSize; | 1449 URLRequestSlowDownloadJob::kSecondDownloadSize; |
| 1470 std::string expected_contents(file_size1, '*'); | 1450 std::string expected_contents(file_size1, '*'); |
| 1471 ASSERT_TRUE(VerifyFile(file1, expected_contents, file_size1)); | 1451 ASSERT_TRUE(VerifyFile(file1, expected_contents, file_size1)); |
| 1472 | 1452 |
| 1473 FilePath file2(download2->GetFullPath()); | 1453 FilePath file2(download2->GetFullPath()); |
| 1474 ASSERT_TRUE(file_util::ContentsEqual(OriginFile(file), file2)); | 1454 ASSERT_TRUE(file_util::ContentsEqual(OriginFile(file), file2)); |
| 1475 } | 1455 } |
| 1476 | 1456 |
| 1477 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { | 1457 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { |
| 1478 ASSERT_TRUE(InitialSetup(false)); | |
| 1479 EXPECT_EQ(1, browser()->tab_count()); | 1458 EXPECT_EQ(1, browser()->tab_count()); |
| 1480 | 1459 |
| 1481 // TODO(rdsmith): Fragile code warning! The code below relies on the | 1460 // TODO(rdsmith): Fragile code warning! The code below relies on the |
| 1482 // DownloadTestObserverInProgress only finishing when the new download | 1461 // DownloadTestObserverInProgress only finishing when the new download |
| 1483 // has reached the state of being entered into the history and being | 1462 // has reached the state of being entered into the history and being |
| 1484 // user-visible (that's what's required for the Remove to be valid and | 1463 // user-visible (that's what's required for the Remove to be valid and |
| 1485 // for the download shelf to be visible). By the pure semantics of | 1464 // for the download shelf to be visible). By the pure semantics of |
| 1486 // DownloadTestObserverInProgress, that's not guaranteed; DownloadItems | 1465 // DownloadTestObserverInProgress, that's not guaranteed; DownloadItems |
| 1487 // are created in the IN_PROGRESS state and made known to the DownloadManager | 1466 // are created in the IN_PROGRESS state and made known to the DownloadManager |
| 1488 // immediately, so any ModelChanged event on the DownloadManager after | 1467 // immediately, so any ModelChanged event on the DownloadManager after |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1520 EXPECT_TRUE(EnsureNoPendingDownloads()); | 1499 EXPECT_TRUE(EnsureNoPendingDownloads()); |
| 1521 | 1500 |
| 1522 // Using "DownloadItem::Remove" follows the discard dangerous download path, | 1501 // Using "DownloadItem::Remove" follows the discard dangerous download path, |
| 1523 // which completely removes the browser from the shelf and closes the shelf | 1502 // which completely removes the browser from the shelf and closes the shelf |
| 1524 // if it was there. Download panel stays open on ChromeOS. | 1503 // if it was there. Download panel stays open on ChromeOS. |
| 1525 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1504 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1526 } | 1505 } |
| 1527 | 1506 |
| 1528 // Confirm a download makes it into the history properly. | 1507 // Confirm a download makes it into the history properly. |
| 1529 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { | 1508 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { |
| 1530 ASSERT_TRUE(InitialSetup(false)); | |
| 1531 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1509 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1532 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1510 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1533 FilePath origin_file(OriginFile(file)); | 1511 FilePath origin_file(OriginFile(file)); |
| 1534 int64 origin_size; | 1512 int64 origin_size; |
| 1535 file_util::GetFileSize(origin_file, &origin_size); | 1513 file_util::GetFileSize(origin_file, &origin_size); |
| 1536 | 1514 |
| 1537 // Download the file and wait. We do not expect the Select File dialog. | 1515 // Download the file and wait. We do not expect the Select File dialog. |
| 1538 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1516 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); |
| 1539 | 1517 |
| 1540 // Get details of what downloads have just happened. | 1518 // Get details of what downloads have just happened. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1558 EXPECT_EQ(url, info.url); | 1536 EXPECT_EQ(url, info.url); |
| 1559 // Ignore start_time. | 1537 // Ignore start_time. |
| 1560 EXPECT_EQ(origin_size, info.received_bytes); | 1538 EXPECT_EQ(origin_size, info.received_bytes); |
| 1561 EXPECT_EQ(origin_size, info.total_bytes); | 1539 EXPECT_EQ(origin_size, info.total_bytes); |
| 1562 EXPECT_EQ(DownloadItem::COMPLETE, info.state); | 1540 EXPECT_EQ(DownloadItem::COMPLETE, info.state); |
| 1563 } | 1541 } |
| 1564 | 1542 |
| 1565 // Test for crbug.com/14505. This tests that chrome:// urls are still functional | 1543 // Test for crbug.com/14505. This tests that chrome:// urls are still functional |
| 1566 // after download of a file while viewing another chrome://. | 1544 // after download of a file while viewing another chrome://. |
| 1567 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { | 1545 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { |
| 1568 ASSERT_TRUE(InitialSetup(false)); | |
| 1569 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1546 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1570 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1547 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1571 GURL flags_url(chrome::kChromeUIFlagsURL); | 1548 GURL flags_url(chrome::kChromeUIFlagsURL); |
| 1572 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); | 1549 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); |
| 1573 | 1550 |
| 1574 ui_test_utils::NavigateToURL(browser(), flags_url); | 1551 ui_test_utils::NavigateToURL(browser(), flags_url); |
| 1575 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); | 1552 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); |
| 1576 ui_test_utils::NavigateToURL(browser(), extensions_url); | 1553 ui_test_utils::NavigateToURL(browser(), extensions_url); |
| 1577 WebContents* contents = browser()->GetSelectedWebContents(); | 1554 WebContents* contents = browser()->GetSelectedWebContents(); |
| 1578 ASSERT_TRUE(contents); | 1555 ASSERT_TRUE(contents); |
| 1579 bool webui_responded = false; | 1556 bool webui_responded = false; |
| 1580 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1557 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 1581 contents->GetRenderViewHost(), | 1558 contents->GetRenderViewHost(), |
| 1582 L"", | 1559 L"", |
| 1583 L"window.domAutomationController.send(window.webui_responded_);", | 1560 L"window.domAutomationController.send(window.webui_responded_);", |
| 1584 &webui_responded)); | 1561 &webui_responded)); |
| 1585 EXPECT_TRUE(webui_responded); | 1562 EXPECT_TRUE(webui_responded); |
| 1586 } | 1563 } |
| 1587 | 1564 |
| 1588 // Test for crbug.com/12745. This tests that if a download is initiated from | 1565 // Test for crbug.com/12745. This tests that if a download is initiated from |
| 1589 // a chrome:// page that has registered and onunload handler, the browser | 1566 // a chrome:// page that has registered and onunload handler, the browser |
| 1590 // will be able to close. | 1567 // will be able to close. |
| 1591 IN_PROC_BROWSER_TEST_F(DownloadTest, BrowserCloseAfterDownload) { | 1568 IN_PROC_BROWSER_TEST_F(DownloadTest, BrowserCloseAfterDownload) { |
| 1592 ASSERT_TRUE(InitialSetup(false)); | |
| 1593 GURL downloads_url(chrome::kChromeUIFlagsURL); | 1569 GURL downloads_url(chrome::kChromeUIFlagsURL); |
| 1594 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1570 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1595 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1571 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1596 | 1572 |
| 1597 ui_test_utils::NavigateToURL(browser(), downloads_url); | 1573 ui_test_utils::NavigateToURL(browser(), downloads_url); |
| 1598 WebContents* contents = browser()->GetSelectedWebContents(); | 1574 WebContents* contents = browser()->GetSelectedWebContents(); |
| 1599 ASSERT_TRUE(contents); | 1575 ASSERT_TRUE(contents); |
| 1600 bool result = false; | 1576 bool result = false; |
| 1601 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1577 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 1602 contents->GetRenderViewHost(), | 1578 contents->GetRenderViewHost(), |
| 1603 L"", | 1579 L"", |
| 1604 L"window.onunload = function() { var do_nothing = 0; }; " | 1580 L"window.onunload = function() { var do_nothing = 0; }; " |
| 1605 L"window.domAutomationController.send(true);", | 1581 L"window.domAutomationController.send(true);", |
| 1606 &result)); | 1582 &result)); |
| 1607 EXPECT_TRUE(result); | 1583 EXPECT_TRUE(result); |
| 1608 | 1584 |
| 1609 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); | 1585 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); |
| 1610 | 1586 |
| 1611 ui_test_utils::WindowedNotificationObserver signal( | 1587 ui_test_utils::WindowedNotificationObserver signal( |
| 1612 chrome::NOTIFICATION_BROWSER_CLOSED, | 1588 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 1613 content::Source<Browser>(browser())); | 1589 content::Source<Browser>(browser())); |
| 1614 browser()->CloseWindow(); | 1590 browser()->CloseWindow(); |
| 1615 signal.Wait(); | 1591 signal.Wait(); |
| 1616 } | 1592 } |
| 1617 | 1593 |
| 1618 // Test to make sure the 'download' attribute in anchor tag is respected. | 1594 // Test to make sure the 'download' attribute in anchor tag is respected. |
| 1619 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { | 1595 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { |
| 1620 ASSERT_TRUE(InitialSetup(false)); | |
| 1621 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); | 1596 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); |
| 1622 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1597 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1623 | 1598 |
| 1624 // Create a download, wait until it's complete, and confirm | 1599 // Create a download, wait until it's complete, and confirm |
| 1625 // we're in the expected state. | 1600 // we're in the expected state. |
| 1626 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser(), 1)); | 1601 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser(), 1)); |
| 1627 ui_test_utils::NavigateToURL(browser(), url); | 1602 ui_test_utils::NavigateToURL(browser(), url); |
| 1628 observer->WaitForFinished(); | 1603 observer->WaitForFinished(); |
| 1629 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1604 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1630 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1605 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1631 | 1606 |
| 1632 // Confirm the downloaded data exists. | 1607 // Confirm the downloaded data exists. |
| 1633 FilePath downloaded_file = GetDownloadDirectory(browser()); | 1608 FilePath downloaded_file = GetDownloadDirectory(browser()); |
| 1634 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); | 1609 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); |
| 1635 EXPECT_TRUE(file_util::PathExists(downloaded_file)); | 1610 EXPECT_TRUE(file_util::PathExists(downloaded_file)); |
| 1636 } | 1611 } |
| 1637 | 1612 |
| 1638 // crbug.com/118159 | 1613 // crbug.com/118159 |
| 1639 #if defined(OS_LINUX) | 1614 #if defined(OS_LINUX) |
| 1640 #define MAYBE_AutoOpen DISABLED_AutoOpen | 1615 #define MAYBE_AutoOpen DISABLED_AutoOpen |
| 1641 #else | 1616 #else |
| 1642 #define MAYBE_AutoOpen AutoOpen | 1617 #define MAYBE_AutoOpen AutoOpen |
| 1643 #endif | 1618 #endif |
| 1644 | 1619 |
| 1645 // Test to make sure auto-open works. | 1620 // Test to make sure auto-open works. |
| 1646 IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_AutoOpen) { | 1621 IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_AutoOpen) { |
| 1647 ASSERT_TRUE(InitialSetup(false)); | |
| 1648 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); | 1622 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); |
| 1649 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1623 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1650 | 1624 |
| 1651 ASSERT_TRUE( | 1625 ASSERT_TRUE( |
| 1652 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); | 1626 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); |
| 1653 | 1627 |
| 1654 // Mock out external opening on all downloads until end of test. | 1628 // Mock out external opening on all downloads until end of test. |
| 1655 MockDownloadOpeningObserver observer( | 1629 MockDownloadOpeningObserver observer( |
| 1656 DownloadManagerForBrowser(browser())); | 1630 DownloadManagerForBrowser(browser())); |
| 1657 | 1631 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1668 // As long as we're here, confirmed everything else is good. | 1642 // As long as we're here, confirmed everything else is good. |
| 1669 EXPECT_EQ(1, browser()->tab_count()); | 1643 EXPECT_EQ(1, browser()->tab_count()); |
| 1670 CheckDownload(browser(), file, file); | 1644 CheckDownload(browser(), file, file); |
| 1671 // Download shelf should close. Download panel stays open on ChromeOS. | 1645 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1672 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1646 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1673 } | 1647 } |
| 1674 | 1648 |
| 1675 // Download an extension. Expect a dangerous download warning. | 1649 // Download an extension. Expect a dangerous download warning. |
| 1676 // Deny the download. | 1650 // Deny the download. |
| 1677 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { | 1651 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { |
| 1678 ASSERT_TRUE(InitialSetup(false)); | |
| 1679 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1652 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1680 | 1653 |
| 1681 scoped_ptr<DownloadTestObserver> observer( | 1654 scoped_ptr<DownloadTestObserver> observer( |
| 1682 DangerousDownloadWaiter( | 1655 DangerousDownloadWaiter( |
| 1683 browser(), 1, | 1656 browser(), 1, |
| 1684 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 1657 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
| 1685 ui_test_utils::NavigateToURL(browser(), extension_url); | 1658 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1686 | 1659 |
| 1687 observer->WaitForFinished(); | 1660 observer->WaitForFinished(); |
| 1688 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED)); | 1661 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED)); |
| 1689 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1662 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1690 | 1663 |
| 1691 // Download shelf should close. Download panel stays open on ChromeOS. | 1664 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1692 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1665 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1693 | 1666 |
| 1694 // Check that the CRX is not installed. | 1667 // Check that the CRX is not installed. |
| 1695 ExtensionService* extension_service = | 1668 ExtensionService* extension_service = |
| 1696 browser()->profile()->GetExtensionService(); | 1669 browser()->profile()->GetExtensionService(); |
| 1697 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1670 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1698 } | 1671 } |
| 1699 | 1672 |
| 1700 // Download an extension. Expect a dangerous download warning. | 1673 // Download an extension. Expect a dangerous download warning. |
| 1701 // Allow the download, deny the install. | 1674 // Allow the download, deny the install. |
| 1702 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { | 1675 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { |
| 1703 ASSERT_TRUE(InitialSetup(false)); | |
| 1704 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1676 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1705 | 1677 |
| 1706 // Install a mock install UI that simulates a user denying permission to | 1678 // Install a mock install UI that simulates a user denying permission to |
| 1707 // finish the install. | 1679 // finish the install. |
| 1708 download_crx_util::SetMockInstallUIForTesting( | 1680 download_crx_util::SetMockInstallUIForTesting( |
| 1709 new MockAbortExtensionInstallUI()); | 1681 new MockAbortExtensionInstallUI()); |
| 1710 | 1682 |
| 1711 scoped_ptr<DownloadTestObserver> observer( | 1683 scoped_ptr<DownloadTestObserver> observer( |
| 1712 DangerousDownloadWaiter( | 1684 DangerousDownloadWaiter( |
| 1713 browser(), 1, | 1685 browser(), 1, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1724 | 1696 |
| 1725 // Check that the extension was not installed. | 1697 // Check that the extension was not installed. |
| 1726 ExtensionService* extension_service = | 1698 ExtensionService* extension_service = |
| 1727 browser()->profile()->GetExtensionService(); | 1699 browser()->profile()->GetExtensionService(); |
| 1728 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1700 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1729 } | 1701 } |
| 1730 | 1702 |
| 1731 // Download an extension. Expect a dangerous download warning. | 1703 // Download an extension. Expect a dangerous download warning. |
| 1732 // Allow the download, and the install. | 1704 // Allow the download, and the install. |
| 1733 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { | 1705 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { |
| 1734 ASSERT_TRUE(InitialSetup(false)); | |
| 1735 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1706 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1736 | 1707 |
| 1737 // Install a mock install UI that simulates a user allowing permission to | 1708 // Install a mock install UI that simulates a user allowing permission to |
| 1738 // finish the install. | 1709 // finish the install. |
| 1739 download_crx_util::SetMockInstallUIForTesting( | 1710 download_crx_util::SetMockInstallUIForTesting( |
| 1740 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1711 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1741 | 1712 |
| 1742 scoped_ptr<DownloadTestObserver> observer( | 1713 scoped_ptr<DownloadTestObserver> observer( |
| 1743 DangerousDownloadWaiter( | 1714 DangerousDownloadWaiter( |
| 1744 browser(), 1, | 1715 browser(), 1, |
| 1745 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1716 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1746 ui_test_utils::NavigateToURL(browser(), extension_url); | 1717 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1747 | 1718 |
| 1748 observer->WaitForFinished(); | 1719 observer->WaitForFinished(); |
| 1749 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1720 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1750 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1721 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1751 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1722 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1752 | 1723 |
| 1753 // Download shelf should close. Download panel stays open on ChromeOS. | 1724 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1754 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1725 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1755 | 1726 |
| 1756 // Check that the extension was installed. | 1727 // Check that the extension was installed. |
| 1757 ExtensionService* extension_service = | 1728 ExtensionService* extension_service = |
| 1758 browser()->profile()->GetExtensionService(); | 1729 browser()->profile()->GetExtensionService(); |
| 1759 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1730 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1760 } | 1731 } |
| 1761 | 1732 |
| 1762 // Test installing a CRX that fails integrity checks. | 1733 // Test installing a CRX that fails integrity checks. |
| 1763 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { | 1734 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { |
| 1764 ASSERT_TRUE(InitialSetup(false)); | |
| 1765 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); | 1735 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); |
| 1766 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1736 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1767 | 1737 |
| 1768 // Install a mock install UI that simulates a user allowing permission to | 1738 // Install a mock install UI that simulates a user allowing permission to |
| 1769 // finish the install, and dismisses any error message. We check that the | 1739 // finish the install, and dismisses any error message. We check that the |
| 1770 // install failed below. | 1740 // install failed below. |
| 1771 download_crx_util::SetMockInstallUIForTesting( | 1741 download_crx_util::SetMockInstallUIForTesting( |
| 1772 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1742 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1773 | 1743 |
| 1774 scoped_ptr<DownloadTestObserver> observer( | 1744 scoped_ptr<DownloadTestObserver> observer( |
| 1775 DangerousDownloadWaiter( | 1745 DangerousDownloadWaiter( |
| 1776 browser(), 1, | 1746 browser(), 1, |
| 1777 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1747 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1778 ui_test_utils::NavigateToURL(browser(), extension_url); | 1748 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1779 | 1749 |
| 1780 observer->WaitForFinished(); | 1750 observer->WaitForFinished(); |
| 1781 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1751 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1782 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1752 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1783 | 1753 |
| 1784 // Check that the extension was not installed. | 1754 // Check that the extension was not installed. |
| 1785 ExtensionService* extension_service = | 1755 ExtensionService* extension_service = |
| 1786 browser()->profile()->GetExtensionService(); | 1756 browser()->profile()->GetExtensionService(); |
| 1787 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1757 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1788 } | 1758 } |
| 1789 | 1759 |
| 1790 // Install a large (100kb) theme. | 1760 // Install a large (100kb) theme. |
| 1791 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { | 1761 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { |
| 1792 ASSERT_TRUE(InitialSetup(false)); | |
| 1793 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); | 1762 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); |
| 1794 | 1763 |
| 1795 // Install a mock install UI that simulates a user allowing permission to | 1764 // Install a mock install UI that simulates a user allowing permission to |
| 1796 // finish the install. | 1765 // finish the install. |
| 1797 download_crx_util::SetMockInstallUIForTesting( | 1766 download_crx_util::SetMockInstallUIForTesting( |
| 1798 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1767 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1799 | 1768 |
| 1800 scoped_ptr<DownloadTestObserver> observer( | 1769 scoped_ptr<DownloadTestObserver> observer( |
| 1801 DangerousDownloadWaiter( | 1770 DangerousDownloadWaiter( |
| 1802 browser(), 1, | 1771 browser(), 1, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1817 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 1786 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
| 1818 } | 1787 } |
| 1819 | 1788 |
| 1820 // Sort download items by db_handle. | 1789 // Sort download items by db_handle. |
| 1821 static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) { | 1790 static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) { |
| 1822 return d1->GetDbHandle() < d2->GetDbHandle(); | 1791 return d1->GetDbHandle() < d2->GetDbHandle(); |
| 1823 } | 1792 } |
| 1824 | 1793 |
| 1825 // Confirm that searching through the history works properly | 1794 // Confirm that searching through the history works properly |
| 1826 IN_PROC_BROWSER_TEST_F(DownloadTest, SearchDownloads) { | 1795 IN_PROC_BROWSER_TEST_F(DownloadTest, SearchDownloads) { |
| 1827 ASSERT_TRUE(InitialSetup(false)); | |
| 1828 | |
| 1829 // Downloads to populate history with. | 1796 // Downloads to populate history with. |
| 1830 base::Time current(base::Time::Now()); | 1797 base::Time current(base::Time::Now()); |
| 1831 DownloadPersistentStoreInfo population_entries[] = { | 1798 DownloadPersistentStoreInfo population_entries[] = { |
| 1832 DownloadPersistentStoreInfo( | 1799 DownloadPersistentStoreInfo( |
| 1833 FilePath(FILE_PATH_LITERAL("/path/to/file")), | 1800 FilePath(FILE_PATH_LITERAL("/path/to/file")), |
| 1834 GURL("http://www.google.com/fantasy_download"), | 1801 GURL("http://www.google.com/fantasy_download"), |
| 1835 GURL(""), | 1802 GURL(""), |
| 1836 current - base::TimeDelta::FromMinutes(5), | 1803 current - base::TimeDelta::FromMinutes(5), |
| 1837 current, | 1804 current, |
| 1838 128, | 1805 128, |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1944 ASSERT_EQ(2u, search_results.size()); | 1911 ASSERT_EQ(2u, search_results.size()); |
| 1945 std::sort(search_results.begin(), search_results.end(), | 1912 std::sort(search_results.begin(), search_results.end(), |
| 1946 DownloadItemSorter); | 1913 DownloadItemSorter); |
| 1947 EXPECT_EQ(2, search_results[0]->GetDbHandle()); | 1914 EXPECT_EQ(2, search_results[0]->GetDbHandle()); |
| 1948 EXPECT_EQ(3, search_results[1]->GetDbHandle()); | 1915 EXPECT_EQ(3, search_results[1]->GetDbHandle()); |
| 1949 search_results.clear(); | 1916 search_results.clear(); |
| 1950 } | 1917 } |
| 1951 | 1918 |
| 1952 // Tests for download initiation functions. | 1919 // Tests for download initiation functions. |
| 1953 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { | 1920 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { |
| 1954 ASSERT_TRUE(InitialSetup(false)); | |
| 1955 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1921 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1956 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1922 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1957 | 1923 |
| 1958 // DownloadUrl always prompts; return acceptance of whatever it prompts. | 1924 // DownloadUrl always prompts; return acceptance of whatever it prompts. |
| 1959 NullSelectFile(browser()); | 1925 NullSelectFile(browser()); |
| 1960 | 1926 |
| 1961 WebContents* web_contents = browser()->GetSelectedWebContents(); | 1927 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 1962 ASSERT_TRUE(web_contents); | 1928 ASSERT_TRUE(web_contents); |
| 1963 | 1929 |
| 1964 DownloadTestObserver* observer( | 1930 DownloadTestObserver* observer( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1976 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1942 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1977 EXPECT_TRUE(observer->select_file_dialog_seen()); | 1943 EXPECT_TRUE(observer->select_file_dialog_seen()); |
| 1978 | 1944 |
| 1979 // Check state. | 1945 // Check state. |
| 1980 EXPECT_EQ(1, browser()->tab_count()); | 1946 EXPECT_EQ(1, browser()->tab_count()); |
| 1981 ASSERT_TRUE(CheckDownload(browser(), file, file)); | 1947 ASSERT_TRUE(CheckDownload(browser(), file, file)); |
| 1982 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1948 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1983 } | 1949 } |
| 1984 | 1950 |
| 1985 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { | 1951 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { |
| 1986 ASSERT_TRUE(InitialSetup(false)); | |
| 1987 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1952 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1988 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1953 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1989 | 1954 |
| 1990 WebContents* web_contents = browser()->GetSelectedWebContents(); | 1955 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 1991 ASSERT_TRUE(web_contents); | 1956 ASSERT_TRUE(web_contents); |
| 1992 | 1957 |
| 1993 ScopedTempDir other_directory; | 1958 ScopedTempDir other_directory; |
| 1994 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); | 1959 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); |
| 1995 FilePath target_file_full_path | 1960 FilePath target_file_full_path |
| 1996 = other_directory.path().Append(file.BaseName()); | 1961 = other_directory.path().Append(file.BaseName()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2009 ASSERT_TRUE(CheckDownloadFullPaths(browser(), | 1974 ASSERT_TRUE(CheckDownloadFullPaths(browser(), |
| 2010 target_file_full_path, | 1975 target_file_full_path, |
| 2011 OriginFile(file))); | 1976 OriginFile(file))); |
| 2012 | 1977 |
| 2013 // Temporary downloads won't be visible. | 1978 // Temporary downloads won't be visible. |
| 2014 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1979 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 2015 } | 1980 } |
| 2016 | 1981 |
| 2017 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaGet) { | 1982 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaGet) { |
| 2018 // Do initial setup. | 1983 // Do initial setup. |
| 2019 ASSERT_TRUE(InitialSetup(false)); | |
| 2020 ASSERT_TRUE(test_server()->Start()); | 1984 ASSERT_TRUE(test_server()->Start()); |
| 2021 NullSelectFile(browser()); | 1985 NullSelectFile(browser()); |
| 2022 std::vector<DownloadItem*> download_items; | 1986 std::vector<DownloadItem*> download_items; |
| 2023 GetDownloads(browser(), &download_items); | 1987 GetDownloads(browser(), &download_items); |
| 2024 ASSERT_TRUE(download_items.empty()); | 1988 ASSERT_TRUE(download_items.empty()); |
| 2025 | 1989 |
| 2026 // Navigate to a non-HTML resource. The resource also has | 1990 // Navigate to a non-HTML resource. The resource also has |
| 2027 // Cache-Control: no-cache set, which normally requires revalidation | 1991 // Cache-Control: no-cache set, which normally requires revalidation |
| 2028 // each time. | 1992 // each time. |
| 2029 GURL url = test_server()->GetURL("files/downloads/image.jpg"); | 1993 GURL url = test_server()->GetURL("files/downloads/image.jpg"); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2071 download_items.clear(); | 2035 download_items.clear(); |
| 2072 GetDownloads(browser(), &download_items); | 2036 GetDownloads(browser(), &download_items); |
| 2073 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); | 2037 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); |
| 2074 ASSERT_EQ(2u, download_items.size()); | 2038 ASSERT_EQ(2u, download_items.size()); |
| 2075 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); | 2039 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); |
| 2076 ASSERT_EQ(url, download_items[1]->GetOriginalUrl()); | 2040 ASSERT_EQ(url, download_items[1]->GetOriginalUrl()); |
| 2077 } | 2041 } |
| 2078 | 2042 |
| 2079 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaPost) { | 2043 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaPost) { |
| 2080 // Do initial setup. | 2044 // Do initial setup. |
| 2081 ASSERT_TRUE(InitialSetup(false)); | |
| 2082 ASSERT_TRUE(test_server()->Start()); | 2045 ASSERT_TRUE(test_server()->Start()); |
| 2083 NullSelectFile(browser()); | 2046 NullSelectFile(browser()); |
| 2084 std::vector<DownloadItem*> download_items; | 2047 std::vector<DownloadItem*> download_items; |
| 2085 GetDownloads(browser(), &download_items); | 2048 GetDownloads(browser(), &download_items); |
| 2086 ASSERT_TRUE(download_items.empty()); | 2049 ASSERT_TRUE(download_items.empty()); |
| 2087 | 2050 |
| 2088 // Navigate to a form page. | 2051 // Navigate to a form page. |
| 2089 GURL form_url = test_server()->GetURL( | 2052 GURL form_url = test_server()->GetURL( |
| 2090 "files/downloads/form_page_to_post.html"); | 2053 "files/downloads/form_page_to_post.html"); |
| 2091 ASSERT_TRUE(form_url.is_valid()); | 2054 ASSERT_TRUE(form_url.is_valid()); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2194 }, | 2157 }, |
| 2195 { // Navigated download with 400 error. | 2158 { // Navigated download with 400 error. |
| 2196 "zip_file_not_found.zip", | 2159 "zip_file_not_found.zip", |
| 2197 DOWNLOAD_NAVIGATE, | 2160 DOWNLOAD_NAVIGATE, |
| 2198 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, | 2161 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, |
| 2199 false, | 2162 false, |
| 2200 false | 2163 false |
| 2201 } | 2164 } |
| 2202 }; | 2165 }; |
| 2203 | 2166 |
| 2204 // Do initial setup. | |
| 2205 ASSERT_TRUE(InitialSetup(false)); | |
| 2206 | |
| 2207 DownloadFilesCheckErrors(ARRAYSIZE_UNSAFE(download_info), download_info); | 2167 DownloadFilesCheckErrors(ARRAYSIZE_UNSAFE(download_info), download_info); |
| 2208 } | 2168 } |
| 2209 | 2169 |
| 2210 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsFile) { | 2170 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsFile) { |
| 2211 FileErrorInjectInfo error_info[] = { | 2171 FileErrorInjectInfo error_info[] = { |
| 2212 { // Navigated download with injected "Disk full" error in Initialize(). | 2172 { // Navigated download with injected "Disk full" error in Initialize(). |
| 2213 { "a_zip_file.zip", | 2173 { "a_zip_file.zip", |
| 2214 DOWNLOAD_NAVIGATE, | 2174 DOWNLOAD_NAVIGATE, |
| 2215 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | 2175 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, |
| 2216 1 | 2176 1 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2403 true | 2363 true |
| 2404 } | 2364 } |
| 2405 }; | 2365 }; |
| 2406 | 2366 |
| 2407 DownloadFilesToReadonlyFolder(ARRAYSIZE_UNSAFE(download_info), download_info); | 2367 DownloadFilesToReadonlyFolder(ARRAYSIZE_UNSAFE(download_info), download_info); |
| 2408 } | 2368 } |
| 2409 | 2369 |
| 2410 // Test that we show a dangerous downloads warning for a dangerous file | 2370 // Test that we show a dangerous downloads warning for a dangerous file |
| 2411 // downloaded through a blob: URL. | 2371 // downloaded through a blob: URL. |
| 2412 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadDangerousBlobData) { | 2372 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadDangerousBlobData) { |
| 2413 ASSERT_TRUE(InitialSetup(false)); | |
| 2414 | |
| 2415 #if defined(OS_WIN) | 2373 #if defined(OS_WIN) |
| 2416 // On Windows, if SafeBrowsing is enabled, certain file types (.exe, .cab, | 2374 // On Windows, if SafeBrowsing is enabled, certain file types (.exe, .cab, |
| 2417 // .msi) will be handled by the DownloadProtectionService. However, if the URL | 2375 // .msi) will be handled by the DownloadProtectionService. However, if the URL |
| 2418 // is non-standard (e.g. blob:) then those files won't be handled by the | 2376 // is non-standard (e.g. blob:) then those files won't be handled by the |
| 2419 // DPS. We should be showing the dangerous download warning for any file | 2377 // DPS. We should be showing the dangerous download warning for any file |
| 2420 // considered dangerous and isn't handled by the DPS. | 2378 // considered dangerous and isn't handled by the DPS. |
| 2421 const char kFilename[] = "foo.exe"; | 2379 const char kFilename[] = "foo.exe"; |
| 2422 #else | 2380 #else |
| 2423 const char kFilename[] = "foo.jar"; | 2381 const char kFilename[] = "foo.jar"; |
| 2424 #endif | 2382 #endif |
| 2425 | 2383 |
| 2426 std::string path("files/downloads/download-dangerous-blob.html?filename="); | 2384 std::string path("files/downloads/download-dangerous-blob.html?filename="); |
| 2427 path += kFilename; | 2385 path += kFilename; |
| 2428 | 2386 |
| 2429 // Need to use http urls because the blob js doesn't work on file urls for | 2387 // Need to use http urls because the blob js doesn't work on file urls for |
| 2430 // security reasons. | 2388 // security reasons. |
| 2431 ASSERT_TRUE(test_server()->Start()); | 2389 ASSERT_TRUE(test_server()->Start()); |
| 2432 GURL url(test_server()->GetURL(path)); | 2390 GURL url(test_server()->GetURL(path)); |
| 2433 | 2391 |
| 2434 DownloadTestObserver* observer(DangerousDownloadWaiter( | 2392 DownloadTestObserver* observer(DangerousDownloadWaiter( |
| 2435 browser(), 1, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 2393 browser(), 1, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 2436 ui_test_utils::NavigateToURL(browser(), url); | 2394 ui_test_utils::NavigateToURL(browser(), url); |
| 2437 observer->WaitForFinished(); | 2395 observer->WaitForFinished(); |
| 2438 | 2396 |
| 2439 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 2397 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 2440 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 2398 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 2441 } | 2399 } |
| OLD | NEW |