Index: chrome/browser/download/notification/download_notification_browsertest.cc |
diff --git a/chrome/browser/download/notification/download_notification_browsertest.cc b/chrome/browser/download/notification/download_notification_browsertest.cc |
index 88e584e5aaeacf2cf0d15300b68eda4daf9c8c98..22d90833657282640f57418da86930bef005fd3e 100644 |
--- a/chrome/browser/download/notification/download_notification_browsertest.cc |
+++ b/chrome/browser/download/notification/download_notification_browsertest.cc |
@@ -361,6 +361,10 @@ IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DownloadFile) { |
EXPECT_EQ(message_center::NOTIFICATION_TYPE_PROGRESS, |
GetNotification(notification_id())->type()); |
+ // Installs observers before requesting the completion. |
+ NotificationAddObserver download_notification_add_observer; |
+ NotificationRemoveObserver download_notification_remove_observer; |
+ |
// Requests to complete the download. |
ui_test_utils::NavigateToURL( |
browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl)); |
@@ -371,6 +375,11 @@ IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DownloadFile) { |
download_change_notification_observer.Wait(); |
} |
+ // Waits for new notification. |
+ download_notification_remove_observer.Wait(); |
+ download_notification_add_observer.Wait(); |
+ |
+ // Checks strings. |
EXPECT_EQ(l10n_util::GetStringFUTF16( |
IDS_DOWNLOAD_STATUS_DOWNLOADED_TITLE, |
download_item()->GetFileNameToReportUser().LossyDisplayName()), |
@@ -378,6 +387,12 @@ IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DownloadFile) { |
EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, |
GetNotification(notification_id())->type()); |
+ // Confirms that there is only one notification. |
+ message_center::NotificationList::Notifications |
+ visible_notifications = GetMessageCenter()->GetVisibleNotifications(); |
+ EXPECT_EQ(1u, visible_notifications.size()); |
+ EXPECT_TRUE(IsInNotifications(visible_notifications, notification_id())); |
+ |
// Opens the message center. |
GetMessageCenter()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER); |
@@ -530,12 +545,111 @@ IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, |
// Confirms that a download is still in progress. |
std::vector<content::DownloadItem*> downloads; |
- GetDownloadManager(browser())->GetAllDownloads(&downloads); |
+ content::DownloadManager* download_manager = GetDownloadManager(browser()); |
+ download_manager->GetAllDownloads(&downloads); |
+ EXPECT_EQ(1u, downloads.size()); |
+ EXPECT_EQ(content::DownloadItem::IN_PROGRESS, downloads[0]->GetState()); |
+ |
+ // Installs observers before requesting the completion. |
+ NotificationAddObserver download_notification_add_observer; |
+ content::DownloadTestObserverTerminal download_terminal_observer( |
+ download_manager, |
+ 1u, /* wait_count */ |
+ content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
+ |
+ // Requests to complete the download and wait for it. |
+ ui_test_utils::NavigateToURL( |
+ browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl)); |
+ download_terminal_observer.WaitForFinished(); |
+ |
+ // Waits that new notification. |
+ download_notification_add_observer.Wait(); |
+ |
+ // Confirms that there is only one notification. |
+ message_center::NotificationList::Notifications |
+ visible_notifications = GetMessageCenter()->GetVisibleNotifications(); |
+ EXPECT_EQ(1u, visible_notifications.size()); |
+ EXPECT_TRUE(IsInNotifications(visible_notifications, notification_id())); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, InterruptDownload) { |
+ CreateDownload(); |
+ |
+ // Installs observers before requesting. |
+ NotificationAddObserver download_notification_add_observer; |
+ NotificationRemoveObserver download_notification_remove_observer; |
+ content::DownloadTestObserverTerminal download_terminal_observer( |
+ GetDownloadManager(browser()), |
+ 1u, /* wait_count */ |
+ content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
+ |
+ // Requests to fail the download and wait for it. |
+ ui_test_utils::NavigateToURL( |
+ browser(), GURL(net::URLRequestSlowDownloadJob::kErrorDownloadUrl)); |
+ download_terminal_observer.WaitForFinished(); |
+ |
+ // Waits that new notification. |
+ download_notification_remove_observer.Wait(); |
+ download_notification_add_observer.Wait(); |
+ |
+ // Confirms that there is only one notification. |
+ message_center::NotificationList::Notifications |
+ visible_notifications = GetMessageCenter()->GetVisibleNotifications(); |
+ EXPECT_EQ(1u, visible_notifications.size()); |
+ EXPECT_TRUE(IsInNotifications(visible_notifications, notification_id())); |
+ |
+ // Checks strings. |
+ EXPECT_EQ(l10n_util::GetStringFUTF16( |
+ IDS_DOWNLOAD_STATUS_DOWNLOAD_FAILED_TITLE, |
+ download_item()->GetFileNameToReportUser().LossyDisplayName()), |
+ GetNotification(notification_id())->title()); |
+ EXPECT_EQ(l10n_util::GetStringFUTF16( |
+ IDS_DOWNLOAD_STATUS_INTERRUPTED, |
+ l10n_util::GetStringUTF16( |
+ IDS_DOWNLOAD_INTERRUPTED_STATUS_NETWORK_ERROR)), |
+ GetNotification(notification_id())->message()); |
+ EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, |
+ GetNotification(notification_id())->type()); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, |
+ InterruptDownloadAfterClosingNotification) { |
+ CreateDownload(); |
+ |
+ // Closes the notification. |
+ NotificationRemoveObserver notification_close_observer; |
+ GetMessageCenter()->RemoveNotification(notification_id(), true /* by_user */); |
+ EXPECT_EQ(notification_id(), notification_close_observer.Wait()); |
+ |
+ EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size()); |
+ |
+ // Confirms that a download is still in progress. |
+ std::vector<content::DownloadItem*> downloads; |
+ content::DownloadManager* download_manager = GetDownloadManager(browser()); |
+ download_manager->GetAllDownloads(&downloads); |
EXPECT_EQ(1u, downloads.size()); |
EXPECT_EQ(content::DownloadItem::IN_PROGRESS, downloads[0]->GetState()); |
- // Cleans the downloading. |
- downloads[0]->Cancel(true); |
+ // Installs observers before requesting the completion. |
+ NotificationAddObserver download_notification_add_observer; |
+ content::DownloadTestObserverTerminal download_terminal_observer( |
+ download_manager, |
+ 1u, /* wait_count */ |
+ content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
+ |
+ // Requests to fail the download and wait for it. |
+ ui_test_utils::NavigateToURL( |
+ browser(), GURL(net::URLRequestSlowDownloadJob::kErrorDownloadUrl)); |
+ download_terminal_observer.WaitForFinished(); |
+ |
+ // Waits that new notification. |
+ download_notification_add_observer.Wait(); |
+ |
+ // Confirms that there is only one notification. |
+ message_center::NotificationList::Notifications |
+ visible_notifications = GetMessageCenter()->GetVisibleNotifications(); |
+ EXPECT_EQ(1u, visible_notifications.size()); |
+ EXPECT_TRUE(IsInNotifications(visible_notifications, notification_id())); |
} |
IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DownloadRemoved) { |