| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/notifications/notification_database.h" | 5 #include "content/browser/notifications/notification_database.h" |
| 6 | 6 |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/public/browser/notification_database_data.h" | 10 #include "content/public/browser/notification_database_data.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 ASSERT_EQ(NotificationDatabase::STATUS_OK, | 192 ASSERT_EQ(NotificationDatabase::STATUS_OK, |
| 193 database->Open(false /* create_if_missing */)); | 193 database->Open(false /* create_if_missing */)); |
| 194 | 194 |
| 195 // Verify that the next notification id was stored in the database, and | 195 // Verify that the next notification id was stored in the database, and |
| 196 // continues where we expect it to be, even after closing and opening it. | 196 // continues where we expect it to be, even after closing and opening it. |
| 197 ASSERT_NO_FATAL_FAILURE(CreateAndWriteNotification( | 197 ASSERT_NO_FATAL_FAILURE(CreateAndWriteNotification( |
| 198 database.get(), origin, 0 /* sw_registration_id */, ¬ification_id)); | 198 database.get(), origin, 0 /* sw_registration_id */, ¬ification_id)); |
| 199 EXPECT_EQ(notification_id, 3); | 199 EXPECT_EQ(notification_id, 3); |
| 200 } | 200 } |
| 201 | 201 |
| 202 TEST_F(NotificationDatabaseTest, NotificationIdIncrementsStorage) { |
| 203 scoped_ptr<NotificationDatabase> database(CreateDatabaseInMemory()); |
| 204 ASSERT_EQ(NotificationDatabase::STATUS_OK, |
| 205 database->Open(true /* create_if_missing */)); |
| 206 |
| 207 GURL origin("https://example.com"); |
| 208 |
| 209 NotificationDatabaseData database_data; |
| 210 database_data.notification_id = -1; |
| 211 |
| 212 int64_t notification_id = 0; |
| 213 ASSERT_EQ(NotificationDatabase::STATUS_OK, |
| 214 database->WriteNotificationData(origin, |
| 215 database_data, |
| 216 ¬ification_id)); |
| 217 |
| 218 ASSERT_EQ(NotificationDatabase::STATUS_OK, |
| 219 database->ReadNotificationData(notification_id, |
| 220 origin, |
| 221 &database_data)); |
| 222 |
| 223 EXPECT_EQ(notification_id, database_data.notification_id); |
| 224 } |
| 225 |
| 202 TEST_F(NotificationDatabaseTest, NotificationIdCorruption) { | 226 TEST_F(NotificationDatabaseTest, NotificationIdCorruption) { |
| 203 base::ScopedTempDir database_dir; | 227 base::ScopedTempDir database_dir; |
| 204 ASSERT_TRUE(database_dir.CreateUniqueTempDir()); | 228 ASSERT_TRUE(database_dir.CreateUniqueTempDir()); |
| 205 | 229 |
| 206 scoped_ptr<NotificationDatabase> database( | 230 scoped_ptr<NotificationDatabase> database( |
| 207 CreateDatabaseOnFileSystem(database_dir.path())); | 231 CreateDatabaseOnFileSystem(database_dir.path())); |
| 208 | 232 |
| 209 ASSERT_EQ(NotificationDatabase::STATUS_OK, | 233 ASSERT_EQ(NotificationDatabase::STATUS_OK, |
| 210 database->Open(true /* create_if_missing */)); | 234 database->Open(true /* create_if_missing */)); |
| 211 | 235 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 | 339 |
| 316 NotificationDatabaseData read_database_data; | 340 NotificationDatabaseData read_database_data; |
| 317 ASSERT_EQ(NotificationDatabase::STATUS_OK, | 341 ASSERT_EQ(NotificationDatabase::STATUS_OK, |
| 318 database->ReadNotificationData(notification_id, | 342 database->ReadNotificationData(notification_id, |
| 319 origin, | 343 origin, |
| 320 &read_database_data)); | 344 &read_database_data)); |
| 321 | 345 |
| 322 // Verify that all members retrieved from the database are exactly the same | 346 // Verify that all members retrieved from the database are exactly the same |
| 323 // as the ones that were written to it. This tests the serialization behavior. | 347 // as the ones that were written to it. This tests the serialization behavior. |
| 324 | 348 |
| 325 EXPECT_EQ(database_data.notification_id, read_database_data.notification_id); | 349 EXPECT_EQ(notification_id, read_database_data.notification_id); |
| 350 |
| 326 EXPECT_EQ(database_data.origin, read_database_data.origin); | 351 EXPECT_EQ(database_data.origin, read_database_data.origin); |
| 327 EXPECT_EQ(database_data.service_worker_registration_id, | 352 EXPECT_EQ(database_data.service_worker_registration_id, |
| 328 read_database_data.service_worker_registration_id); | 353 read_database_data.service_worker_registration_id); |
| 329 | 354 |
| 330 const PlatformNotificationData& read_notification_data = | 355 const PlatformNotificationData& read_notification_data = |
| 331 read_database_data.notification_data; | 356 read_database_data.notification_data; |
| 332 | 357 |
| 333 EXPECT_EQ(notification_data.title, read_notification_data.title); | 358 EXPECT_EQ(notification_data.title, read_notification_data.title); |
| 334 EXPECT_EQ(notification_data.direction, read_notification_data.direction); | 359 EXPECT_EQ(notification_data.direction, read_notification_data.direction); |
| 335 EXPECT_EQ(notification_data.lang, read_notification_data.lang); | 360 EXPECT_EQ(notification_data.lang, read_notification_data.lang); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 | 583 |
| 559 std::vector<NotificationDatabaseData> notifications; | 584 std::vector<NotificationDatabaseData> notifications; |
| 560 ASSERT_EQ(NotificationDatabase::STATUS_OK, | 585 ASSERT_EQ(NotificationDatabase::STATUS_OK, |
| 561 database->ReadAllNotificationDataForServiceWorkerRegistration( | 586 database->ReadAllNotificationDataForServiceWorkerRegistration( |
| 562 origin, kExampleServiceWorkerRegistrationId, ¬ifications)); | 587 origin, kExampleServiceWorkerRegistrationId, ¬ifications)); |
| 563 | 588 |
| 564 EXPECT_EQ(0u, notifications.size()); | 589 EXPECT_EQ(0u, notifications.size()); |
| 565 } | 590 } |
| 566 | 591 |
| 567 } // namespace content | 592 } // namespace content |
| OLD | NEW |