Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / download / notification / download_notification_browsertest.cc
blob2765115a55c972fb2a3daea7bddc2a6aae16cc4b
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/message_loop/message_loop.h"
7 #include "base/path_service.h"
8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chromeos/profiles/profile_helper.h"
11 #include "chrome/browser/download/chrome_download_manager_delegate.h"
12 #include "chrome/browser/download/download_prefs.h"
13 #include "chrome/browser/download/download_service.h"
14 #include "chrome/browser/download/download_service_factory.h"
15 #include "chrome/browser/download/notification/download_group_notification.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/signin/signin_manager_factory.h"
18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_commands.h"
20 #include "chrome/common/chrome_paths.h"
21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/grit/chromium_strings.h"
23 #include "chrome/grit/generated_resources.h"
24 #include "chrome/test/base/in_process_browser_test.h"
25 #include "chrome/test/base/ui_test_utils.h"
26 #include "chromeos/chromeos_switches.h"
27 #include "components/signin/core/browser/signin_manager_base.h"
28 #include "content/public/browser/browser_context.h"
29 #include "content/public/browser/download_item.h"
30 #include "content/public/browser/download_manager.h"
31 #include "content/public/test/download_test_observer.h"
32 #include "grit/theme_resources.h"
33 #include "net/test/embedded_test_server/embedded_test_server.h"
34 #include "net/test/url_request/url_request_slow_download_job.h"
35 #include "ui/base/l10n/l10n_util.h"
36 #include "ui/message_center/message_center.h"
37 #include "ui/message_center/message_center_observer.h"
38 #include "url/gurl.h"
40 namespace {
42 enum {
43 DUMMY_ACCOUNT_INDEX = 0,
44 PRIMARY_ACCOUNT_INDEX = 1,
45 SECONDARY_ACCOUNT_INDEX_START = 2,
48 // Structure to describe an account info.
49 struct TestAccountInfo {
50 const char* const email;
51 const char* const gaia_id;
52 const char* const hash;
53 const char* const display_name;
56 // Accounts for multi profile test.
57 static const TestAccountInfo kTestAccounts[] = {
58 {"__dummy__@invalid.domain", "10000", "hashdummy", "Dummy Account"},
59 {"alice@invalid.domain", "10001", "hashalice", "Alice"},
60 {"bob@invalid.domain", "10002", "hashbobbo", "Bob"},
61 {"charlie@invalid.domain", "10003", "hashcharl", "Charlie"},
64 bool IsInNotifications(
65 const message_center::NotificationList::Notifications& notifications,
66 const std::string& id) {
67 for (const auto& notification : notifications) {
68 if (notification->id() == id)
69 return true;
71 return false;
74 // Base class observing notification events.
75 class MessageCenterChangeObserver
76 : public message_center::MessageCenterObserver {
77 public:
78 MessageCenterChangeObserver() {
79 message_center::MessageCenter::Get()->AddObserver(this);
82 ~MessageCenterChangeObserver() override {
83 message_center::MessageCenter::Get()->RemoveObserver(this);
86 protected:
87 void RunLoop() {
88 base::MessageLoop::ScopedNestableTaskAllower allow(
89 base::MessageLoop::current());
90 run_loop_->Run();
93 void QuitRunLoop() {
94 run_loop_->Quit();
97 void ResetRunLoop() {
98 run_loop_.reset(new base::RunLoop);
101 private:
102 scoped_ptr<base::RunLoop> run_loop_;
104 DISALLOW_COPY_AND_ASSIGN(MessageCenterChangeObserver);
107 // Class observing of "ADD" notification events.
108 class NotificationAddObserver : public MessageCenterChangeObserver {
109 public:
110 NotificationAddObserver() : count_(1) {}
111 explicit NotificationAddObserver(int count) : count_(count) {
112 MessageCenterChangeObserver();
114 ~NotificationAddObserver() override {}
116 bool Wait() {
117 if (count_ <= 0)
118 return count_ == 0;
120 waiting_ = true;
121 ResetRunLoop();
122 RunLoop();
123 waiting_ = false;
124 return count_ == 0;
127 // message_center::MessageCenterObserver:
128 void OnNotificationAdded(const std::string& notification_id) override {
129 count_--;
131 notification_ids_.push_back(notification_id);
133 if (waiting_ && count_ == 0)
134 QuitRunLoop();
137 const std::string& notification_id() const { return notification_ids_.at(0); }
138 const std::vector<std::string>& notification_ids() const {
139 return notification_ids_;
142 private:
143 std::vector<std::string> notification_ids_;
144 bool waiting_ = false;
145 int count_;
147 DISALLOW_COPY_AND_ASSIGN(NotificationAddObserver);
150 // Class observing of "UPDATE" notification events.
151 class NotificationUpdateObserver : public MessageCenterChangeObserver {
152 public:
153 NotificationUpdateObserver() {}
154 ~NotificationUpdateObserver() override {}
156 std::string Wait() {
157 if (!notification_id_.empty())
158 return notification_id_;
160 waiting_ = true;
161 ResetRunLoop();
162 RunLoop();
163 waiting_ = false;
165 std::string notification_id(notification_id_);
166 notification_id_.clear();
167 return notification_id;
170 void OnNotificationUpdated(const std::string& notification_id) override {
171 if (notification_id_.empty()) {
172 notification_id_ = notification_id;
174 if (waiting_)
175 QuitRunLoop();
179 private:
180 std::string notification_id_;
181 bool waiting_ = false;
183 DISALLOW_COPY_AND_ASSIGN(NotificationUpdateObserver);
186 // Class observing of "REMOVE" notification events.
187 class NotificationRemoveObserver : public MessageCenterChangeObserver {
188 public:
189 NotificationRemoveObserver() {}
190 ~NotificationRemoveObserver() override {}
192 std::string Wait() {
193 if (!notification_id_.empty())
194 return notification_id_;
196 waiting_ = true;
197 ResetRunLoop();
198 RunLoop();
199 waiting_ = false;
200 return notification_id_;
203 // message_center::MessageCenterObserver:
204 void OnNotificationRemoved(
205 const std::string& notification_id, bool by_user) override {
206 if (notification_id_.empty()) {
207 notification_id_ = notification_id;
209 if (waiting_)
210 QuitRunLoop();
214 private:
215 std::string notification_id_;
216 bool waiting_ = false;
218 DISALLOW_COPY_AND_ASSIGN(NotificationRemoveObserver);
221 class TestChromeDownloadManagerDelegate : public ChromeDownloadManagerDelegate {
222 public:
223 explicit TestChromeDownloadManagerDelegate(Profile* profile)
224 : ChromeDownloadManagerDelegate(profile), opened_(false) {}
225 ~TestChromeDownloadManagerDelegate() override {}
227 // ChromeDownloadManagerDelegate override:
228 void OpenDownload(content::DownloadItem* item) override { opened_ = true; }
230 // Return if the download is opened.
231 bool opened() const { return opened_; }
233 private:
234 bool opened_;
237 // Utility method to retrieve a message center.
238 message_center::MessageCenter* GetMessageCenter() {
239 return message_center::MessageCenter::Get();
242 // Utility method to retrieve a notification object by id.
243 message_center::Notification* GetNotification(const std::string& id) {
244 return GetMessageCenter()->FindVisibleNotificationById(id);
247 } // anonnymous namespace
249 // Base class for tests
250 class DownloadNotificationTestBase : public InProcessBrowserTest {
251 public:
252 ~DownloadNotificationTestBase() override {}
254 void SetUpCommandLine(base::CommandLine* command_line) override {
255 // TODO(yoshiki): Remove this after the download notification launches.
256 command_line->AppendSwitchASCII(switches::kEnableDownloadNotification,
257 "enabled");
260 void SetUp() override {
261 base::FilePath test_data_dir;
262 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
263 embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
265 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
266 embedded_test_server()->StopThread();
267 InProcessBrowserTest::SetUp();
270 void SetUpOnMainThread() override {
271 embedded_test_server()->RestartThreadAndListen();
273 content::BrowserThread::PostTask(
274 content::BrowserThread::IO, FROM_HERE,
275 base::Bind(&net::URLRequestSlowDownloadJob::AddUrlHandler));
278 content::DownloadManager* GetDownloadManager(Browser* browser) {
279 return content::BrowserContext::GetDownloadManager(browser->profile());
283 //////////////////////////////////////////////////
284 // Test with a single profile
285 //////////////////////////////////////////////////
287 class DownloadNotificationTest : public DownloadNotificationTestBase {
288 public:
289 ~DownloadNotificationTest() override {}
291 void SetUpOnMainThread() override {
292 Profile* profile = browser()->profile();
294 scoped_ptr<TestChromeDownloadManagerDelegate> test_delegate;
295 test_delegate.reset(new TestChromeDownloadManagerDelegate(profile));
296 test_delegate->GetDownloadIdReceiverCallback().Run(
297 content::DownloadItem::kInvalidId + 1);
298 DownloadServiceFactory::GetForBrowserContext(profile)
299 ->SetDownloadManagerDelegateForTesting(test_delegate.Pass());
301 DownloadNotificationTestBase::SetUpOnMainThread();
304 TestChromeDownloadManagerDelegate* GetDownloadManagerDelegate() const {
305 return static_cast<TestChromeDownloadManagerDelegate*>(
306 DownloadServiceFactory::GetForBrowserContext(browser()->profile())
307 ->GetDownloadManagerDelegate());
310 void PrepareIncognitoBrowser() {
311 incognito_browser_ = CreateIncognitoBrowser();
312 Profile* incognito_profile = incognito_browser_->profile();
314 scoped_ptr<TestChromeDownloadManagerDelegate> incognito_test_delegate;
315 incognito_test_delegate.reset(
316 new TestChromeDownloadManagerDelegate(incognito_profile));
317 DownloadServiceFactory::GetForBrowserContext(incognito_profile)
318 ->SetDownloadManagerDelegateForTesting(incognito_test_delegate.Pass());
321 TestChromeDownloadManagerDelegate* GetIncognitoDownloadManagerDelegate()
322 const {
323 Profile* incognito_profile = incognito_browser()->profile();
324 return static_cast<TestChromeDownloadManagerDelegate*>(
325 DownloadServiceFactory::GetForBrowserContext(incognito_profile)->
326 GetDownloadManagerDelegate());
329 void CreateDownload() {
330 return CreateDownloadForBrowserAndURL(
331 browser(),
332 GURL(net::URLRequestSlowDownloadJob::kKnownSizeUrl));
335 void CreateDownloadForBrowserAndURL(Browser* browser, GURL url) {
336 // Starts a download.
337 NotificationAddObserver download_start_notification_observer;
338 ui_test_utils::NavigateToURL(browser, url);
339 EXPECT_TRUE(download_start_notification_observer.Wait());
341 // Confirms that a notification is created.
342 notification_id_ = download_start_notification_observer.notification_id();
343 EXPECT_FALSE(notification_id_.empty());
344 ASSERT_TRUE(notification());
346 // Confirms that there is only one notification.
347 message_center::NotificationList::Notifications
348 visible_notifications = GetMessageCenter()->GetVisibleNotifications();
349 EXPECT_EQ(1u, visible_notifications.size());
350 EXPECT_TRUE(IsInNotifications(visible_notifications, notification_id_));
352 // Confirms that a download is also started.
353 std::vector<content::DownloadItem*> downloads;
354 GetDownloadManager(browser)->GetAllDownloads(&downloads);
355 EXPECT_EQ(1u, downloads.size());
356 download_item_ = downloads[0];
357 ASSERT_TRUE(download_item_);
360 content::DownloadItem* download_item() const { return download_item_; }
361 std::string notification_id() const { return notification_id_; }
362 message_center::Notification* notification() const {
363 return GetNotification(notification_id_);
365 Browser* incognito_browser() const { return incognito_browser_; }
366 base::FilePath GetDownloadPath() {
367 return DownloadPrefs::FromDownloadManager(GetDownloadManager(browser()))->
368 DownloadPath();
371 private:
372 content::DownloadItem* download_item_ = nullptr;
373 Browser* incognito_browser_ = nullptr;
374 std::string notification_id_;
377 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DownloadFile) {
378 CreateDownload();
380 EXPECT_EQ(l10n_util::GetStringFUTF16(
381 IDS_DOWNLOAD_STATUS_IN_PROGRESS_TITLE,
382 download_item()->GetFileNameToReportUser().LossyDisplayName()),
383 GetNotification(notification_id())->title());
384 EXPECT_EQ(message_center::NOTIFICATION_TYPE_PROGRESS,
385 GetNotification(notification_id())->type());
387 NotificationUpdateObserver download_notification_update_observer;
389 // Requests to complete the download.
390 ui_test_utils::NavigateToURL(
391 browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl));
393 // Waits for download completion.
394 while (download_item()->GetState() != content::DownloadItem::COMPLETE) {
395 NotificationUpdateObserver download_change_notification_observer;
396 download_change_notification_observer.Wait();
399 // Waits for new notification.
400 download_notification_update_observer.Wait();
402 // Checks strings.
403 EXPECT_EQ(l10n_util::GetStringFUTF16(
404 IDS_DOWNLOAD_STATUS_DOWNLOADED_TITLE,
405 download_item()->GetFileNameToReportUser().LossyDisplayName()),
406 GetNotification(notification_id())->title());
407 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
408 GetNotification(notification_id())->type());
410 // Confirms that there is only one notification.
411 message_center::NotificationList::Notifications
412 visible_notifications = GetMessageCenter()->GetVisibleNotifications();
413 EXPECT_EQ(1u, visible_notifications.size());
414 EXPECT_TRUE(IsInNotifications(visible_notifications, notification_id()));
416 // Opens the message center.
417 GetMessageCenter()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER);
419 // Try to open the downloaded item by clicking the notification.
420 EXPECT_FALSE(GetDownloadManagerDelegate()->opened());
421 GetMessageCenter()->ClickOnNotification(notification_id());
422 EXPECT_TRUE(GetDownloadManagerDelegate()->opened());
424 EXPECT_FALSE(GetNotification(notification_id()));
427 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DownloadDangerousFile) {
428 GURL download_url(embedded_test_server()->GetURL(
429 "/downloads/dangerous/dangerous.swf"));
431 content::DownloadTestObserverTerminal download_terminal_observer(
432 GetDownloadManager(browser()),
433 1u, /* wait_count */
434 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_IGNORE);
436 CreateDownloadForBrowserAndURL(browser(), download_url);
438 base::FilePath filename = download_item()->GetFileNameToReportUser();
440 // Checks the download status.
441 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE,
442 download_item()->GetDangerType());
443 EXPECT_TRUE(download_item()->IsDangerous());
445 // Opens the message center.
446 GetMessageCenter()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER);
448 NotificationRemoveObserver notification_close_observer;
449 NotificationAddObserver notification_add_observer;
451 // Cicks the "keep" button.
452 notification()->ButtonClick(1); // 2nd button: "Keep"
453 // Clicking makes the message center closed.
454 GetMessageCenter()->SetVisibility(message_center::VISIBILITY_TRANSIENT);
456 // Confirms that the notification is closed and re-shown.
457 EXPECT_EQ(notification_id(), notification_close_observer.Wait());
458 notification_add_observer.Wait();
459 EXPECT_EQ(notification_id(), notification_add_observer.notification_id());
460 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size());
462 // Checks the download status.
463 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED,
464 download_item()->GetDangerType());
465 EXPECT_FALSE(download_item()->IsDangerous());
467 // Wait for the download completion.
468 download_terminal_observer.WaitForFinished();
470 // Checks the download status.
471 EXPECT_FALSE(download_item()->IsDangerous());
472 EXPECT_EQ(content::DownloadItem::COMPLETE, download_item()->GetState());
474 // Checks the downloaded file.
475 EXPECT_TRUE(base::PathExists(GetDownloadPath().Append(filename.BaseName())));
478 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DiscardDangerousFile) {
479 GURL download_url(embedded_test_server()->GetURL(
480 "/downloads/dangerous/dangerous.swf"));
482 content::DownloadTestObserverTerminal download_terminal_observer(
483 GetDownloadManager(browser()),
484 1u, /* wait_count */
485 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_IGNORE);
487 CreateDownloadForBrowserAndURL(browser(), download_url);
489 base::FilePath filename = download_item()->GetFileNameToReportUser();
491 // Checks the download status.
492 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE,
493 download_item()->GetDangerType());
494 EXPECT_TRUE(download_item()->IsDangerous());
496 // Opens the message center.
497 GetMessageCenter()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER);
498 // Ensures the notification exists.
499 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size());
501 NotificationRemoveObserver notification_close_observer;
503 // Clicks the "Discard" button.
504 notification()->ButtonClick(0); // 1st button: "Discard"
505 // Clicking makes the message center closed.
506 GetMessageCenter()->SetVisibility(message_center::VISIBILITY_TRANSIENT);
508 // Confirms that the notification is closed.
509 EXPECT_EQ(notification_id(), notification_close_observer.Wait());
511 // Ensures the notification has closed.
512 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size());
514 // Wait for the download completion.
515 download_terminal_observer.WaitForFinished();
517 // Checks there is neither any download nor any notification.
518 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size());
519 std::vector<content::DownloadItem*> downloads;
520 GetDownloadManager(browser())->GetAllDownloads(&downloads);
521 EXPECT_EQ(0u, downloads.size());
523 // Checks the downloaded file doesn't exist.
524 EXPECT_FALSE(base::PathExists(GetDownloadPath().Append(filename.BaseName())));
527 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DownloadImageFile) {
528 GURL download_url(embedded_test_server()->GetURL(
529 "/downloads/image-octet-stream.png"));
531 content::DownloadTestObserverTerminal download_terminal_observer(
532 GetDownloadManager(browser()), 1u, /* wait_count */
533 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_IGNORE);
535 CreateDownloadForBrowserAndURL(browser(), download_url);
537 // Wait for the download completion.
538 download_terminal_observer.WaitForFinished();
540 // Waits for download completion.
541 while (GetNotification(notification_id())->image().IsEmpty()) {
542 NotificationUpdateObserver download_change_notification_observer;
543 download_change_notification_observer.Wait();
547 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest,
548 CloseNotificationAfterDownload) {
549 CreateDownload();
551 // Requests to complete the download.
552 ui_test_utils::NavigateToURL(
553 browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl));
555 // Waits for download completion.
556 while (download_item()->GetState() != content::DownloadItem::COMPLETE) {
557 NotificationUpdateObserver download_change_notification_observer;
558 download_change_notification_observer.Wait();
561 // Opens the message center.
562 GetMessageCenter()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER);
564 // Closes the notification.
565 NotificationRemoveObserver notification_close_observer;
566 GetMessageCenter()->RemoveNotification(notification_id(), true /* by_user */);
567 EXPECT_EQ(notification_id(), notification_close_observer.Wait());
569 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size());
571 // Confirms that a download is also started.
572 std::vector<content::DownloadItem*> downloads;
573 GetDownloadManager(browser())->GetAllDownloads(&downloads);
574 EXPECT_EQ(1u, downloads.size());
575 EXPECT_EQ(content::DownloadItem::COMPLETE, downloads[0]->GetState());
578 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest,
579 CloseNotificationWhileDownloading) {
580 CreateDownload();
582 // Closes the notification.
583 NotificationRemoveObserver notification_close_observer;
584 GetMessageCenter()->RemoveNotification(notification_id(), true /* by_user */);
585 EXPECT_EQ(notification_id(), notification_close_observer.Wait());
587 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size());
589 // Confirms that a download is still in progress.
590 std::vector<content::DownloadItem*> downloads;
591 content::DownloadManager* download_manager = GetDownloadManager(browser());
592 download_manager->GetAllDownloads(&downloads);
593 EXPECT_EQ(1u, downloads.size());
594 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, downloads[0]->GetState());
596 // Installs observers before requesting the completion.
597 NotificationAddObserver download_notification_add_observer;
598 content::DownloadTestObserverTerminal download_terminal_observer(
599 download_manager,
600 1u, /* wait_count */
601 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
603 // Requests to complete the download and wait for it.
604 ui_test_utils::NavigateToURL(
605 browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl));
606 download_terminal_observer.WaitForFinished();
608 // Waits that new notification.
609 download_notification_add_observer.Wait();
611 // Confirms that there is only one notification.
612 message_center::NotificationList::Notifications
613 visible_notifications = GetMessageCenter()->GetVisibleNotifications();
614 EXPECT_EQ(1u, visible_notifications.size());
615 EXPECT_TRUE(IsInNotifications(visible_notifications, notification_id()));
618 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, InterruptDownload) {
619 CreateDownload();
621 // Installs observers before requesting.
622 NotificationUpdateObserver download_notification_update_observer;
623 content::DownloadTestObserverTerminal download_terminal_observer(
624 GetDownloadManager(browser()),
625 1u, /* wait_count */
626 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
628 // Requests to fail the download and wait for it.
629 ui_test_utils::NavigateToURL(
630 browser(), GURL(net::URLRequestSlowDownloadJob::kErrorDownloadUrl));
631 download_terminal_observer.WaitForFinished();
633 // Waits that new notification.
634 download_notification_update_observer.Wait();
636 // Confirms that there is only one notification.
637 message_center::NotificationList::Notifications
638 visible_notifications = GetMessageCenter()->GetVisibleNotifications();
639 EXPECT_EQ(1u, visible_notifications.size());
640 EXPECT_TRUE(IsInNotifications(visible_notifications, notification_id()));
642 // Checks strings.
643 EXPECT_EQ(l10n_util::GetStringFUTF16(
644 IDS_DOWNLOAD_STATUS_DOWNLOAD_FAILED_TITLE,
645 download_item()->GetFileNameToReportUser().LossyDisplayName()),
646 GetNotification(notification_id())->title());
647 EXPECT_EQ(l10n_util::GetStringFUTF16(
648 IDS_DOWNLOAD_STATUS_INTERRUPTED,
649 l10n_util::GetStringUTF16(
650 IDS_DOWNLOAD_INTERRUPTED_DESCRIPTION_NETWORK_ERROR)),
651 GetNotification(notification_id())->message().substr(48));
652 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
653 GetNotification(notification_id())->type());
656 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest,
657 InterruptDownloadAfterClosingNotification) {
658 CreateDownload();
660 // Closes the notification.
661 NotificationRemoveObserver notification_close_observer;
662 GetMessageCenter()->RemoveNotification(notification_id(), true /* by_user */);
663 EXPECT_EQ(notification_id(), notification_close_observer.Wait());
665 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size());
667 // Confirms that a download is still in progress.
668 std::vector<content::DownloadItem*> downloads;
669 content::DownloadManager* download_manager = GetDownloadManager(browser());
670 download_manager->GetAllDownloads(&downloads);
671 EXPECT_EQ(1u, downloads.size());
672 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, downloads[0]->GetState());
674 // Installs observers before requesting the completion.
675 NotificationAddObserver download_notification_add_observer;
676 content::DownloadTestObserverTerminal download_terminal_observer(
677 download_manager,
678 1u, /* wait_count */
679 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
681 // Requests to fail the download and wait for it.
682 ui_test_utils::NavigateToURL(
683 browser(), GURL(net::URLRequestSlowDownloadJob::kErrorDownloadUrl));
684 download_terminal_observer.WaitForFinished();
686 // Waits that new notification.
687 download_notification_add_observer.Wait();
689 // Confirms that there is only one notification.
690 message_center::NotificationList::Notifications
691 visible_notifications = GetMessageCenter()->GetVisibleNotifications();
692 EXPECT_EQ(1u, visible_notifications.size());
693 EXPECT_TRUE(IsInNotifications(visible_notifications, notification_id()));
696 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DownloadRemoved) {
697 CreateDownload();
699 NotificationRemoveObserver notification_close_observer;
700 download_item()->Remove();
701 EXPECT_EQ(notification_id(), notification_close_observer.Wait());
703 // Confirms that the notification is removed.
704 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size());
706 // Confirms that the download item is removed.
707 std::vector<content::DownloadItem*> downloads;
708 GetDownloadManager(browser())->GetAllDownloads(&downloads);
709 EXPECT_EQ(0u, downloads.size());
712 #if defined(MEMORY_SANITIZER)
713 # define MAYBE_DownloadMultipleFiles DISABLED_DownloadMultipleFiles
714 #else
715 # define MAYBE_DownloadMultipleFiles DownloadMultipleFiles
716 #endif
718 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, MAYBE_DownloadMultipleFiles) {
719 GURL url1(net::URLRequestSlowDownloadJob::kUnknownSizeUrl);
720 GURL url2(net::URLRequestSlowDownloadJob::kKnownSizeUrl);
722 // Starts the 1st download.
723 NotificationAddObserver download_start_notification_observer1;
724 ui_test_utils::NavigateToURL(browser(), url1);
725 EXPECT_TRUE(download_start_notification_observer1.Wait());
726 std::string notification_id1 =
727 download_start_notification_observer1.notification_id();
728 EXPECT_FALSE(notification_id1.empty());
730 // Confirms that there is a download.
731 std::vector<content::DownloadItem*> downloads;
732 GetDownloadManager(browser())->GetAllDownloads(&downloads);
733 EXPECT_EQ(1u, downloads.size());
734 content::DownloadItem* download1or2 = downloads[0];
736 // Starts the 2nd download and waits for 2 notifications (normal and
737 // grouped one).
738 NotificationAddObserver download_start_notification_observer2(2);
739 ui_test_utils::NavigateToURL(browser(), url2);
740 EXPECT_TRUE(download_start_notification_observer2.Wait());
742 // Confirms that there are 2 downloads.
743 downloads.clear();
744 GetDownloadManager(browser())->GetAllDownloads(&downloads);
745 content::DownloadItem* download1 = downloads[0];
746 content::DownloadItem* download2 = downloads[1];
747 EXPECT_EQ(2u, downloads.size());
748 EXPECT_NE(download1, download2);
749 EXPECT_TRUE(download1 == download1or2 || download2 == download1or2);
751 // Confirms that there is only one group notification.
752 message_center::NotificationList::Notifications
753 visible_notifications = GetMessageCenter()->GetVisibleNotifications();
754 EXPECT_EQ(3u, visible_notifications.size());
756 std::string notification_id2;
757 std::string notification_id_group;
758 for (auto notification : visible_notifications) {
759 if (notification->id() == notification_id1) {
760 continue;
761 } else if (notification->type() ==
762 message_center::NOTIFICATION_TYPE_PROGRESS) {
763 notification_id2 = (notification->id());
764 } else if (notification->type() ==
765 message_center::NOTIFICATION_TYPE_MULTIPLE) {
766 notification_id_group = (notification->id());
769 EXPECT_TRUE(!notification_id2.empty());
770 EXPECT_TRUE(!notification_id_group.empty());
771 EXPECT_NE(notification_id2, notification_id_group);
773 // Confirms the types of download notifications are correct.
774 EXPECT_EQ(message_center::NOTIFICATION_TYPE_MULTIPLE,
775 GetNotification(notification_id_group)->type());
776 EXPECT_EQ(2u, GetNotification(notification_id_group)->items().size());
777 EXPECT_EQ(2u, GetNotification(notification_id_group)->items().size());
779 // Requests to complete the downloads.
780 ui_test_utils::NavigateToURL(
781 browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl));
783 // Waits for the completion of downloads.
784 NotificationUpdateObserver download_change_notification_observer;
785 while (download1->GetState() != content::DownloadItem::COMPLETE ||
786 download2->GetState() != content::DownloadItem::COMPLETE) {
787 download_change_notification_observer.Wait();
790 visible_notifications = GetMessageCenter()->GetVisibleNotifications();
791 EXPECT_EQ(3u, visible_notifications.size());
792 EXPECT_TRUE(IsInNotifications(visible_notifications,
793 notification_id_group));
794 EXPECT_TRUE(IsInNotifications(visible_notifications,
795 notification_id1));
796 EXPECT_TRUE(IsInNotifications(visible_notifications,
797 notification_id2));
799 // Confirms the types of download notifications are correct.
800 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
801 GetNotification(notification_id1)->type());
802 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
803 GetNotification(notification_id2)->type());
804 EXPECT_EQ(message_center::NOTIFICATION_TYPE_MULTIPLE,
805 GetNotification(notification_id_group)->type());
806 EXPECT_EQ(2u, GetNotification(notification_id_group)->items().size());
807 EXPECT_EQ(DownloadGroupNotification::TruncateFileName(download2),
808 GetNotification(notification_id_group)->items()[0].title);
809 EXPECT_EQ(DownloadGroupNotification::TruncateFileName(download1),
810 GetNotification(notification_id_group)->items()[1].title);
813 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest,
814 DownloadMultipleFilesOneByOne) {
815 CreateDownload();
816 content::DownloadItem* first_download_item = download_item();
817 content::DownloadItem* second_download_item = nullptr;
818 std::string first_notification_id = notification_id();
819 std::string second_notification_id;
821 // Requests to complete the first download.
822 ui_test_utils::NavigateToURL(
823 browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl));
825 // Waits for completion of the first download.
826 while (first_download_item->GetState() != content::DownloadItem::COMPLETE) {
827 NotificationUpdateObserver download_change_notification_observer;
828 download_change_notification_observer.Wait();
830 EXPECT_EQ(content::DownloadItem::COMPLETE, first_download_item->GetState());
832 // Checks the message center.
833 EXPECT_EQ(1u, GetMessageCenter()->GetVisibleNotifications().size());
835 // Starts the second download.
836 GURL url(net::URLRequestSlowDownloadJob::kKnownSizeUrl);
837 NotificationAddObserver download_start_notification_observer;
838 ui_test_utils::NavigateToURL(browser(), url);
839 EXPECT_TRUE(download_start_notification_observer.Wait());
841 // Confirms that the second notification is created.
842 second_notification_id =
843 download_start_notification_observer.notification_id();
844 EXPECT_FALSE(second_notification_id.empty());
845 ASSERT_TRUE(GetNotification(second_notification_id));
847 // Confirms that there are two notifications, including the second
848 // notification.
849 message_center::NotificationList::Notifications
850 visible_notifications = GetMessageCenter()->GetVisibleNotifications();
851 EXPECT_EQ(2u, visible_notifications.size());
852 EXPECT_TRUE(IsInNotifications(visible_notifications, first_notification_id));
853 EXPECT_TRUE(IsInNotifications(visible_notifications, second_notification_id));
855 // Confirms that the second download is also started.
856 std::vector<content::DownloadItem*> downloads;
857 GetDownloadManager(browser())->GetAllDownloads(&downloads);
858 EXPECT_EQ(2u, downloads.size());
859 EXPECT_TRUE(first_download_item == downloads[0] ||
860 first_download_item == downloads[1]);
861 // Stores the second download.
862 if (first_download_item == downloads[0])
863 second_download_item = downloads[1];
864 else
865 second_download_item = downloads[0];
867 EXPECT_EQ(content::DownloadItem::IN_PROGRESS,
868 second_download_item->GetState());
870 // Requests to complete the second download.
871 ui_test_utils::NavigateToURL(
872 browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl));
874 // Waits for completion of the second download.
875 while (second_download_item->GetState() != content::DownloadItem::COMPLETE) {
876 NotificationUpdateObserver download_change_notification_observer;
877 download_change_notification_observer.Wait();
880 // Opens the message center.
881 GetMessageCenter()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER);
882 // Checks the message center.
883 EXPECT_EQ(2u, GetMessageCenter()->GetVisibleNotifications().size());
886 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, CancelDownload) {
887 CreateDownload();
889 // Opens the message center.
890 GetMessageCenter()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER);
892 // Cancels the notification by clicking the "cancel' button.
893 NotificationRemoveObserver notification_close_observer;
894 notification()->ButtonClick(1);
895 EXPECT_EQ(notification_id(), notification_close_observer.Wait());
896 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size());
898 // Confirms that a download is also cancelled.
899 std::vector<content::DownloadItem*> downloads;
900 GetDownloadManager(browser())->GetAllDownloads(&downloads);
901 EXPECT_EQ(1u, downloads.size());
902 EXPECT_EQ(content::DownloadItem::CANCELLED, downloads[0]->GetState());
905 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest,
906 DownloadCancelledByUserExternally) {
907 CreateDownload();
909 // Cancels the notification by clicking the "cancel' button.
910 NotificationRemoveObserver notification_close_observer;
911 download_item()->Cancel(true /* by_user */);
912 EXPECT_EQ(notification_id(), notification_close_observer.Wait());
913 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size());
915 // Confirms that a download is also cancelled.
916 std::vector<content::DownloadItem*> downloads;
917 GetDownloadManager(browser())->GetAllDownloads(&downloads);
918 EXPECT_EQ(1u, downloads.size());
919 EXPECT_EQ(content::DownloadItem::CANCELLED, downloads[0]->GetState());
922 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest,
923 DownloadCancelledExternally) {
924 CreateDownload();
926 // Cancels the notification by clicking the "cancel' button.
927 NotificationRemoveObserver notification_close_observer;
928 download_item()->Cancel(false /* by_user */);
929 EXPECT_EQ(notification_id(), notification_close_observer.Wait());
930 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size());
932 // Confirms that a download is also cancelled.
933 std::vector<content::DownloadItem*> downloads;
934 GetDownloadManager(browser())->GetAllDownloads(&downloads);
935 EXPECT_EQ(1u, downloads.size());
936 EXPECT_EQ(content::DownloadItem::CANCELLED, downloads[0]->GetState());
939 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, IncognitoDownloadFile) {
940 PrepareIncognitoBrowser();
942 // Starts an incognito download.
943 CreateDownloadForBrowserAndURL(
944 incognito_browser(),
945 GURL(net::URLRequestSlowDownloadJob::kKnownSizeUrl));
947 EXPECT_EQ(l10n_util::GetStringFUTF16(
948 IDS_DOWNLOAD_STATUS_IN_PROGRESS_TITLE,
949 download_item()->GetFileNameToReportUser().LossyDisplayName()),
950 GetNotification(notification_id())->title());
951 EXPECT_EQ(message_center::NOTIFICATION_TYPE_PROGRESS,
952 GetNotification(notification_id())->type());
953 EXPECT_TRUE(download_item()->GetBrowserContext()->IsOffTheRecord());
955 // Requests to complete the download.
956 ui_test_utils::NavigateToURL(
957 incognito_browser(),
958 GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl));
960 // Waits for download completion.
961 while (download_item()->GetState() != content::DownloadItem::COMPLETE) {
962 NotificationUpdateObserver download_change_notification_observer;
963 download_change_notification_observer.Wait();
966 EXPECT_EQ(l10n_util::GetStringFUTF16(
967 IDS_DOWNLOAD_STATUS_DOWNLOADED_TITLE,
968 download_item()->GetFileNameToReportUser().LossyDisplayName()),
969 GetNotification(notification_id())->title());
970 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
971 GetNotification(notification_id())->type());
973 // Opens the message center.
974 GetMessageCenter()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER);
976 // Try to open the downloaded item by clicking the notification.
977 EXPECT_FALSE(GetIncognitoDownloadManagerDelegate()->opened());
978 GetMessageCenter()->ClickOnNotification(notification_id());
979 EXPECT_TRUE(GetIncognitoDownloadManagerDelegate()->opened());
980 EXPECT_FALSE(GetDownloadManagerDelegate()->opened());
982 EXPECT_FALSE(GetNotification(notification_id()));
983 chrome::CloseWindow(incognito_browser());
986 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest,
987 SimultaneousIncognitoAndNormalDownloads) {
988 PrepareIncognitoBrowser();
990 GURL url_incognito(net::URLRequestSlowDownloadJob::kUnknownSizeUrl);
991 GURL url_normal(net::URLRequestSlowDownloadJob::kKnownSizeUrl);
993 // Starts the incognito download.
994 NotificationAddObserver download_start_notification_observer1;
995 ui_test_utils::NavigateToURL(incognito_browser(), url_incognito);
996 EXPECT_TRUE(download_start_notification_observer1.Wait());
997 std::string notification_id1 =
998 download_start_notification_observer1.notification_id();
999 EXPECT_FALSE(notification_id1.empty());
1001 // Confirms that there is a download.
1002 std::vector<content::DownloadItem*> downloads;
1003 GetDownloadManager(browser())->GetAllDownloads(&downloads);
1004 EXPECT_EQ(0u, downloads.size());
1005 downloads.clear();
1006 GetDownloadManager(incognito_browser())->GetAllDownloads(&downloads);
1007 EXPECT_EQ(1u, downloads.size());
1008 content::DownloadItem* download_incognito = downloads[0];
1010 // Starts the normal download.
1011 NotificationAddObserver download_start_notification_observer2;
1012 ui_test_utils::NavigateToURL(browser(), url_normal);
1013 EXPECT_TRUE(download_start_notification_observer2.Wait());
1014 std::string notification_id2 =
1015 download_start_notification_observer2.notification_id();
1016 EXPECT_FALSE(notification_id2.empty());
1018 // Confirms that there are 2 downloads.
1019 downloads.clear();
1020 GetDownloadManager(browser())->GetAllDownloads(&downloads);
1021 content::DownloadItem* download_normal = downloads[0];
1022 EXPECT_EQ(1u, downloads.size());
1023 EXPECT_NE(download_normal, download_incognito);
1024 downloads.clear();
1025 GetDownloadManager(incognito_browser())->GetAllDownloads(&downloads);
1026 EXPECT_EQ(1u, downloads.size());
1027 EXPECT_EQ(download_incognito, downloads[0]);
1029 // Confirms the types of download notifications are correct.
1030 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
1031 GetNotification(notification_id1)->type());
1032 EXPECT_EQ(message_center::NOTIFICATION_TYPE_PROGRESS,
1033 GetNotification(notification_id2)->type());
1035 EXPECT_TRUE(download_incognito->GetBrowserContext()->IsOffTheRecord());
1036 EXPECT_FALSE(download_normal->GetBrowserContext()->IsOffTheRecord());
1038 // Requests to complete the downloads.
1039 ui_test_utils::NavigateToURL(
1040 browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl));
1042 // Waits for the completion of downloads.
1043 while (download_normal->GetState() != content::DownloadItem::COMPLETE ||
1044 download_incognito->GetState() != content::DownloadItem::COMPLETE) {
1045 NotificationUpdateObserver download_change_notification_observer;
1046 download_change_notification_observer.Wait();
1049 // Confirms the types of download notifications are correct.
1050 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
1051 GetNotification(notification_id1)->type());
1052 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
1053 GetNotification(notification_id2)->type());
1055 chrome::CloseWindow(incognito_browser());
1058 //////////////////////////////////////////////////
1059 // Test with multi profiles
1060 //////////////////////////////////////////////////
1062 class MultiProfileDownloadNotificationTest
1063 : public DownloadNotificationTestBase {
1064 public:
1065 ~MultiProfileDownloadNotificationTest() override {}
1067 void SetUpCommandLine(base::CommandLine* command_line) override {
1068 DownloadNotificationTestBase::SetUpCommandLine(command_line);
1070 // Logs in to a dummy profile.
1071 command_line->AppendSwitchASCII(chromeos::switches::kLoginUser,
1072 kTestAccounts[DUMMY_ACCOUNT_INDEX].email);
1073 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
1074 kTestAccounts[DUMMY_ACCOUNT_INDEX].hash);
1077 // Logs in to the primary profile.
1078 void SetUpOnMainThread() override {
1079 const TestAccountInfo& info = kTestAccounts[PRIMARY_ACCOUNT_INDEX];
1081 AddUser(info, true);
1082 DownloadNotificationTestBase::SetUpOnMainThread();
1085 // Loads all users to the current session and sets up necessary fields.
1086 // This is used for preparing all accounts in PRE_ test setup, and for testing
1087 // actual login behavior.
1088 void AddAllUsers() {
1089 for (size_t i = 0; i < arraysize(kTestAccounts); ++i)
1090 AddUser(kTestAccounts[i], i >= SECONDARY_ACCOUNT_INDEX_START);
1093 Profile* GetProfileByIndex(int index) {
1094 return chromeos::ProfileHelper::GetProfileByUserIdHash(
1095 kTestAccounts[index].hash);
1098 // Adds a new user for testing to the current session.
1099 void AddUser(const TestAccountInfo& info, bool log_in) {
1100 user_manager::UserManager* const user_manager =
1101 user_manager::UserManager::Get();
1102 if (log_in)
1103 user_manager->UserLoggedIn(info.email, info.hash, false);
1104 user_manager->SaveUserDisplayName(info.email,
1105 base::UTF8ToUTF16(info.display_name));
1106 SigninManagerFactory::GetForProfile(
1107 chromeos::ProfileHelper::GetProfileByUserIdHash(info.hash))
1108 ->SetAuthenticatedAccountInfo(info.gaia_id, info.email);
1112 IN_PROC_BROWSER_TEST_F(MultiProfileDownloadNotificationTest,
1113 PRE_DownloadMultipleFiles) {
1114 AddAllUsers();
1117 IN_PROC_BROWSER_TEST_F(MultiProfileDownloadNotificationTest,
1118 DownloadMultipleFiles) {
1119 AddAllUsers();
1121 GURL url(net::URLRequestSlowDownloadJob::kUnknownSizeUrl);
1123 Profile* profile1 = GetProfileByIndex(1);
1124 Profile* profile2 = GetProfileByIndex(2);
1125 Browser* browser1 = CreateBrowser(profile1);
1126 Browser* browser2 = CreateBrowser(profile2);
1127 EXPECT_NE(browser1, browser2);
1129 // First user starts a download.
1130 NotificationAddObserver download_start_notification_observer1;
1131 ui_test_utils::NavigateToURL(browser1, url);
1132 download_start_notification_observer1.Wait();
1134 // Confirms that the download is started.
1135 std::vector<content::DownloadItem*> downloads;
1136 GetDownloadManager(browser1)->GetAllDownloads(&downloads);
1137 EXPECT_EQ(1u, downloads.size());
1138 content::DownloadItem* download1 = downloads[0];
1140 // Confirms that a download notification is generated.
1141 std::string notification_id_user1 =
1142 download_start_notification_observer1.notification_id();
1143 EXPECT_FALSE(notification_id_user1.empty());
1145 // Second user starts a download.
1146 NotificationAddObserver download_start_notification_observer2;
1147 ui_test_utils::NavigateToURL(browser2, url);
1148 download_start_notification_observer2.Wait();
1149 std::string notification_id_user2_1 =
1150 download_start_notification_observer2.notification_id();
1151 EXPECT_FALSE(notification_id_user2_1.empty());
1153 // Confirms that the second user has only 1 download.
1154 downloads.clear();
1155 GetDownloadManager(browser2)->GetAllDownloads(&downloads);
1156 ASSERT_EQ(1u, downloads.size());
1158 // Second user starts another download.
1159 NotificationAddObserver download_start_notification_observer3(2);
1160 ui_test_utils::NavigateToURL(browser2, url);
1161 download_start_notification_observer3.Wait();
1162 std::string notification_id_user2_2;
1163 std::string notification_id_user2_group;
1165 auto added_notification_ids =
1166 download_start_notification_observer3.notification_ids();
1167 EXPECT_EQ(2u, added_notification_ids.size());
1168 for (auto notification_id : added_notification_ids) {
1169 if (GetNotification(notification_id)->type() ==
1170 message_center::NOTIFICATION_TYPE_MULTIPLE) {
1171 notification_id_user2_group = notification_id;
1172 } else {
1173 notification_id_user2_2 = notification_id;
1177 EXPECT_FALSE(notification_id_user2_2.empty());
1178 EXPECT_FALSE(notification_id_user2_group.empty());
1180 // Confirms that the second user has 2 downloads.
1181 downloads.clear();
1182 GetDownloadManager(browser2)->GetAllDownloads(&downloads);
1183 ASSERT_EQ(2u, downloads.size());
1184 content::DownloadItem* download2 = downloads[0];
1185 content::DownloadItem* download3 = downloads[1];
1186 EXPECT_NE(download1, download2);
1187 EXPECT_NE(download1, download3);
1188 EXPECT_NE(download2, download3);
1190 // Confirms that the first user still has only 1 download.
1191 downloads.clear();
1192 GetDownloadManager(browser1)->GetAllDownloads(&downloads);
1193 ASSERT_EQ(1u, downloads.size());
1194 EXPECT_EQ(download1, downloads[0]);
1196 // Confirms the types of download notifications are correct.
1197 // Normal notification for user1.
1198 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
1199 GetNotification(notification_id_user1)->type());
1200 // Group notification for user2.
1201 EXPECT_EQ(message_center::NOTIFICATION_TYPE_MULTIPLE,
1202 GetNotification(notification_id_user2_group)->type());
1203 EXPECT_EQ(2u,
1204 GetNotification(notification_id_user2_group)->items().size());
1205 // Normal notification for user2.
1206 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
1207 GetNotification(notification_id_user2_1)->type());
1208 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
1209 GetNotification(notification_id_user2_2)->type());
1211 // Requests to complete the downloads.
1212 NotificationUpdateObserver download_change_notification_observer;
1213 ui_test_utils::NavigateToURL(
1214 browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl));
1216 // Waits for the completion of downloads.
1217 while (download1->GetState() != content::DownloadItem::COMPLETE ||
1218 download2->GetState() != content::DownloadItem::COMPLETE ||
1219 download3->GetState() != content::DownloadItem::COMPLETE) {
1220 // Requests again, since sometimes the request may fail.
1221 ui_test_utils::NavigateToURL(
1222 browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl));
1223 download_change_notification_observer.Wait();
1226 // Confirms the types of download notifications are correct.
1227 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
1228 GetNotification(notification_id_user1)->type());
1229 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
1230 GetNotification(notification_id_user2_1)->type());
1231 // There is still a group notification.
1232 EXPECT_EQ(message_center::NOTIFICATION_TYPE_MULTIPLE,
1233 GetNotification(notification_id_user2_group)->type());
1234 EXPECT_EQ(2u,
1235 GetNotification(notification_id_user2_group)->items().size());
1236 // Normal notifications for user2.
1237 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
1238 GetNotification(notification_id_user2_1)->type());
1239 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
1240 GetNotification(notification_id_user2_2)->type());