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

Unified Diff: content/browser/service_worker/service_worker_job_unittest.cc

Issue 345583002: ServiceWorker: Add a function to abort all pending jobs in SWJobCoordinator (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments and add test cases Created 6 years, 6 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/browser/service_worker/service_worker_job_unittest.cc
diff --git a/content/browser/service_worker/service_worker_job_unittest.cc b/content/browser/service_worker/service_worker_job_unittest.cc
index 885793763ac36db1b83083833b158eb65f89031c..45ebb71f82b2cec411b7447bde4ddac1f6bf76ba 100644
--- a/content/browser/service_worker/service_worker_job_unittest.cc
+++ b/content/browser/service_worker/service_worker_job_unittest.cc
@@ -584,4 +584,119 @@ TEST_F(ServiceWorkerJobTest, ParallelUnreg) {
ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration);
}
+TEST_F(ServiceWorkerJobTest, AbortAll_Register) {
+ GURL pattern1("http://www1.example.com/*");
+ GURL pattern2("http://www2.example.com/*");
+ GURL script_url1("http://www1.example.com/service_worker.js");
+ GURL script_url2("http://www2.example.com/service_worker.js");
+
+ bool registration_called1 = false;
+ scoped_refptr<ServiceWorkerRegistration> registration1;
+ job_coordinator()->Register(
+ pattern1,
+ script_url1,
+ render_process_id_,
+ SaveRegistration(SERVICE_WORKER_ERROR_ABORT,
+ &registration_called1, &registration1));
+
+ bool registration_called2 = false;
+ scoped_refptr<ServiceWorkerRegistration> registration2;
+ job_coordinator()->Register(
+ pattern2,
+ script_url2,
+ render_process_id_,
+ SaveRegistration(SERVICE_WORKER_ERROR_ABORT,
+ &registration_called2, &registration2));
+
+ ASSERT_FALSE(registration_called1);
+ ASSERT_FALSE(registration_called2);
+ job_coordinator()->AbortAll();
+
+ base::RunLoop().RunUntilIdle();
+ ASSERT_TRUE(registration_called1);
+ ASSERT_TRUE(registration_called2);
+
+ bool find_called1 = false;
+ storage()->FindRegistrationForPattern(
+ pattern1,
+ SaveFoundRegistration(
+ SERVICE_WORKER_ERROR_NOT_FOUND, &find_called1, &registration1));
+
+ bool find_called2 = false;
+ storage()->FindRegistrationForPattern(
+ pattern2,
+ SaveFoundRegistration(
+ SERVICE_WORKER_ERROR_NOT_FOUND, &find_called2, &registration2));
+
+ base::RunLoop().RunUntilIdle();
+ ASSERT_TRUE(find_called1);
+ ASSERT_TRUE(find_called2);
+ ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration1);
+ ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration2);
falken 2014/06/19 08:10:56 nit: would it make sense to make change these last
nhiroki 2014/06/19 10:04:05 Done.
+}
+
+TEST_F(ServiceWorkerJobTest, AbortAll_Unregister) {
+ GURL pattern1("http://www1.example.com/*");
+ GURL pattern2("http://www2.example.com/*");
+
+ bool unregistration_called1 = false;
+ scoped_refptr<ServiceWorkerRegistration> registration1;
+ job_coordinator()->Unregister(
+ pattern1,
+ SaveUnregistration(SERVICE_WORKER_ERROR_ABORT,
+ &unregistration_called1));
+
+ bool unregistration_called2 = false;
+ job_coordinator()->Unregister(
+ pattern2,
+ SaveUnregistration(SERVICE_WORKER_ERROR_ABORT,
+ &unregistration_called2));
+
+ ASSERT_FALSE(unregistration_called1);
+ ASSERT_FALSE(unregistration_called2);
+ job_coordinator()->AbortAll();
+
+ base::RunLoop().RunUntilIdle();
+ ASSERT_TRUE(unregistration_called1);
+ ASSERT_TRUE(unregistration_called2);
+}
+
+TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) {
+ GURL pattern("http://www.example.com/*");
+ GURL script_url("http://www.example.com/service_worker.js");
+
+ bool registration_called = false;
+ scoped_refptr<ServiceWorkerRegistration> registration;
+ job_coordinator()->Register(
+ pattern,
+ script_url,
+ render_process_id_,
+ SaveRegistration(SERVICE_WORKER_ERROR_ABORT,
+ &registration_called, &registration));
+
+ bool unregistration_called = false;
+ job_coordinator()->Unregister(
+ pattern,
+ SaveUnregistration(SERVICE_WORKER_ERROR_ABORT,
+ &unregistration_called));
+
+ ASSERT_FALSE(registration_called);
+ ASSERT_FALSE(unregistration_called);
+ job_coordinator()->AbortAll();
+
+ base::RunLoop().RunUntilIdle();
+ ASSERT_TRUE(registration_called);
+ ASSERT_TRUE(unregistration_called);
+
+ bool find_called = false;
+ storage()->FindRegistrationForPattern(
+ pattern,
+ SaveFoundRegistration(
+ SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, &registration));
+
+ base::RunLoop().RunUntilIdle();
+ ASSERT_TRUE(find_called);
+ ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration);
falken 2014/06/19 08:10:56 maybe this one too
nhiroki 2014/06/19 10:04:05 Done.
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698