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 7164f45f504485e77ddea0b50566e3a90d56c91d..95386d20acd3aca9a41339e4d49f4f1b518d8036 100644 |
--- a/content/browser/service_worker/service_worker_context_unittest.cc |
+++ b/content/browser/service_worker/service_worker_context_unittest.cc |
@@ -273,6 +273,89 @@ TEST_F(ServiceWorkerContextTest, Unregister) { |
base::RunLoop().RunUntilIdle(); |
} |
+// Make sure registrations are cleaned up when they are unregistered in bulk. |
+TEST_F(ServiceWorkerContextTest, UnregisterMultiple) { |
+ GURL origin1_p1("http://www.example.com/test"); |
+ GURL origin1_p2("http://www.example.com/hello"); |
+ GURL origin2_p1("http://www.example.com:8080/again"); |
+ GURL origin3_p1("http://www.other.com/"); |
+ |
+ bool called = false; |
+ int64 registration_id1 = kInvalidServiceWorkerRegistrationId; |
+ int64 registration_id2 = kInvalidServiceWorkerRegistrationId; |
+ int64 registration_id3 = kInvalidServiceWorkerRegistrationId; |
+ int64 registration_id4 = kInvalidServiceWorkerRegistrationId; |
+ context()->RegisterServiceWorker( |
+ origin1_p1, |
+ GURL("http://www.example.com/service_worker.js"), |
+ NULL, |
+ MakeRegisteredCallback(&called, ®istration_id1)); |
+ context()->RegisterServiceWorker( |
+ origin1_p2, |
+ GURL("http://www.example.com/service_worker2.js"), |
+ NULL, |
+ MakeRegisteredCallback(&called, ®istration_id2)); |
+ context()->RegisterServiceWorker( |
+ origin2_p1, |
+ GURL("http://www.example.com:8080/service_worker3.js"), |
+ NULL, |
+ MakeRegisteredCallback(&called, ®istration_id3)); |
+ context()->RegisterServiceWorker( |
+ origin3_p1, |
+ GURL("http://www.other.com/service_worker4.js"), |
+ NULL, |
+ MakeRegisteredCallback(&called, ®istration_id4)); |
+ |
+ ASSERT_FALSE(called); |
+ base::RunLoop().RunUntilIdle(); |
+ ASSERT_TRUE(called); |
+ |
+ EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id1); |
+ EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id2); |
+ EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id3); |
+ EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id4); |
+ |
+ called = false; |
+ context()->UnregisterServiceWorkers(origin1_p1.GetOrigin(), |
+ MakeUnregisteredCallback(&called)); |
+ |
+ ASSERT_FALSE(called); |
+ base::RunLoop().RunUntilIdle(); |
+ ASSERT_TRUE(called); |
+ |
+ context()->storage()->FindRegistrationForId( |
+ registration_id1, |
+ origin1_p1.GetOrigin(), |
+ base::Bind(&ExpectRegisteredWorkers, |
+ SERVICE_WORKER_ERROR_NOT_FOUND, |
+ false /* expect_waiting */, |
+ false /* expect_active */)); |
+ context()->storage()->FindRegistrationForId( |
+ registration_id2, |
+ origin1_p2.GetOrigin(), |
+ base::Bind(&ExpectRegisteredWorkers, |
+ SERVICE_WORKER_ERROR_NOT_FOUND, |
+ false /* expect_waiting */, |
+ false /* expect_active */)); |
+ context()->storage()->FindRegistrationForId( |
+ registration_id3, |
+ origin2_p1.GetOrigin(), |
+ base::Bind(&ExpectRegisteredWorkers, |
+ SERVICE_WORKER_OK, |
+ false /* expect_waiting */, |
+ true /* expect_active */)); |
+ |
+ context()->storage()->FindRegistrationForId( |
+ registration_id4, |
+ origin3_p1.GetOrigin(), |
+ base::Bind(&ExpectRegisteredWorkers, |
+ SERVICE_WORKER_OK, |
+ false /* expect_waiting */, |
+ true /* expect_active */)); |
+ |
+ base::RunLoop().RunUntilIdle(); |
+} |
+ |
// Make sure registering a new script shares an existing registration. |
TEST_F(ServiceWorkerContextTest, RegisterNewScript) { |
GURL pattern("http://www.example.com/"); |