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/background_sync/background_sync_manager.h" | 5 #include "content/browser/background_sync/background_sync_manager.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "content/browser/background_sync/background_sync_network_observer.h" | 21 #include "content/browser/background_sync/background_sync_network_observer.h" |
22 #include "content/browser/background_sync/background_sync_status.h" | 22 #include "content/browser/background_sync/background_sync_status.h" |
23 #include "content/browser/browser_thread_impl.h" | 23 #include "content/browser/browser_thread_impl.h" |
24 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 24 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
25 #include "content/browser/service_worker/service_worker_context_core.h" | 25 #include "content/browser/service_worker/service_worker_context_core.h" |
26 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 26 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
27 #include "content/browser/service_worker/service_worker_storage.h" | 27 #include "content/browser/service_worker/service_worker_storage.h" |
28 #include "content/browser/storage_partition_impl.h" | 28 #include "content/browser/storage_partition_impl.h" |
29 #include "content/public/browser/background_sync_parameters.h" | 29 #include "content/public/browser/background_sync_parameters.h" |
30 #include "content/public/browser/permission_type.h" | 30 #include "content/public/browser/permission_type.h" |
31 #include "content/public/common/permission_status.mojom.h" | |
32 #include "content/public/test/background_sync_test_util.h" | 31 #include "content/public/test/background_sync_test_util.h" |
33 #include "content/public/test/test_browser_context.h" | 32 #include "content/public/test/test_browser_context.h" |
34 #include "content/public/test/test_browser_thread_bundle.h" | 33 #include "content/public/test/test_browser_thread_bundle.h" |
35 #include "content/test/mock_background_sync_controller.h" | 34 #include "content/test/mock_background_sync_controller.h" |
36 #include "content/test/mock_permission_manager.h" | 35 #include "content/test/mock_permission_manager.h" |
37 #include "content/test/test_background_sync_manager.h" | 36 #include "content/test/test_background_sync_manager.h" |
38 #include "net/base/network_change_notifier.h" | 37 #include "net/base/network_change_notifier.h" |
39 #include "testing/gmock/include/gmock/gmock.h" | 38 #include "testing/gmock/include/gmock/gmock.h" |
40 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
| 40 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
41 | 41 |
42 namespace content { | 42 namespace content { |
43 | 43 |
44 namespace { | 44 namespace { |
45 | 45 |
46 using ::testing::Return; | 46 using ::testing::Return; |
47 using ::testing::_; | 47 using ::testing::_; |
48 | 48 |
49 const char kPattern1[] = "https://example.com/a"; | 49 const char kPattern1[] = "https://example.com/a"; |
50 const char kPattern2[] = "https://example.com/b"; | 50 const char kPattern2[] = "https://example.com/b"; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 120 |
121 // TODO(jkarlin): Create a new object with all of the necessary SW calls | 121 // TODO(jkarlin): Create a new object with all of the necessary SW calls |
122 // so that we can inject test versions instead of bringing up all of this | 122 // so that we can inject test versions instead of bringing up all of this |
123 // extra SW stuff. | 123 // extra SW stuff. |
124 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); | 124 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); |
125 | 125 |
126 scoped_ptr<MockPermissionManager> mock_permission_manager( | 126 scoped_ptr<MockPermissionManager> mock_permission_manager( |
127 new testing::NiceMock<MockPermissionManager>()); | 127 new testing::NiceMock<MockPermissionManager>()); |
128 ON_CALL(*mock_permission_manager, | 128 ON_CALL(*mock_permission_manager, |
129 GetPermissionStatus(PermissionType::BACKGROUND_SYNC, _, _)) | 129 GetPermissionStatus(PermissionType::BACKGROUND_SYNC, _, _)) |
130 .WillByDefault(Return(mojom::PermissionStatus::GRANTED)); | 130 .WillByDefault(Return(blink::mojom::PermissionStatus::GRANTED)); |
131 helper_->browser_context()->SetPermissionManager( | 131 helper_->browser_context()->SetPermissionManager( |
132 std::move(mock_permission_manager)); | 132 std::move(mock_permission_manager)); |
133 | 133 |
134 // Create a StoragePartition with the correct BrowserContext so that the | 134 // Create a StoragePartition with the correct BrowserContext so that the |
135 // BackgroundSyncManager can find the BrowserContext through it. | 135 // BackgroundSyncManager can find the BrowserContext through it. |
136 storage_partition_impl_.reset(new StoragePartitionImpl( | 136 storage_partition_impl_.reset(new StoragePartitionImpl( |
137 helper_->browser_context(), base::FilePath(), nullptr, nullptr, nullptr, | 137 helper_->browser_context(), base::FilePath(), nullptr, nullptr, nullptr, |
138 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, | 138 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, |
139 nullptr, nullptr, nullptr, nullptr)); | 139 nullptr, nullptr, nullptr, nullptr)); |
140 helper_->context_wrapper()->set_storage_partition( | 140 helper_->context_wrapper()->set_storage_partition( |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 462 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
463 } | 463 } |
464 | 464 |
465 TEST_F(BackgroundSyncManagerTest, RegisterPermissionDenied) { | 465 TEST_F(BackgroundSyncManagerTest, RegisterPermissionDenied) { |
466 GURL expected_origin = GURL(kPattern1).GetOrigin(); | 466 GURL expected_origin = GURL(kPattern1).GetOrigin(); |
467 MockPermissionManager* mock_permission_manager = GetPermissionManager(); | 467 MockPermissionManager* mock_permission_manager = GetPermissionManager(); |
468 | 468 |
469 EXPECT_CALL(*mock_permission_manager, | 469 EXPECT_CALL(*mock_permission_manager, |
470 GetPermissionStatus(PermissionType::BACKGROUND_SYNC, | 470 GetPermissionStatus(PermissionType::BACKGROUND_SYNC, |
471 expected_origin, expected_origin)) | 471 expected_origin, expected_origin)) |
472 .WillOnce(testing::Return(mojom::PermissionStatus::DENIED)); | 472 .WillOnce(testing::Return(blink::mojom::PermissionStatus::DENIED)); |
473 EXPECT_FALSE(Register(sync_options_1_)); | 473 EXPECT_FALSE(Register(sync_options_1_)); |
474 } | 474 } |
475 | 475 |
476 TEST_F(BackgroundSyncManagerTest, RegisterPermissionGranted) { | 476 TEST_F(BackgroundSyncManagerTest, RegisterPermissionGranted) { |
477 GURL expected_origin = GURL(kPattern1).GetOrigin(); | 477 GURL expected_origin = GURL(kPattern1).GetOrigin(); |
478 MockPermissionManager* mock_permission_manager = GetPermissionManager(); | 478 MockPermissionManager* mock_permission_manager = GetPermissionManager(); |
479 | 479 |
480 EXPECT_CALL(*mock_permission_manager, | 480 EXPECT_CALL(*mock_permission_manager, |
481 GetPermissionStatus(PermissionType::BACKGROUND_SYNC, | 481 GetPermissionStatus(PermissionType::BACKGROUND_SYNC, |
482 expected_origin, expected_origin)) | 482 expected_origin, expected_origin)) |
483 .WillOnce(testing::Return(mojom::PermissionStatus::GRANTED)); | 483 .WillOnce(testing::Return(blink::mojom::PermissionStatus::GRANTED)); |
484 EXPECT_TRUE(Register(sync_options_1_)); | 484 EXPECT_TRUE(Register(sync_options_1_)); |
485 } | 485 } |
486 | 486 |
487 TEST_F(BackgroundSyncManagerTest, TwoRegistrations) { | 487 TEST_F(BackgroundSyncManagerTest, TwoRegistrations) { |
488 EXPECT_TRUE(Register(sync_options_1_)); | 488 EXPECT_TRUE(Register(sync_options_1_)); |
489 EXPECT_TRUE(Register(sync_options_2_)); | 489 EXPECT_TRUE(Register(sync_options_2_)); |
490 } | 490 } |
491 | 491 |
492 TEST_F(BackgroundSyncManagerTest, GetRegistrationNonExisting) { | 492 TEST_F(BackgroundSyncManagerTest, GetRegistrationNonExisting) { |
493 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 493 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1311 // Run it again. | 1311 // Run it again. |
1312 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); | 1312 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); |
1313 test_background_sync_manager_->delayed_task().Run(); | 1313 test_background_sync_manager_->delayed_task().Run(); |
1314 base::RunLoop().RunUntilIdle(); | 1314 base::RunLoop().RunUntilIdle(); |
1315 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 1315 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
1316 EXPECT_EQ(mojom::BackgroundSyncEventLastChance::IS_LAST_CHANCE, | 1316 EXPECT_EQ(mojom::BackgroundSyncEventLastChance::IS_LAST_CHANCE, |
1317 test_background_sync_manager_->last_chance()); | 1317 test_background_sync_manager_->last_chance()); |
1318 } | 1318 } |
1319 | 1319 |
1320 } // namespace content | 1320 } // namespace content |
OLD | NEW |