OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <memory> | 5 #include <memory> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/strings/string_piece.h" |
| 13 #include "base/strings/string_split.h" |
12 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
13 #include "base/test/scoped_feature_list.h" | 15 #include "base/test/scoped_feature_list.h" |
14 #include "base/time/time.h" | 16 #include "base/time/time.h" |
15 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 17 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
16 #include "chrome/browser/notifications/message_center_display_service.h" | 18 #include "chrome/browser/notifications/message_center_display_service.h" |
17 #include "chrome/browser/notifications/notification.h" | 19 #include "chrome/browser/notifications/notification.h" |
18 #include "chrome/browser/notifications/notification_test_util.h" | 20 #include "chrome/browser/notifications/notification_test_util.h" |
19 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 21 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
20 #include "chrome/browser/notifications/web_notification_delegate.h" | 22 #include "chrome/browser/notifications/web_notification_delegate.h" |
21 #include "chrome/browser/permissions/permission_manager.h" | 23 #include "chrome/browser/permissions/permission_manager.h" |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 const Notification& notification = ui_manager()->GetNotificationAt(0); | 572 const Notification& notification = ui_manager()->GetNotificationAt(0); |
571 ASSERT_EQ(1u, notification.buttons().size()); | 573 ASSERT_EQ(1u, notification.buttons().size()); |
572 EXPECT_EQ("actionTitle1", base::UTF16ToUTF8(notification.buttons()[0].title)); | 574 EXPECT_EQ("actionTitle1", base::UTF16ToUTF8(notification.buttons()[0].title)); |
573 | 575 |
574 notification.delegate()->ButtonClickWithReply(0, base::ASCIIToUTF16("hello")); | 576 notification.delegate()->ButtonClickWithReply(0, base::ASCIIToUTF16("hello")); |
575 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 577 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
576 EXPECT_EQ("action_button_click actionId1 hello", script_result); | 578 EXPECT_EQ("action_button_click actionId1 hello", script_result); |
577 } | 579 } |
578 | 580 |
579 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 581 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 582 GetDisplayedNotifications) { |
| 583 RequestAndAcceptPermission(); |
| 584 |
| 585 std::string script_result; |
| 586 std::string script_message; |
| 587 ASSERT_TRUE(RunScript("DisplayNonPersistentNotification('NonPersistent')", |
| 588 &script_result)); |
| 589 EXPECT_EQ("ok", script_result); |
| 590 ASSERT_TRUE(RunScript("DisplayPersistentNotification('PersistentI')", |
| 591 &script_result)); |
| 592 EXPECT_EQ("ok", script_result); |
| 593 ASSERT_TRUE(RunScript("DisplayPersistentNotification('PersistentII')", |
| 594 &script_result)); |
| 595 EXPECT_EQ("ok", script_result); |
| 596 |
| 597 // Only the persistent ones should show. |
| 598 ASSERT_TRUE(RunScript("GetDisplayedNotifications()", &script_result)); |
| 599 EXPECT_EQ("ok", script_result); |
| 600 |
| 601 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_message)); |
| 602 |
| 603 std::vector<std::string> notifications = base::SplitString( |
| 604 script_message, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 605 ASSERT_EQ(2u, notifications.size()); |
| 606 |
| 607 // Now remove one of the notifications straight from the ui manager |
| 608 // without going through the database. |
| 609 const Notification& notification = ui_manager()->GetNotificationAt(1); |
| 610 |
| 611 // p: is the prefix for persistent notifications. See |
| 612 // content/browser/notifications/notification_id_generator.{h,cc} for details |
| 613 ASSERT_TRUE( |
| 614 base::StartsWith(notification.id(), "p:", base::CompareCase::SENSITIVE)); |
| 615 ASSERT_TRUE(ui_manager()->SilentDismissById( |
| 616 notification.delegate_id(), |
| 617 NotificationUIManager::GetProfileID(browser()->profile()))); |
| 618 ASSERT_TRUE(RunScript("GetDisplayedNotifications()", &script_result)); |
| 619 EXPECT_EQ("ok", script_result); |
| 620 |
| 621 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_message)); |
| 622 notifications = base::SplitString(script_message, ",", base::KEEP_WHITESPACE, |
| 623 base::SPLIT_WANT_ALL); |
| 624 ASSERT_EQ(1u, notifications.size()); |
| 625 } |
| 626 |
| 627 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
580 TestShouldDisplayNormal) { | 628 TestShouldDisplayNormal) { |
581 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); | 629 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); |
582 EnableFullscreenNotifications(); | 630 EnableFullscreenNotifications(); |
583 | 631 |
584 std::string script_result; | 632 std::string script_result; |
585 ASSERT_TRUE(RunScript( | 633 ASSERT_TRUE(RunScript( |
586 "DisplayPersistentNotification('display_normal')", &script_result)); | 634 "DisplayPersistentNotification('display_normal')", &script_result)); |
587 EXPECT_EQ("ok", script_result); | 635 EXPECT_EQ("ok", script_result); |
588 | 636 |
589 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 637 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 RunScript("DisplayPersistentAllOptionsNotification()", &script_result)); | 776 RunScript("DisplayPersistentAllOptionsNotification()", &script_result)); |
729 EXPECT_EQ("ok", script_result); | 777 EXPECT_EQ("ok", script_result); |
730 | 778 |
731 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 779 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
732 const Notification& notification = ui_manager()->GetNotificationAt(0); | 780 const Notification& notification = ui_manager()->GetNotificationAt(0); |
733 | 781 |
734 // Since the kNotificationContentImage kill switch has disabled images, the | 782 // Since the kNotificationContentImage kill switch has disabled images, the |
735 // notification should be shown without an image. | 783 // notification should be shown without an image. |
736 EXPECT_TRUE(notification.image().IsEmpty()); | 784 EXPECT_TRUE(notification.image().IsEmpty()); |
737 } | 785 } |
OLD | NEW |