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

Unified Diff: chrome/browser/download/notification/download_notification_browsertest.cc

Issue 1105953002: Pop up the notification when the download is interrupted or completed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dn-xxxx-close-bug
Patch Set: Adressed comment and pop up the notification after completion Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
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 503728d86d000e1304e70f4af56872b2aa9fef42..c0f2ba858145ef8ba9949640bbe14ac7895f31c1 100644
--- a/chrome/browser/download/notification/download_notification_browsertest.cc
+++ b/chrome/browser/download/notification/download_notification_browsertest.cc
@@ -23,6 +23,7 @@
#include "content/public/browser/browser_context.h"
#include "content/public/browser/download_item.h"
#include "content/public/browser/download_manager.h"
+#include "content/public/test/download_test_observer.h"
#include "grit/theme_resources.h"
#include "net/test/url_request/url_request_slow_download_job.h"
#include "ui/base/l10n/l10n_util.h"
@@ -330,6 +331,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));
@@ -340,6 +345,11 @@ IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DownloadFile) {
download_change_notification_observer.Wait();
}
+ // Waits for new notification is popped up.
+ 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()),
@@ -347,6 +357,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);
@@ -402,12 +418,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());
- // 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 complete the download and wait for it.
+ ui_test_utils::NavigateToURL(
+ browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl));
+ download_terminal_observer.WaitForFinished();
+
+ // Waits that new notification is popped up.
+ 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 is popped up.
+ 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());
+
+ // 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 is popped up.
+ 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) {

Powered by Google App Engine
This is Rietveld 408576698