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

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

Issue 7245013: Checking that items exist in the downloads panel on ChromeOS. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/stl_util-inl.h" 10 #include "base/stl_util-inl.h"
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 } 601 }
602 602
603 // Create a DownloadsObserver that will wait for the 603 // Create a DownloadsObserver that will wait for the
604 // specified number of downloads to finish, or for 604 // specified number of downloads to finish, or for
605 // a dangerous download warning to be shown. 605 // a dangerous download warning to be shown.
606 DownloadsObserver* DangerousInstallWaiter( 606 DownloadsObserver* DangerousInstallWaiter(
607 Browser* browser, 607 Browser* browser,
608 int num_downloads, 608 int num_downloads,
609 DownloadItem::DownloadState final_state, 609 DownloadItem::DownloadState final_state,
610 DangerousDownloadAction dangerous_download_action) { 610 DangerousDownloadAction dangerous_download_action) {
611
achuithb 2011/06/24 21:08:53 Fix lint error.
612 DownloadManager* download_manager = 611 DownloadManager* download_manager =
613 browser->profile()->GetDownloadManager(); 612 browser->profile()->GetDownloadManager();
614 return new DownloadsObserver( 613 return new DownloadsObserver(
615 download_manager, num_downloads, 614 download_manager, num_downloads,
616 final_state, 615 final_state,
617 true, // Bail on select file 616 true, // Bail on select file
618 dangerous_download_action); 617 dangerous_download_action);
619 } 618 }
620 619
621 // Download |url|, then wait for the download to finish. 620 // Download |url|, then wait for the download to finish.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 browser, 743 browser,
745 finish_url, 744 finish_url,
746 NEW_FOREGROUND_TAB, 745 NEW_FOREGROUND_TAB,
747 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 746 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
748 observer->WaitForFinished(); 747 observer->WaitForFinished();
749 748
750 EXPECT_EQ(2, browser->tab_count()); 749 EXPECT_EQ(2, browser->tab_count());
751 750
752 // TODO(ahendrickson): check download status text after downloading. 751 // TODO(ahendrickson): check download status text after downloading.
753 752
754 // Make sure the download shelf is showing.
755 CheckDownloadUIVisible(browser, true, true);
756
757 FilePath basefilename(filename.BaseName()); 753 FilePath basefilename(filename.BaseName());
758 net::FileURLToFilePath(url, &filename); 754 net::FileURLToFilePath(url, &filename);
759 FilePath download_path = downloads_directory_.path().Append(basefilename); 755 FilePath download_path = downloads_directory_.path().Append(basefilename);
756 CheckDownloadUI(browser, true, true, basefilename);
760 757
761 bool downloaded_path_exists = file_util::PathExists(download_path); 758 bool downloaded_path_exists = file_util::PathExists(download_path);
762 EXPECT_TRUE(downloaded_path_exists); 759 EXPECT_TRUE(downloaded_path_exists);
763 if (!downloaded_path_exists) 760 if (!downloaded_path_exists)
764 return false; 761 return false;
765 762
766 // Delete the file we just downloaded. 763 // Delete the file we just downloaded.
767 EXPECT_TRUE(file_util::DieFileDie(download_path, true)); 764 EXPECT_TRUE(file_util::DieFileDie(download_path, true));
768 EXPECT_FALSE(file_util::PathExists(download_path)); 765 EXPECT_FALSE(file_util::PathExists(download_path));
769 766
770 return true; 767 return true;
771 } 768 }
772 769
773 void GetDownloads(Browser* browser, std::vector<DownloadItem*>* downloads) { 770 void GetDownloads(Browser* browser, std::vector<DownloadItem*>* downloads) {
774 DCHECK(downloads); 771 DCHECK(downloads);
775 DownloadManager* manager = browser->profile()->GetDownloadManager(); 772 DownloadManager* manager = browser->profile()->GetDownloadManager();
776 manager->SearchDownloads(string16(), downloads); 773 manager->SearchDownloads(string16(), downloads);
777 } 774 }
778 775
779 // Figure out if the appropriate download visibility was done. A 776 // Check that the download UI (shelf on non-chromeos or panel on chromeos)
780 // utility function to support ChromeOS variations. 777 // is visible or not as expected. Additionally, check that the filename
781 static void CheckDownloadUIVisible(Browser* browser, 778 // is correct (currently only on chromeos).
Randy Smith (Not in Mondays) 2011/06/26 21:11:45 nit: Suggested comment change "filename is correct
achuithb 2011/06/27 18:34:21 Done.
782 bool expected_non_chromeos, 779 void CheckDownloadUI(Browser* browser, bool expected_non_cros,
783 bool expected_chromeos) { 780 bool expected_cros, const FilePath& filename) {
784 #if defined(OS_CHROMEOS) 781 #if defined(OS_CHROMEOS)
785 EXPECT_EQ(expected_chromeos, 782 Browser* popup = ActiveDownloadsUI::GetPopup(browser->profile());
786 NULL != ActiveDownloadsUI::GetPopup(browser->profile())); 783 EXPECT_EQ(expected_cros, popup != NULL);
784 if (!popup || filename.empty())
785 return;
786
787 ActiveDownloadsUI* downloads_ui = static_cast<ActiveDownloadsUI*>(
788 popup->GetSelectedTabContents()->web_ui());
789 ASSERT_TRUE(downloads_ui);
790 const ActiveDownloadsUI::DownloadList& downloads =
791 downloads_ui->GetDownloads();
792 EXPECT_EQ(downloads.size(), 1U);
793
794 FilePath full_path(DestinationFile(browser, filename));
795 bool exists = false;
796 for (size_t i = 0; i < downloads.size(); ++i) {
797 if (downloads[i]->full_path() == full_path) {
798 exists = true;
799 break;
800 }
801 }
802 EXPECT_TRUE(exists);
787 #else 803 #else
788 EXPECT_EQ(expected_non_chromeos, 804 EXPECT_EQ(expected_non_cros, browser->window()->IsDownloadShelfVisible());
789 browser->window()->IsDownloadShelfVisible()); 805 // TODO: Check for filename match in download shelf.
790 #endif 806 #endif
791 } 807 }
792
793 static void ExpectWindowCountAfterDownload(size_t expected) { 808 static void ExpectWindowCountAfterDownload(size_t expected) {
794 #if defined(OS_CHROMEOS) 809 #if defined(OS_CHROMEOS)
795 // On ChromeOS, a download panel is created to display 810 // On ChromeOS, a download panel is created to display
796 // download information, and this counts as a window. 811 // download information, and this counts as a window.
797 expected++; 812 expected++;
798 #endif 813 #endif
799 EXPECT_EQ(expected, BrowserList::size()); 814 EXPECT_EQ(expected, BrowserList::size());
800 } 815 }
801 816
802 private: 817 private:
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 ASSERT_TRUE(InitialSetup(false)); 947 ASSERT_TRUE(InitialSetup(false));
933 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 948 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
934 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 949 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
935 950
936 // Download the file and wait. We do not expect the Select File dialog. 951 // Download the file and wait. We do not expect the Select File dialog.
937 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 952 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
938 953
939 // Check state. 954 // Check state.
940 EXPECT_EQ(1, browser()->tab_count()); 955 EXPECT_EQ(1, browser()->tab_count());
941 CheckDownload(browser(), file, file); 956 CheckDownload(browser(), file, file);
942 CheckDownloadUIVisible(browser(), true, true); 957 CheckDownloadUI(browser(), true, true, file);
943 } 958 }
944 959
945 #if defined(OS_WIN) 960 #if defined(OS_WIN)
946 // Download a file and confirm that the zone identifier (on windows) 961 // Download a file and confirm that the zone identifier (on windows)
947 // is set to internet. 962 // is set to internet.
948 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { 963 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) {
949 ASSERT_TRUE(InitialSetup(false)); 964 ASSERT_TRUE(InitialSetup(false));
950 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 965 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
951 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 966 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
952 967
953 // Download the file and wait. We do not expect the Select File dialog. 968 // Download the file and wait. We do not expect the Select File dialog.
954 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 969 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
955 970
956 // Check state. Special file state must be checked before CheckDownload, 971 // Check state. Special file state must be checked before CheckDownload,
957 // as CheckDownload will delete the output file. 972 // as CheckDownload will delete the output file.
958 EXPECT_EQ(1, browser()->tab_count()); 973 EXPECT_EQ(1, browser()->tab_count());
959 FilePath downloaded_file(DestinationFile(browser(), file)); 974 FilePath downloaded_file(DestinationFile(browser(), file));
960 if (file_util::VolumeSupportsADS(downloaded_file)) 975 if (file_util::VolumeSupportsADS(downloaded_file))
961 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); 976 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file));
962 CheckDownload(browser(), file, file); 977 CheckDownload(browser(), file, file);
963 CheckDownloadUIVisible(browser(), true, true); 978 CheckDownloadUI(browser(), true, true, file);
964 } 979 }
965 #endif 980 #endif
966 981
967 // Put up a Select File dialog when the file is downloaded, due to its MIME 982 // Put up a Select File dialog when the file is downloaded, due to its MIME
968 // type. 983 // type.
969 // 984 //
970 // This test runs correctly, but leaves behind turds in the test user's 985 // This test runs correctly, but leaves behind turds in the test user's
971 // download directory because of http://crbug.com/62099. No big loss; it 986 // download directory because of http://crbug.com/62099. No big loss; it
972 // was primarily confirming DownloadsObserver wait on select file dialog 987 // was primarily confirming DownloadsObserver wait on select file dialog
973 // functionality anyway. 988 // functionality anyway.
974 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { 989 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) {
975 ASSERT_TRUE(InitialSetup(true)); 990 ASSERT_TRUE(InitialSetup(true));
976 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 991 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
977 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 992 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
978 993
979 // Download the file and wait. We expect the Select File dialog to appear 994 // Download the file and wait. We expect the Select File dialog to appear
980 // due to the MIME type. 995 // due to the MIME type.
981 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG); 996 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG);
982 997
983 // Check state. 998 // Check state.
984 EXPECT_EQ(1, browser()->tab_count()); 999 EXPECT_EQ(1, browser()->tab_count());
985 // Since we exited while the Select File dialog was visible, there should not 1000 // Since we exited while the Select File dialog was visible, there should not
986 // be anything in the download shelf and so it should not be visible. 1001 // be anything in the download shelf and so it should not be visible.
987 CheckDownloadUIVisible(browser(), false, false); 1002 CheckDownloadUI(browser(), false, false, FilePath());
988 } 1003 }
989 1004
990 // Access a file with a viewable mime-type, verify that a download 1005 // Access a file with a viewable mime-type, verify that a download
991 // did not initiate. 1006 // did not initiate.
992 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { 1007 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) {
993 ASSERT_TRUE(InitialSetup(false)); 1008 ASSERT_TRUE(InitialSetup(false));
994 FilePath file(FILE_PATH_LITERAL("download-test2.html")); 1009 FilePath file(FILE_PATH_LITERAL("download-test2.html"));
995 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1010 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
996 FilePath file_path(DestinationFile(browser(), file)); 1011 FilePath file_path(DestinationFile(browser(), file));
997 1012
998 // Open a web page and wait. 1013 // Open a web page and wait.
999 ui_test_utils::NavigateToURL(browser(), url); 1014 ui_test_utils::NavigateToURL(browser(), url);
1000 1015
1001 // Check that we did not download the web page. 1016 // Check that we did not download the web page.
1002 EXPECT_FALSE(file_util::PathExists(file_path)); 1017 EXPECT_FALSE(file_util::PathExists(file_path));
1003 1018
1004 // Check state. 1019 // Check state.
1005 EXPECT_EQ(1, browser()->tab_count()); 1020 EXPECT_EQ(1, browser()->tab_count());
1006 CheckDownloadUIVisible(browser(), false, false); 1021 CheckDownloadUI(browser(), false, false, FilePath());
1007 } 1022 }
1008 1023
1009 // Download a 0-size file with a content-disposition header, verify that the 1024 // Download a 0-size file with a content-disposition header, verify that the
1010 // download tab opened and the file exists as the filename specified in the 1025 // download tab opened and the file exists as the filename specified in the
1011 // header. This also ensures we properly handle empty file downloads. 1026 // header. This also ensures we properly handle empty file downloads.
1012 // The download shelf should be visible in the current tab. 1027 // The download shelf should be visible in the current tab.
1013 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { 1028 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) {
1014 ASSERT_TRUE(InitialSetup(false)); 1029 ASSERT_TRUE(InitialSetup(false));
1015 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); 1030 FilePath file(FILE_PATH_LITERAL("download-test3.gif"));
1016 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1031 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1017 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); 1032 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif"));
1018 1033
1019 // Download a file and wait. 1034 // Download a file and wait.
1020 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 1035 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
1021 1036
1022 CheckDownload(browser(), download_file, file); 1037 CheckDownload(browser(), download_file, file);
1023 1038
1024 // Check state. 1039 // Check state.
1025 EXPECT_EQ(1, browser()->tab_count()); 1040 EXPECT_EQ(1, browser()->tab_count());
1026 CheckDownloadUIVisible(browser(), true, true); 1041 CheckDownloadUI(browser(), true, true, download_file);
1027 } 1042 }
1028 1043
1029 #if !defined(OS_CHROMEOS) // Download shelf is not per-window on ChromeOS. 1044 #if !defined(OS_CHROMEOS) // Download shelf is not per-window on ChromeOS.
1030 // Test that the download shelf is per-window by starting a download in one 1045 // Test that the download shelf is per-window by starting a download in one
1031 // tab, opening a second tab, closing the shelf, going back to the first tab, 1046 // tab, opening a second tab, closing the shelf, going back to the first tab,
1032 // and checking that the shelf is closed. 1047 // and checking that the shelf is closed.
1033 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { 1048 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) {
1034 ASSERT_TRUE(InitialSetup(false)); 1049 ASSERT_TRUE(InitialSetup(false));
1035 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); 1050 FilePath file(FILE_PATH_LITERAL("download-test3.gif"));
1036 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1051 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1037 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); 1052 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif"));
1038 1053
1039 // Download a file and wait. 1054 // Download a file and wait.
1040 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 1055 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
1041 1056
1042 CheckDownload(browser(), download_file, file); 1057 CheckDownload(browser(), download_file, file);
1043 1058
1044 // Check state. 1059 // Check state.
1045 EXPECT_EQ(1, browser()->tab_count()); 1060 EXPECT_EQ(1, browser()->tab_count());
1046 CheckDownloadUIVisible(browser(), true, true); 1061 CheckDownloadUI(browser(), true, true, download_file);
1047 1062
1048 // Open a second tab and wait. 1063 // Open a second tab and wait.
1049 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL), 1064 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL),
1050 browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED)); 1065 browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED));
1051 EXPECT_EQ(2, browser()->tab_count()); 1066 EXPECT_EQ(2, browser()->tab_count());
1052 CheckDownloadUIVisible(browser(), true, true); 1067 CheckDownloadUI(browser(), true, true, download_file);
1053 1068
1054 // Hide the download shelf. 1069 // Hide the download shelf.
1055 browser()->window()->GetDownloadShelf()->Close(); 1070 browser()->window()->GetDownloadShelf()->Close();
1056 CheckDownloadUIVisible(browser(), false, false); 1071 CheckDownloadUI(browser(), false, false, FilePath());
1057 1072
1058 // Go to the first tab. 1073 // Go to the first tab.
1059 browser()->ActivateTabAt(0, true); 1074 browser()->ActivateTabAt(0, true);
1060 EXPECT_EQ(2, browser()->tab_count()); 1075 EXPECT_EQ(2, browser()->tab_count());
1061 1076
1062 // The download shelf should not be visible. 1077 // The download shelf should not be visible.
1063 CheckDownloadUIVisible(browser(), false, false); 1078 CheckDownloadUI(browser(), false, false, FilePath());
1064 } 1079 }
1065 #endif // !OS_CHROMEOS 1080 #endif // !OS_CHROMEOS
1066 1081
1067 // UnknownSize and KnownSize are tests which depend on 1082 // UnknownSize and KnownSize are tests which depend on
1068 // URLRequestSlowDownloadJob to serve content in a certain way. Data will be 1083 // URLRequestSlowDownloadJob to serve content in a certain way. Data will be
1069 // sent in two chunks where the first chunk is 35K and the second chunk is 10K. 1084 // sent in two chunks where the first chunk is 35K and the second chunk is 10K.
1070 // The test will first attempt to download a file; but the server will "pause" 1085 // The test will first attempt to download a file; but the server will "pause"
1071 // in the middle until the server receives a second request for 1086 // in the middle until the server receives a second request for
1072 // "download-finish". At that time, the download will finish. 1087 // "download-finish". At that time, the download will finish.
1073 // These tests don't currently test much due to holes in |RunSizeTest()|. See 1088 // These tests don't currently test much due to holes in |RunSizeTest()|. See
(...skipping 27 matching lines...) Expand all
1101 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1116 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1102 // Since |incognito| is a separate browser, we have to set it up explicitly. 1117 // Since |incognito| is a separate browser, we have to set it up explicitly.
1103 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, 1118 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload,
1104 false); 1119 false);
1105 DownloadAndWait(incognito, url, EXPECT_NO_SELECT_DIALOG); 1120 DownloadAndWait(incognito, url, EXPECT_NO_SELECT_DIALOG);
1106 1121
1107 // We should still have 2 windows. 1122 // We should still have 2 windows.
1108 ExpectWindowCountAfterDownload(2); 1123 ExpectWindowCountAfterDownload(2);
1109 1124
1110 // Verify that the download shelf is showing for the Incognito window. 1125 // Verify that the download shelf is showing for the Incognito window.
1111 CheckDownloadUIVisible(incognito, true, true); 1126 CheckDownloadUI(incognito, true, true, file);
1112 1127
1113 #if !defined(OS_MACOSX) 1128 #if !defined(OS_MACOSX)
1114 // On Mac OS X, the UI window close is delayed until the outermost 1129 // On Mac OS X, the UI window close is delayed until the outermost
1115 // message loop runs. So it isn't possible to get a BROWSER_CLOSED 1130 // message loop runs. So it isn't possible to get a BROWSER_CLOSED
1116 // notification inside of a test. 1131 // notification inside of a test.
1117 ui_test_utils::WindowedNotificationObserver signal( 1132 ui_test_utils::WindowedNotificationObserver signal(
1118 NotificationType::BROWSER_CLOSED, 1133 NotificationType::BROWSER_CLOSED,
1119 Source<Browser>(incognito)); 1134 Source<Browser>(incognito));
1120 #endif 1135 #endif
1121 1136
1122 // Close the Incognito window and don't crash. 1137 // Close the Incognito window and don't crash.
1123 incognito->CloseWindow(); 1138 incognito->CloseWindow();
1124 1139
1125 #if !defined(OS_MACOSX) 1140 #if !defined(OS_MACOSX)
1126 signal.Wait(); 1141 signal.Wait();
1127 ExpectWindowCountAfterDownload(1); 1142 ExpectWindowCountAfterDownload(1);
1128 #endif 1143 #endif
1129 1144
1130 // Verify that the regular window does not have a download shelf. 1145 // Verify that the regular window does not have a download shelf.
1131 // On ChromeOS, the download panel is common to both profiles, so 1146 // On ChromeOS, the download panel is common to both profiles, so
1132 // it is still visible. 1147 // it is still visible.
1133 CheckDownloadUIVisible(browser(), false, true); 1148 CheckDownloadUI(browser(), false, true, file);
1134 1149
1135 CheckDownload(browser(), file, file); 1150 CheckDownload(browser(), file, file);
1136 } 1151 }
1137 1152
1138 // Navigate to a new background page, but don't download. Confirm that the 1153 // Navigate to a new background page, but don't download. Confirm that the
1139 // download shelf is not visible and that we have two tabs. 1154 // download shelf is not visible and that we have two tabs.
1140 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) { 1155 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) {
1141 ASSERT_TRUE(InitialSetup(false)); 1156 ASSERT_TRUE(InitialSetup(false));
1142 // Because it's an HTML link, it should open a web page rather than 1157 // Because it's an HTML link, it should open a web page rather than
1143 // downloading. 1158 // downloading.
1144 FilePath file1(FILE_PATH_LITERAL("download-test2.html")); 1159 FilePath file1(FILE_PATH_LITERAL("download-test2.html"));
1145 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); 1160 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1));
1146 1161
1147 // Open a web page and wait. 1162 // Open a web page and wait.
1148 ui_test_utils::NavigateToURLWithDisposition( 1163 ui_test_utils::NavigateToURLWithDisposition(
1149 browser(), 1164 browser(),
1150 url, 1165 url,
1151 NEW_BACKGROUND_TAB, 1166 NEW_BACKGROUND_TAB,
1152 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1167 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1153 1168
1154 // We should have two tabs now. 1169 // We should have two tabs now.
1155 EXPECT_EQ(2, browser()->tab_count()); 1170 EXPECT_EQ(2, browser()->tab_count());
1156 CheckDownloadUIVisible(browser(), false, false); 1171 CheckDownloadUI(browser(), false, false, FilePath());
1157 } 1172 }
1158 1173
1159 // Download a file in a background tab. Verify that the tab is closed 1174 // Download a file in a background tab. Verify that the tab is closed
1160 // automatically, and that the download shelf is visible in the current tab. 1175 // automatically, and that the download shelf is visible in the current tab.
1161 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab1) { 1176 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab1) {
1162 ASSERT_TRUE(InitialSetup(false)); 1177 ASSERT_TRUE(InitialSetup(false));
1163 1178
1164 // Download a file in a new background tab and wait. The tab is automatically 1179 // Download a file in a new background tab and wait. The tab is automatically
1165 // closed when the download begins. 1180 // closed when the download begins.
1166 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1181 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1167 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1182 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1168 DownloadAndWaitWithDisposition( 1183 DownloadAndWaitWithDisposition(
1169 browser(), 1184 browser(),
1170 url, 1185 url,
1171 NEW_BACKGROUND_TAB, 1186 NEW_BACKGROUND_TAB,
1172 EXPECT_NO_SELECT_DIALOG, 1187 EXPECT_NO_SELECT_DIALOG,
1173 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1188 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1174 1189
1175 // When the download finishes, we should still have one tab. 1190 // When the download finishes, we should still have one tab.
1176 CheckDownloadUIVisible(browser(), true, true); 1191 CheckDownloadUI(browser(), true, true, file);
1177 EXPECT_EQ(1, browser()->tab_count()); 1192 EXPECT_EQ(1, browser()->tab_count());
1178 1193
1179 CheckDownload(browser(), file, file); 1194 CheckDownload(browser(), file, file);
1180 } 1195 }
1181 1196
1182 // Open a web page in the current tab, then download a file in another tab via 1197 // Open a web page in the current tab, then download a file in another tab via
1183 // a Javascript call. 1198 // a Javascript call.
1184 // Verify that we have 2 tabs, and the download shelf is visible in the current 1199 // Verify that we have 2 tabs, and the download shelf is visible in the current
1185 // tab. 1200 // tab.
1186 // 1201 //
(...skipping 11 matching lines...) Expand all
1198 1213
1199 // Download a file in a new tab and wait (via Javascript). 1214 // Download a file in a new tab and wait (via Javascript).
1200 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1215 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1201 DownloadAndWaitWithDisposition(browser(), 1216 DownloadAndWaitWithDisposition(browser(),
1202 GURL("javascript:openNew()"), 1217 GURL("javascript:openNew()"),
1203 CURRENT_TAB, 1218 CURRENT_TAB,
1204 EXPECT_NO_SELECT_DIALOG, 1219 EXPECT_NO_SELECT_DIALOG,
1205 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1220 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1206 1221
1207 // When the download finishes, we should have two tabs. 1222 // When the download finishes, we should have two tabs.
1208 CheckDownloadUIVisible(browser(), true, true); 1223 CheckDownloadUI(browser(), true, true, file);
1209 EXPECT_EQ(2, browser()->tab_count()); 1224 EXPECT_EQ(2, browser()->tab_count());
1210 1225
1211 CheckDownload(browser(), file, file); 1226 CheckDownload(browser(), file, file);
1212 } 1227 }
1213 1228
1214 // Open a web page in the current tab, open another tab via a Javascript call, 1229 // Open a web page in the current tab, open another tab via a Javascript call,
1215 // then download a file in the new tab. 1230 // then download a file in the new tab.
1216 // Verify that we have 2 tabs, and the download shelf is visible in the current 1231 // Verify that we have 2 tabs, and the download shelf is visible in the current
1217 // tab. 1232 // tab.
1218 // 1233 //
(...skipping 21 matching lines...) Expand all
1240 // Download a file and wait. 1255 // Download a file and wait.
1241 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1256 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1242 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1257 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1243 DownloadAndWaitWithDisposition(browser(), 1258 DownloadAndWaitWithDisposition(browser(),
1244 url, 1259 url,
1245 CURRENT_TAB, 1260 CURRENT_TAB,
1246 EXPECT_NO_SELECT_DIALOG, 1261 EXPECT_NO_SELECT_DIALOG,
1247 ui_test_utils::BROWSER_TEST_NONE); 1262 ui_test_utils::BROWSER_TEST_NONE);
1248 1263
1249 // When the download finishes, we should have two tabs. 1264 // When the download finishes, we should have two tabs.
1250 CheckDownloadUIVisible(browser(), true, true); 1265 CheckDownloadUI(browser(), true, true, file);
1251 EXPECT_EQ(2, browser()->tab_count()); 1266 EXPECT_EQ(2, browser()->tab_count());
1252 1267
1253 CheckDownload(browser(), file, file); 1268 CheckDownload(browser(), file, file);
1254 } 1269 }
1255 1270
1256 // Open a web page in the current tab, then download a file via Javascript, 1271 // Open a web page in the current tab, then download a file via Javascript,
1257 // which will do so in a temporary tab. 1272 // which will do so in a temporary tab.
1258 // Verify that we have 1 tab, and the download shelf is visible. 1273 // Verify that we have 1 tab, and the download shelf is visible.
1259 // 1274 //
1260 // The download_page3.html page contains an openNew() function that opens a 1275 // The download_page3.html page contains an openNew() function that opens a
(...skipping 12 matching lines...) Expand all
1273 // Download a file and wait. 1288 // Download a file and wait.
1274 // The file to download is "download-test1.lib". 1289 // The file to download is "download-test1.lib".
1275 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1290 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1276 DownloadAndWaitWithDisposition(browser(), 1291 DownloadAndWaitWithDisposition(browser(),
1277 GURL("javascript:openNew()"), 1292 GURL("javascript:openNew()"),
1278 CURRENT_TAB, 1293 CURRENT_TAB,
1279 EXPECT_NO_SELECT_DIALOG, 1294 EXPECT_NO_SELECT_DIALOG,
1280 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1295 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1281 1296
1282 // When the download finishes, we should still have one tab. 1297 // When the download finishes, we should still have one tab.
1283 CheckDownloadUIVisible(browser(), true, true); 1298 CheckDownloadUI(browser(), true, true, file);
1284 EXPECT_EQ(1, browser()->tab_count()); 1299 EXPECT_EQ(1, browser()->tab_count());
1285 1300
1286 CheckDownload(browser(), file, file); 1301 CheckDownload(browser(), file, file);
1287 } 1302 }
1288 1303
1289 // Open a web page in the current tab, then call Javascript via a button to 1304 // Open a web page in the current tab, then call Javascript via a button to
1290 // download a file in a new tab, which is closed automatically when the 1305 // download a file in a new tab, which is closed automatically when the
1291 // download begins. 1306 // download begins.
1292 // Verify that we have 1 tab, and the download shelf is visible. 1307 // Verify that we have 1 tab, and the download shelf is visible.
1293 // 1308 //
(...skipping 14 matching lines...) Expand all
1308 // The file to download is "download-test1.lib". 1323 // The file to download is "download-test1.lib".
1309 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1324 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1310 DownloadAndWaitWithDisposition( 1325 DownloadAndWaitWithDisposition(
1311 browser(), 1326 browser(),
1312 GURL("javascript:document.getElementById('form').submit()"), 1327 GURL("javascript:document.getElementById('form').submit()"),
1313 CURRENT_TAB, 1328 CURRENT_TAB,
1314 EXPECT_NO_SELECT_DIALOG, 1329 EXPECT_NO_SELECT_DIALOG,
1315 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1330 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1316 1331
1317 // When the download finishes, we should still have one tab. 1332 // When the download finishes, we should still have one tab.
1318 CheckDownloadUIVisible(browser(), true, true); 1333 CheckDownloadUI(browser(), true, true, file);
1319 EXPECT_EQ(1, browser()->tab_count()); 1334 EXPECT_EQ(1, browser()->tab_count());
1320 1335
1321 CheckDownload(browser(), file, file); 1336 CheckDownload(browser(), file, file);
1322 } 1337 }
1323 1338
1324 // Download a file in a new window. 1339 // Download a file in a new window.
1325 // Verify that we have 2 windows, and the download shelf is not visible in the 1340 // Verify that we have 2 windows, and the download shelf is not visible in the
1326 // first window, but is visible in the second window. 1341 // first window, but is visible in the second window.
1327 // Close the new window. 1342 // Close the new window.
1328 // Verify that we have 1 window, and the download shelf is not visible. 1343 // Verify that we have 1 window, and the download shelf is not visible.
(...skipping 12 matching lines...) Expand all
1341 DownloadAndWaitWithDisposition(browser(), 1356 DownloadAndWaitWithDisposition(browser(),
1342 url, 1357 url,
1343 NEW_WINDOW, 1358 NEW_WINDOW,
1344 EXPECT_NO_SELECT_DIALOG, 1359 EXPECT_NO_SELECT_DIALOG,
1345 ui_test_utils::BROWSER_TEST_NONE); 1360 ui_test_utils::BROWSER_TEST_NONE);
1346 1361
1347 // When the download finishes, the download shelf SHOULD NOT be visible in 1362 // When the download finishes, the download shelf SHOULD NOT be visible in
1348 // the first window. 1363 // the first window.
1349 ExpectWindowCountAfterDownload(2); 1364 ExpectWindowCountAfterDownload(2);
1350 EXPECT_EQ(1, browser()->tab_count()); 1365 EXPECT_EQ(1, browser()->tab_count());
1351 // Except on Chrome OS, where the download window sticks around. 1366 // Download shelf should close. Download panel stays open on ChromeOS.
1352 CheckDownloadUIVisible(browser(), false, true); 1367 CheckDownloadUI(browser(), false, true, file);
1353 1368
1354 // The download shelf SHOULD be visible in the second window. 1369 // The download shelf SHOULD be visible in the second window.
1355 std::set<Browser*> original_browsers; 1370 std::set<Browser*> original_browsers;
1356 original_browsers.insert(browser()); 1371 original_browsers.insert(browser());
1357 Browser* download_browser = 1372 Browser* download_browser =
1358 ui_test_utils::GetBrowserNotInSet(original_browsers); 1373 ui_test_utils::GetBrowserNotInSet(original_browsers);
1359 ASSERT_TRUE(download_browser != NULL); 1374 ASSERT_TRUE(download_browser != NULL);
1360 EXPECT_NE(download_browser, browser()); 1375 EXPECT_NE(download_browser, browser());
1361 EXPECT_EQ(1, download_browser->tab_count()); 1376 EXPECT_EQ(1, download_browser->tab_count());
1362 CheckDownloadUIVisible(download_browser, true, true); 1377 CheckDownloadUI(download_browser, true, true, file);
1363 1378
1364 #if !defined(OS_MACOSX) 1379 #if !defined(OS_MACOSX)
1365 // On Mac OS X, the UI window close is delayed until the outermost 1380 // On Mac OS X, the UI window close is delayed until the outermost
1366 // message loop runs. So it isn't possible to get a BROWSER_CLOSED 1381 // message loop runs. So it isn't possible to get a BROWSER_CLOSED
1367 // notification inside of a test. 1382 // notification inside of a test.
1368 ui_test_utils::WindowedNotificationObserver signal( 1383 ui_test_utils::WindowedNotificationObserver signal(
1369 NotificationType::BROWSER_CLOSED, 1384 NotificationType::BROWSER_CLOSED,
1370 Source<Browser>(download_browser)); 1385 Source<Browser>(download_browser));
1371 #endif 1386 #endif
1372 1387
1373 // Close the new window. 1388 // Close the new window.
1374 download_browser->CloseWindow(); 1389 download_browser->CloseWindow();
1375 1390
1376 #if !defined(OS_MACOSX) 1391 #if !defined(OS_MACOSX)
1377 signal.Wait(); 1392 signal.Wait();
1378 EXPECT_EQ(first_browser, browser()); 1393 EXPECT_EQ(first_browser, browser());
1379 ExpectWindowCountAfterDownload(1); 1394 ExpectWindowCountAfterDownload(1);
1380 #endif 1395 #endif
1381 1396
1382 EXPECT_EQ(1, browser()->tab_count()); 1397 EXPECT_EQ(1, browser()->tab_count());
1383 // On ChromeOS, the popup sticks around. 1398 // Download shelf should close. Download panel stays open on ChromeOS.
1384 CheckDownloadUIVisible(browser(), false, true); 1399 CheckDownloadUI(browser(), false, true, file);
1385 1400
1386 CheckDownload(browser(), file, file); 1401 CheckDownload(browser(), file, file);
1387 } 1402 }
1388 1403
1389 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { 1404 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) {
1390 ASSERT_TRUE(InitialSetup(false)); 1405 ASSERT_TRUE(InitialSetup(false));
1391 EXPECT_EQ(1, browser()->tab_count()); 1406 EXPECT_EQ(1, browser()->tab_count());
1392 1407
1393 // TODO(rdsmith): Fragile code warning! The code below relies on the 1408 // TODO(rdsmith): Fragile code warning! The code below relies on the
1394 // DownloadsObserver only finishing when the new download has reached 1409 // DownloadsObserver only finishing when the new download has reached
(...skipping 17 matching lines...) Expand all
1412 CreateInProgressWaiter(browser(), 1)); 1427 CreateInProgressWaiter(browser(), 1));
1413 ui_test_utils::NavigateToURL( 1428 ui_test_utils::NavigateToURL(
1414 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); 1429 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl));
1415 observer->WaitForFinished(); 1430 observer->WaitForFinished();
1416 1431
1417 std::vector<DownloadItem*> downloads; 1432 std::vector<DownloadItem*> downloads;
1418 browser()->profile()->GetDownloadManager()->SearchDownloads( 1433 browser()->profile()->GetDownloadManager()->SearchDownloads(
1419 string16(), &downloads); 1434 string16(), &downloads);
1420 ASSERT_EQ(1u, downloads.size()); 1435 ASSERT_EQ(1u, downloads.size());
1421 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state()); 1436 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state());
1422 CheckDownloadUIVisible(browser(), true, true); 1437 CheckDownloadUI(browser(), true, true, FilePath());
1423 1438
1424 // Cancel the download and wait for download system quiesce. 1439 // Cancel the download and wait for download system quiesce.
1425 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); 1440 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
1426 scoped_refptr<DownloadsFlushObserver> flush_observer( 1441 scoped_refptr<DownloadsFlushObserver> flush_observer(
1427 new DownloadsFlushObserver(browser()->profile()->GetDownloadManager())); 1442 new DownloadsFlushObserver(browser()->profile()->GetDownloadManager()));
1428 flush_observer->WaitForFlush(); 1443 flush_observer->WaitForFlush();
1429 1444
1430 // Get the important info from other threads and check it. 1445 // Get the important info from other threads and check it.
1431 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); 1446 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector());
1432 info->WaitForDataCollected(); 1447 info->WaitForDataCollected();
1433 EXPECT_EQ(0, info->rdh_pending_requests()); 1448 EXPECT_EQ(0, info->rdh_pending_requests());
1434 EXPECT_EQ(0, info->dfm_pending_downloads()); 1449 EXPECT_EQ(0, info->dfm_pending_downloads());
1435 1450
1436 // Using "DownloadItem::Remove" follows the discard dangerous download path, 1451 // Using "DownloadItem::Remove" follows the discard dangerous download path,
1437 // which completely removes the browser from the shelf and closes the shelf 1452 // which completely removes the browser from the shelf and closes the shelf
1438 // if it was there. Chrome OS is an exception to this, where if we 1453 // if it was there. Download panel stays open on ChromeOS.
1439 // bring up the downloads panel, it stays there. 1454 CheckDownloadUI(browser(), false, true, FilePath());
1440 CheckDownloadUIVisible(browser(), false, true);
1441 } 1455 }
1442 1456
1443 // Confirm a download makes it into the history properly. 1457 // Confirm a download makes it into the history properly.
1444 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { 1458 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) {
1445 ASSERT_TRUE(InitialSetup(false)); 1459 ASSERT_TRUE(InitialSetup(false));
1446 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1460 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1447 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1461 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1448 FilePath origin_file(OriginFile(file)); 1462 FilePath origin_file(OriginFile(file));
1449 int64 origin_size; 1463 int64 origin_size;
1450 file_util::GetFileSize(origin_file, &origin_size); 1464 file_util::GetFileSize(origin_file, &origin_size);
1451 1465
1452 // Download the file and wait. We do not expect the Select File dialog. 1466 // Download the file and wait. We do not expect the Select File dialog.
1453 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 1467 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
1454 1468
1455 // Get details of what downloads have just happened. 1469 // Get details of what downloads have just happened.
1456 std::vector<DownloadItem*> downloads; 1470 std::vector<DownloadItem*> downloads;
1457 GetDownloads(browser(), &downloads); 1471 GetDownloads(browser(), &downloads);
1458 ASSERT_EQ(1u, downloads.size()); 1472 ASSERT_EQ(1u, downloads.size());
1459 int64 db_handle = downloads[0]->db_handle(); 1473 int64 db_handle = downloads[0]->db_handle();
1460 1474
1461 // Check state. 1475 // Check state.
1462 EXPECT_EQ(1, browser()->tab_count()); 1476 EXPECT_EQ(1, browser()->tab_count());
1463 CheckDownload(browser(), file, file); 1477 CheckDownload(browser(), file, file);
1464 CheckDownloadUIVisible(browser(), true, true); 1478 CheckDownloadUI(browser(), true, true, file);
1465 1479
1466 // Check history results. 1480 // Check history results.
1467 DownloadsHistoryDataCollector history_collector( 1481 DownloadsHistoryDataCollector history_collector(
1468 db_handle, 1482 db_handle,
1469 browser()->profile()->GetDownloadManager()); 1483 browser()->profile()->GetDownloadManager());
1470 DownloadHistoryInfo info; 1484 DownloadHistoryInfo info;
1471 EXPECT_TRUE(history_collector.GetDownloadsHistoryEntry(&info)) << db_handle; 1485 EXPECT_TRUE(history_collector.GetDownloadsHistoryEntry(&info)) << db_handle;
1472 EXPECT_EQ(file, info.path.BaseName()); 1486 EXPECT_EQ(file, info.path.BaseName());
1473 EXPECT_EQ(url, info.url); 1487 EXPECT_EQ(url, info.url);
1474 // Ignore start_time. 1488 // Ignore start_time.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 std::vector<DownloadItem*> downloads; 1566 std::vector<DownloadItem*> downloads;
1553 browser()->profile()->GetDownloadManager()->SearchDownloads( 1567 browser()->profile()->GetDownloadManager()->SearchDownloads(
1554 string16(), &downloads); 1568 string16(), &downloads);
1555 ASSERT_EQ(1u, downloads.size()); 1569 ASSERT_EQ(1u, downloads.size());
1556 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state()); 1570 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state());
1557 EXPECT_TRUE(downloads[0]->opened()); 1571 EXPECT_TRUE(downloads[0]->opened());
1558 1572
1559 // As long as we're here, confirmed everything else is good. 1573 // As long as we're here, confirmed everything else is good.
1560 EXPECT_EQ(1, browser()->tab_count()); 1574 EXPECT_EQ(1, browser()->tab_count());
1561 CheckDownload(browser(), file, file); 1575 CheckDownload(browser(), file, file);
1562 // Dissapears on most UIs, but the download panel sticks around for 1576 // Download shelf should close. Download panel stays open on ChromeOS.
1563 // chrome os. 1577 CheckDownloadUI(browser(), false, true, file);
1564 CheckDownloadUIVisible(browser(), false, true);
1565 } 1578 }
1566 1579
1567 // Download an extension. Expect a dangerous download warning. 1580 // Download an extension. Expect a dangerous download warning.
1568 // Deny the download. 1581 // Deny the download.
1569 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { 1582 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) {
1570 ASSERT_TRUE(InitialSetup(false)); 1583 ASSERT_TRUE(InitialSetup(false));
1571 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); 1584 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath));
1572 1585
1573 scoped_ptr<DownloadsObserver> observer( 1586 scoped_ptr<DownloadsObserver> observer(
1574 DangerousInstallWaiter(browser(), 1587 DangerousInstallWaiter(browser(),
1575 1, 1588 1,
1576 DownloadItem::CANCELLED, 1589 DownloadItem::CANCELLED,
1577 ON_DANGEROUS_DOWNLOAD_DENY)); 1590 ON_DANGEROUS_DOWNLOAD_DENY));
1578 ui_test_utils::NavigateToURL(browser(), extension_url); 1591 ui_test_utils::NavigateToURL(browser(), extension_url);
1579 1592
1580 observer->WaitForFinished(); 1593 observer->WaitForFinished();
1581 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1594 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1582 1595
1583 CheckDownloadUIVisible(browser(), false, true); 1596 // Download shelf should close. Download panel stays open on ChromeOS.
1597 CheckDownloadUI(browser(), false, true, FilePath());
1584 1598
1585 // Check that the CRX is not installed. 1599 // Check that the CRX is not installed.
1586 ExtensionService* extension_service = 1600 ExtensionService* extension_service =
1587 browser()->profile()->GetExtensionService(); 1601 browser()->profile()->GetExtensionService();
1588 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 1602 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
1589 } 1603 }
1590 1604
1591 // Download an extension. Expect a dangerous download warning. 1605 // Download an extension. Expect a dangerous download warning.
1592 // Allow the download, deny the install. 1606 // Allow the download, deny the install.
1593 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { 1607 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) {
1594 ASSERT_TRUE(InitialSetup(false)); 1608 ASSERT_TRUE(InitialSetup(false));
1595 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); 1609 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath));
1596 1610
1597 // Install a mock install UI that simulates a user denying permission to 1611 // Install a mock install UI that simulates a user denying permission to
1598 // finish the install. 1612 // finish the install.
1599 download_crx_util::SetMockInstallUIForTesting( 1613 download_crx_util::SetMockInstallUIForTesting(
1600 new MockAbortExtensionInstallUI()); 1614 new MockAbortExtensionInstallUI());
1601 1615
1602 scoped_ptr<DownloadsObserver> observer( 1616 scoped_ptr<DownloadsObserver> observer(
1603 DangerousInstallWaiter(browser(), 1617 DangerousInstallWaiter(browser(),
1604 1, 1618 1,
1605 DownloadItem::COMPLETE, 1619 DownloadItem::COMPLETE,
1606 ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1620 ON_DANGEROUS_DOWNLOAD_ACCEPT));
1607 ui_test_utils::NavigateToURL(browser(), extension_url); 1621 ui_test_utils::NavigateToURL(browser(), extension_url);
1608 1622
1609 observer->WaitForFinished(); 1623 observer->WaitForFinished();
1610 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1624 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1611 1625
1612 // DL Shelf should close. Download panel sticks around on ChromeOS. 1626 // Download shelf should close. Download panel stays open on ChromeOS.
1613 CheckDownloadUIVisible(browser(), false, true); 1627 CheckDownloadUI(browser(), false, true, FilePath());
1614 1628
1615 // Check that the extension was not installed. 1629 // Check that the extension was not installed.
1616 ExtensionService* extension_service = 1630 ExtensionService* extension_service =
1617 browser()->profile()->GetExtensionService(); 1631 browser()->profile()->GetExtensionService();
1618 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 1632 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
1619 } 1633 }
1620 1634
1621 // Download an extension. Expect a dangerous download warning. 1635 // Download an extension. Expect a dangerous download warning.
1622 // Allow the download, and the install. 1636 // Allow the download, and the install.
1623 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { 1637 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) {
1624 ASSERT_TRUE(InitialSetup(false)); 1638 ASSERT_TRUE(InitialSetup(false));
1625 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); 1639 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath));
1626 1640
1627 // Install a mock install UI that simulates a user allowing permission to 1641 // Install a mock install UI that simulates a user allowing permission to
1628 // finish the install. 1642 // finish the install.
1629 download_crx_util::SetMockInstallUIForTesting( 1643 download_crx_util::SetMockInstallUIForTesting(
1630 new MockAutoConfirmExtensionInstallUI(browser()->profile())); 1644 new MockAutoConfirmExtensionInstallUI(browser()->profile()));
1631 1645
1632 scoped_ptr<DownloadsObserver> observer( 1646 scoped_ptr<DownloadsObserver> observer(
1633 DangerousInstallWaiter(browser(), 1647 DangerousInstallWaiter(browser(),
1634 1, 1648 1,
1635 DownloadItem::COMPLETE, 1649 DownloadItem::COMPLETE,
1636 ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1650 ON_DANGEROUS_DOWNLOAD_ACCEPT));
1637 ui_test_utils::NavigateToURL(browser(), extension_url); 1651 ui_test_utils::NavigateToURL(browser(), extension_url);
1638 1652
1639 observer->WaitForFinished(); 1653 observer->WaitForFinished();
1640 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1654 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1641 1655
1642 // DL Shelf should close. Download panel sticks around on ChromeOS. 1656 // Download shelf should close. Download panel stays open on ChromeOS.
1643 CheckDownloadUIVisible(browser(), false, true); 1657 CheckDownloadUI(browser(), false, true, FilePath());
1644 1658
1645 // Check that the extension was installed. 1659 // Check that the extension was installed.
1646 ExtensionService* extension_service = 1660 ExtensionService* extension_service =
1647 browser()->profile()->GetExtensionService(); 1661 browser()->profile()->GetExtensionService();
1648 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); 1662 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false));
1649 } 1663 }
1650 1664
1651 // Test installing a CRX that fails integrity checks. 1665 // Test installing a CRX that fails integrity checks.
1652 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { 1666 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) {
1653 ASSERT_TRUE(InitialSetup(false)); 1667 ASSERT_TRUE(InitialSetup(false));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 scoped_ptr<DownloadsObserver> observer( 1702 scoped_ptr<DownloadsObserver> observer(
1689 DangerousInstallWaiter(browser(), 1703 DangerousInstallWaiter(browser(),
1690 1, 1704 1,
1691 DownloadItem::COMPLETE, 1705 DownloadItem::COMPLETE,
1692 ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1706 ON_DANGEROUS_DOWNLOAD_ACCEPT));
1693 ui_test_utils::NavigateToURL(browser(), extension_url); 1707 ui_test_utils::NavigateToURL(browser(), extension_url);
1694 1708
1695 observer->WaitForFinished(); 1709 observer->WaitForFinished();
1696 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1710 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1697 1711
1698 // DL Shelf should close. Download panel sticks around on ChromeOS. 1712 // Download shelf should close. Download panel stays open on ChromeOS.
1699 CheckDownloadUIVisible(browser(), false, true); 1713 CheckDownloadUI(browser(), false, true, FilePath());
1700 1714
1701 // Check that the extension was installed. 1715 // Check that the extension was installed.
1702 ExtensionService* extension_service = 1716 ExtensionService* extension_service =
1703 browser()->profile()->GetExtensionService(); 1717 browser()->profile()->GetExtensionService();
1704 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); 1718 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false));
1705 } 1719 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698