Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Unified Diff: content/child/service_worker/service_worker_dispatcher_unittest.cc

Issue 1307133003: ServiceWorker: Make APIs that return ServiceWorkerRegistration coin a new JS object (2/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: split CreateRegistration() Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..3cce4043809761e0dd5c0c42c1a2346c9c53eab5 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()->AdoptRegistration(info, attrs));
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);
+ 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());
}

Powered by Google App Engine
This is Rietveld 408576698