| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 EXPECT_FALSE(success()); | 389 EXPECT_FALSE(success()); |
| 390 } | 390 } |
| 391 | 391 |
| 392 TEST_F(PlatformNotificationContextTest, DestroyOnDiskDatabase) { | 392 TEST_F(PlatformNotificationContextTest, DestroyOnDiskDatabase) { |
| 393 base::ScopedTempDir database_dir; | 393 base::ScopedTempDir database_dir; |
| 394 ASSERT_TRUE(database_dir.CreateUniqueTempDir()); | 394 ASSERT_TRUE(database_dir.CreateUniqueTempDir()); |
| 395 | 395 |
| 396 // Manually construct the PlatformNotificationContextImpl because this test | 396 // Manually construct the PlatformNotificationContextImpl because this test |
| 397 // requires the database to be created on the filesystem. | 397 // requires the database to be created on the filesystem. |
| 398 scoped_refptr<PlatformNotificationContextImpl> context( | 398 scoped_refptr<PlatformNotificationContextImpl> context( |
| 399 new PlatformNotificationContextImpl(database_dir.path(), | 399 new PlatformNotificationContextImpl(database_dir.GetPath(), |
| 400 browser_context(), nullptr)); | 400 browser_context(), nullptr)); |
| 401 | 401 |
| 402 OverrideTaskRunnerForTesting(context.get()); | 402 OverrideTaskRunnerForTesting(context.get()); |
| 403 | 403 |
| 404 // Trigger a read-operation to force creating the database. | 404 // Trigger a read-operation to force creating the database. |
| 405 context->ReadNotificationData( | 405 context->ReadNotificationData( |
| 406 42 /* notification_id */, GURL("https://example.com"), | 406 42 /* notification_id */, GURL("https://example.com"), |
| 407 base::Bind(&PlatformNotificationContextTest::DidReadNotificationData, | 407 base::Bind(&PlatformNotificationContextTest::DidReadNotificationData, |
| 408 base::Unretained(this))); | 408 base::Unretained(this))); |
| 409 | 409 |
| 410 base::RunLoop().RunUntilIdle(); | 410 base::RunLoop().RunUntilIdle(); |
| 411 | 411 |
| 412 EXPECT_FALSE(IsDirectoryEmpty(database_dir.path())); | 412 EXPECT_FALSE(IsDirectoryEmpty(database_dir.GetPath())); |
| 413 EXPECT_FALSE(success()); | 413 EXPECT_FALSE(success()); |
| 414 | 414 |
| 415 // Blow away the database by faking a Service Worker Context wipe-out. | 415 // Blow away the database by faking a Service Worker Context wipe-out. |
| 416 context->OnStorageWiped(); | 416 context->OnStorageWiped(); |
| 417 | 417 |
| 418 base::RunLoop().RunUntilIdle(); | 418 base::RunLoop().RunUntilIdle(); |
| 419 | 419 |
| 420 // The database's directory should be empty at this point. | 420 // The database's directory should be empty at this point. |
| 421 EXPECT_TRUE(IsDirectoryEmpty(database_dir.path())); | 421 EXPECT_TRUE(IsDirectoryEmpty(database_dir.GetPath())); |
| 422 } | 422 } |
| 423 | 423 |
| 424 TEST_F(PlatformNotificationContextTest, ReadAllServiceWorkerDataEmpty) { | 424 TEST_F(PlatformNotificationContextTest, ReadAllServiceWorkerDataEmpty) { |
| 425 scoped_refptr<PlatformNotificationContextImpl> context = | 425 scoped_refptr<PlatformNotificationContextImpl> context = |
| 426 CreatePlatformNotificationContext(); | 426 CreatePlatformNotificationContext(); |
| 427 | 427 |
| 428 GURL origin("https://example.com"); | 428 GURL origin("https://example.com"); |
| 429 | 429 |
| 430 std::vector<NotificationDatabaseData> notification_database_datas; | 430 std::vector<NotificationDatabaseData> notification_database_datas; |
| 431 context->ReadAllNotificationDataForServiceWorkerRegistration( | 431 context->ReadAllNotificationDataForServiceWorkerRegistration( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 ASSERT_EQ(10u, notification_database_datas.size()); | 477 ASSERT_EQ(10u, notification_database_datas.size()); |
| 478 | 478 |
| 479 for (int i = 0; i < 10; ++i) { | 479 for (int i = 0; i < 10; ++i) { |
| 480 EXPECT_EQ(origin, notification_database_datas[i].origin); | 480 EXPECT_EQ(origin, notification_database_datas[i].origin); |
| 481 EXPECT_EQ(kFakeServiceWorkerRegistrationId, | 481 EXPECT_EQ(kFakeServiceWorkerRegistrationId, |
| 482 notification_database_datas[i].service_worker_registration_id); | 482 notification_database_datas[i].service_worker_registration_id); |
| 483 } | 483 } |
| 484 } | 484 } |
| 485 | 485 |
| 486 } // namespace content | 486 } // namespace content |
| OLD | NEW |