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/child/service_worker/service_worker_dispatcher.h" |
5 #include "base/macros.h" | 6 #include "base/macros.h" |
6 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
7 #include "content/child/service_worker/service_worker_dispatcher.h" | |
8 #include "content/child/service_worker/service_worker_handle_reference.h" | 8 #include "content/child/service_worker/service_worker_handle_reference.h" |
9 #include "content/child/service_worker/service_worker_provider_context.h" | 9 #include "content/child/service_worker/service_worker_provider_context.h" |
10 #include "content/child/service_worker/web_service_worker_impl.h" | 10 #include "content/child/service_worker/web_service_worker_impl.h" |
11 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 11 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
12 #include "content/child/thread_safe_sender.h" | 12 #include "content/child/thread_safe_sender.h" |
13 #include "content/common/service_worker/service_worker_messages.h" | 13 #include "content/common/service_worker/service_worker_messages.h" |
| 14 #include "content/common/service_worker/service_worker_provider_interfaces.mojom
.h" |
14 #include "content/common/service_worker/service_worker_types.h" | 15 #include "content/common/service_worker/service_worker_types.h" |
15 #include "ipc/ipc_sync_message_filter.h" | 16 #include "ipc/ipc_sync_message_filter.h" |
16 #include "ipc/ipc_test_sink.h" | 17 #include "ipc/ipc_test_sink.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerProviderClient.h" | 19 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerProviderClient.h" |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 OnAssociateRegistration_ProviderContextForController) { | 189 OnAssociateRegistration_ProviderContextForController) { |
189 // Assume that these objects are passed from the browser process and own | 190 // Assume that these objects are passed from the browser process and own |
190 // references to browser-side registration/worker representations. | 191 // references to browser-side registration/worker representations. |
191 ServiceWorkerRegistrationObjectInfo info; | 192 ServiceWorkerRegistrationObjectInfo info; |
192 ServiceWorkerVersionAttributes attrs; | 193 ServiceWorkerVersionAttributes attrs; |
193 CreateObjectInfoAndVersionAttributes(&info, &attrs); | 194 CreateObjectInfoAndVersionAttributes(&info, &attrs); |
194 | 195 |
195 // Set up ServiceWorkerProviderContext for ServiceWorkerGlobalScope. | 196 // Set up ServiceWorkerProviderContext for ServiceWorkerGlobalScope. |
196 const int kProviderId = 10; | 197 const int kProviderId = 10; |
197 scoped_refptr<ServiceWorkerProviderContext> provider_context( | 198 scoped_refptr<ServiceWorkerProviderContext> provider_context( |
198 new ServiceWorkerProviderContext(kProviderId, | 199 new ServiceWorkerProviderContext( |
199 SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, | 200 kProviderId, SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, |
200 thread_safe_sender())); | 201 mojom::ServiceWorkerProviderAssociatedRequest(), |
| 202 thread_safe_sender())); |
201 | 203 |
202 // The passed references should be adopted and owned by the provider context. | 204 // The passed references should be adopted and owned by the provider context. |
203 OnAssociateRegistration(kDocumentMainThreadId, kProviderId, info, attrs); | 205 OnAssociateRegistration(kDocumentMainThreadId, kProviderId, info, attrs); |
204 EXPECT_EQ(0UL, ipc_sink()->message_count()); | 206 EXPECT_EQ(0UL, ipc_sink()->message_count()); |
205 | 207 |
206 // Destruction of the provider context should release references to the | 208 // Destruction of the provider context should release references to the |
207 // associated registration and its versions. | 209 // associated registration and its versions. |
208 provider_context = nullptr; | 210 provider_context = nullptr; |
209 ASSERT_EQ(4UL, ipc_sink()->message_count()); | 211 ASSERT_EQ(4UL, ipc_sink()->message_count()); |
210 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 212 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
(...skipping 10 matching lines...) Expand all Loading... |
221 OnAssociateRegistration_ProviderContextForControllee) { | 223 OnAssociateRegistration_ProviderContextForControllee) { |
222 // Assume that these objects are passed from the browser process and own | 224 // Assume that these objects are passed from the browser process and own |
223 // references to browser-side registration/worker representations. | 225 // references to browser-side registration/worker representations. |
224 ServiceWorkerRegistrationObjectInfo info; | 226 ServiceWorkerRegistrationObjectInfo info; |
225 ServiceWorkerVersionAttributes attrs; | 227 ServiceWorkerVersionAttributes attrs; |
226 CreateObjectInfoAndVersionAttributes(&info, &attrs); | 228 CreateObjectInfoAndVersionAttributes(&info, &attrs); |
227 | 229 |
228 // Set up ServiceWorkerProviderContext for a document context. | 230 // Set up ServiceWorkerProviderContext for a document context. |
229 const int kProviderId = 10; | 231 const int kProviderId = 10; |
230 scoped_refptr<ServiceWorkerProviderContext> provider_context( | 232 scoped_refptr<ServiceWorkerProviderContext> provider_context( |
231 new ServiceWorkerProviderContext(kProviderId, | 233 new ServiceWorkerProviderContext( |
232 SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 234 kProviderId, SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
233 thread_safe_sender())); | 235 mojom::ServiceWorkerProviderAssociatedRequest(), |
| 236 thread_safe_sender())); |
234 | 237 |
235 // The passed references should be adopted and only the registration reference | 238 // The passed references should be adopted and only the registration reference |
236 // should be owned by the provider context. | 239 // should be owned by the provider context. |
237 OnAssociateRegistration(kDocumentMainThreadId, kProviderId, info, attrs); | 240 OnAssociateRegistration(kDocumentMainThreadId, kProviderId, info, attrs); |
238 ASSERT_EQ(3UL, ipc_sink()->message_count()); | 241 ASSERT_EQ(3UL, ipc_sink()->message_count()); |
239 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 242 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
240 ipc_sink()->GetMessageAt(0)->type()); | 243 ipc_sink()->GetMessageAt(0)->type()); |
241 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 244 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
242 ipc_sink()->GetMessageAt(1)->type()); | 245 ipc_sink()->GetMessageAt(1)->type()); |
243 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 246 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
(...skipping 26 matching lines...) Expand all Loading... |
270 std::set<uint32_t>()); | 273 std::set<uint32_t>()); |
271 ASSERT_EQ(1UL, ipc_sink()->message_count()); | 274 ASSERT_EQ(1UL, ipc_sink()->message_count()); |
272 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 275 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
273 ipc_sink()->GetMessageAt(0)->type()); | 276 ipc_sink()->GetMessageAt(0)->type()); |
274 ipc_sink()->ClearMessages(); | 277 ipc_sink()->ClearMessages(); |
275 | 278 |
276 // (2) In the case there is no WebSWProviderClient but SWProviderContext for | 279 // (2) In the case there is no WebSWProviderClient but SWProviderContext for |
277 // the provider, the passed referecence should be adopted and owned by the | 280 // the provider, the passed referecence should be adopted and owned by the |
278 // provider context. | 281 // provider context. |
279 scoped_refptr<ServiceWorkerProviderContext> provider_context( | 282 scoped_refptr<ServiceWorkerProviderContext> provider_context( |
280 new ServiceWorkerProviderContext(kProviderId, | 283 new ServiceWorkerProviderContext( |
281 SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 284 kProviderId, SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
282 thread_safe_sender())); | 285 mojom::ServiceWorkerProviderAssociatedRequest(), |
| 286 thread_safe_sender())); |
283 OnAssociateRegistration(kDocumentMainThreadId, kProviderId, info, attrs); | 287 OnAssociateRegistration(kDocumentMainThreadId, kProviderId, info, attrs); |
284 ipc_sink()->ClearMessages(); | 288 ipc_sink()->ClearMessages(); |
285 OnSetControllerServiceWorker(kDocumentMainThreadId, kProviderId, attrs.active, | 289 OnSetControllerServiceWorker(kDocumentMainThreadId, kProviderId, attrs.active, |
286 should_notify_controllerchange, | 290 should_notify_controllerchange, |
287 std::set<uint32_t>()); | 291 std::set<uint32_t>()); |
288 EXPECT_EQ(0UL, ipc_sink()->message_count()); | 292 EXPECT_EQ(0UL, ipc_sink()->message_count()); |
289 | 293 |
290 // Destruction of the provider context should release references to the | 294 // Destruction of the provider context should release references to the |
291 // associated registration and the controller. | 295 // associated registration and the controller. |
292 provider_context = nullptr; | 296 provider_context = nullptr; |
(...skipping 26 matching lines...) Expand all Loading... |
319 ipc_sink()->GetMessageAt(2)->type()); | 323 ipc_sink()->GetMessageAt(2)->type()); |
320 provider_client.reset(); | 324 provider_client.reset(); |
321 ipc_sink()->ClearMessages(); | 325 ipc_sink()->ClearMessages(); |
322 | 326 |
323 // (4) In the case there are both SWProviderContext and SWProviderClient for | 327 // (4) In the case there are both SWProviderContext and SWProviderClient for |
324 // the provider, the passed referecence should be adopted and owned by the | 328 // the provider, the passed referecence should be adopted and owned by the |
325 // provider context. In addition, the new reference should be created for the | 329 // provider context. In addition, the new reference should be created for the |
326 // provider client and immediately released due to limitation of the mock | 330 // provider client and immediately released due to limitation of the mock |
327 // implementation. | 331 // implementation. |
328 provider_context = new ServiceWorkerProviderContext( | 332 provider_context = new ServiceWorkerProviderContext( |
329 kProviderId, SERVICE_WORKER_PROVIDER_FOR_WINDOW, thread_safe_sender()); | 333 kProviderId, SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
| 334 mojom::ServiceWorkerProviderAssociatedRequest(), thread_safe_sender()); |
330 OnAssociateRegistration(kDocumentMainThreadId, kProviderId, info, attrs); | 335 OnAssociateRegistration(kDocumentMainThreadId, kProviderId, info, attrs); |
331 provider_client.reset( | 336 provider_client.reset( |
332 new MockWebServiceWorkerProviderClientImpl(kProviderId, dispatcher())); | 337 new MockWebServiceWorkerProviderClientImpl(kProviderId, dispatcher())); |
333 ASSERT_FALSE(provider_client->is_set_controlled_called()); | 338 ASSERT_FALSE(provider_client->is_set_controlled_called()); |
334 ipc_sink()->ClearMessages(); | 339 ipc_sink()->ClearMessages(); |
335 OnSetControllerServiceWorker(kDocumentMainThreadId, kProviderId, attrs.active, | 340 OnSetControllerServiceWorker(kDocumentMainThreadId, kProviderId, attrs.active, |
336 should_notify_controllerchange, | 341 should_notify_controllerchange, |
337 std::set<uint32_t>()); | 342 std::set<uint32_t>()); |
338 EXPECT_TRUE(provider_client->is_set_controlled_called()); | 343 EXPECT_TRUE(provider_client->is_set_controlled_called()); |
339 ASSERT_EQ(2UL, ipc_sink()->message_count()); | 344 ASSERT_EQ(2UL, ipc_sink()->message_count()); |
340 EXPECT_EQ(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount::ID, | 345 EXPECT_EQ(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount::ID, |
341 ipc_sink()->GetMessageAt(0)->type()); | 346 ipc_sink()->GetMessageAt(0)->type()); |
342 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 347 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
343 ipc_sink()->GetMessageAt(1)->type()); | 348 ipc_sink()->GetMessageAt(1)->type()); |
344 } | 349 } |
345 | 350 |
346 // Test that clearing the controller by sending a kInvalidServiceWorkerHandle | 351 // Test that clearing the controller by sending a kInvalidServiceWorkerHandle |
347 // results in the provider context having a null controller. | 352 // results in the provider context having a null controller. |
348 TEST_F(ServiceWorkerDispatcherTest, OnSetControllerServiceWorker_Null) { | 353 TEST_F(ServiceWorkerDispatcherTest, OnSetControllerServiceWorker_Null) { |
349 const int kProviderId = 10; | 354 const int kProviderId = 10; |
350 bool should_notify_controllerchange = true; | 355 bool should_notify_controllerchange = true; |
351 | 356 |
352 ServiceWorkerRegistrationObjectInfo info; | 357 ServiceWorkerRegistrationObjectInfo info; |
353 ServiceWorkerVersionAttributes attrs; | 358 ServiceWorkerVersionAttributes attrs; |
354 CreateObjectInfoAndVersionAttributes(&info, &attrs); | 359 CreateObjectInfoAndVersionAttributes(&info, &attrs); |
355 | 360 |
356 std::unique_ptr<MockWebServiceWorkerProviderClientImpl> provider_client( | 361 std::unique_ptr<MockWebServiceWorkerProviderClientImpl> provider_client( |
357 new MockWebServiceWorkerProviderClientImpl(kProviderId, dispatcher())); | 362 new MockWebServiceWorkerProviderClientImpl(kProviderId, dispatcher())); |
358 scoped_refptr<ServiceWorkerProviderContext> provider_context( | 363 scoped_refptr<ServiceWorkerProviderContext> provider_context( |
359 new ServiceWorkerProviderContext(kProviderId, | 364 new ServiceWorkerProviderContext( |
360 SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 365 kProviderId, SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
361 thread_safe_sender())); | 366 mojom::ServiceWorkerProviderAssociatedRequest(), |
| 367 thread_safe_sender())); |
362 | 368 |
363 OnAssociateRegistration(kDocumentMainThreadId, kProviderId, info, attrs); | 369 OnAssociateRegistration(kDocumentMainThreadId, kProviderId, info, attrs); |
364 | 370 |
365 // Set the controller to kInvalidServiceWorkerHandle. | 371 // Set the controller to kInvalidServiceWorkerHandle. |
366 OnSetControllerServiceWorker( | 372 OnSetControllerServiceWorker( |
367 kDocumentMainThreadId, kProviderId, ServiceWorkerObjectInfo(), | 373 kDocumentMainThreadId, kProviderId, ServiceWorkerObjectInfo(), |
368 should_notify_controllerchange, std::set<uint32_t>()); | 374 should_notify_controllerchange, std::set<uint32_t>()); |
369 | 375 |
370 // Check that it became null. | 376 // Check that it became null. |
371 EXPECT_EQ(nullptr, provider_context->controller()); | 377 EXPECT_EQ(nullptr, provider_context->controller()); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 ipc_sink()->GetMessageAt(0)->type()); | 532 ipc_sink()->GetMessageAt(0)->type()); |
527 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 533 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
528 ipc_sink()->GetMessageAt(1)->type()); | 534 ipc_sink()->GetMessageAt(1)->type()); |
529 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 535 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
530 ipc_sink()->GetMessageAt(2)->type()); | 536 ipc_sink()->GetMessageAt(2)->type()); |
531 EXPECT_EQ(ServiceWorkerHostMsg_DecrementRegistrationRefCount::ID, | 537 EXPECT_EQ(ServiceWorkerHostMsg_DecrementRegistrationRefCount::ID, |
532 ipc_sink()->GetMessageAt(3)->type()); | 538 ipc_sink()->GetMessageAt(3)->type()); |
533 } | 539 } |
534 | 540 |
535 } // namespace content | 541 } // namespace content |
OLD | NEW |