summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorpeter <peter@chromium.org>2015-03-20 12:14:40 -0700
committerCommit bot <commit-bot@chromium.org>2015-03-20 19:15:31 +0000
commitd5c5bf15d23b854079b1494e0a44210e30cce79f (patch)
tree474925d94f5dfc75e930aea39295f5b23568bd99 /content
parentfd697fc2963b8adccc629356fd94cbc08f3b9880 (diff)
downloadchromium_src-d5c5bf15d23b854079b1494e0a44210e30cce79f.zip
chromium_src-d5c5bf15d23b854079b1494e0a44210e30cce79f.tar.gz
chromium_src-d5c5bf15d23b854079b1494e0a44210e30cce79f.tar.bz2
Write the assigned notification id to the stored notification data.
This makes sure that when the notifications are being retrieved, they always have the appropriate ID set. BUG=447628 Review URL: https://codereview.chromium.org/1025743002 Cr-Commit-Position: refs/heads/master@{#321611}
Diffstat (limited to 'content')
-rw-r--r--content/browser/notifications/notification_database.cc9
-rw-r--r--content/browser/notifications/notification_database_unittest.cc27
2 files changed, 32 insertions, 4 deletions
diff --git a/content/browser/notifications/notification_database.cc b/content/browser/notifications/notification_database.cc
index 25350b9..f97ef4c 100644
--- a/content/browser/notifications/notification_database.cc
+++ b/content/browser/notifications/notification_database.cc
@@ -189,16 +189,19 @@ NotificationDatabase::Status NotificationDatabase::WriteNotificationData(
DCHECK(notification_id);
DCHECK(origin.is_valid());
+ DCHECK_GE(next_notification_id_, kFirstNotificationId);
+
+ NotificationDatabaseData storage_data = notification_database_data;
+ storage_data.notification_id = next_notification_id_;
+
std::string serialized_data;
- if (!SerializeNotificationDatabaseData(notification_database_data,
+ if (!SerializeNotificationDatabaseData(storage_data,
&serialized_data)) {
DLOG(ERROR) << "Unable to serialize data for a notification belonging "
<< "to: " << origin;
return STATUS_ERROR_FAILED;
}
- DCHECK_GE(next_notification_id_, kFirstNotificationId);
-
leveldb::WriteBatch batch;
batch.Put(CreateDataKey(origin, next_notification_id_), serialized_data);
batch.Put(kNextNotificationIdKey,
diff --git a/content/browser/notifications/notification_database_unittest.cc b/content/browser/notifications/notification_database_unittest.cc
index 207b238..65c537e 100644
--- a/content/browser/notifications/notification_database_unittest.cc
+++ b/content/browser/notifications/notification_database_unittest.cc
@@ -199,6 +199,30 @@ TEST_F(NotificationDatabaseTest, NotificationIdIncrements) {
EXPECT_EQ(notification_id, 3);
}
+TEST_F(NotificationDatabaseTest, NotificationIdIncrementsStorage) {
+ scoped_ptr<NotificationDatabase> database(CreateDatabaseInMemory());
+ ASSERT_EQ(NotificationDatabase::STATUS_OK,
+ database->Open(true /* create_if_missing */));
+
+ GURL origin("https://example.com");
+
+ NotificationDatabaseData database_data;
+ database_data.notification_id = -1;
+
+ int64_t notification_id = 0;
+ ASSERT_EQ(NotificationDatabase::STATUS_OK,
+ database->WriteNotificationData(origin,
+ database_data,
+ &notification_id));
+
+ ASSERT_EQ(NotificationDatabase::STATUS_OK,
+ database->ReadNotificationData(notification_id,
+ origin,
+ &database_data));
+
+ EXPECT_EQ(notification_id, database_data.notification_id);
+}
+
TEST_F(NotificationDatabaseTest, NotificationIdCorruption) {
base::ScopedTempDir database_dir;
ASSERT_TRUE(database_dir.CreateUniqueTempDir());
@@ -322,7 +346,8 @@ TEST_F(NotificationDatabaseTest, ReadNotificationDataReflection) {
// Verify that all members retrieved from the database are exactly the same
// as the ones that were written to it. This tests the serialization behavior.
- EXPECT_EQ(database_data.notification_id, read_database_data.notification_id);
+ EXPECT_EQ(notification_id, read_database_data.notification_id);
+
EXPECT_EQ(database_data.origin, read_database_data.origin);
EXPECT_EQ(database_data.service_worker_registration_id,
read_database_data.service_worker_registration_id);