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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/files/file_util.h" |
| 7 #include "base/files/scoped_temp_dir.h" |
6 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
7 #include "content/browser/notifications/platform_notification_context_impl.h" | 9 #include "content/browser/notifications/platform_notification_context_impl.h" |
8 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 10 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
9 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 11 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
10 #include "content/common/service_worker/service_worker_types.h" | 12 #include "content/common/service_worker/service_worker_types.h" |
11 #include "content/public/browser/notification_database_data.h" | 13 #include "content/public/browser/notification_database_data.h" |
12 #include "content/public/test/test_browser_thread_bundle.h" | 14 #include "content/public/test/test_browser_thread_bundle.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "url/gurl.h" | 16 #include "url/gurl.h" |
15 | 17 |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 notification_id(), | 276 notification_id(), |
275 origin, | 277 origin, |
276 base::Bind(&PlatformNotificationContextTest::DidReadNotificationData, | 278 base::Bind(&PlatformNotificationContextTest::DidReadNotificationData, |
277 base::Unretained(this))); | 279 base::Unretained(this))); |
278 | 280 |
279 base::RunLoop().RunUntilIdle(); | 281 base::RunLoop().RunUntilIdle(); |
280 | 282 |
281 EXPECT_FALSE(success()); | 283 EXPECT_FALSE(success()); |
282 } | 284 } |
283 | 285 |
| 286 TEST_F(PlatformNotificationContextTest, DestroyDatabaseOnStorageWiped) { |
| 287 scoped_refptr<PlatformNotificationContextImpl> context = |
| 288 CreatePlatformNotificationContext(); |
| 289 |
| 290 GURL origin("https://example.com"); |
| 291 NotificationDatabaseData notification_database_data; |
| 292 |
| 293 context->WriteNotificationData( |
| 294 origin, |
| 295 notification_database_data, |
| 296 base::Bind(&PlatformNotificationContextTest::DidWriteNotificationData, |
| 297 base::Unretained(this))); |
| 298 |
| 299 base::RunLoop().RunUntilIdle(); |
| 300 |
| 301 // The write operation should have succeeded with a notification id. |
| 302 ASSERT_TRUE(success()); |
| 303 EXPECT_GT(notification_id(), 0); |
| 304 |
| 305 // Call the OnStorageWiped override from the ServiceWorkerContextObserver, |
| 306 // which indicates that the database should go away entirely. |
| 307 context->OnStorageWiped(); |
| 308 |
| 309 // Verify that reading notification data fails because the data does not |
| 310 // exist anymore. Deliberately omit RunUntilIdle(), since this is unlikely to |
| 311 // be the case when OnStorageWiped gets called in production. |
| 312 context->ReadNotificationData( |
| 313 notification_id(), |
| 314 origin, |
| 315 base::Bind(&PlatformNotificationContextTest::DidReadNotificationData, |
| 316 base::Unretained(this))); |
| 317 |
| 318 base::RunLoop().RunUntilIdle(); |
| 319 |
| 320 EXPECT_FALSE(success()); |
| 321 } |
| 322 |
| 323 TEST_F(PlatformNotificationContextTest, DestroyOnDiskDatabase) { |
| 324 base::ScopedTempDir database_dir; |
| 325 ASSERT_TRUE(database_dir.CreateUniqueTempDir()); |
| 326 |
| 327 // Manually construct the PlatformNotificationContextImpl because this test |
| 328 // requires the database to be created on the filesystem. |
| 329 scoped_refptr<PlatformNotificationContextImpl> context( |
| 330 new PlatformNotificationContextImpl(database_dir.path(), nullptr)); |
| 331 |
| 332 OverrideTaskRunnerForTesting(context.get()); |
| 333 |
| 334 // Trigger a read-operation to force creating the database. |
| 335 context->ReadNotificationData( |
| 336 42 /* notification_id */, |
| 337 GURL("https://example.com"), |
| 338 base::Bind(&PlatformNotificationContextTest::DidReadNotificationData, |
| 339 base::Unretained(this))); |
| 340 |
| 341 base::RunLoop().RunUntilIdle(); |
| 342 |
| 343 EXPECT_FALSE(IsDirectoryEmpty(database_dir.path())); |
| 344 EXPECT_FALSE(success()); |
| 345 |
| 346 // Blow away the database by faking a Service Worker Context wipe-out. |
| 347 context->OnStorageWiped(); |
| 348 |
| 349 base::RunLoop().RunUntilIdle(); |
| 350 |
| 351 // The database's directory should be empty at this point. |
| 352 EXPECT_TRUE(IsDirectoryEmpty(database_dir.path())); |
| 353 } |
| 354 |
284 } // namespace content | 355 } // namespace content |
OLD | NEW |