| 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 "content/child/service_worker/service_worker_dispatcher.h" |
| 6 #include "content/child/service_worker/service_worker_handle_reference.h" | 6 #include "content/child/service_worker/service_worker_handle_reference.h" |
| 7 #include "content/child/service_worker/service_worker_provider_context.h" | 7 #include "content/child/service_worker/service_worker_provider_context.h" |
| 8 #include "content/child/service_worker/web_service_worker_impl.h" | 8 #include "content/child/service_worker/web_service_worker_impl.h" |
| 9 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 9 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 10 #include "content/child/thread_safe_sender.h" | 10 #include "content/child/thread_safe_sender.h" |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 OnSetControllerServiceWorker(kDocumentMainThreadId, kProviderId, attrs.active, | 323 OnSetControllerServiceWorker(kDocumentMainThreadId, kProviderId, attrs.active, |
| 324 should_notify_controllerchange); | 324 should_notify_controllerchange); |
| 325 EXPECT_TRUE(provider_client->is_set_controlled_called()); | 325 EXPECT_TRUE(provider_client->is_set_controlled_called()); |
| 326 ASSERT_EQ(2UL, ipc_sink()->message_count()); | 326 ASSERT_EQ(2UL, ipc_sink()->message_count()); |
| 327 EXPECT_EQ(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount::ID, | 327 EXPECT_EQ(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount::ID, |
| 328 ipc_sink()->GetMessageAt(0)->type()); | 328 ipc_sink()->GetMessageAt(0)->type()); |
| 329 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 329 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
| 330 ipc_sink()->GetMessageAt(1)->type()); | 330 ipc_sink()->GetMessageAt(1)->type()); |
| 331 } | 331 } |
| 332 | 332 |
| 333 // Test that clearing the controller by sending a kInvalidServiceWorkerHandle |
| 334 // results in the provider context having a null controller. |
| 335 TEST_F(ServiceWorkerDispatcherTest, OnSetControllerServiceWorker_Null) { |
| 336 const int kProviderId = 10; |
| 337 bool should_notify_controllerchange = true; |
| 338 |
| 339 ServiceWorkerRegistrationObjectInfo info; |
| 340 ServiceWorkerVersionAttributes attrs; |
| 341 CreateObjectInfoAndVersionAttributes(&info, &attrs); |
| 342 |
| 343 scoped_ptr<MockWebServiceWorkerProviderClientImpl> provider_client( |
| 344 new MockWebServiceWorkerProviderClientImpl(kProviderId, dispatcher())); |
| 345 scoped_refptr<ServiceWorkerProviderContext> provider_context( |
| 346 new ServiceWorkerProviderContext(kProviderId, |
| 347 SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
| 348 thread_safe_sender())); |
| 349 |
| 350 OnAssociateRegistration(kDocumentMainThreadId, kProviderId, info, attrs); |
| 351 |
| 352 // Set the controller to kInvalidServiceWorkerHandle. |
| 353 OnSetControllerServiceWorker(kDocumentMainThreadId, kProviderId, |
| 354 ServiceWorkerObjectInfo(), |
| 355 should_notify_controllerchange); |
| 356 |
| 357 // Check that it became null. |
| 358 EXPECT_EQ(nullptr, provider_context->controller()); |
| 359 EXPECT_TRUE(provider_client->is_set_controlled_called()); |
| 360 } |
| 361 |
| 333 TEST_F(ServiceWorkerDispatcherTest, OnPostMessage) { | 362 TEST_F(ServiceWorkerDispatcherTest, OnPostMessage) { |
| 334 const int kProviderId = 10; | 363 const int kProviderId = 10; |
| 335 | 364 |
| 336 // Assume that these objects are passed from the browser process and own | 365 // Assume that these objects are passed from the browser process and own |
| 337 // references to browser-side registration/worker representations. | 366 // references to browser-side registration/worker representations. |
| 338 ServiceWorkerRegistrationObjectInfo info; | 367 ServiceWorkerRegistrationObjectInfo info; |
| 339 ServiceWorkerVersionAttributes attrs; | 368 ServiceWorkerVersionAttributes attrs; |
| 340 CreateObjectInfoAndVersionAttributes(&info, &attrs); | 369 CreateObjectInfoAndVersionAttributes(&info, &attrs); |
| 341 | 370 |
| 342 ServiceWorkerMsg_MessageToDocument_Params params; | 371 ServiceWorkerMsg_MessageToDocument_Params params; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 ipc_sink()->GetMessageAt(0)->type()); | 513 ipc_sink()->GetMessageAt(0)->type()); |
| 485 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 514 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
| 486 ipc_sink()->GetMessageAt(1)->type()); | 515 ipc_sink()->GetMessageAt(1)->type()); |
| 487 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, | 516 EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID, |
| 488 ipc_sink()->GetMessageAt(2)->type()); | 517 ipc_sink()->GetMessageAt(2)->type()); |
| 489 EXPECT_EQ(ServiceWorkerHostMsg_DecrementRegistrationRefCount::ID, | 518 EXPECT_EQ(ServiceWorkerHostMsg_DecrementRegistrationRefCount::ID, |
| 490 ipc_sink()->GetMessageAt(3)->type()); | 519 ipc_sink()->GetMessageAt(3)->type()); |
| 491 } | 520 } |
| 492 | 521 |
| 493 } // namespace content | 522 } // namespace content |
| OLD | NEW |