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

Side by Side 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: rebase 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/chromeos/profiles/profile_helper.h" 9 #include "chrome/browser/chromeos/profiles/profile_helper.h"
10 #include "chrome/browser/download/chrome_download_manager_delegate.h" 10 #include "chrome/browser/download/chrome_download_manager_delegate.h"
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DownloadFile) { 354 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DownloadFile) {
355 CreateDownload(); 355 CreateDownload();
356 356
357 EXPECT_EQ(l10n_util::GetStringFUTF16( 357 EXPECT_EQ(l10n_util::GetStringFUTF16(
358 IDS_DOWNLOAD_STATUS_IN_PROGRESS_TITLE, 358 IDS_DOWNLOAD_STATUS_IN_PROGRESS_TITLE,
359 download_item()->GetFileNameToReportUser().LossyDisplayName()), 359 download_item()->GetFileNameToReportUser().LossyDisplayName()),
360 GetNotification(notification_id())->title()); 360 GetNotification(notification_id())->title());
361 EXPECT_EQ(message_center::NOTIFICATION_TYPE_PROGRESS, 361 EXPECT_EQ(message_center::NOTIFICATION_TYPE_PROGRESS,
362 GetNotification(notification_id())->type()); 362 GetNotification(notification_id())->type());
363 363
364 // Installs observers before requesting the completion.
365 NotificationAddObserver download_notification_add_observer;
366 NotificationRemoveObserver download_notification_remove_observer;
367
364 // Requests to complete the download. 368 // Requests to complete the download.
365 ui_test_utils::NavigateToURL( 369 ui_test_utils::NavigateToURL(
366 browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl)); 370 browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl));
367 371
368 // Waits for download completion. 372 // Waits for download completion.
369 while (download_item()->GetState() != content::DownloadItem::COMPLETE) { 373 while (download_item()->GetState() != content::DownloadItem::COMPLETE) {
370 NotificationUpdateObserver download_change_notification_observer; 374 NotificationUpdateObserver download_change_notification_observer;
371 download_change_notification_observer.Wait(); 375 download_change_notification_observer.Wait();
372 } 376 }
373 377
378 // Waits for new notification is popped up.
asanka 2015/05/14 21:36:17 // Waits for new notification.
asanka 2015/05/14 21:36:17 // Waits for new notification.
yoshiki 2015/05/15 06:27:09 Done.
379 download_notification_remove_observer.Wait();
380 download_notification_add_observer.Wait();
381
382 // Checks strings.
374 EXPECT_EQ(l10n_util::GetStringFUTF16( 383 EXPECT_EQ(l10n_util::GetStringFUTF16(
375 IDS_DOWNLOAD_STATUS_DOWNLOADED_TITLE, 384 IDS_DOWNLOAD_STATUS_DOWNLOADED_TITLE,
376 download_item()->GetFileNameToReportUser().LossyDisplayName()), 385 download_item()->GetFileNameToReportUser().LossyDisplayName()),
377 GetNotification(notification_id())->title()); 386 GetNotification(notification_id())->title());
378 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, 387 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE,
379 GetNotification(notification_id())->type()); 388 GetNotification(notification_id())->type());
380 389
390 // Confirms that there is only one notification.
391 message_center::NotificationList::Notifications
392 visible_notifications = GetMessageCenter()->GetVisibleNotifications();
393 EXPECT_EQ(1u, visible_notifications.size());
394 EXPECT_TRUE(IsInNotifications(visible_notifications, notification_id()));
395
381 // Opens the message center. 396 // Opens the message center.
382 GetMessageCenter()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER); 397 GetMessageCenter()->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER);
383 398
384 // Try to open the downloaded item by clicking the notification. 399 // Try to open the downloaded item by clicking the notification.
385 EXPECT_FALSE(GetDownloadManagerDelegate()->opened()); 400 EXPECT_FALSE(GetDownloadManagerDelegate()->opened());
386 GetMessageCenter()->ClickOnNotification(notification_id()); 401 GetMessageCenter()->ClickOnNotification(notification_id());
387 EXPECT_TRUE(GetDownloadManagerDelegate()->opened()); 402 EXPECT_TRUE(GetDownloadManagerDelegate()->opened());
388 403
389 EXPECT_FALSE(GetNotification(notification_id())); 404 EXPECT_FALSE(GetNotification(notification_id()));
390 } 405 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 538
524 // Closes the notification. 539 // Closes the notification.
525 NotificationRemoveObserver notification_close_observer; 540 NotificationRemoveObserver notification_close_observer;
526 GetMessageCenter()->RemoveNotification(notification_id(), true /* by_user */); 541 GetMessageCenter()->RemoveNotification(notification_id(), true /* by_user */);
527 EXPECT_EQ(notification_id(), notification_close_observer.Wait()); 542 EXPECT_EQ(notification_id(), notification_close_observer.Wait());
528 543
529 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size()); 544 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size());
530 545
531 // Confirms that a download is still in progress. 546 // Confirms that a download is still in progress.
532 std::vector<content::DownloadItem*> downloads; 547 std::vector<content::DownloadItem*> downloads;
533 GetDownloadManager(browser())->GetAllDownloads(&downloads); 548 content::DownloadManager* download_manager = GetDownloadManager(browser());
549 download_manager->GetAllDownloads(&downloads);
534 EXPECT_EQ(1u, downloads.size()); 550 EXPECT_EQ(1u, downloads.size());
535 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, downloads[0]->GetState()); 551 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, downloads[0]->GetState());
536 552
537 // Cleans the downloading. 553 // Installs observers before requesting the completion.
538 downloads[0]->Cancel(true); 554 NotificationAddObserver download_notification_add_observer;
555 content::DownloadTestObserverTerminal download_terminal_observer(
556 download_manager,
557 1u, /* wait_count */
558 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
559
560 // Requests to complete the download and wait for it.
561 ui_test_utils::NavigateToURL(
562 browser(), GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl));
563 download_terminal_observer.WaitForFinished();
564
565 // Waits that new notification is popped up.
asanka 2015/05/14 21:36:17 // Waits for new notification.
yoshiki 2015/05/15 06:27:09 Done.
566 download_notification_add_observer.Wait();
567
568 // Confirms that there is only one notification.
569 message_center::NotificationList::Notifications
570 visible_notifications = GetMessageCenter()->GetVisibleNotifications();
571 EXPECT_EQ(1u, visible_notifications.size());
572 EXPECT_TRUE(IsInNotifications(visible_notifications, notification_id()));
573 }
574
575 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, InterruptDownload) {
576 CreateDownload();
577
578 // Installs observers before requesting.
579 NotificationAddObserver download_notification_add_observer;
580 NotificationRemoveObserver download_notification_remove_observer;
581 content::DownloadTestObserverTerminal download_terminal_observer(
582 GetDownloadManager(browser()),
583 1u, /* wait_count */
584 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
585
586 // Requests to fail the download and wait for it.
587 ui_test_utils::NavigateToURL(
588 browser(), GURL(net::URLRequestSlowDownloadJob::kErrorDownloadUrl));
589 download_terminal_observer.WaitForFinished();
590
591 // Waits that new notification is popped up.
asanka 2015/05/14 21:36:16 ditto
yoshiki 2015/05/15 06:27:09 Done.
592 download_notification_remove_observer.Wait();
593 download_notification_add_observer.Wait();
594
595 // Confirms that there is only one notification.
596 message_center::NotificationList::Notifications
597 visible_notifications = GetMessageCenter()->GetVisibleNotifications();
598 EXPECT_EQ(1u, visible_notifications.size());
599 EXPECT_TRUE(IsInNotifications(visible_notifications, notification_id()));
600
601 // Checks strings.
602 EXPECT_EQ(l10n_util::GetStringFUTF16(
603 IDS_DOWNLOAD_STATUS_DOWNLOAD_FAILED_TITLE,
604 download_item()->GetFileNameToReportUser().LossyDisplayName()),
605 GetNotification(notification_id())->title());
606 EXPECT_EQ(l10n_util::GetStringFUTF16(
607 IDS_DOWNLOAD_STATUS_INTERRUPTED,
608 l10n_util::GetStringUTF16(
609 IDS_DOWNLOAD_INTERRUPTED_STATUS_NETWORK_ERROR)),
610 GetNotification(notification_id())->message());
611 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE,
612 GetNotification(notification_id())->type());
613 }
614
615 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest,
616 InterruptDownloadAfterClosingNotification) {
617 CreateDownload();
618
619 // Closes the notification.
620 NotificationRemoveObserver notification_close_observer;
621 GetMessageCenter()->RemoveNotification(notification_id(), true /* by_user */);
622 EXPECT_EQ(notification_id(), notification_close_observer.Wait());
623
624 EXPECT_EQ(0u, GetMessageCenter()->GetVisibleNotifications().size());
625
626 // Confirms that a download is still in progress.
627 std::vector<content::DownloadItem*> downloads;
628 content::DownloadManager* download_manager = GetDownloadManager(browser());
629 download_manager->GetAllDownloads(&downloads);
630 EXPECT_EQ(1u, downloads.size());
631 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, downloads[0]->GetState());
632
633 // Installs observers before requesting the completion.
634 NotificationAddObserver download_notification_add_observer;
635 content::DownloadTestObserverTerminal download_terminal_observer(
636 download_manager,
637 1u, /* wait_count */
638 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
639
640 // Requests to fail the download and wait for it.
641 ui_test_utils::NavigateToURL(
642 browser(), GURL(net::URLRequestSlowDownloadJob::kErrorDownloadUrl));
643 download_terminal_observer.WaitForFinished();
644
645 // Waits that new notification is popped up.
646 download_notification_add_observer.Wait();
647
648 // Confirms that there is only one notification.
649 message_center::NotificationList::Notifications
650 visible_notifications = GetMessageCenter()->GetVisibleNotifications();
651 EXPECT_EQ(1u, visible_notifications.size());
652 EXPECT_TRUE(IsInNotifications(visible_notifications, notification_id()));
539 } 653 }
540 654
541 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DownloadRemoved) { 655 IN_PROC_BROWSER_TEST_F(DownloadNotificationTest, DownloadRemoved) {
542 CreateDownload(); 656 CreateDownload();
543 657
544 NotificationRemoveObserver notification_close_observer; 658 NotificationRemoveObserver notification_close_observer;
545 download_item()->Remove(); 659 download_item()->Remove();
546 EXPECT_EQ(notification_id(), notification_close_observer.Wait()); 660 EXPECT_EQ(notification_id(), notification_close_observer.Wait());
547 661
548 // Confirms that the notification is removed. 662 // Confirms that the notification is removed.
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 } 1044 }
931 1045
932 // Confirms the types of download notifications are correct. 1046 // Confirms the types of download notifications are correct.
933 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, 1047 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE,
934 GetNotification(notification_id1)->type()); 1048 GetNotification(notification_id1)->type());
935 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, 1049 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE,
936 GetNotification(notification_id2)->type()); 1050 GetNotification(notification_id2)->type());
937 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, 1051 EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE,
938 GetNotification(notification_id3)->type()); 1052 GetNotification(notification_id3)->type());
939 } 1053 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698