Chromium Code Reviews| 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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 notification_id(), | 274 notification_id(), |
| 273 origin, | 275 origin, |
| 274 base::Bind(&PlatformNotificationContextTest::DidReadNotificationData, | 276 base::Bind(&PlatformNotificationContextTest::DidReadNotificationData, |
| 275 base::Unretained(this))); | 277 base::Unretained(this))); |
| 276 | 278 |
| 277 base::RunLoop().RunUntilIdle(); | 279 base::RunLoop().RunUntilIdle(); |
| 278 | 280 |
| 279 EXPECT_FALSE(success()); | 281 EXPECT_FALSE(success()); |
| 280 } | 282 } |
| 281 | 283 |
| 284 TEST_F(PlatformNotificationContextTest, DestroyDatabaseOnStorageWiped) { | |
| 285 scoped_refptr<PlatformNotificationContextImpl> context = | |
| 286 CreatePlatformNotificationContext(); | |
| 287 | |
| 288 GURL origin("https://example.com"); | |
| 289 NotificationDatabaseData notification_database_data; | |
| 290 | |
| 291 context->WriteNotificationData( | |
| 292 origin, | |
| 293 notification_database_data, | |
| 294 base::Bind(&PlatformNotificationContextTest::DidWriteNotificationData, | |
| 295 base::Unretained(this))); | |
| 296 | |
| 297 base::RunLoop().RunUntilIdle(); | |
|
johnme
2015/03/20 15:29:06
As in https://codereview.chromium.org/1014703007/,
Peter Beverloo
2015/03/20 18:55:37
As replied there - it's not flaky because they're
| |
| 298 | |
| 299 // The write operation should have succeeded with a notification id. | |
| 300 ASSERT_TRUE(success()); | |
| 301 EXPECT_GT(notification_id(), 0); | |
| 302 | |
| 303 // Call the OnStorageWiped override from the ServiceWorkerContextObserver, | |
| 304 // which indicates that the database should go away entirely. | |
| 305 context->OnStorageWiped(); | |
| 306 | |
| 307 // Verify that reading notification data fails because the data does not | |
| 308 // exist anymore. Deliberately omit RunUntilIdle(), since this is unlikely to | |
| 309 // be the case when OnStorageWiped gets called in production. | |
| 310 context->ReadNotificationData( | |
| 311 notification_id(), | |
| 312 origin, | |
| 313 base::Bind(&PlatformNotificationContextTest::DidReadNotificationData, | |
| 314 base::Unretained(this))); | |
| 315 | |
| 316 base::RunLoop().RunUntilIdle(); | |
| 317 | |
| 318 EXPECT_FALSE(success()); | |
| 319 } | |
| 320 | |
| 321 TEST_F(PlatformNotificationContextTest, DestroyOnDiskDatabase) { | |
| 322 base::ScopedTempDir database_dir; | |
| 323 ASSERT_TRUE(database_dir.CreateUniqueTempDir()); | |
| 324 | |
| 325 // Manually construct the PlatformNotificationContextImpl because this test | |
| 326 // requires the database to be created on the filesystem. | |
| 327 scoped_refptr<PlatformNotificationContextImpl> context( | |
| 328 new PlatformNotificationContextImpl(database_dir.path(), nullptr)); | |
| 329 | |
| 330 OverrideTaskRunnerForTesting(context.get()); | |
| 331 | |
| 332 // Trigger a read-operation to force creating the database. | |
| 333 context->ReadNotificationData( | |
| 334 42 /* notification_id */, | |
| 335 GURL("https://example.com"), | |
| 336 base::Bind(&PlatformNotificationContextTest::DidReadNotificationData, | |
| 337 base::Unretained(this))); | |
| 338 | |
| 339 base::RunLoop().RunUntilIdle(); | |
| 340 | |
| 341 EXPECT_FALSE(success()); | |
| 342 | |
| 343 // Blow away the database by faking a Service Worker Context wipe-out. | |
| 344 context->OnStorageWiped(); | |
| 345 | |
| 346 base::RunLoop().RunUntilIdle(); | |
| 347 | |
| 348 // The database's directory should be empty at this point. | |
| 349 EXPECT_TRUE(IsDirectoryEmpty(database_dir.path())); | |
|
johnme
2015/03/20 15:29:06
It's not immediately obvious that a read operation
Peter Beverloo
2015/03/20 18:55:37
Done.
| |
| 350 } | |
| 351 | |
| 282 } // namespace content | 352 } // namespace content |
| OLD | NEW |