Skip to content

Commit

Permalink
Fixes unable to clear notification
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Jan 23, 2019
1 parent 5d1639d commit 135e96c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/test/browser_test_utils.h"
#include "rewards_notification_service.h"

using namespace brave_rewards;

Expand Down Expand Up @@ -46,8 +47,14 @@ class BraveRewardsNotificationBrowserTest
void OnNotificationDeleted(
RewardsNotificationService* rewards_notification_service,
const RewardsNotificationService::RewardsNotification& notification) override {
EXPECT_STREQ(notification.id_.c_str(), "rewards_notification_grant");
EXPECT_TRUE(notification.timestamp_ != 0);

if (notification.id_ == "not_valid") {
EXPECT_TRUE(notification.type_ ==
RewardsNotificationService::REWARDS_NOTIFICATION_INVALID);
} else {
EXPECT_STREQ(notification.id_.c_str(), "rewards_notification_grant");
EXPECT_TRUE(notification.timestamp_ != 0);
}

delete_notification_callback_was_called_ = true;
}
Expand Down Expand Up @@ -118,3 +125,23 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsNotificationBrowserTest, AddGrantNotification

rewards_notification_service_->RemoveObserver(this);
}

IN_PROC_BROWSER_TEST_F(BraveRewardsNotificationBrowserTest, AddGrantNotificationAndFakeItAndDeleteIt) {
rewards_notification_service_->AddObserver(this);

RewardsNotificationService::RewardsNotificationArgs args;
args.push_back("foo");
args.push_back("bar");

rewards_notification_service_->AddNotification(
RewardsNotificationService::REWARDS_NOTIFICATION_GRANT, args,
"rewards_notification_grant");
WaitForAddNotificationCallback();

EXPECT_STREQ(notification_id_.c_str(), "rewards_notification_grant");

rewards_notification_service_->DeleteNotification("not_valid");
WaitForDeleteNotificationCallback();

rewards_notification_service_->RemoveObserver(this);
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,19 @@ void RewardsNotificationServiceImpl::AddNotification(

void RewardsNotificationServiceImpl::DeleteNotification(RewardsNotificationID id) {
DCHECK(!id.empty());
if (rewards_notifications_.find(id) == rewards_notifications_.end())
return;
RewardsNotification rewards_notification = rewards_notifications_[id];
rewards_notifications_.erase(id);
RewardsNotification rewards_notification;
if (rewards_notifications_.find(id) == rewards_notifications_.end()) {
rewards_notification.id_ = id;
rewards_notification.type_ = RewardsNotificationType::REWARDS_NOTIFICATION_INVALID;

// clean up, so that we don't have long standing notifications
if (rewards_notifications_.size() == 1) {
rewards_notifications_.clear();
}
} else {
rewards_notification = rewards_notifications_[id];
rewards_notifications_.erase(id);
}
OnNotificationDeleted(rewards_notification);
}

Expand Down

0 comments on commit 135e96c

Please sign in to comment.