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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/power_monitor/power_monitor.h" | 10 #include "base/power_monitor/power_monitor.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 CreateTestHelper(); | 99 CreateTestHelper(); |
100 CreateBackgroundSyncContext(); | 100 CreateBackgroundSyncContext(); |
101 CreateServiceWorkerRegistration(); | 101 CreateServiceWorkerRegistration(); |
102 CreateBackgroundSyncServiceImpl(); | 102 CreateBackgroundSyncServiceImpl(); |
103 } | 103 } |
104 | 104 |
105 void TearDown() override { | 105 void TearDown() override { |
106 // This must be explicitly destroyed here to ensure that destruction | 106 // This must be explicitly destroyed here to ensure that destruction |
107 // of both the BackgroundSyncContext and the BackgroundSyncManager occurs on | 107 // of both the BackgroundSyncContext and the BackgroundSyncManager occurs on |
108 // the correct thread. | 108 // the correct thread. |
| 109 background_sync_context_->Shutdown(); |
| 110 base::RunLoop().RunUntilIdle(); |
109 background_sync_context_ = nullptr; | 111 background_sync_context_ = nullptr; |
110 } | 112 } |
111 | 113 |
112 // SetUp helper methods | 114 // SetUp helper methods |
113 void CreateTestHelper() { | 115 void CreateTestHelper() { |
114 embedded_worker_helper_.reset( | 116 embedded_worker_helper_.reset( |
115 new EmbeddedWorkerTestHelper(base::FilePath(), kRenderProcessId)); | 117 new EmbeddedWorkerTestHelper(base::FilePath(), kRenderProcessId)); |
116 } | 118 } |
117 | 119 |
118 void CreateBackgroundSyncContext() { | 120 void CreateBackgroundSyncContext() { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 void RemoveWindowClient() { | 164 void RemoveWindowClient() { |
163 sw_registration_->active_version()->RemoveControllee(provider_host_.get()); | 165 sw_registration_->active_version()->RemoveControllee(provider_host_.get()); |
164 } | 166 } |
165 | 167 |
166 void CreateBackgroundSyncServiceImpl() { | 168 void CreateBackgroundSyncServiceImpl() { |
167 // Create a dummy mojo channel so that the BackgroundSyncServiceImpl can be | 169 // Create a dummy mojo channel so that the BackgroundSyncServiceImpl can be |
168 // instantiated | 170 // instantiated |
169 mojo::InterfaceRequest<BackgroundSyncService> service_request = | 171 mojo::InterfaceRequest<BackgroundSyncService> service_request = |
170 mojo::GetProxy(&service_ptr_); | 172 mojo::GetProxy(&service_ptr_); |
171 // Create a new BackgroundSyncServiceImpl bound to the dummy channel | 173 // Create a new BackgroundSyncServiceImpl bound to the dummy channel |
172 service_impl_.reset(new BackgroundSyncServiceImpl(background_sync_context_, | 174 service_impl_.reset(new BackgroundSyncServiceImpl( |
173 service_request.Pass())); | 175 background_sync_context_.get(), service_request.Pass())); |
174 base::RunLoop().RunUntilIdle(); | 176 base::RunLoop().RunUntilIdle(); |
175 } | 177 } |
176 | 178 |
177 // Helpers for testing BackgroundSyncServiceImpl methods | 179 // Helpers for testing BackgroundSyncServiceImpl methods |
178 void RegisterOneShot( | 180 void RegisterOneShot( |
179 SyncRegistrationPtr sync, | 181 SyncRegistrationPtr sync, |
180 const BackgroundSyncService::RegisterCallback& callback) { | 182 const BackgroundSyncService::RegisterCallback& callback) { |
181 service_impl_->Register(sync.Pass(), sw_registration_id_, callback); | 183 service_impl_->Register(sync.Pass(), sw_registration_id_, callback); |
182 base::RunLoop().RunUntilIdle(); | 184 base::RunLoop().RunUntilIdle(); |
183 } | 185 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 GetRegistrationsOneShot(base::Bind(&ErrorAndRegistrationListCallback, | 335 GetRegistrationsOneShot(base::Bind(&ErrorAndRegistrationListCallback, |
334 &getregistrations_called, | 336 &getregistrations_called, |
335 &getregistrations_error, &array_size)); | 337 &getregistrations_error, &array_size)); |
336 EXPECT_TRUE(getregistrations_called); | 338 EXPECT_TRUE(getregistrations_called); |
337 EXPECT_EQ(BackgroundSyncError::BACKGROUND_SYNC_ERROR_NONE, | 339 EXPECT_EQ(BackgroundSyncError::BACKGROUND_SYNC_ERROR_NONE, |
338 getregistrations_error); | 340 getregistrations_error); |
339 EXPECT_EQ(1UL, array_size); | 341 EXPECT_EQ(1UL, array_size); |
340 } | 342 } |
341 | 343 |
342 } // namespace content | 344 } // namespace content |
OLD | NEW |