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

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

Issue 10073017: Remove Active Downloads UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 8 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
« no previous file with comments | « chrome/browser/browser_resources.grd ('k') | chrome/browser/download/save_page_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 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 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 543 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
544 CheckDownloadStatesForBrowser(browser, 1, DownloadItem::COMPLETE); 544 CheckDownloadStatesForBrowser(browser, 1, DownloadItem::COMPLETE);
545 545
546 EXPECT_EQ(2, browser->tab_count()); 546 EXPECT_EQ(2, browser->tab_count());
547 547
548 // TODO(ahendrickson): check download status text after downloading. 548 // TODO(ahendrickson): check download status text after downloading.
549 549
550 FilePath basefilename(filename.BaseName()); 550 FilePath basefilename(filename.BaseName());
551 net::FileURLToFilePath(url, &filename); 551 net::FileURLToFilePath(url, &filename);
552 FilePath download_path = downloads_directory_.path().Append(basefilename); 552 FilePath download_path = downloads_directory_.path().Append(basefilename);
553 CheckDownloadUI(browser, true, true, basefilename); 553 EXPECT_TRUE(browser->window()->IsDownloadShelfVisible());
554 554
555 bool downloaded_path_exists = file_util::PathExists(download_path); 555 bool downloaded_path_exists = file_util::PathExists(download_path);
556 EXPECT_TRUE(downloaded_path_exists); 556 EXPECT_TRUE(downloaded_path_exists);
557 if (!downloaded_path_exists) 557 if (!downloaded_path_exists)
558 return false; 558 return false;
559 559
560 // Check the file contents. 560 // Check the file contents.
561 size_t file_size = URLRequestSlowDownloadJob::kFirstDownloadSize + 561 size_t file_size = URLRequestSlowDownloadJob::kFirstDownloadSize +
562 URLRequestSlowDownloadJob::kSecondDownloadSize; 562 URLRequestSlowDownloadJob::kSecondDownloadSize;
563 std::string expected_contents(file_size, '*'); 563 std::string expected_contents(file_size, '*');
564 EXPECT_TRUE(VerifyFile(download_path, expected_contents, file_size)); 564 EXPECT_TRUE(VerifyFile(download_path, expected_contents, file_size));
565 565
566 // Delete the file we just downloaded. 566 // Delete the file we just downloaded.
567 EXPECT_TRUE(file_util::DieFileDie(download_path, true)); 567 EXPECT_TRUE(file_util::DieFileDie(download_path, true));
568 EXPECT_FALSE(file_util::PathExists(download_path)); 568 EXPECT_FALSE(file_util::PathExists(download_path));
569 569
570 return true; 570 return true;
571 } 571 }
572 572
573 void GetDownloads(Browser* browser, std::vector<DownloadItem*>* downloads) { 573 void GetDownloads(Browser* browser, std::vector<DownloadItem*>* downloads) {
574 DCHECK(downloads); 574 DCHECK(downloads);
575 DownloadManager* manager = DownloadManagerForBrowser(browser); 575 DownloadManager* manager = DownloadManagerForBrowser(browser);
576 manager->SearchDownloads(string16(), downloads); 576 manager->SearchDownloads(string16(), downloads);
577 } 577 }
578 578
579 // Check that the download UI (shelf on non-chromeos or panel on chromeos)
580 // is visible or not as expected. Additionally, check that the filename
581 // is present in the UI (currently only on chromeos).
582 void CheckDownloadUI(Browser* browser, bool expected_non_cros,
583 bool expected_cros, const FilePath& filename) {
584 EXPECT_EQ(expected_non_cros, browser->window()->IsDownloadShelfVisible());
585 // TODO: Check for filename match in download shelf.
586 }
587 static void ExpectWindowCountAfterDownload(size_t expected) { 579 static void ExpectWindowCountAfterDownload(size_t expected) {
588 EXPECT_EQ(expected, BrowserList::size()); 580 EXPECT_EQ(expected, BrowserList::size());
589 } 581 }
590 582
591 // Arrange for select file calls on the given browser from the 583 // Arrange for select file calls on the given browser from the
592 // download manager to always choose the suggested file. 584 // download manager to always choose the suggested file.
593 void NullSelectFile(Browser* browser) { 585 void NullSelectFile(Browser* browser) {
594 PickSuggestedFileDelegate* new_delegate = 586 PickSuggestedFileDelegate* new_delegate =
595 new PickSuggestedFileDelegate(browser->profile()); 587 new PickSuggestedFileDelegate(browser->profile());
596 588
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 ASSERT_TRUE(InitialSetup(false)); 869 ASSERT_TRUE(InitialSetup(false));
878 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 870 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
879 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 871 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
880 872
881 // Download the file and wait. We do not expect the Select File dialog. 873 // Download the file and wait. We do not expect the Select File dialog.
882 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 874 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
883 875
884 // Check state. 876 // Check state.
885 EXPECT_EQ(1, browser()->tab_count()); 877 EXPECT_EQ(1, browser()->tab_count());
886 CheckDownload(browser(), file, file); 878 CheckDownload(browser(), file, file);
887 CheckDownloadUI(browser(), true, true, file); 879 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
888 } 880 }
889 881
890 #if defined(OS_WIN) 882 #if defined(OS_WIN)
891 // Download a file and confirm that the zone identifier (on windows) 883 // Download a file and confirm that the zone identifier (on windows)
892 // is set to internet. 884 // is set to internet.
893 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { 885 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) {
894 ASSERT_TRUE(InitialSetup(false)); 886 ASSERT_TRUE(InitialSetup(false));
895 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 887 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
896 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 888 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
897 889
898 // Download the file and wait. We do not expect the Select File dialog. 890 // Download the file and wait. We do not expect the Select File dialog.
899 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 891 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
900 892
901 // Check state. Special file state must be checked before CheckDownload, 893 // Check state. Special file state must be checked before CheckDownload,
902 // as CheckDownload will delete the output file. 894 // as CheckDownload will delete the output file.
903 EXPECT_EQ(1, browser()->tab_count()); 895 EXPECT_EQ(1, browser()->tab_count());
904 FilePath downloaded_file(DestinationFile(browser(), file)); 896 FilePath downloaded_file(DestinationFile(browser(), file));
905 if (file_util::VolumeSupportsADS(downloaded_file)) 897 if (file_util::VolumeSupportsADS(downloaded_file))
906 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); 898 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file));
907 CheckDownload(browser(), file, file); 899 CheckDownload(browser(), file, file);
908 CheckDownloadUI(browser(), true, true, file); 900 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
909 } 901 }
910 #endif 902 #endif
911 903
912 // Put up a Select File dialog when the file is downloaded, due to 904 // Put up a Select File dialog when the file is downloaded, due to
913 // downloads preferences settings. 905 // downloads preferences settings.
914 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { 906 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) {
915 ASSERT_TRUE(InitialSetup(true)); 907 ASSERT_TRUE(InitialSetup(true));
916 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 908 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
917 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 909 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
918 910
(...skipping 11 matching lines...) Expand all
930 browser(), url, CURRENT_TAB, 922 browser(), url, CURRENT_TAB,
931 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 923 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
932 observer->WaitForFinished(); 924 observer->WaitForFinished();
933 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 925 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
934 CheckDownloadStates(1, DownloadItem::COMPLETE); 926 CheckDownloadStates(1, DownloadItem::COMPLETE);
935 EXPECT_TRUE(observer->select_file_dialog_seen()); 927 EXPECT_TRUE(observer->select_file_dialog_seen());
936 928
937 // Check state. 929 // Check state.
938 EXPECT_EQ(1, browser()->tab_count()); 930 EXPECT_EQ(1, browser()->tab_count());
939 CheckDownload(browser(), file, file); 931 CheckDownload(browser(), file, file);
940 CheckDownloadUI(browser(), true, true, file); 932 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
941 } 933 }
942 934
943 // Access a file with a viewable mime-type, verify that a download 935 // Access a file with a viewable mime-type, verify that a download
944 // did not initiate. 936 // did not initiate.
945 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { 937 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) {
946 ASSERT_TRUE(InitialSetup(false)); 938 ASSERT_TRUE(InitialSetup(false));
947 FilePath file(FILE_PATH_LITERAL("download-test2.html")); 939 FilePath file(FILE_PATH_LITERAL("download-test2.html"));
948 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 940 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
949 FilePath file_path(DestinationFile(browser(), file)); 941 FilePath file_path(DestinationFile(browser(), file));
950 942
951 // Open a web page and wait. 943 // Open a web page and wait.
952 ui_test_utils::NavigateToURL(browser(), url); 944 ui_test_utils::NavigateToURL(browser(), url);
953 945
954 // Check that we did not download the web page. 946 // Check that we did not download the web page.
955 EXPECT_FALSE(file_util::PathExists(file_path)); 947 EXPECT_FALSE(file_util::PathExists(file_path));
956 948
957 // Check state. 949 // Check state.
958 EXPECT_EQ(1, browser()->tab_count()); 950 EXPECT_EQ(1, browser()->tab_count());
959 CheckDownloadUI(browser(), false, false, FilePath()); 951 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
960 } 952 }
961 953
962 // Verify that when the DownloadResourceThrottle cancels a download, the 954 // Verify that when the DownloadResourceThrottle cancels a download, the
963 // download never makes it to the downloads system. 955 // download never makes it to the downloads system.
964 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadResourceThrottleCancels) { 956 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadResourceThrottleCancels) {
965 ASSERT_TRUE(InitialSetup(false)); 957 ASSERT_TRUE(InitialSetup(false));
966 958
967 // Navigate to a page with the same domain as the file to download. We can't 959 // Navigate to a page with the same domain as the file to download. We can't
968 // navigate directly to the file we don't want to download because cross-site 960 // navigate directly to the file we don't want to download because cross-site
969 // navigations reset the TabDownloadState. 961 // navigations reset the TabDownloadState.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 base::Bind(&MessageLoop::Quit, 996 base::Bind(&MessageLoop::Quit,
1005 base::Unretained(MessageLoopForUI::current()))); 997 base::Unretained(MessageLoopForUI::current())));
1006 998
1007 // Check that we did not download the file. 999 // Check that we did not download the file.
1008 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1000 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1009 FilePath file_path(DestinationFile(browser(), file)); 1001 FilePath file_path(DestinationFile(browser(), file));
1010 EXPECT_FALSE(file_util::PathExists(file_path)); 1002 EXPECT_FALSE(file_util::PathExists(file_path));
1011 1003
1012 // Check state. 1004 // Check state.
1013 EXPECT_EQ(1, browser()->tab_count()); 1005 EXPECT_EQ(1, browser()->tab_count());
1014 CheckDownloadUI(browser(), false, false, FilePath()); 1006 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1015 1007
1016 // Verify that there's no pending download. 1008 // Verify that there's no pending download.
1017 EXPECT_TRUE(EnsureNoPendingDownloads()); 1009 EXPECT_TRUE(EnsureNoPendingDownloads());
1018 } 1010 }
1019 1011
1020 // Download a 0-size file with a content-disposition header, verify that the 1012 // Download a 0-size file with a content-disposition header, verify that the
1021 // download tab opened and the file exists as the filename specified in the 1013 // download tab opened and the file exists as the filename specified in the
1022 // header. This also ensures we properly handle empty file downloads. 1014 // header. This also ensures we properly handle empty file downloads.
1023 // The download shelf should be visible in the current tab. 1015 // The download shelf should be visible in the current tab.
1024 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { 1016 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) {
1025 ASSERT_TRUE(InitialSetup(false)); 1017 ASSERT_TRUE(InitialSetup(false));
1026 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); 1018 FilePath file(FILE_PATH_LITERAL("download-test3.gif"));
1027 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1019 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1028 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); 1020 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif"));
1029 1021
1030 // Download a file and wait. 1022 // Download a file and wait.
1031 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 1023 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
1032 1024
1033 CheckDownload(browser(), download_file, file); 1025 CheckDownload(browser(), download_file, file);
1034 1026
1035 // Check state. 1027 // Check state.
1036 EXPECT_EQ(1, browser()->tab_count()); 1028 EXPECT_EQ(1, browser()->tab_count());
1037 CheckDownloadUI(browser(), true, true, download_file); 1029 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1038 } 1030 }
1039 1031
1040 // Test that the download shelf is per-window by starting a download in one 1032 // Test that the download shelf is per-window by starting a download in one
1041 // tab, opening a second tab, closing the shelf, going back to the first tab, 1033 // tab, opening a second tab, closing the shelf, going back to the first tab,
1042 // and checking that the shelf is closed. 1034 // and checking that the shelf is closed.
1043 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { 1035 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) {
1044 ASSERT_TRUE(InitialSetup(false)); 1036 ASSERT_TRUE(InitialSetup(false));
1045 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); 1037 FilePath file(FILE_PATH_LITERAL("download-test3.gif"));
1046 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1038 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1047 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); 1039 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif"));
1048 1040
1049 // Download a file and wait. 1041 // Download a file and wait.
1050 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 1042 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
1051 1043
1052 CheckDownload(browser(), download_file, file); 1044 CheckDownload(browser(), download_file, file);
1053 1045
1054 // Check state. 1046 // Check state.
1055 EXPECT_EQ(1, browser()->tab_count()); 1047 EXPECT_EQ(1, browser()->tab_count());
1056 CheckDownloadUI(browser(), true, true, download_file); 1048 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1057 1049
1058 // Open a second tab and wait. 1050 // Open a second tab and wait.
1059 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL), 1051 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL),
1060 browser()->AddSelectedTabWithURL( 1052 browser()->AddSelectedTabWithURL(
1061 GURL(), content::PAGE_TRANSITION_TYPED)); 1053 GURL(), content::PAGE_TRANSITION_TYPED));
1062 EXPECT_EQ(2, browser()->tab_count()); 1054 EXPECT_EQ(2, browser()->tab_count());
1063 CheckDownloadUI(browser(), true, true, download_file); 1055 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1064 1056
1065 // Hide the download shelf. 1057 // Hide the download shelf.
1066 browser()->window()->GetDownloadShelf()->Close(); 1058 browser()->window()->GetDownloadShelf()->Close();
1067 CheckDownloadUI(browser(), false, false, FilePath()); 1059 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1068 1060
1069 // Go to the first tab. 1061 // Go to the first tab.
1070 browser()->ActivateTabAt(0, true); 1062 browser()->ActivateTabAt(0, true);
1071 EXPECT_EQ(2, browser()->tab_count()); 1063 EXPECT_EQ(2, browser()->tab_count());
1072 1064
1073 // The download shelf should not be visible. 1065 // The download shelf should not be visible.
1074 CheckDownloadUI(browser(), false, false, FilePath()); 1066 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1075 } 1067 }
1076 1068
1077 // Check whether the downloads shelf is closed when the downloads tab is 1069 // Check whether the downloads shelf is closed when the downloads tab is
1078 // invoked. 1070 // invoked.
1079 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseShelfOnDownloadsTab) { 1071 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseShelfOnDownloadsTab) {
1080 ASSERT_TRUE(InitialSetup(false)); 1072 ASSERT_TRUE(InitialSetup(false));
1081 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1073 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1082 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1074 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1083 1075
1084 // Download the file and wait. We do not expect the Select File dialog. 1076 // Download the file and wait. We do not expect the Select File dialog.
1085 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 1077 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
1086 1078
1087 // Check state. 1079 // Check state.
1088 EXPECT_EQ(1, browser()->tab_count()); 1080 EXPECT_EQ(1, browser()->tab_count());
1089 CheckDownloadUI(browser(), true, true, file); 1081 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1090 1082
1091 // Open the downloads tab. 1083 // Open the downloads tab.
1092 browser()->ShowDownloadsTab(); 1084 browser()->ShowDownloadsTab();
1093 // The shelf should now be closed. 1085 // The shelf should now be closed.
1094 CheckDownloadUI(browser(), false, false, FilePath()); 1086 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1095 } 1087 }
1096 1088
1097 // UnknownSize and KnownSize are tests which depend on 1089 // UnknownSize and KnownSize are tests which depend on
1098 // URLRequestSlowDownloadJob to serve content in a certain way. Data will be 1090 // URLRequestSlowDownloadJob to serve content in a certain way. Data will be
1099 // sent in two chunks where the first chunk is 35K and the second chunk is 10K. 1091 // sent in two chunks where the first chunk is 35K and the second chunk is 10K.
1100 // The test will first attempt to download a file; but the server will "pause" 1092 // The test will first attempt to download a file; but the server will "pause"
1101 // in the middle until the server receives a second request for 1093 // in the middle until the server receives a second request for
1102 // "download-finish". At that time, the download will finish. 1094 // "download-finish". At that time, the download will finish.
1103 // These tests don't currently test much due to holes in |RunSizeTest()|. See 1095 // These tests don't currently test much due to holes in |RunSizeTest()|. See
1104 // comments in that routine for details. 1096 // comments in that routine for details.
(...skipping 25 matching lines...) Expand all
1130 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1122 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1131 // Since |incognito| is a separate browser, we have to set it up explicitly. 1123 // Since |incognito| is a separate browser, we have to set it up explicitly.
1132 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, 1124 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload,
1133 false); 1125 false);
1134 DownloadAndWait(incognito, url, EXPECT_NO_SELECT_DIALOG); 1126 DownloadAndWait(incognito, url, EXPECT_NO_SELECT_DIALOG);
1135 1127
1136 // We should still have 2 windows. 1128 // We should still have 2 windows.
1137 ExpectWindowCountAfterDownload(2); 1129 ExpectWindowCountAfterDownload(2);
1138 1130
1139 // Verify that the download shelf is showing for the Incognito window. 1131 // Verify that the download shelf is showing for the Incognito window.
1140 CheckDownloadUI(incognito, true, true, file); 1132 EXPECT_TRUE(incognito->window()->IsDownloadShelfVisible());
1141 1133
1142 #if !defined(OS_MACOSX) 1134 #if !defined(OS_MACOSX)
1143 // On Mac OS X, the UI window close is delayed until the outermost 1135 // On Mac OS X, the UI window close is delayed until the outermost
1144 // message loop runs. So it isn't possible to get a BROWSER_CLOSED 1136 // message loop runs. So it isn't possible to get a BROWSER_CLOSED
1145 // notification inside of a test. 1137 // notification inside of a test.
1146 ui_test_utils::WindowedNotificationObserver signal( 1138 ui_test_utils::WindowedNotificationObserver signal(
1147 chrome::NOTIFICATION_BROWSER_CLOSED, 1139 chrome::NOTIFICATION_BROWSER_CLOSED,
1148 content::Source<Browser>(incognito)); 1140 content::Source<Browser>(incognito));
1149 #endif 1141 #endif
1150 1142
1151 // Close the Incognito window and don't crash. 1143 // Close the Incognito window and don't crash.
1152 incognito->CloseWindow(); 1144 incognito->CloseWindow();
1153 1145
1154 #if !defined(OS_MACOSX) 1146 #if !defined(OS_MACOSX)
1155 signal.Wait(); 1147 signal.Wait();
1156 ExpectWindowCountAfterDownload(1); 1148 ExpectWindowCountAfterDownload(1);
1157 #endif 1149 #endif
1158 1150
1159 // Verify that the regular window does not have a download shelf. 1151 // Verify that the regular window does not have a download shelf.
1160 // On ChromeOS, the download panel is common to both profiles, so 1152 // On ChromeOS, the download panel is common to both profiles, so
1161 // it is still visible. 1153 // it is still visible.
1162 CheckDownloadUI(browser(), false, true, file); 1154 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1163 1155
1164 CheckDownload(browser(), file, file); 1156 CheckDownload(browser(), file, file);
1165 } 1157 }
1166 1158
1167 // Navigate to a new background page, but don't download. Confirm that the 1159 // Navigate to a new background page, but don't download. Confirm that the
1168 // download shelf is not visible and that we have two tabs. 1160 // download shelf is not visible and that we have two tabs.
1169 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) { 1161 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) {
1170 ASSERT_TRUE(InitialSetup(false)); 1162 ASSERT_TRUE(InitialSetup(false));
1171 // Because it's an HTML link, it should open a web page rather than 1163 // Because it's an HTML link, it should open a web page rather than
1172 // downloading. 1164 // downloading.
1173 FilePath file1(FILE_PATH_LITERAL("download-test2.html")); 1165 FilePath file1(FILE_PATH_LITERAL("download-test2.html"));
1174 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); 1166 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1));
1175 1167
1176 // Open a web page and wait. 1168 // Open a web page and wait.
1177 ui_test_utils::NavigateToURLWithDisposition( 1169 ui_test_utils::NavigateToURLWithDisposition(
1178 browser(), 1170 browser(),
1179 url, 1171 url,
1180 NEW_BACKGROUND_TAB, 1172 NEW_BACKGROUND_TAB,
1181 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1173 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1182 1174
1183 // We should have two tabs now. 1175 // We should have two tabs now.
1184 EXPECT_EQ(2, browser()->tab_count()); 1176 EXPECT_EQ(2, browser()->tab_count());
1185 CheckDownloadUI(browser(), false, false, FilePath()); 1177 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1186 } 1178 }
1187 1179
1188 // Download a file in a background tab. Verify that the tab is closed 1180 // Download a file in a background tab. Verify that the tab is closed
1189 // automatically, and that the download shelf is visible in the current tab. 1181 // automatically, and that the download shelf is visible in the current tab.
1190 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab1) { 1182 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab1) {
1191 ASSERT_TRUE(InitialSetup(false)); 1183 ASSERT_TRUE(InitialSetup(false));
1192 1184
1193 // Download a file in a new background tab and wait. The tab is automatically 1185 // Download a file in a new background tab and wait. The tab is automatically
1194 // closed when the download begins. 1186 // closed when the download begins.
1195 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1187 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1196 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1188 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1197 DownloadAndWaitWithDisposition( 1189 DownloadAndWaitWithDisposition(
1198 browser(), 1190 browser(),
1199 url, 1191 url,
1200 NEW_BACKGROUND_TAB, 1192 NEW_BACKGROUND_TAB,
1201 EXPECT_NO_SELECT_DIALOG, 1193 EXPECT_NO_SELECT_DIALOG,
1202 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1194 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1203 1195
1204 // When the download finishes, we should still have one tab. 1196 // When the download finishes, we should still have one tab.
1205 CheckDownloadUI(browser(), true, true, file); 1197 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1206 EXPECT_EQ(1, browser()->tab_count()); 1198 EXPECT_EQ(1, browser()->tab_count());
1207 1199
1208 CheckDownload(browser(), file, file); 1200 CheckDownload(browser(), file, file);
1209 } 1201 }
1210 1202
1211 // Open a web page in the current tab, then download a file in another tab via 1203 // Open a web page in the current tab, then download a file in another tab via
1212 // a Javascript call. 1204 // a Javascript call.
1213 // Verify that we have 2 tabs, and the download shelf is visible in the current 1205 // Verify that we have 2 tabs, and the download shelf is visible in the current
1214 // tab. 1206 // tab.
1215 // 1207 //
(...skipping 11 matching lines...) Expand all
1227 1219
1228 // Download a file in a new tab and wait (via Javascript). 1220 // Download a file in a new tab and wait (via Javascript).
1229 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1221 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1230 DownloadAndWaitWithDisposition(browser(), 1222 DownloadAndWaitWithDisposition(browser(),
1231 GURL("javascript:openNew()"), 1223 GURL("javascript:openNew()"),
1232 CURRENT_TAB, 1224 CURRENT_TAB,
1233 EXPECT_NO_SELECT_DIALOG, 1225 EXPECT_NO_SELECT_DIALOG,
1234 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1226 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1235 1227
1236 // When the download finishes, we should have two tabs. 1228 // When the download finishes, we should have two tabs.
1237 CheckDownloadUI(browser(), true, true, file); 1229 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1238 EXPECT_EQ(2, browser()->tab_count()); 1230 EXPECT_EQ(2, browser()->tab_count());
1239 1231
1240 CheckDownload(browser(), file, file); 1232 CheckDownload(browser(), file, file);
1241 } 1233 }
1242 1234
1243 // Open a web page in the current tab, open another tab via a Javascript call, 1235 // Open a web page in the current tab, open another tab via a Javascript call,
1244 // then download a file in the new tab. 1236 // then download a file in the new tab.
1245 // Verify that we have 2 tabs, and the download shelf is visible in the current 1237 // Verify that we have 2 tabs, and the download shelf is visible in the current
1246 // tab. 1238 // tab.
1247 // 1239 //
(...skipping 21 matching lines...) Expand all
1269 // Download a file and wait. 1261 // Download a file and wait.
1270 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1262 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1271 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1263 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1272 DownloadAndWaitWithDisposition(browser(), 1264 DownloadAndWaitWithDisposition(browser(),
1273 url, 1265 url,
1274 CURRENT_TAB, 1266 CURRENT_TAB,
1275 EXPECT_NO_SELECT_DIALOG, 1267 EXPECT_NO_SELECT_DIALOG,
1276 ui_test_utils::BROWSER_TEST_NONE); 1268 ui_test_utils::BROWSER_TEST_NONE);
1277 1269
1278 // When the download finishes, we should have two tabs. 1270 // When the download finishes, we should have two tabs.
1279 CheckDownloadUI(browser(), true, true, file); 1271 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1280 EXPECT_EQ(2, browser()->tab_count()); 1272 EXPECT_EQ(2, browser()->tab_count());
1281 1273
1282 CheckDownload(browser(), file, file); 1274 CheckDownload(browser(), file, file);
1283 } 1275 }
1284 1276
1285 // Open a web page in the current tab, then download a file via Javascript, 1277 // Open a web page in the current tab, then download a file via Javascript,
1286 // which will do so in a temporary tab. 1278 // which will do so in a temporary tab.
1287 // Verify that we have 1 tab, and the download shelf is visible. 1279 // Verify that we have 1 tab, and the download shelf is visible.
1288 // 1280 //
1289 // The download_page3.html page contains an openNew() function that opens a 1281 // The download_page3.html page contains an openNew() function that opens a
(...skipping 12 matching lines...) Expand all
1302 // Download a file and wait. 1294 // Download a file and wait.
1303 // The file to download is "download-test1.lib". 1295 // The file to download is "download-test1.lib".
1304 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1296 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1305 DownloadAndWaitWithDisposition(browser(), 1297 DownloadAndWaitWithDisposition(browser(),
1306 GURL("javascript:openNew()"), 1298 GURL("javascript:openNew()"),
1307 CURRENT_TAB, 1299 CURRENT_TAB,
1308 EXPECT_NO_SELECT_DIALOG, 1300 EXPECT_NO_SELECT_DIALOG,
1309 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1301 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1310 1302
1311 // When the download finishes, we should still have one tab. 1303 // When the download finishes, we should still have one tab.
1312 CheckDownloadUI(browser(), true, true, file); 1304 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1313 EXPECT_EQ(1, browser()->tab_count()); 1305 EXPECT_EQ(1, browser()->tab_count());
1314 1306
1315 CheckDownload(browser(), file, file); 1307 CheckDownload(browser(), file, file);
1316 } 1308 }
1317 1309
1318 // Open a web page in the current tab, then call Javascript via a button to 1310 // Open a web page in the current tab, then call Javascript via a button to
1319 // download a file in a new tab, which is closed automatically when the 1311 // download a file in a new tab, which is closed automatically when the
1320 // download begins. 1312 // download begins.
1321 // Verify that we have 1 tab, and the download shelf is visible. 1313 // Verify that we have 1 tab, and the download shelf is visible.
1322 // 1314 //
(...skipping 14 matching lines...) Expand all
1337 // The file to download is "download-test1.lib". 1329 // The file to download is "download-test1.lib".
1338 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1330 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1339 DownloadAndWaitWithDisposition( 1331 DownloadAndWaitWithDisposition(
1340 browser(), 1332 browser(),
1341 GURL("javascript:document.getElementById('form').submit()"), 1333 GURL("javascript:document.getElementById('form').submit()"),
1342 CURRENT_TAB, 1334 CURRENT_TAB,
1343 EXPECT_NO_SELECT_DIALOG, 1335 EXPECT_NO_SELECT_DIALOG,
1344 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1336 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1345 1337
1346 // When the download finishes, we should still have one tab. 1338 // When the download finishes, we should still have one tab.
1347 CheckDownloadUI(browser(), true, true, file); 1339 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1348 EXPECT_EQ(1, browser()->tab_count()); 1340 EXPECT_EQ(1, browser()->tab_count());
1349 1341
1350 CheckDownload(browser(), file, file); 1342 CheckDownload(browser(), file, file);
1351 } 1343 }
1352 1344
1353 // Download a file in a new window. 1345 // Download a file in a new window.
1354 // Verify that we have 2 windows, and the download shelf is not visible in the 1346 // Verify that we have 2 windows, and the download shelf is not visible in the
1355 // first window, but is visible in the second window. 1347 // first window, but is visible in the second window.
1356 // Close the new window. 1348 // Close the new window.
1357 // Verify that we have 1 window, and the download shelf is not visible. 1349 // Verify that we have 1 window, and the download shelf is not visible.
(...skipping 13 matching lines...) Expand all
1371 url, 1363 url,
1372 NEW_WINDOW, 1364 NEW_WINDOW,
1373 EXPECT_NO_SELECT_DIALOG, 1365 EXPECT_NO_SELECT_DIALOG,
1374 ui_test_utils::BROWSER_TEST_NONE); 1366 ui_test_utils::BROWSER_TEST_NONE);
1375 1367
1376 // When the download finishes, the download shelf SHOULD NOT be visible in 1368 // When the download finishes, the download shelf SHOULD NOT be visible in
1377 // the first window. 1369 // the first window.
1378 ExpectWindowCountAfterDownload(2); 1370 ExpectWindowCountAfterDownload(2);
1379 EXPECT_EQ(1, browser()->tab_count()); 1371 EXPECT_EQ(1, browser()->tab_count());
1380 // Download shelf should close. Download panel stays open on ChromeOS. 1372 // Download shelf should close. Download panel stays open on ChromeOS.
1381 CheckDownloadUI(browser(), false, true, file); 1373 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1382 1374
1383 // The download shelf SHOULD be visible in the second window. 1375 // The download shelf SHOULD be visible in the second window.
1384 std::set<Browser*> original_browsers; 1376 std::set<Browser*> original_browsers;
1385 original_browsers.insert(browser()); 1377 original_browsers.insert(browser());
1386 Browser* download_browser = 1378 Browser* download_browser =
1387 ui_test_utils::GetBrowserNotInSet(original_browsers); 1379 ui_test_utils::GetBrowserNotInSet(original_browsers);
1388 ASSERT_TRUE(download_browser != NULL); 1380 ASSERT_TRUE(download_browser != NULL);
1389 EXPECT_NE(download_browser, browser()); 1381 EXPECT_NE(download_browser, browser());
1390 EXPECT_EQ(1, download_browser->tab_count()); 1382 EXPECT_EQ(1, download_browser->tab_count());
1391 CheckDownloadUI(download_browser, true, true, file); 1383 EXPECT_TRUE(download_browser->window()->IsDownloadShelfVisible());
1392 1384
1393 #if !defined(OS_MACOSX) 1385 #if !defined(OS_MACOSX)
1394 // On Mac OS X, the UI window close is delayed until the outermost 1386 // On Mac OS X, the UI window close is delayed until the outermost
1395 // message loop runs. So it isn't possible to get a BROWSER_CLOSED 1387 // message loop runs. So it isn't possible to get a BROWSER_CLOSED
1396 // notification inside of a test. 1388 // notification inside of a test.
1397 ui_test_utils::WindowedNotificationObserver signal( 1389 ui_test_utils::WindowedNotificationObserver signal(
1398 chrome::NOTIFICATION_BROWSER_CLOSED, 1390 chrome::NOTIFICATION_BROWSER_CLOSED,
1399 content::Source<Browser>(download_browser)); 1391 content::Source<Browser>(download_browser));
1400 #endif 1392 #endif
1401 1393
1402 // Close the new window. 1394 // Close the new window.
1403 download_browser->CloseWindow(); 1395 download_browser->CloseWindow();
1404 1396
1405 #if !defined(OS_MACOSX) 1397 #if !defined(OS_MACOSX)
1406 signal.Wait(); 1398 signal.Wait();
1407 EXPECT_EQ(first_browser, browser()); 1399 EXPECT_EQ(first_browser, browser());
1408 ExpectWindowCountAfterDownload(1); 1400 ExpectWindowCountAfterDownload(1);
1409 #endif 1401 #endif
1410 1402
1411 EXPECT_EQ(1, browser()->tab_count()); 1403 EXPECT_EQ(1, browser()->tab_count());
1412 // Download shelf should close. Download panel stays open on ChromeOS. 1404 // Download shelf should close. Download panel stays open on ChromeOS.
1413 CheckDownloadUI(browser(), false, true, file); 1405 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1414 1406
1415 CheckDownload(browser(), file, file); 1407 CheckDownload(browser(), file, file);
1416 } 1408 }
1417 1409
1418 // Check that downloading multiple (in this case, 2) files does not result in 1410 // Check that downloading multiple (in this case, 2) files does not result in
1419 // corrupted files. 1411 // corrupted files.
1420 IN_PROC_BROWSER_TEST_F(DownloadTest, MultiDownload) { 1412 IN_PROC_BROWSER_TEST_F(DownloadTest, MultiDownload) {
1421 ASSERT_TRUE(InitialSetup(false)); 1413 ASSERT_TRUE(InitialSetup(false));
1422 EXPECT_EQ(1, browser()->tab_count()); 1414 EXPECT_EQ(1, browser()->tab_count());
1423 1415
1424 // Create a download, wait until it's started, and confirm 1416 // Create a download, wait until it's started, and confirm
1425 // we're in the expected state. 1417 // we're in the expected state.
1426 scoped_ptr<DownloadTestObserver> observer1( 1418 scoped_ptr<DownloadTestObserver> observer1(
1427 CreateInProgressWaiter(browser(), 1)); 1419 CreateInProgressWaiter(browser(), 1));
1428 ui_test_utils::NavigateToURL( 1420 ui_test_utils::NavigateToURL(
1429 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); 1421 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl));
1430 observer1->WaitForFinished(); 1422 observer1->WaitForFinished();
1431 1423
1432 std::vector<DownloadItem*> downloads; 1424 std::vector<DownloadItem*> downloads;
1433 browser()->profile()->GetDownloadManager()->SearchDownloads( 1425 browser()->profile()->GetDownloadManager()->SearchDownloads(
1434 string16(), &downloads); 1426 string16(), &downloads);
1435 ASSERT_EQ(1u, downloads.size()); 1427 ASSERT_EQ(1u, downloads.size());
1436 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); 1428 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState());
1437 CheckDownloadUI(browser(), true, true, FilePath()); 1429 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1438 DownloadItem* download1 = downloads[0]; // The only download. 1430 DownloadItem* download1 = downloads[0]; // The only download.
1439 1431
1440 // Start the second download and wait until it's done. 1432 // Start the second download and wait until it's done.
1441 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1433 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1442 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1434 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1443 // Download the file and wait. We do not expect the Select File dialog. 1435 // Download the file and wait. We do not expect the Select File dialog.
1444 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 1436 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
1445 1437
1446 // Should now have 2 items on the download shelf. 1438 // Should now have 2 items on the download shelf.
1447 downloads.clear(); 1439 downloads.clear();
1448 browser()->profile()->GetDownloadManager()->SearchDownloads( 1440 browser()->profile()->GetDownloadManager()->SearchDownloads(
1449 string16(), &downloads); 1441 string16(), &downloads);
1450 ASSERT_EQ(2u, downloads.size()); 1442 ASSERT_EQ(2u, downloads.size());
1451 // We don't know the order of the downloads. 1443 // We don't know the order of the downloads.
1452 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; 1444 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0];
1453 1445
1454 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); 1446 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState());
1455 ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState()); 1447 ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState());
1456 // The download shelf should be open. 1448 // The download shelf should be open.
1457 CheckDownloadUI(browser(), true, true, FilePath()); 1449 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1458 1450
1459 // Allow the first request to finish. We do this by loading a third URL 1451 // Allow the first request to finish. We do this by loading a third URL
1460 // in a separate tab. 1452 // in a separate tab.
1461 scoped_ptr<DownloadTestObserver> observer2(CreateWaiter(browser(), 1)); 1453 scoped_ptr<DownloadTestObserver> observer2(CreateWaiter(browser(), 1));
1462 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); 1454 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl);
1463 ui_test_utils::NavigateToURLWithDisposition( 1455 ui_test_utils::NavigateToURLWithDisposition(
1464 browser(), 1456 browser(),
1465 finish_url, 1457 finish_url,
1466 NEW_FOREGROUND_TAB, 1458 NEW_FOREGROUND_TAB,
1467 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1459 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1468 observer2->WaitForFinished(); // Wait for the third request. 1460 observer2->WaitForFinished(); // Wait for the third request.
1469 EXPECT_EQ(1u, observer2->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1461 EXPECT_EQ(1u, observer2->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1470 1462
1471 // Get the important info from other threads and check it. 1463 // Get the important info from other threads and check it.
1472 EXPECT_TRUE(EnsureNoPendingDownloads()); 1464 EXPECT_TRUE(EnsureNoPendingDownloads());
1473 1465
1474 CheckDownloadUI(browser(), true, true, FilePath()); 1466 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1475 1467
1476 // The |DownloadItem|s should now be done and have the final file names. 1468 // The |DownloadItem|s should now be done and have the final file names.
1477 // Verify that the files have the expected data and size. 1469 // Verify that the files have the expected data and size.
1478 // |file1| should be full of '*'s, and |file2| should be the same as the 1470 // |file1| should be full of '*'s, and |file2| should be the same as the
1479 // source file. 1471 // source file.
1480 FilePath file1(download1->GetFullPath()); 1472 FilePath file1(download1->GetFullPath());
1481 size_t file_size1 = URLRequestSlowDownloadJob::kFirstDownloadSize + 1473 size_t file_size1 = URLRequestSlowDownloadJob::kFirstDownloadSize +
1482 URLRequestSlowDownloadJob::kSecondDownloadSize; 1474 URLRequestSlowDownloadJob::kSecondDownloadSize;
1483 std::string expected_contents(file_size1, '*'); 1475 std::string expected_contents(file_size1, '*');
1484 ASSERT_TRUE(VerifyFile(file1, expected_contents, file_size1)); 1476 ASSERT_TRUE(VerifyFile(file1, expected_contents, file_size1));
(...skipping 28 matching lines...) Expand all
1513 CreateInProgressWaiter(browser(), 1)); 1505 CreateInProgressWaiter(browser(), 1));
1514 ui_test_utils::NavigateToURL( 1506 ui_test_utils::NavigateToURL(
1515 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); 1507 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl));
1516 observer->WaitForFinished(); 1508 observer->WaitForFinished();
1517 1509
1518 std::vector<DownloadItem*> downloads; 1510 std::vector<DownloadItem*> downloads;
1519 DownloadManagerForBrowser(browser())->SearchDownloads( 1511 DownloadManagerForBrowser(browser())->SearchDownloads(
1520 string16(), &downloads); 1512 string16(), &downloads);
1521 ASSERT_EQ(1u, downloads.size()); 1513 ASSERT_EQ(1u, downloads.size());
1522 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); 1514 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState());
1523 CheckDownloadUI(browser(), true, true, FilePath()); 1515 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1524 1516
1525 // Cancel the download and wait for download system quiesce. 1517 // Cancel the download and wait for download system quiesce.
1526 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); 1518 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
1527 scoped_refptr<DownloadTestFlushObserver> flush_observer( 1519 scoped_refptr<DownloadTestFlushObserver> flush_observer(
1528 new DownloadTestFlushObserver( 1520 new DownloadTestFlushObserver(
1529 DownloadManagerForBrowser(browser()))); 1521 DownloadManagerForBrowser(browser())));
1530 flush_observer->WaitForFlush(); 1522 flush_observer->WaitForFlush();
1531 1523
1532 // Get the important info from other threads and check it. 1524 // Get the important info from other threads and check it.
1533 EXPECT_TRUE(EnsureNoPendingDownloads()); 1525 EXPECT_TRUE(EnsureNoPendingDownloads());
1534 1526
1535 // Using "DownloadItem::Remove" follows the discard dangerous download path, 1527 // Using "DownloadItem::Remove" follows the discard dangerous download path,
1536 // which completely removes the browser from the shelf and closes the shelf 1528 // which completely removes the browser from the shelf and closes the shelf
1537 // if it was there. Download panel stays open on ChromeOS. 1529 // if it was there. Download panel stays open on ChromeOS.
1538 CheckDownloadUI(browser(), false, true, FilePath()); 1530 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1539 } 1531 }
1540 1532
1541 // Confirm a download makes it into the history properly. 1533 // Confirm a download makes it into the history properly.
1542 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { 1534 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) {
1543 ASSERT_TRUE(InitialSetup(false)); 1535 ASSERT_TRUE(InitialSetup(false));
1544 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1536 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1545 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1537 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1546 FilePath origin_file(OriginFile(file)); 1538 FilePath origin_file(OriginFile(file));
1547 int64 origin_size; 1539 int64 origin_size;
1548 file_util::GetFileSize(origin_file, &origin_size); 1540 file_util::GetFileSize(origin_file, &origin_size);
1549 1541
1550 // Download the file and wait. We do not expect the Select File dialog. 1542 // Download the file and wait. We do not expect the Select File dialog.
1551 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 1543 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
1552 1544
1553 // Get details of what downloads have just happened. 1545 // Get details of what downloads have just happened.
1554 std::vector<DownloadItem*> downloads; 1546 std::vector<DownloadItem*> downloads;
1555 GetDownloads(browser(), &downloads); 1547 GetDownloads(browser(), &downloads);
1556 ASSERT_EQ(1u, downloads.size()); 1548 ASSERT_EQ(1u, downloads.size());
1557 int64 db_handle = downloads[0]->GetDbHandle(); 1549 int64 db_handle = downloads[0]->GetDbHandle();
1558 1550
1559 // Check state. 1551 // Check state.
1560 EXPECT_EQ(1, browser()->tab_count()); 1552 EXPECT_EQ(1, browser()->tab_count());
1561 CheckDownload(browser(), file, file); 1553 CheckDownload(browser(), file, file);
1562 CheckDownloadUI(browser(), true, true, file); 1554 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1563 1555
1564 // Check history results. 1556 // Check history results.
1565 DownloadsHistoryDataCollector history_collector( 1557 DownloadsHistoryDataCollector history_collector(
1566 db_handle, 1558 db_handle,
1567 DownloadManagerForBrowser(browser())); 1559 DownloadManagerForBrowser(browser()));
1568 DownloadPersistentStoreInfo info; 1560 DownloadPersistentStoreInfo info;
1569 EXPECT_TRUE(history_collector.GetDownloadsHistoryEntry(&info)) << db_handle; 1561 EXPECT_TRUE(history_collector.GetDownloadsHistoryEntry(&info)) << db_handle;
1570 EXPECT_EQ(file, info.path.BaseName()); 1562 EXPECT_EQ(file, info.path.BaseName());
1571 EXPECT_EQ(url, info.url); 1563 EXPECT_EQ(url, info.url);
1572 // Ignore start_time. 1564 // Ignore start_time.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1675 DownloadManagerForBrowser(browser())->SearchDownloads( 1667 DownloadManagerForBrowser(browser())->SearchDownloads(
1676 string16(), &downloads); 1668 string16(), &downloads);
1677 ASSERT_EQ(1u, downloads.size()); 1669 ASSERT_EQ(1u, downloads.size());
1678 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); 1670 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState());
1679 EXPECT_TRUE(downloads[0]->GetOpened()); 1671 EXPECT_TRUE(downloads[0]->GetOpened());
1680 1672
1681 // As long as we're here, confirmed everything else is good. 1673 // As long as we're here, confirmed everything else is good.
1682 EXPECT_EQ(1, browser()->tab_count()); 1674 EXPECT_EQ(1, browser()->tab_count());
1683 CheckDownload(browser(), file, file); 1675 CheckDownload(browser(), file, file);
1684 // Download shelf should close. Download panel stays open on ChromeOS. 1676 // Download shelf should close. Download panel stays open on ChromeOS.
1685 CheckDownloadUI(browser(), false, true, FilePath()); 1677 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1686 } 1678 }
1687 1679
1688 // Download an extension. Expect a dangerous download warning. 1680 // Download an extension. Expect a dangerous download warning.
1689 // Deny the download. 1681 // Deny the download.
1690 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { 1682 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) {
1691 ASSERT_TRUE(InitialSetup(false)); 1683 ASSERT_TRUE(InitialSetup(false));
1692 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); 1684 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath));
1693 1685
1694 scoped_ptr<DownloadTestObserver> observer( 1686 scoped_ptr<DownloadTestObserver> observer(
1695 DangerousDownloadWaiter( 1687 DangerousDownloadWaiter(
1696 browser(), 1, 1688 browser(), 1,
1697 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); 1689 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
1698 ui_test_utils::NavigateToURL(browser(), extension_url); 1690 ui_test_utils::NavigateToURL(browser(), extension_url);
1699 1691
1700 observer->WaitForFinished(); 1692 observer->WaitForFinished();
1701 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED)); 1693 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED));
1702 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1694 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1703 1695
1704 // Download shelf should close. Download panel stays open on ChromeOS. 1696 // Download shelf should close. Download panel stays open on ChromeOS.
1705 CheckDownloadUI(browser(), false, true, FilePath()); 1697 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1706 1698
1707 // Check that the CRX is not installed. 1699 // Check that the CRX is not installed.
1708 ExtensionService* extension_service = 1700 ExtensionService* extension_service =
1709 browser()->profile()->GetExtensionService(); 1701 browser()->profile()->GetExtensionService();
1710 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 1702 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
1711 } 1703 }
1712 1704
1713 // Download an extension. Expect a dangerous download warning. 1705 // Download an extension. Expect a dangerous download warning.
1714 // Allow the download, deny the install. 1706 // Allow the download, deny the install.
1715 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { 1707 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) {
(...skipping 10 matching lines...) Expand all
1726 browser(), 1, 1718 browser(), 1,
1727 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1719 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1728 ui_test_utils::NavigateToURL(browser(), extension_url); 1720 ui_test_utils::NavigateToURL(browser(), extension_url);
1729 1721
1730 observer->WaitForFinished(); 1722 observer->WaitForFinished();
1731 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1723 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1732 CheckDownloadStates(1, DownloadItem::COMPLETE); 1724 CheckDownloadStates(1, DownloadItem::COMPLETE);
1733 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1725 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1734 1726
1735 // Download shelf should close. Download panel stays open on ChromeOS. 1727 // Download shelf should close. Download panel stays open on ChromeOS.
1736 CheckDownloadUI(browser(), false, true, FilePath()); 1728 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1737 1729
1738 // Check that the extension was not installed. 1730 // Check that the extension was not installed.
1739 ExtensionService* extension_service = 1731 ExtensionService* extension_service =
1740 browser()->profile()->GetExtensionService(); 1732 browser()->profile()->GetExtensionService();
1741 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 1733 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
1742 } 1734 }
1743 1735
1744 // Download an extension. Expect a dangerous download warning. 1736 // Download an extension. Expect a dangerous download warning.
1745 // Allow the download, and the install. 1737 // Allow the download, and the install.
1746 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { 1738 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) {
(...skipping 10 matching lines...) Expand all
1757 browser(), 1, 1749 browser(), 1,
1758 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1750 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1759 ui_test_utils::NavigateToURL(browser(), extension_url); 1751 ui_test_utils::NavigateToURL(browser(), extension_url);
1760 1752
1761 observer->WaitForFinished(); 1753 observer->WaitForFinished();
1762 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1754 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1763 CheckDownloadStates(1, DownloadItem::COMPLETE); 1755 CheckDownloadStates(1, DownloadItem::COMPLETE);
1764 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1756 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1765 1757
1766 // Download shelf should close. Download panel stays open on ChromeOS. 1758 // Download shelf should close. Download panel stays open on ChromeOS.
1767 CheckDownloadUI(browser(), false, true, FilePath()); 1759 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1768 1760
1769 // Check that the extension was installed. 1761 // Check that the extension was installed.
1770 ExtensionService* extension_service = 1762 ExtensionService* extension_service =
1771 browser()->profile()->GetExtensionService(); 1763 browser()->profile()->GetExtensionService();
1772 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); 1764 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false));
1773 } 1765 }
1774 1766
1775 // Test installing a CRX that fails integrity checks. 1767 // Test installing a CRX that fails integrity checks.
1776 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { 1768 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) {
1777 ASSERT_TRUE(InitialSetup(false)); 1769 ASSERT_TRUE(InitialSetup(false));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1815 browser(), 1, 1807 browser(), 1,
1816 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1808 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1817 ui_test_utils::NavigateToURL(browser(), extension_url); 1809 ui_test_utils::NavigateToURL(browser(), extension_url);
1818 1810
1819 observer->WaitForFinished(); 1811 observer->WaitForFinished();
1820 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1812 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1821 CheckDownloadStates(1, DownloadItem::COMPLETE); 1813 CheckDownloadStates(1, DownloadItem::COMPLETE);
1822 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1814 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1823 1815
1824 // Download shelf should close. Download panel stays open on ChromeOS. 1816 // Download shelf should close. Download panel stays open on ChromeOS.
1825 CheckDownloadUI(browser(), false, true, FilePath()); 1817 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1826 1818
1827 // Check that the extension was installed. 1819 // Check that the extension was installed.
1828 ExtensionService* extension_service = 1820 ExtensionService* extension_service =
1829 browser()->profile()->GetExtensionService(); 1821 browser()->profile()->GetExtensionService();
1830 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); 1822 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false));
1831 } 1823 }
1832 1824
1833 // Sort download items by db_handle. 1825 // Sort download items by db_handle.
1834 static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) { 1826 static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) {
1835 return d1->GetDbHandle() < d2->GetDbHandle(); 1827 return d1->GetDbHandle() < d2->GetDbHandle();
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1985 url, GURL(""), "", false, -1, save_info, web_contents, 1977 url, GURL(""), "", false, -1, save_info, web_contents,
1986 DownloadManager::OnStartedCallback()); 1978 DownloadManager::OnStartedCallback());
1987 observer->WaitForFinished(); 1979 observer->WaitForFinished();
1988 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1980 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1989 CheckDownloadStates(1, DownloadItem::COMPLETE); 1981 CheckDownloadStates(1, DownloadItem::COMPLETE);
1990 EXPECT_TRUE(observer->select_file_dialog_seen()); 1982 EXPECT_TRUE(observer->select_file_dialog_seen());
1991 1983
1992 // Check state. 1984 // Check state.
1993 EXPECT_EQ(1, browser()->tab_count()); 1985 EXPECT_EQ(1, browser()->tab_count());
1994 ASSERT_TRUE(CheckDownload(browser(), file, file)); 1986 ASSERT_TRUE(CheckDownload(browser(), file, file));
1995 CheckDownloadUI(browser(), true, true, file); 1987 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1996 } 1988 }
1997 1989
1998 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { 1990 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) {
1999 ASSERT_TRUE(InitialSetup(false)); 1991 ASSERT_TRUE(InitialSetup(false));
2000 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1992 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
2001 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1993 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
2002 1994
2003 WebContents* web_contents = browser()->GetSelectedWebContents(); 1995 WebContents* web_contents = browser()->GetSelectedWebContents();
2004 ASSERT_TRUE(web_contents); 1996 ASSERT_TRUE(web_contents);
2005 1997
(...skipping 11 matching lines...) Expand all
2017 observer->WaitForFinished(); 2009 observer->WaitForFinished();
2018 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2010 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2019 2011
2020 // Check state. 2012 // Check state.
2021 EXPECT_EQ(1, browser()->tab_count()); 2013 EXPECT_EQ(1, browser()->tab_count());
2022 ASSERT_TRUE(CheckDownloadFullPaths(browser(), 2014 ASSERT_TRUE(CheckDownloadFullPaths(browser(),
2023 target_file_full_path, 2015 target_file_full_path,
2024 OriginFile(file))); 2016 OriginFile(file)));
2025 2017
2026 // Temporary downloads won't be visible. 2018 // Temporary downloads won't be visible.
2027 CheckDownloadUI(browser(), false, false, file); 2019 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
2028 } 2020 }
2029 2021
2030 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaGet) { 2022 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaGet) {
2031 // Do initial setup. 2023 // Do initial setup.
2032 ASSERT_TRUE(InitialSetup(false)); 2024 ASSERT_TRUE(InitialSetup(false));
2033 ASSERT_TRUE(test_server()->Start()); 2025 ASSERT_TRUE(test_server()->Start());
2034 NullSelectFile(browser()); 2026 NullSelectFile(browser());
2035 std::vector<DownloadItem*> download_items; 2027 std::vector<DownloadItem*> download_items;
2036 GetDownloads(browser(), &download_items); 2028 GetDownloads(browser(), &download_items);
2037 ASSERT_TRUE(download_items.empty()); 2029 ASSERT_TRUE(download_items.empty());
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
2503 downloads.clear(); 2495 downloads.clear();
2504 GetDownloads(browser(), &downloads); 2496 GetDownloads(browser(), &downloads);
2505 EXPECT_EQ(0u, downloads.size()); 2497 EXPECT_EQ(0u, downloads.size());
2506 2498
2507 if (creation_observer->succeeded()) { 2499 if (creation_observer->succeeded()) {
2508 // Wait until the download is done. We don't care how it's finished. 2500 // Wait until the download is done. We don't care how it's finished.
2509 backup_observer.WaitForFinished(); 2501 backup_observer.WaitForFinished();
2510 } 2502 }
2511 DownloadManagerForBrowser(browser())->RemoveAllDownloads(); 2503 DownloadManagerForBrowser(browser())->RemoveAllDownloads();
2512 } 2504 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_resources.grd ('k') | chrome/browser/download/save_page_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698