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

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

Issue 126603002: Implement registration job ordering (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 6 years, 11 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 d755884c645ca70dd3d136e6decd67bd679b1937..8c5d8cc74697b10d6be6517708bdb2c245d77f80 100644
--- a/content/browser/service_worker/service_worker_job_unittest.cc
+++ b/content/browser/service_worker/service_worker_job_unittest.cc
@@ -368,4 +368,155 @@ TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) {
ASSERT_EQ(new_registration, old_registration);
}
+// Register and then unregister the pattern, in parallel. Job coordinator should
+// process jobs until the last job.
+TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) {
+ 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,
+ SaveRegistration(REGISTRATION_OK, &registration_called, &registration));
+
+ bool unregistration_called = false;
+ job_coordinator_->Unregister(
+ pattern, SaveUnregistration(REGISTRATION_OK, &unregistration_called));
+
+ ASSERT_FALSE(registration_called);
+ ASSERT_FALSE(unregistration_called);
+ base::RunLoop().RunUntilIdle();
+ ASSERT_TRUE(registration_called);
+ ASSERT_TRUE(unregistration_called);
+
+ ASSERT_TRUE(registration->is_shutdown());
+
+ bool find_called = false;
+ storage_->FindRegistrationForPattern(
+ pattern,
+ SaveFoundRegistration(
+ false, REGISTRATION_OK, &find_called, &registration));
+
+ base::RunLoop().RunUntilIdle();
+
+ ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration);
+}
+
+// Register conflicting scripts for the same pattern. The most recent
+// registration should win, and the old registration should have been
+// shutdown.
+TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) {
+ GURL pattern("http://www.example.com/*");
+
+ GURL script_url1("http://www.example.com/service_worker1.js");
+ bool registration1_called = false;
+ scoped_refptr<ServiceWorkerRegistration> registration1;
+ job_coordinator_->Register(
+ pattern,
+ script_url1,
+ SaveRegistration(REGISTRATION_OK, &registration1_called, &registration1));
+
+ GURL script_url2("http://www.example.com/service_worker2.js");
+ bool registration2_called = false;
+ scoped_refptr<ServiceWorkerRegistration> registration2;
+ job_coordinator_->Register(
+ pattern,
+ script_url2,
+ SaveRegistration(REGISTRATION_OK, &registration2_called, &registration2));
+
+ ASSERT_FALSE(registration1_called);
+ ASSERT_FALSE(registration2_called);
+ base::RunLoop().RunUntilIdle();
+ ASSERT_TRUE(registration1_called);
+ ASSERT_TRUE(registration2_called);
+
+ scoped_refptr<ServiceWorkerRegistration> registration;
+ bool find_called = false;
+ storage_->FindRegistrationForPattern(
+ pattern,
+ SaveFoundRegistration(
+ true, REGISTRATION_OK, &find_called, &registration));
+
+ base::RunLoop().RunUntilIdle();
+
+ EXPECT_TRUE(registration1->is_shutdown());
+ EXPECT_FALSE(registration2->is_shutdown());
+ ASSERT_EQ(registration2, registration);
+}
+
+// Register the exact same pattern + script. Requests should be
+// coalesced such that both callers get the exact same registration
+// object.
+TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) {
+ GURL pattern("http://www.example.com/*");
+
+ GURL script_url("http://www.example.com/service_worker1.js");
+ bool registration1_called = false;
+ scoped_refptr<ServiceWorkerRegistration> registration1;
+ job_coordinator_->Register(
+ pattern,
+ script_url,
+ SaveRegistration(REGISTRATION_OK, &registration1_called, &registration1));
+
+ bool registration2_called = false;
+ scoped_refptr<ServiceWorkerRegistration> registration2;
+ job_coordinator_->Register(
+ pattern,
+ script_url,
+ SaveRegistration(REGISTRATION_OK, &registration2_called, &registration2));
+
+ ASSERT_FALSE(registration1_called);
+ ASSERT_FALSE(registration2_called);
+ base::RunLoop().RunUntilIdle();
+ ASSERT_TRUE(registration1_called);
+ ASSERT_TRUE(registration2_called);
+
+ ASSERT_EQ(registration1, registration2);
+
+ scoped_refptr<ServiceWorkerRegistration> registration;
+ bool find_called = false;
+ storage_->FindRegistrationForPattern(
+ pattern,
+ SaveFoundRegistration(
+ true, REGISTRATION_OK, &find_called, &registration));
+
+ base::RunLoop().RunUntilIdle();
+ ASSERT_EQ(registration, registration1);
+}
+
+// Call simulataneous unregister calls.
+TEST_F(ServiceWorkerJobTest, ParallelUnreg) {
+ GURL pattern("http://www.example.com/*");
+
+ GURL script_url("http://www.example.com/service_worker.js");
+ bool unregistration1_called = false;
+ job_coordinator_->Unregister(
+ pattern, SaveUnregistration(REGISTRATION_OK, &unregistration1_called));
+
+ bool unregistration2_called = false;
+ job_coordinator_->Unregister(
+ pattern, SaveUnregistration(REGISTRATION_OK, &unregistration2_called));
+
+ ASSERT_FALSE(unregistration1_called);
+ ASSERT_FALSE(unregistration2_called);
+ base::RunLoop().RunUntilIdle();
+ ASSERT_TRUE(unregistration1_called);
+ ASSERT_TRUE(unregistration2_called);
+
+ // There isn't really a way to test that they are being coalesced,
+ // but we can make sure they can exist simultaneously without
+ // crashing.
+ scoped_refptr<ServiceWorkerRegistration> registration;
+ bool find_called = false;
+ storage_->FindRegistrationForPattern(
+ pattern,
+ SaveFoundRegistration(
+ false, REGISTRATION_OK, &find_called, &registration));
+
+ base::RunLoop().RunUntilIdle();
+ ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698