Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes unable to clear notification #1427

Merged
merged 1 commit into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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