Chromium Code Reviews| Index: content/browser/service_worker/service_worker_context_unittest.cc |
| diff --git a/content/browser/service_worker/service_worker_context_unittest.cc b/content/browser/service_worker/service_worker_context_unittest.cc |
| index ad550f87d8a9c9fdf4bf4558ad1a1c509d172c7d..01c2858724c49fa10d5f60fbd0e5503cd6b45b2d 100644 |
| --- a/content/browser/service_worker/service_worker_context_unittest.cc |
| +++ b/content/browser/service_worker/service_worker_context_unittest.cc |
| @@ -53,6 +53,21 @@ ServiceWorkerContextCore::UnregistrationCallback MakeUnregisteredCallback( |
| return base::Bind(&CallCompletedCallback, called); |
| } |
| +void SaveRegistrationIdCallback(bool* called, |
| + int64* store_registration_id, |
| + ServiceWorkerStatusCode status, |
| + int64 registration_id) { |
| + EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status); |
| + *called = true; |
| + *store_registration_id = registration_id; |
| +} |
| + |
| +ServiceWorkerContextCore::GetRegistrationCallback MakeGetRegistrationCallback( |
| + bool* called, |
| + int64* store_registration_id) { |
| + return base::Bind(&SaveRegistrationIdCallback, called, store_registration_id); |
|
nhiroki
2014/09/10 04:07:22
nit: This indirection doesn't seem very helpful, o
Kunihiko Sakamoto
2014/09/10 08:22:44
Agreed - inlined it.
|
| +} |
| + |
| void ExpectRegisteredWorkers( |
| ServiceWorkerStatusCode expect_status, |
| int64 expect_version_id, |
| @@ -455,4 +470,36 @@ TEST_F(ServiceWorkerContextTest, DeleteAndStartOver) { |
| base::RunLoop().RunUntilIdle(); |
| } |
| +TEST_F(ServiceWorkerContextTest, GetRegistration) { |
| + GURL pattern("http://www.example.com/"); |
| + GURL document_url("http://www.example.com/foo"); |
| + |
| + bool called = false; |
| + int64 registration_id = kInvalidServiceWorkerRegistrationId; |
| + int64 version_id = kInvalidServiceWorkerVersionId; |
| + context()->RegisterServiceWorker( |
| + pattern, |
| + GURL("http://www.example.com/service_worker.js"), |
| + render_process_id_, |
| + NULL, |
| + MakeRegisteredCallback(&called, ®istration_id, &version_id)); |
| + |
| + ASSERT_FALSE(called); |
| + base::RunLoop().RunUntilIdle(); |
| + ASSERT_TRUE(called); |
| + EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
| + EXPECT_NE(kInvalidServiceWorkerVersionId, version_id); |
| + |
| + called = false; |
| + int64 result_registration_id; |
| + context()->GetRegistration( |
| + document_url, |
| + MakeGetRegistrationCallback(&called, &result_registration_id)); |
| + |
| + ASSERT_FALSE(called); |
| + base::RunLoop().RunUntilIdle(); |
| + ASSERT_TRUE(called); |
| + EXPECT_EQ(registration_id, result_registration_id); |
|
nhiroki
2014/09/10 04:07:22
Can you test a case that there is no registration
Kunihiko Sakamoto
2014/09/10 08:22:44
Done.
|
| +} |
| + |
| } // namespace content |