| Index: content/child/service_worker/service_worker_dispatcher_unittest.cc
|
| diff --git a/content/child/service_worker/service_worker_dispatcher_unittest.cc b/content/child/service_worker/service_worker_dispatcher_unittest.cc
|
| index 6cd9621364d54dcbeeb5bbb45b7178208c15be3f..9ce3a7688439c7f35ff2fa03a4ea3daa126cc5fd 100644
|
| --- a/content/child/service_worker/service_worker_dispatcher_unittest.cc
|
| +++ b/content/child/service_worker/service_worker_dispatcher_unittest.cc
|
| @@ -65,6 +65,15 @@ class ServiceWorkerDispatcherTest : public testing::Test {
|
| return ContainsKey(dispatcher_->registrations_, registration_handle_id);
|
| }
|
|
|
| + void OnAssociateRegistrationWithServiceWorker(
|
| + int thread_id,
|
| + int provider_id,
|
| + const ServiceWorkerRegistrationObjectInfo& info,
|
| + const ServiceWorkerVersionAttributes& attrs) {
|
| + dispatcher_->OnAssociateRegistrationWithServiceWorker(
|
| + thread_id, provider_id, info, attrs);
|
| + }
|
| +
|
| void OnAssociateRegistration(int thread_id,
|
| int provider_id,
|
| const ServiceWorkerRegistrationObjectInfo& info,
|
| @@ -72,6 +81,10 @@ class ServiceWorkerDispatcherTest : public testing::Test {
|
| dispatcher_->OnAssociateRegistration(thread_id, provider_id, info, attrs);
|
| }
|
|
|
| + void OnDisassociateRegistration(int thread_id, int provider_id) {
|
| + dispatcher_->OnDisassociateRegistration(thread_id, provider_id);
|
| + }
|
| +
|
| void OnSetControllerServiceWorker(int thread_id,
|
| int provider_id,
|
| const ServiceWorkerObjectInfo& info,
|
| @@ -126,7 +139,105 @@ class MockWebServiceWorkerProviderClientImpl
|
| };
|
|
|
| // TODO(nhiroki): Add tests for message handlers especially to receive reference
|
| -// counts like OnAssociateRegistration().
|
| +// counts.
|
| +
|
| +TEST_F(ServiceWorkerDispatcherTest, OnAssociateRegistrationWithServiceWorker) {
|
| + const int kProviderId = 10;
|
| +
|
| + // Assume that these objects are passed from the browser process and own
|
| + // references to browser-side registration/worker representations.
|
| + ServiceWorkerRegistrationObjectInfo info;
|
| + ServiceWorkerVersionAttributes attrs;
|
| + CreateObjectInfoAndVersionAttributes(&info, &attrs);
|
| +
|
| + // The passed references should be adopted but immediately destroyed because
|
| + // there is no provider context to own the references.
|
| + OnAssociateRegistrationWithServiceWorker(kDocumentMainThreadId, kProviderId,
|
| + info, attrs);
|
| + ASSERT_EQ(4UL, ipc_sink()->message_count());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID,
|
| + ipc_sink()->GetMessageAt(0)->type());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID,
|
| + ipc_sink()->GetMessageAt(1)->type());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID,
|
| + ipc_sink()->GetMessageAt(2)->type());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_DecrementRegistrationRefCount::ID,
|
| + ipc_sink()->GetMessageAt(3)->type());
|
| + ipc_sink()->ClearMessages();
|
| +
|
| + // Set up ServiceWorkerProviderContext for ServiceWorkerGlobalScope.
|
| + scoped_refptr<ServiceWorkerProviderContext> provider_context(
|
| + new ServiceWorkerProviderContext(kProviderId,
|
| + SERVICE_WORKER_PROVIDER_FOR_CONTROLLER,
|
| + thread_safe_sender()));
|
| +
|
| + // The passed references should be adopted and owned by the provider context.
|
| + OnAssociateRegistrationWithServiceWorker(kDocumentMainThreadId, kProviderId,
|
| + info, attrs);
|
| + EXPECT_EQ(0UL, ipc_sink()->message_count());
|
| +
|
| + // Destruction of the provider context should release references to the
|
| + // associated registration and its versions.
|
| + provider_context = nullptr;
|
| + ASSERT_EQ(4UL, ipc_sink()->message_count());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID,
|
| + ipc_sink()->GetMessageAt(0)->type());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID,
|
| + ipc_sink()->GetMessageAt(1)->type());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID,
|
| + ipc_sink()->GetMessageAt(2)->type());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_DecrementRegistrationRefCount::ID,
|
| + ipc_sink()->GetMessageAt(3)->type());
|
| +}
|
| +
|
| +TEST_F(ServiceWorkerDispatcherTest, OnAssociateRegistration) {
|
| + const int kProviderId = 10;
|
| +
|
| + // Assume that these objects are passed from the browser process and own
|
| + // references to browser-side registration/worker representations.
|
| + ServiceWorkerRegistrationObjectInfo info;
|
| + ServiceWorkerVersionAttributes attrs;
|
| + CreateObjectInfoAndVersionAttributes(&info, &attrs);
|
| +
|
| + // The passed references should be adopted but immediately destroyed because
|
| + // there is no provider context to own the references.
|
| + OnAssociateRegistration(kDocumentMainThreadId, kProviderId, info, attrs);
|
| + ASSERT_EQ(4UL, ipc_sink()->message_count());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID,
|
| + ipc_sink()->GetMessageAt(0)->type());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID,
|
| + ipc_sink()->GetMessageAt(1)->type());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID,
|
| + ipc_sink()->GetMessageAt(2)->type());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_DecrementRegistrationRefCount::ID,
|
| + ipc_sink()->GetMessageAt(3)->type());
|
| + ipc_sink()->ClearMessages();
|
| +
|
| + // Set up ServiceWorkerProviderContext for a document context.
|
| + scoped_refptr<ServiceWorkerProviderContext> provider_context(
|
| + new ServiceWorkerProviderContext(kProviderId,
|
| + SERVICE_WORKER_PROVIDER_FOR_WINDOW,
|
| + thread_safe_sender()));
|
| +
|
| + // The passed references should be adopted and only the registration reference
|
| + // should be owned by the provider context.
|
| + OnAssociateRegistration(kDocumentMainThreadId, kProviderId, info, attrs);
|
| + ASSERT_EQ(3UL, ipc_sink()->message_count());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID,
|
| + ipc_sink()->GetMessageAt(0)->type());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID,
|
| + ipc_sink()->GetMessageAt(1)->type());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount::ID,
|
| + ipc_sink()->GetMessageAt(2)->type());
|
| + ipc_sink()->ClearMessages();
|
| +
|
| + // Disassociating the provider context from the registration should release
|
| + // the reference.
|
| + OnDisassociateRegistration(kDocumentMainThreadId, kProviderId);
|
| + ASSERT_EQ(1UL, ipc_sink()->message_count());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_DecrementRegistrationRefCount::ID,
|
| + ipc_sink()->GetMessageAt(0)->type());
|
| +}
|
|
|
| TEST_F(ServiceWorkerDispatcherTest, OnSetControllerServiceWorker) {
|
| const int kProviderId = 10;
|
|
|