| 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..08820e0739777e1239f82c9fb773901fbd886b51 100644
|
| --- a/content/browser/service_worker/service_worker_context_unittest.cc
|
| +++ b/content/browser/service_worker/service_worker_context_unittest.cc
|
| @@ -53,6 +53,15 @@ 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;
|
| +}
|
| +
|
| void ExpectRegisteredWorkers(
|
| ServiceWorkerStatusCode expect_status,
|
| int64 expect_version_id,
|
| @@ -455,4 +464,70 @@ 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,
|
| + base::Bind(&SaveRegistrationIdCallback, &called,
|
| + &result_registration_id));
|
| +
|
| + ASSERT_FALSE(called);
|
| + base::RunLoop().RunUntilIdle();
|
| + ASSERT_TRUE(called);
|
| + EXPECT_EQ(registration_id, result_registration_id);
|
| +}
|
| +
|
| +TEST_F(ServiceWorkerContextTest, GetRegistration_NotFound) {
|
| + GURL pattern("http://www.example.com/scope");
|
| + GURL document_url("http://www.example.com/out_of_scope");
|
| +
|
| + 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,
|
| + base::Bind(&SaveRegistrationIdCallback, &called,
|
| + &result_registration_id));
|
| +
|
| + ASSERT_FALSE(called);
|
| + base::RunLoop().RunUntilIdle();
|
| + ASSERT_TRUE(called);
|
| + EXPECT_EQ(kInvalidServiceWorkerRegistrationId, result_registration_id);
|
| +}
|
| +
|
| } // namespace content
|
|
|