Chromium Code Reviews| Index: chrome/browser/download/download_browsertest.cc |
| =================================================================== |
| --- chrome/browser/download/download_browsertest.cc (revision 90234) |
| +++ chrome/browser/download/download_browsertest.cc (working copy) |
| @@ -608,7 +608,6 @@ |
| int num_downloads, |
| DownloadItem::DownloadState final_state, |
| DangerousDownloadAction dangerous_download_action) { |
| - |
|
achuithb
2011/06/24 21:08:53
Fix lint error.
|
| DownloadManager* download_manager = |
| browser->profile()->GetDownloadManager(); |
| return new DownloadsObserver( |
| @@ -751,12 +750,10 @@ |
| // TODO(ahendrickson): check download status text after downloading. |
| - // Make sure the download shelf is showing. |
| - CheckDownloadUIVisible(browser, true, true); |
| - |
| FilePath basefilename(filename.BaseName()); |
| net::FileURLToFilePath(url, &filename); |
| FilePath download_path = downloads_directory_.path().Append(basefilename); |
| + CheckDownloadUI(browser, true, true, basefilename); |
| bool downloaded_path_exists = file_util::PathExists(download_path); |
| EXPECT_TRUE(downloaded_path_exists); |
| @@ -776,20 +773,38 @@ |
| manager->SearchDownloads(string16(), downloads); |
| } |
| - // Figure out if the appropriate download visibility was done. A |
| - // utility function to support ChromeOS variations. |
| - static void CheckDownloadUIVisible(Browser* browser, |
| - bool expected_non_chromeos, |
| - bool expected_chromeos) { |
| + // Check that the download UI (shelf on non-chromeos or panel on chromeos) |
| + // is visible or not as expected. Additionally, check that the filename |
| + // 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.
|
| + void CheckDownloadUI(Browser* browser, bool expected_non_cros, |
| + bool expected_cros, const FilePath& filename) { |
| #if defined(OS_CHROMEOS) |
| - EXPECT_EQ(expected_chromeos, |
| - NULL != ActiveDownloadsUI::GetPopup(browser->profile())); |
| + Browser* popup = ActiveDownloadsUI::GetPopup(browser->profile()); |
| + EXPECT_EQ(expected_cros, popup != NULL); |
| + if (!popup || filename.empty()) |
| + return; |
| + |
| + ActiveDownloadsUI* downloads_ui = static_cast<ActiveDownloadsUI*>( |
| + popup->GetSelectedTabContents()->web_ui()); |
| + ASSERT_TRUE(downloads_ui); |
| + const ActiveDownloadsUI::DownloadList& downloads = |
| + downloads_ui->GetDownloads(); |
| + EXPECT_EQ(downloads.size(), 1U); |
| + |
| + FilePath full_path(DestinationFile(browser, filename)); |
| + bool exists = false; |
| + for (size_t i = 0; i < downloads.size(); ++i) { |
| + if (downloads[i]->full_path() == full_path) { |
| + exists = true; |
| + break; |
| + } |
| + } |
| + EXPECT_TRUE(exists); |
| #else |
| - EXPECT_EQ(expected_non_chromeos, |
| - browser->window()->IsDownloadShelfVisible()); |
| + EXPECT_EQ(expected_non_cros, browser->window()->IsDownloadShelfVisible()); |
| + // TODO: Check for filename match in download shelf. |
| #endif |
| } |
| - |
| static void ExpectWindowCountAfterDownload(size_t expected) { |
| #if defined(OS_CHROMEOS) |
| // On ChromeOS, a download panel is created to display |
| @@ -939,7 +954,7 @@ |
| // Check state. |
| EXPECT_EQ(1, browser()->tab_count()); |
| CheckDownload(browser(), file, file); |
| - CheckDownloadUIVisible(browser(), true, true); |
| + CheckDownloadUI(browser(), true, true, file); |
| } |
| #if defined(OS_WIN) |
| @@ -960,7 +975,7 @@ |
| if (file_util::VolumeSupportsADS(downloaded_file)) |
| EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); |
| CheckDownload(browser(), file, file); |
| - CheckDownloadUIVisible(browser(), true, true); |
| + CheckDownloadUI(browser(), true, true, file); |
| } |
| #endif |
| @@ -984,7 +999,7 @@ |
| EXPECT_EQ(1, browser()->tab_count()); |
| // Since we exited while the Select File dialog was visible, there should not |
| // be anything in the download shelf and so it should not be visible. |
| - CheckDownloadUIVisible(browser(), false, false); |
| + CheckDownloadUI(browser(), false, false, FilePath()); |
| } |
| // Access a file with a viewable mime-type, verify that a download |
| @@ -1003,7 +1018,7 @@ |
| // Check state. |
| EXPECT_EQ(1, browser()->tab_count()); |
| - CheckDownloadUIVisible(browser(), false, false); |
| + CheckDownloadUI(browser(), false, false, FilePath()); |
| } |
| // Download a 0-size file with a content-disposition header, verify that the |
| @@ -1023,7 +1038,7 @@ |
| // Check state. |
| EXPECT_EQ(1, browser()->tab_count()); |
| - CheckDownloadUIVisible(browser(), true, true); |
| + CheckDownloadUI(browser(), true, true, download_file); |
| } |
| #if !defined(OS_CHROMEOS) // Download shelf is not per-window on ChromeOS. |
| @@ -1043,24 +1058,24 @@ |
| // Check state. |
| EXPECT_EQ(1, browser()->tab_count()); |
| - CheckDownloadUIVisible(browser(), true, true); |
| + CheckDownloadUI(browser(), true, true, download_file); |
| // Open a second tab and wait. |
| EXPECT_NE(static_cast<TabContentsWrapper*>(NULL), |
| browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED)); |
| EXPECT_EQ(2, browser()->tab_count()); |
| - CheckDownloadUIVisible(browser(), true, true); |
| + CheckDownloadUI(browser(), true, true, download_file); |
| // Hide the download shelf. |
| browser()->window()->GetDownloadShelf()->Close(); |
| - CheckDownloadUIVisible(browser(), false, false); |
| + CheckDownloadUI(browser(), false, false, FilePath()); |
| // Go to the first tab. |
| browser()->ActivateTabAt(0, true); |
| EXPECT_EQ(2, browser()->tab_count()); |
| // The download shelf should not be visible. |
| - CheckDownloadUIVisible(browser(), false, false); |
| + CheckDownloadUI(browser(), false, false, FilePath()); |
| } |
| #endif // !OS_CHROMEOS |
| @@ -1108,7 +1123,7 @@ |
| ExpectWindowCountAfterDownload(2); |
| // Verify that the download shelf is showing for the Incognito window. |
| - CheckDownloadUIVisible(incognito, true, true); |
| + CheckDownloadUI(incognito, true, true, file); |
| #if !defined(OS_MACOSX) |
| // On Mac OS X, the UI window close is delayed until the outermost |
| @@ -1130,7 +1145,7 @@ |
| // Verify that the regular window does not have a download shelf. |
| // On ChromeOS, the download panel is common to both profiles, so |
| // it is still visible. |
| - CheckDownloadUIVisible(browser(), false, true); |
| + CheckDownloadUI(browser(), false, true, file); |
| CheckDownload(browser(), file, file); |
| } |
| @@ -1153,7 +1168,7 @@ |
| // We should have two tabs now. |
| EXPECT_EQ(2, browser()->tab_count()); |
| - CheckDownloadUIVisible(browser(), false, false); |
| + CheckDownloadUI(browser(), false, false, FilePath()); |
| } |
| // Download a file in a background tab. Verify that the tab is closed |
| @@ -1173,7 +1188,7 @@ |
| ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| // When the download finishes, we should still have one tab. |
| - CheckDownloadUIVisible(browser(), true, true); |
| + CheckDownloadUI(browser(), true, true, file); |
| EXPECT_EQ(1, browser()->tab_count()); |
| CheckDownload(browser(), file, file); |
| @@ -1205,7 +1220,7 @@ |
| ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| // When the download finishes, we should have two tabs. |
| - CheckDownloadUIVisible(browser(), true, true); |
| + CheckDownloadUI(browser(), true, true, file); |
| EXPECT_EQ(2, browser()->tab_count()); |
| CheckDownload(browser(), file, file); |
| @@ -1247,7 +1262,7 @@ |
| ui_test_utils::BROWSER_TEST_NONE); |
| // When the download finishes, we should have two tabs. |
| - CheckDownloadUIVisible(browser(), true, true); |
| + CheckDownloadUI(browser(), true, true, file); |
| EXPECT_EQ(2, browser()->tab_count()); |
| CheckDownload(browser(), file, file); |
| @@ -1280,7 +1295,7 @@ |
| ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| // When the download finishes, we should still have one tab. |
| - CheckDownloadUIVisible(browser(), true, true); |
| + CheckDownloadUI(browser(), true, true, file); |
| EXPECT_EQ(1, browser()->tab_count()); |
| CheckDownload(browser(), file, file); |
| @@ -1315,7 +1330,7 @@ |
| ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| // When the download finishes, we should still have one tab. |
| - CheckDownloadUIVisible(browser(), true, true); |
| + CheckDownloadUI(browser(), true, true, file); |
| EXPECT_EQ(1, browser()->tab_count()); |
| CheckDownload(browser(), file, file); |
| @@ -1348,8 +1363,8 @@ |
| // the first window. |
| ExpectWindowCountAfterDownload(2); |
| EXPECT_EQ(1, browser()->tab_count()); |
| - // Except on Chrome OS, where the download window sticks around. |
| - CheckDownloadUIVisible(browser(), false, true); |
| + // Download shelf should close. Download panel stays open on ChromeOS. |
| + CheckDownloadUI(browser(), false, true, file); |
| // The download shelf SHOULD be visible in the second window. |
| std::set<Browser*> original_browsers; |
| @@ -1359,7 +1374,7 @@ |
| ASSERT_TRUE(download_browser != NULL); |
| EXPECT_NE(download_browser, browser()); |
| EXPECT_EQ(1, download_browser->tab_count()); |
| - CheckDownloadUIVisible(download_browser, true, true); |
| + CheckDownloadUI(download_browser, true, true, file); |
| #if !defined(OS_MACOSX) |
| // On Mac OS X, the UI window close is delayed until the outermost |
| @@ -1380,8 +1395,8 @@ |
| #endif |
| EXPECT_EQ(1, browser()->tab_count()); |
| - // On ChromeOS, the popup sticks around. |
| - CheckDownloadUIVisible(browser(), false, true); |
| + // Download shelf should close. Download panel stays open on ChromeOS. |
| + CheckDownloadUI(browser(), false, true, file); |
| CheckDownload(browser(), file, file); |
| } |
| @@ -1419,7 +1434,7 @@ |
| string16(), &downloads); |
| ASSERT_EQ(1u, downloads.size()); |
| ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state()); |
| - CheckDownloadUIVisible(browser(), true, true); |
| + CheckDownloadUI(browser(), true, true, FilePath()); |
| // Cancel the download and wait for download system quiesce. |
| downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
| @@ -1435,9 +1450,8 @@ |
| // Using "DownloadItem::Remove" follows the discard dangerous download path, |
| // which completely removes the browser from the shelf and closes the shelf |
| - // if it was there. Chrome OS is an exception to this, where if we |
| - // bring up the downloads panel, it stays there. |
| - CheckDownloadUIVisible(browser(), false, true); |
| + // if it was there. Download panel stays open on ChromeOS. |
| + CheckDownloadUI(browser(), false, true, FilePath()); |
| } |
| // Confirm a download makes it into the history properly. |
| @@ -1461,7 +1475,7 @@ |
| // Check state. |
| EXPECT_EQ(1, browser()->tab_count()); |
| CheckDownload(browser(), file, file); |
| - CheckDownloadUIVisible(browser(), true, true); |
| + CheckDownloadUI(browser(), true, true, file); |
| // Check history results. |
| DownloadsHistoryDataCollector history_collector( |
| @@ -1559,9 +1573,8 @@ |
| // As long as we're here, confirmed everything else is good. |
| EXPECT_EQ(1, browser()->tab_count()); |
| CheckDownload(browser(), file, file); |
| - // Dissapears on most UIs, but the download panel sticks around for |
| - // chrome os. |
| - CheckDownloadUIVisible(browser(), false, true); |
| + // Download shelf should close. Download panel stays open on ChromeOS. |
| + CheckDownloadUI(browser(), false, true, file); |
| } |
| // Download an extension. Expect a dangerous download warning. |
| @@ -1580,7 +1593,8 @@ |
| observer->WaitForFinished(); |
| EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| - CheckDownloadUIVisible(browser(), false, true); |
| + // Download shelf should close. Download panel stays open on ChromeOS. |
| + CheckDownloadUI(browser(), false, true, FilePath()); |
| // Check that the CRX is not installed. |
| ExtensionService* extension_service = |
| @@ -1609,8 +1623,8 @@ |
| observer->WaitForFinished(); |
| EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| - // DL Shelf should close. Download panel sticks around on ChromeOS. |
| - CheckDownloadUIVisible(browser(), false, true); |
| + // Download shelf should close. Download panel stays open on ChromeOS. |
| + CheckDownloadUI(browser(), false, true, FilePath()); |
| // Check that the extension was not installed. |
| ExtensionService* extension_service = |
| @@ -1639,8 +1653,8 @@ |
| observer->WaitForFinished(); |
| EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| - // DL Shelf should close. Download panel sticks around on ChromeOS. |
| - CheckDownloadUIVisible(browser(), false, true); |
| + // Download shelf should close. Download panel stays open on ChromeOS. |
| + CheckDownloadUI(browser(), false, true, FilePath()); |
| // Check that the extension was installed. |
| ExtensionService* extension_service = |
| @@ -1695,8 +1709,8 @@ |
| observer->WaitForFinished(); |
| EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| - // DL Shelf should close. Download panel sticks around on ChromeOS. |
| - CheckDownloadUIVisible(browser(), false, true); |
| + // Download shelf should close. Download panel stays open on ChromeOS. |
| + CheckDownloadUI(browser(), false, true, FilePath()); |
| // Check that the extension was installed. |
| ExtensionService* extension_service = |