Index: content/browser/notifications/platform_notification_context_unittest.cc |
diff --git a/content/browser/notifications/platform_notification_context_unittest.cc b/content/browser/notifications/platform_notification_context_unittest.cc |
index 30672719e5a10278a382f60bb9f71a70e32977ae..46b46b8589736ffefe9c3c80726d8529f9c4bb24 100644 |
--- a/content/browser/notifications/platform_notification_context_unittest.cc |
+++ b/content/browser/notifications/platform_notification_context_unittest.cc |
@@ -32,6 +32,11 @@ class PlatformNotificationContextTest : public ::testing::Test { |
notification_id_ = notification_id; |
} |
+ // Callback to provide when deleting notification data from the database. |
+ void DidDeleteNotificationData(bool success) { |
+ success_ = success; |
+ } |
+ |
protected: |
// Creates a new PlatformNotificationContext instance. When using this method, |
// the underlying database will always be created in memory. The current |
@@ -115,4 +120,66 @@ TEST_F(PlatformNotificationContextTest, WriteReadNotification) { |
EXPECT_EQ(notification_database_data.origin, read_database_data.origin); |
} |
+TEST_F(PlatformNotificationContextTest, DeleteInvalidNotification) { |
+ scoped_refptr<PlatformNotificationContext> context = |
+ CreatePlatformNotificationContext(); |
+ |
+ context->DeleteNotificationData( |
+ 42 /* notification_id */, |
+ GURL("https://example.com"), |
+ base::Bind(&PlatformNotificationContextTest::DidDeleteNotificationData, |
+ base::Unretained(this))); |
+ |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ // The notification did not exist, so DeleteNotificationData() should inform |
+ // us of that. Most callers won't actually care about this return status |
+ // except for correctness reasons - their goal has been satisfied: the data |
+ // does not exist in the database. |
+ EXPECT_FALSE(success()); |
+} |
+ |
+TEST_F(PlatformNotificationContextTest, DeleteNotification) { |
+ scoped_refptr<PlatformNotificationContext> context = |
+ CreatePlatformNotificationContext(); |
+ |
+ GURL origin("https://example.com"); |
+ NotificationDatabaseData notification_database_data; |
+ |
+ context->WriteNotificationData( |
+ origin, |
+ notification_database_data, |
+ base::Bind(&PlatformNotificationContextTest::DidWriteNotificationData, |
+ base::Unretained(this))); |
+ |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ // The write operation should have succeeded with a notification id. |
+ ASSERT_TRUE(success()); |
+ EXPECT_GT(notification_id(), 0); |
+ |
+ context->DeleteNotificationData( |
+ notification_id(), |
+ origin, |
+ base::Bind(&PlatformNotificationContextTest::DidDeleteNotificationData, |
+ base::Unretained(this))); |
+ |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ // The notification existed, so it should have been removed successfully. |
+ ASSERT_TRUE(success()); |
+ |
+ context->ReadNotificationData( |
+ notification_id(), |
+ origin, |
+ base::Bind(&PlatformNotificationContextTest::DidReadNotificationData, |
+ base::Unretained(this))); |
+ |
+ base::RunLoop().RunUntilIdle(); |
+ |
+ // The notification was removed, so we shouldn't be able to read it from |
+ // the database anymore. |
+ EXPECT_FALSE(success()); |
+} |
+ |
} // namespace content |