Commit 5fe97d36 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Notification scheduler: Invoke callback when scheduling notification.

For a few failure cases, we should invoke the ScheduleCallback and
reports a failure in ScheduledNotificationManager.

Bug: 998998
Change-Id: I22e623001412007e05d7788d15267992b5c9ab11
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1797138Reviewed-by: default avatarHesen Zhang <hesen@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695412}
parent 83d1f043
...@@ -101,6 +101,7 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager { ...@@ -101,6 +101,7 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager {
if (!clients_.count(type) || if (!clients_.count(type) ||
(notifications_.count(type) && notifications_[type].count(guid))) { (notifications_.count(type) && notifications_[type].count(guid))) {
// TODO(xingliu): Report duplicate guid failure. // TODO(xingliu): Report duplicate guid failure.
std::move(callback).Run(false);
return; return;
} }
...@@ -109,6 +110,7 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager { ...@@ -109,6 +110,7 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager {
if (!valid) { if (!valid) {
stats::LogNotificationLifeCycleEvent( stats::LogNotificationLifeCycleEvent(
stats::NotificationLifeCycleEvent::kInvalidInput, type); stats::NotificationLifeCycleEvent::kInvalidInput, type);
std::move(callback).Run(false);
return; return;
} }
......
...@@ -345,6 +345,43 @@ TEST_F(ScheduledNotificationManagerTest, ScheduleNotification) { ...@@ -345,6 +345,43 @@ TEST_F(ScheduledNotificationManagerTest, ScheduleNotification) {
EXPECT_EQ(buttons[1].type, ActionButtonType::kUnhelpful); EXPECT_EQ(buttons[1].type, ActionButtonType::kUnhelpful);
} }
// Verifies that schedules a notification with unregistered client will fail.
TEST_F(ScheduledNotificationManagerTest, ScheduleInvalidNotification) {
InitWithData(std::vector<NotificationEntry>());
NotificationData notification_data;
notification_data.title = base::UTF8ToUTF16(kTitle);
ScheduleParams schedule_params;
// Client type kTest3 is not registered.
auto params = std::make_unique<NotificationParams>(
SchedulerClientType::kTest3, notification_data, schedule_params);
EXPECT_CALL(*icon_store(), AddIcons(_, _)).Times(0);
EXPECT_CALL(*notification_store(), Add(_, _, _)).Times(0);
ScheduleNotification(std::move(params), false /*expected_success*/);
}
// Verifies that schedules a notification with duplicate guid will fail.
TEST_F(ScheduledNotificationManagerTest, ScheduleNotificationDuplicateGuid) {
auto entry = CreateNotificationEntry(SchedulerClientType::kTest1);
entry.guid = kGuid;
InitWithData(std::vector<NotificationEntry>({entry}));
NotificationData notification_data;
notification_data.title = base::UTF8ToUTF16(kTitle);
ScheduleParams schedule_params;
auto params = std::make_unique<NotificationParams>(
SchedulerClientType::kTest1, notification_data, schedule_params);
params->schedule_params.deliver_time_start = base::Time::Now();
params->schedule_params.deliver_time_end =
base::Time::Now() + base::TimeDelta::FromDays(1);
// Duplicate guid.
params->guid = kGuid;
EXPECT_CALL(*icon_store(), AddIcons(_, _)).Times(0);
EXPECT_CALL(*notification_store(), Add(_, _, _)).Times(0);
ScheduleNotification(std::move(params), false /*expected_success*/);
}
// Test to schedule a notification without guid, we will auto generated one. // Test to schedule a notification without guid, we will auto generated one.
TEST_F(ScheduledNotificationManagerTest, ScheduleNotificationEmptyGuid) { TEST_F(ScheduledNotificationManagerTest, ScheduleNotificationEmptyGuid) {
InitWithData(std::vector<NotificationEntry>()); InitWithData(std::vector<NotificationEntry>());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment