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 std::vector<std::string> notifications = base::SplitString( | |
Peter Beverloo
2016/12/02 13:43:34
Consider using (from <algorithm>):
ASSERT_EQ(1,
Miguel Garcia
2016/12/06 12:01:18
I rather count the elements, if I count the separa
| |
603 script_message, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | |
604 ASSERT_EQ(2u, notifications.size()); | |
605 | |
606 // Now remove one notifications straight from the ui manager | |
607 // without going through the database. | |
608 // GetNotifications should report the correct number. | |
609 const Notification& notification = ui_manager()->GetNotificationAt(1); | |
610 base::StringPiece notification_id(notification.id()); | |
611 ASSERT_TRUE(notification_id.starts_with("p:")); | |
Peter Beverloo
2016/12/02 13:43:34
ASSERT_TRUE(
base::StartsWith(notification.i
Miguel Garcia
2016/12/06 12:01:18
Done.
| |
612 ASSERT_TRUE(ui_manager()->ClearNotificationById( | |
613 notification.delegate_id(), | |
614 NotificationUIManager::GetProfileID(browser()->profile()))); | |
615 ASSERT_TRUE(RunScript("GetDisplayedNotifications()", &script_result)); | |
616 EXPECT_EQ("ok", script_result); | |
617 | |
618 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_message)); | |
619 notifications = base::SplitString(script_message, ",", base::KEEP_WHITESPACE, | |
620 base::SPLIT_WANT_ALL); | |
621 ASSERT_EQ(1u, notifications.size()); | |
622 } | |
623 | |
624 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | |
580 TestShouldDisplayNormal) { | 625 TestShouldDisplayNormal) { |
581 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); | 626 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); |
582 EnableFullscreenNotifications(); | 627 EnableFullscreenNotifications(); |
583 | 628 |
584 std::string script_result; | 629 std::string script_result; |
585 ASSERT_TRUE(RunScript( | 630 ASSERT_TRUE(RunScript( |
586 "DisplayPersistentNotification('display_normal')", &script_result)); | 631 "DisplayPersistentNotification('display_normal')", &script_result)); |
587 EXPECT_EQ("ok", script_result); | 632 EXPECT_EQ("ok", script_result); |
588 | 633 |
589 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 634 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 RunScript("DisplayPersistentAllOptionsNotification()", &script_result)); | 773 RunScript("DisplayPersistentAllOptionsNotification()", &script_result)); |
729 EXPECT_EQ("ok", script_result); | 774 EXPECT_EQ("ok", script_result); |
730 | 775 |
731 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); | 776 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
732 const Notification& notification = ui_manager()->GetNotificationAt(0); | 777 const Notification& notification = ui_manager()->GetNotificationAt(0); |
733 | 778 |
734 // Since the kNotificationContentImage kill switch has disabled images, the | 779 // Since the kNotificationContentImage kill switch has disabled images, the |
735 // notification should be shown without an image. | 780 // notification should be shown without an image. |
736 EXPECT_TRUE(notification.image().IsEmpty()); | 781 EXPECT_TRUE(notification.image().IsEmpty()); |
737 } | 782 } |
OLD | NEW |