Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(814)

Unified Diff: content/browser/notifications/platform_notification_context_unittest.cc

Issue 1057573002: Implement the ability to get all notifications in Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-db-Integrate
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 fc088c698d2b521098541b233038c18fae4bcdcf..6dca0d0534ce71211f730266881a624542858f75 100644
--- a/content/browser/notifications/platform_notification_context_unittest.cc
+++ b/content/browser/notifications/platform_notification_context_unittest.cc
@@ -20,6 +20,9 @@ namespace content {
// Fake render process id to use in tests requiring one.
const int kFakeRenderProcessId = 99;
+// Fake Service Worker registration id to use in tests requiring one.
+const int64_t kFakeServiceWorkerRegistrationId = 42;
+
class PlatformNotificationContextTest : public ::testing::Test {
public:
PlatformNotificationContextTest()
@@ -64,6 +67,19 @@ class PlatformNotificationContextTest : public ::testing::Test {
*store_status = status;
}
+ // Callback to provide when reading multiple notifications from the database.
+ // Will store the success value in the class member, and write the read
+ // notification datas to |store_notification_datas|.
+ void DidReadAllNotificationDatas(
+ std::vector<NotificationDatabaseData>* store_notification_datas,
+ bool success,
+ const std::vector<NotificationDatabaseData>& notification_datas) {
+ DCHECK(store_notification_datas);
+
+ success_ = success;
+ *store_notification_datas = notification_datas;
+ }
+
protected:
// Creates a new PlatformNotificationContextImpl instance. When using this
// method, the underlying database will always be created in memory. The
@@ -352,4 +368,71 @@ TEST_F(PlatformNotificationContextTest, DestroyOnDiskDatabase) {
EXPECT_TRUE(IsDirectoryEmpty(database_dir.path()));
}
+TEST_F(PlatformNotificationContextTest, ReadAllServiceWorkerDataEmpty) {
+ scoped_refptr<PlatformNotificationContextImpl> context =
+ CreatePlatformNotificationContext();
+
+ GURL origin("https://example.com");
+
+ std::vector<NotificationDatabaseData> notification_database_datas;
+ context->ReadAllNotificationDataForServiceWorkerRegistration(
+ origin,
+ kFakeServiceWorkerRegistrationId,
+ base::Bind(&PlatformNotificationContextTest::DidReadAllNotificationDatas,
+ base::Unretained(this),
+ &notification_database_datas));
+
+ base::RunLoop().RunUntilIdle();
+
+ EXPECT_TRUE(success());
+ EXPECT_EQ(0u, notification_database_datas.size());
+}
+
+TEST_F(PlatformNotificationContextTest, ReadAllServiceWorkerDataFilled) {
+ scoped_refptr<PlatformNotificationContextImpl> context =
+ CreatePlatformNotificationContext();
+
+ GURL origin("https://example.com");
+
+ NotificationDatabaseData notification_database_data;
+ notification_database_data.origin = origin;
+ notification_database_data.service_worker_registration_id =
+ kFakeServiceWorkerRegistrationId;
+
+ // Insert ten notifications into the database belonging to origin and the
+ // test Service Worker Registration id.
+ for (int i = 0; i < 10; ++i) {
+ context->WriteNotificationData(
+ origin,
+ notification_database_data,
+ base::Bind(&PlatformNotificationContextTest::DidWriteNotificationData,
+ base::Unretained(this)));
+
+ base::RunLoop().RunUntilIdle();
+
+ ASSERT_TRUE(success());
+ }
+
+ // Now read the notifications from the database again. There should be ten,
+ // all set with the correct origin and Service Worker Registration id.
+ std::vector<NotificationDatabaseData> notification_database_datas;
+ context->ReadAllNotificationDataForServiceWorkerRegistration(
+ origin,
+ kFakeServiceWorkerRegistrationId,
+ base::Bind(&PlatformNotificationContextTest::DidReadAllNotificationDatas,
+ base::Unretained(this),
+ &notification_database_datas));
+
+ base::RunLoop().RunUntilIdle();
+
+ ASSERT_TRUE(success());
+ ASSERT_EQ(10u, notification_database_datas.size());
+
+ for (int i = 0; i < 10; ++i) {
+ EXPECT_EQ(origin, notification_database_datas[i].origin);
+ EXPECT_EQ(kFakeServiceWorkerRegistrationId,
+ notification_database_datas[i].service_worker_registration_id);
+ }
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698