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 // GetNotifications should report the correct number. | |
Peter Beverloo
2016/12/13 11:41:12
nit: 609 is a stray comment line? what does it rel
Miguel Garcia
2016/12/13 16:43:09
It meant that GetNotifications should still report
| |
610 const Notification& notification = ui_manager()->GetNotificationAt(1); | |
611 | |
612 // p: is the prefix for persistent notifications. See | |
613 // content/browser/notifications/notification_id_generator.{h,cc} for details | |
614 ASSERT_TRUE( | |
615 base::StartsWith(notification.id(), "p:", base::CompareCase::SENSITIVE)); | |
616 ASSERT_TRUE(ui_manager()->SilentDismissById( | |
617 notification.delegate_id(), | |
618 NotificationUIManager::GetProfileID(browser()->profile()))); | |
619 ASSERT_TRUE(RunScript("GetDisplayedNotifications()", &script_result)); | |
620 EXPECT_EQ("ok", script_result); | |
621 | |
622 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_message)); | |
623 notifications = base::SplitString(script_message, ",", base::KEEP_WHITESPACE, | |
624 base::SPLIT_WANT_ALL); | |
625 ASSERT_EQ(1u, notifications.size()); | |
626 } | |
627 | |
628 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | |
580 TestShouldDisplayNormal) { | 629 TestShouldDisplayNormal) { |
581 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); | 630 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); |
582 EnableFullscreenNotifications(); | 631 EnableFullscreenNotifications(); |
583 | 632 |
584 std::string script_result; | 633 std::string script_result; |
585 ASSERT_TRUE(RunScript( | 634 ASSERT_TRUE(RunScript( |
586 "DisplayPersistentNotification('display_normal')", &script_result)); | 635 "DisplayPersistentNotification('display_normal')", &script_result)); |
587 EXPECT_EQ("ok", script_result); | 636 EXPECT_EQ("ok", script_result); |
588 | 637 |
589 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 638 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 RunScript("DisplayPersistentAllOptionsNotification()", &script_result)); | 777 RunScript("DisplayPersistentAllOptionsNotification()", &script_result)); |
729 EXPECT_EQ("ok", script_result); | 778 EXPECT_EQ("ok", script_result); |
730 | 779 |
731 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 780 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
732 const Notification& notification = ui_manager()->GetNotificationAt(0); | 781 const Notification& notification = ui_manager()->GetNotificationAt(0); |
733 | 782 |
734 // Since the kNotificationContentImage kill switch has disabled images, the | 783 // Since the kNotificationContentImage kill switch has disabled images, the |
735 // notification should be shown without an image. | 784 // notification should be shown without an image. |
736 EXPECT_TRUE(notification.image().IsEmpty()); | 785 EXPECT_TRUE(notification.image().IsEmpty()); |
737 } | 786 } |
OLD | NEW |