| 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_service_impl.h" | 5 #include "content/browser/background_sync/background_sync_service_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 |
| 9 #include <memory> |
| 8 #include <utility> | 10 #include <utility> |
| 9 | 11 |
| 10 #include "base/bind.h" | 12 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 14 #include "content/browser/background_sync/background_sync_context_impl.h" | 15 #include "content/browser/background_sync/background_sync_context_impl.h" |
| 15 #include "content/browser/background_sync/background_sync_network_observer.h" | 16 #include "content/browser/background_sync/background_sync_network_observer.h" |
| 16 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 17 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 17 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 18 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 18 #include "content/browser/storage_partition_impl.h" | 19 #include "content/browser/storage_partition_impl.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/permission_type.h" | 21 #include "content/public/browser/permission_type.h" |
| 21 #include "content/public/test/background_sync_test_util.h" | 22 #include "content/public/test/background_sync_test_util.h" |
| 22 #include "content/public/test/test_browser_context.h" | 23 #include "content/public/test/test_browser_context.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 background_sync_context_ = nullptr; | 112 background_sync_context_ = nullptr; |
| 112 | 113 |
| 113 // Restore the network observer functionality for subsequent tests | 114 // Restore the network observer functionality for subsequent tests |
| 114 background_sync_test_util::SetIgnoreNetworkChangeNotifier(false); | 115 background_sync_test_util::SetIgnoreNetworkChangeNotifier(false); |
| 115 } | 116 } |
| 116 | 117 |
| 117 // SetUp helper methods | 118 // SetUp helper methods |
| 118 void CreateTestHelper() { | 119 void CreateTestHelper() { |
| 119 embedded_worker_helper_.reset( | 120 embedded_worker_helper_.reset( |
| 120 new EmbeddedWorkerTestHelper(base::FilePath())); | 121 new EmbeddedWorkerTestHelper(base::FilePath())); |
| 121 scoped_ptr<MockPermissionManager> mock_permission_manager( | 122 std::unique_ptr<MockPermissionManager> mock_permission_manager( |
| 122 new testing::NiceMock<MockPermissionManager>()); | 123 new testing::NiceMock<MockPermissionManager>()); |
| 123 ON_CALL(*mock_permission_manager, | 124 ON_CALL(*mock_permission_manager, |
| 124 GetPermissionStatus(PermissionType::BACKGROUND_SYNC, _, _)) | 125 GetPermissionStatus(PermissionType::BACKGROUND_SYNC, _, _)) |
| 125 .WillByDefault( | 126 .WillByDefault( |
| 126 testing::Return(blink::mojom::PermissionStatus::GRANTED)); | 127 testing::Return(blink::mojom::PermissionStatus::GRANTED)); |
| 127 embedded_worker_helper_->browser_context()->SetPermissionManager( | 128 embedded_worker_helper_->browser_context()->SetPermissionManager( |
| 128 std::move(mock_permission_manager)); | 129 std::move(mock_permission_manager)); |
| 129 } | 130 } |
| 130 | 131 |
| 131 void CreateStoragePartition() { | 132 void CreateStoragePartition() { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 service_impl_->Register(std::move(sync), sw_registration_id_, callback); | 197 service_impl_->Register(std::move(sync), sw_registration_id_, callback); |
| 197 base::RunLoop().RunUntilIdle(); | 198 base::RunLoop().RunUntilIdle(); |
| 198 } | 199 } |
| 199 | 200 |
| 200 void GetRegistrations( | 201 void GetRegistrations( |
| 201 const mojom::BackgroundSyncService::GetRegistrationsCallback& callback) { | 202 const mojom::BackgroundSyncService::GetRegistrationsCallback& callback) { |
| 202 service_impl_->GetRegistrations(sw_registration_id_, callback); | 203 service_impl_->GetRegistrations(sw_registration_id_, callback); |
| 203 base::RunLoop().RunUntilIdle(); | 204 base::RunLoop().RunUntilIdle(); |
| 204 } | 205 } |
| 205 | 206 |
| 206 scoped_ptr<TestBrowserThreadBundle> thread_bundle_; | 207 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; |
| 207 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 208 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 208 scoped_ptr<EmbeddedWorkerTestHelper> embedded_worker_helper_; | 209 std::unique_ptr<EmbeddedWorkerTestHelper> embedded_worker_helper_; |
| 209 scoped_ptr<StoragePartitionImpl> storage_partition_impl_; | 210 std::unique_ptr<StoragePartitionImpl> storage_partition_impl_; |
| 210 scoped_refptr<BackgroundSyncContextImpl> background_sync_context_; | 211 scoped_refptr<BackgroundSyncContextImpl> background_sync_context_; |
| 211 int64_t sw_registration_id_; | 212 int64_t sw_registration_id_; |
| 212 scoped_refptr<ServiceWorkerRegistration> sw_registration_; | 213 scoped_refptr<ServiceWorkerRegistration> sw_registration_; |
| 213 mojom::BackgroundSyncServicePtr service_ptr_; | 214 mojom::BackgroundSyncServicePtr service_ptr_; |
| 214 BackgroundSyncServiceImpl* | 215 BackgroundSyncServiceImpl* |
| 215 service_impl_; // Owned by background_sync_context_ | 216 service_impl_; // Owned by background_sync_context_ |
| 216 mojom::SyncRegistrationPtr default_sync_registration_; | 217 mojom::SyncRegistrationPtr default_sync_registration_; |
| 217 }; | 218 }; |
| 218 | 219 |
| 219 // Tests | 220 // Tests |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 EXPECT_EQ(mojom::BackgroundSyncError::NONE, register_error); | 255 EXPECT_EQ(mojom::BackgroundSyncError::NONE, register_error); |
| 255 GetRegistrations(base::Bind(&ErrorAndRegistrationListCallback, | 256 GetRegistrations(base::Bind(&ErrorAndRegistrationListCallback, |
| 256 &getregistrations_called, &getregistrations_error, | 257 &getregistrations_called, &getregistrations_error, |
| 257 &array_size)); | 258 &array_size)); |
| 258 EXPECT_TRUE(getregistrations_called); | 259 EXPECT_TRUE(getregistrations_called); |
| 259 EXPECT_EQ(mojom::BackgroundSyncError::NONE, getregistrations_error); | 260 EXPECT_EQ(mojom::BackgroundSyncError::NONE, getregistrations_error); |
| 260 EXPECT_EQ(1UL, array_size); | 261 EXPECT_EQ(1UL, array_size); |
| 261 } | 262 } |
| 262 | 263 |
| 263 } // namespace content | 264 } // namespace content |
| OLD | NEW |