| 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 b4dbbdb4dee7ba7eeb4092af938327309cd70230..b29c1464c65aa410f9d762d3203f9eab64f2c645 100644
|
| --- a/content/child/service_worker/service_worker_dispatcher_unittest.cc
|
| +++ b/content/child/service_worker/service_worker_dispatcher_unittest.cc
|
| @@ -55,12 +55,6 @@ class ServiceWorkerDispatcherTest : public testing::Test {
|
| attrs->installing.version_id = 202;
|
| }
|
|
|
| - WebServiceWorkerRegistrationImpl* FindOrCreateRegistration(
|
| - const ServiceWorkerRegistrationObjectInfo& info,
|
| - const ServiceWorkerVersionAttributes& attrs) {
|
| - return dispatcher_->FindOrCreateRegistration(info, attrs);
|
| - }
|
| -
|
| bool ContainsServiceWorker(int handle_id) {
|
| return ContainsKey(dispatcher_->service_workers_, handle_id);
|
| }
|
| @@ -139,79 +133,59 @@ TEST_F(ServiceWorkerDispatcherTest, GetServiceWorker) {
|
| EXPECT_EQ(0UL, ipc_sink()->message_count());
|
| }
|
|
|
| -TEST_F(ServiceWorkerDispatcherTest, CreateServiceWorkerRegistration) {
|
| +TEST_F(ServiceWorkerDispatcherTest, CreateRegistration) {
|
| ServiceWorkerRegistrationObjectInfo info;
|
| ServiceWorkerVersionAttributes attrs;
|
| CreateObjectInfoAndVersionAttributes(&info, &attrs);
|
|
|
| - // Should return a registration object newly created with incrementing
|
| - // refcount.
|
| - bool adopt_handle = false;
|
| + // Should return a registration object newly created with adopting refcount.
|
| scoped_ptr<WebServiceWorkerRegistrationImpl> registration(
|
| - dispatcher()->CreateServiceWorkerRegistration(info, adopt_handle));
|
| + dispatcher()->CreateRegistration(info, attrs, true));
|
| EXPECT_TRUE(registration);
|
| - EXPECT_TRUE(ContainsRegistration(info.handle_id));
|
| - ASSERT_EQ(1UL, ipc_sink()->message_count());
|
| - EXPECT_EQ(ServiceWorkerHostMsg_IncrementRegistrationRefCount::ID,
|
| - ipc_sink()->GetMessageAt(0)->type());
|
| + EXPECT_EQ(info.registration_id, registration->registration_id());
|
| + EXPECT_EQ(0UL, ipc_sink()->message_count());
|
|
|
| + // The registration dtor decrements the refcount.
|
| registration.reset();
|
| - EXPECT_FALSE(ContainsRegistration(info.handle_id));
|
| + 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();
|
|
|
| - // Should return another registration object newly created with adopting
|
| + // Should return a registration object newly created with incrementing
|
| // refcount.
|
| - adopt_handle = true;
|
| - scoped_ptr<WebServiceWorkerRegistrationImpl> another_registration(
|
| - dispatcher()->CreateServiceWorkerRegistration(info, adopt_handle));
|
| - EXPECT_TRUE(another_registration);
|
| + registration = dispatcher()->CreateRegistration(info, attrs, false);
|
| + EXPECT_TRUE(registration);
|
| EXPECT_TRUE(ContainsRegistration(info.handle_id));
|
| - EXPECT_EQ(0UL, ipc_sink()->message_count());
|
| + ASSERT_EQ(4UL, ipc_sink()->message_count());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_IncrementRegistrationRefCount::ID,
|
| + ipc_sink()->GetMessageAt(0)->type());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount::ID,
|
| + ipc_sink()->GetMessageAt(1)->type());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount::ID,
|
| + ipc_sink()->GetMessageAt(2)->type());
|
| + EXPECT_EQ(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount::ID,
|
| + ipc_sink()->GetMessageAt(3)->type());
|
|
|
| - another_registration.reset();
|
| ipc_sink()->ClearMessages();
|
|
|
| - // should return nullptr when a given object info is invalid.
|
| - adopt_handle = false;
|
| - scoped_ptr<WebServiceWorkerRegistrationImpl> invalid_registration(
|
| - dispatcher()->CreateServiceWorkerRegistration(
|
| - ServiceWorkerRegistrationObjectInfo(), adopt_handle));
|
| - EXPECT_FALSE(invalid_registration);
|
| - EXPECT_FALSE(ContainsRegistration(info.handle_id));
|
| - EXPECT_EQ(0UL, ipc_sink()->message_count());
|
| -
|
| - adopt_handle = true;
|
| - invalid_registration.reset(dispatcher()->CreateServiceWorkerRegistration(
|
| - ServiceWorkerRegistrationObjectInfo(), adopt_handle));
|
| - EXPECT_FALSE(invalid_registration);
|
| - EXPECT_FALSE(ContainsRegistration(info.handle_id));
|
| - EXPECT_EQ(0UL, ipc_sink()->message_count());
|
| -}
|
| -
|
| -TEST_F(ServiceWorkerDispatcherTest, FindOrCreateRegistration) {
|
| - ServiceWorkerRegistrationObjectInfo info;
|
| - ServiceWorkerVersionAttributes attrs;
|
| - CreateObjectInfoAndVersionAttributes(&info, &attrs);
|
| -
|
| - // Should return a registration object newly created with adopting refcounts.
|
| - scoped_ptr<WebServiceWorkerRegistrationImpl> registration(
|
| - FindOrCreateRegistration(info, attrs));
|
| - EXPECT_TRUE(registration);
|
| - EXPECT_EQ(info.registration_id, registration->registration_id());
|
| - EXPECT_EQ(0UL, ipc_sink()->message_count());
|
| -
|
| - // Should return the existing registration object with adopting refcounts.
|
| - WebServiceWorkerRegistrationImpl* existing_registration =
|
| - FindOrCreateRegistration(info, attrs);
|
| - EXPECT_EQ(registration, existing_registration);
|
| + // The registration dtor decrements the refcount.
|
| + registration.reset();
|
| ASSERT_EQ(4UL, ipc_sink()->message_count());
|
| - EXPECT_EQ(ServiceWorkerHostMsg_DecrementRegistrationRefCount::ID,
|
| + 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_DecrementServiceWorkerRefCount::ID,
|
| + EXPECT_EQ(ServiceWorkerHostMsg_DecrementRegistrationRefCount::ID,
|
| ipc_sink()->GetMessageAt(3)->type());
|
| }
|
|
|
|
|