Chromium Code Reviews| Index: content/browser/service_worker/service_worker_storage_unittest.cc |
| diff --git a/content/browser/service_worker/service_worker_storage_unittest.cc b/content/browser/service_worker/service_worker_storage_unittest.cc |
| index de20af395e3b8d3fec87f9e74183d451fb630255..b602d76d88b79e620af9d3f3eb84b7fe585666f9 100644 |
| --- a/content/browser/service_worker/service_worker_storage_unittest.cc |
| +++ b/content/browser/service_worker/service_worker_storage_unittest.cc |
| @@ -442,4 +442,212 @@ TEST_F(ServiceWorkerStorageTest, InstallingRegistrationsAreFindable) { |
| was_called = false; |
| } |
| +TEST_F(ServiceWorkerStorageTest, FindRegistration_ExactMatch) { |
| + const GURL kDocumentUrl("http://www.example.com/scope/foobar"); |
| + bool was_called = false; |
| + ServiceWorkerStatusCode result = SERVICE_WORKER_OK; |
| + scoped_refptr<ServiceWorkerRegistration> found_registration; |
| + |
| + // Registration for "/scope/fooba*". |
|
jsbell
2014/05/21 19:20:03
There's a lot of repeated code here - can this be
|
| + const GURL kScope1("http://www.example.com/scope/fooba*"); |
| + const GURL kScript1("http://www.example.com/script1.js"); |
| + const int64 kRegistrationId1 = 1; |
| + const int64 kVersionId1 = 1; |
| + scoped_refptr<ServiceWorkerRegistration> live_registration1 = |
| + new ServiceWorkerRegistration( |
| + kScope1, kScript1, kRegistrationId1, context_ptr_); |
| + scoped_refptr<ServiceWorkerVersion> live_version1 = |
| + new ServiceWorkerVersion( |
| + live_registration1, kVersionId1, context_ptr_); |
| + live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); |
| + live_registration1->set_pending_version(live_version1); |
| + |
| + // Registration for "/scope/foobar". |
| + const GURL kScope2("http://www.example.com/scope/foobar"); |
| + const GURL kScript2("http://www.example.com/script2.js"); |
| + const int64 kRegistrationId2 = 2; |
| + const int64 kVersionId2 = 2; |
| + scoped_refptr<ServiceWorkerRegistration> live_registration2 = |
| + new ServiceWorkerRegistration( |
| + kScope2, kScript2, kRegistrationId2, context_ptr_); |
| + scoped_refptr<ServiceWorkerVersion> live_version2 = |
| + new ServiceWorkerVersion( |
| + live_registration2, kVersionId2, context_ptr_); |
| + live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); |
| + live_registration2->set_pending_version(live_version2); |
| + |
| + // Registration for "/scope/foobar*". |
| + const GURL kScope3("http://www.example.com/scope/foobar*"); |
| + const GURL kScript3("http://www.example.com/script3.js"); |
| + const int64 kRegistrationId3 = 3; |
| + const int64 kVersionId3 = 3; |
| + scoped_refptr<ServiceWorkerRegistration> live_registration3 = |
| + new ServiceWorkerRegistration( |
| + kScope3, kScript3, kRegistrationId3, context_ptr_); |
| + scoped_refptr<ServiceWorkerVersion> live_version3 = |
| + new ServiceWorkerVersion( |
| + live_registration3, kVersionId3, context_ptr_); |
| + live_version3->SetStatus(ServiceWorkerVersion::INSTALLED); |
| + live_registration3->set_pending_version(live_version3); |
| + |
| + // Notify storage of they being installed. |
| + storage()->NotifyInstallingRegistration(live_registration1); |
| + storage()->NotifyInstallingRegistration(live_registration2); |
| + storage()->NotifyInstallingRegistration(live_registration3); |
| + |
| + // Find a registration among installing ones. |
| + storage()->FindRegistrationForDocument( |
| + kDocumentUrl, |
| + MakeFindCallback(&was_called, &result, &found_registration)); |
| + base::RunLoop().RunUntilIdle(); |
| + ASSERT_TRUE(was_called); |
| + EXPECT_EQ(SERVICE_WORKER_OK, result); |
| + EXPECT_EQ(live_registration2, found_registration); |
|
jsbell
2014/05/21 19:20:03
See note about exact match vs. longest match. Per
|
| + was_called = false; |
| + found_registration = NULL; |
| + |
| + // Store registrations. |
| + storage()->StoreRegistration(live_registration1, live_version1, |
| + MakeStatusCallback(&was_called, &result)); |
| + EXPECT_FALSE(was_called); |
| + base::RunLoop().RunUntilIdle(); |
| + ASSERT_TRUE(was_called); |
| + EXPECT_EQ(SERVICE_WORKER_OK, result); |
| + was_called = false; |
| + storage()->StoreRegistration(live_registration2, live_version2, |
| + MakeStatusCallback(&was_called, &result)); |
| + EXPECT_FALSE(was_called); |
| + base::RunLoop().RunUntilIdle(); |
| + ASSERT_TRUE(was_called); |
| + EXPECT_EQ(SERVICE_WORKER_OK, result); |
| + was_called = false; |
| + storage()->StoreRegistration(live_registration3, live_version3, |
| + MakeStatusCallback(&was_called, &result)); |
| + EXPECT_FALSE(was_called); |
| + base::RunLoop().RunUntilIdle(); |
| + ASSERT_TRUE(was_called); |
| + EXPECT_EQ(SERVICE_WORKER_OK, result); |
| + was_called = false; |
| + |
| + // Notify storage of installations no longer happening. |
| + storage()->NotifyDoneInstallingRegistration(live_registration1); |
| + storage()->NotifyDoneInstallingRegistration(live_registration2); |
| + storage()->NotifyDoneInstallingRegistration(live_registration3); |
| + |
| + // Find a registration among installed ones. |
| + storage()->FindRegistrationForDocument( |
| + kDocumentUrl, |
| + MakeFindCallback(&was_called, &result, &found_registration)); |
| + base::RunLoop().RunUntilIdle(); |
| + ASSERT_TRUE(was_called); |
| + EXPECT_EQ(SERVICE_WORKER_OK, result); |
| + EXPECT_EQ(live_registration2, found_registration); |
| + was_called = false; |
| + found_registration = NULL; |
| +} |
| + |
| +TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestWildcardMatch) { |
| + const GURL kDocumentUrl("http://www.example.com/scope/foobar"); |
| + bool was_called = false; |
| + ServiceWorkerStatusCode result = SERVICE_WORKER_OK; |
| + scoped_refptr<ServiceWorkerRegistration> found_registration; |
| + |
| + // Registration for "/scope/foo*". |
| + const GURL kScope1("http://www.example.com/scope/foo*"); |
| + const GURL kScript1("http://www.example.com/script1.js"); |
| + const int64 kRegistrationId1 = 1; |
| + const int64 kVersionId1 = 1; |
| + scoped_refptr<ServiceWorkerRegistration> live_registration1 = |
| + new ServiceWorkerRegistration( |
| + kScope1, kScript1, kRegistrationId1, context_ptr_); |
| + scoped_refptr<ServiceWorkerVersion> live_version1 = |
| + new ServiceWorkerVersion( |
| + live_registration1, kVersionId1, context_ptr_); |
| + live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); |
| + live_registration1->set_pending_version(live_version1); |
| + |
| + // Registration for "/scope/fooba*". |
| + const GURL kScope2("http://www.example.com/scope/fooba*"); |
| + const GURL kScript2("http://www.example.com/script2.js"); |
| + const int64 kRegistrationId2 = 2; |
| + const int64 kVersionId2 = 2; |
| + scoped_refptr<ServiceWorkerRegistration> live_registration2 = |
| + new ServiceWorkerRegistration( |
| + kScope2, kScript2, kRegistrationId2, context_ptr_); |
| + scoped_refptr<ServiceWorkerVersion> live_version2 = |
| + new ServiceWorkerVersion( |
| + live_registration2, kVersionId2, context_ptr_); |
| + live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); |
| + live_registration2->set_pending_version(live_version2); |
| + |
| + // Registration for "/scope/foob*". |
| + const GURL kScope3("http://www.example.com/scope/foob*"); |
| + const GURL kScript3("http://www.example.com/script3.js"); |
| + const int64 kRegistrationId3 = 3; |
| + const int64 kVersionId3 = 3; |
| + scoped_refptr<ServiceWorkerRegistration> live_registration3 = |
| + new ServiceWorkerRegistration( |
| + kScope3, kScript3, kRegistrationId3, context_ptr_); |
| + scoped_refptr<ServiceWorkerVersion> live_version3 = |
| + new ServiceWorkerVersion( |
| + live_registration3, kVersionId3, context_ptr_); |
| + live_version3->SetStatus(ServiceWorkerVersion::INSTALLED); |
| + live_registration3->set_pending_version(live_version3); |
| + |
| + // Notify storage of they being installed. |
| + storage()->NotifyInstallingRegistration(live_registration1); |
| + storage()->NotifyInstallingRegistration(live_registration2); |
| + storage()->NotifyInstallingRegistration(live_registration3); |
| + |
| + // Find a registration among installing ones. |
| + storage()->FindRegistrationForDocument( |
| + kDocumentUrl, |
| + MakeFindCallback(&was_called, &result, &found_registration)); |
| + base::RunLoop().RunUntilIdle(); |
| + ASSERT_TRUE(was_called); |
| + EXPECT_EQ(SERVICE_WORKER_OK, result); |
| + EXPECT_EQ(live_registration2, found_registration); |
| + was_called = false; |
| + found_registration = NULL; |
| + |
| + // Store registrations. |
| + storage()->StoreRegistration(live_registration1, live_version1, |
| + MakeStatusCallback(&was_called, &result)); |
| + EXPECT_FALSE(was_called); |
| + base::RunLoop().RunUntilIdle(); |
| + ASSERT_TRUE(was_called); |
| + EXPECT_EQ(SERVICE_WORKER_OK, result); |
| + was_called = false; |
| + storage()->StoreRegistration(live_registration2, live_version2, |
| + MakeStatusCallback(&was_called, &result)); |
| + EXPECT_FALSE(was_called); |
| + base::RunLoop().RunUntilIdle(); |
| + ASSERT_TRUE(was_called); |
| + EXPECT_EQ(SERVICE_WORKER_OK, result); |
| + was_called = false; |
| + storage()->StoreRegistration(live_registration3, live_version3, |
| + MakeStatusCallback(&was_called, &result)); |
| + EXPECT_FALSE(was_called); |
| + base::RunLoop().RunUntilIdle(); |
| + ASSERT_TRUE(was_called); |
| + EXPECT_EQ(SERVICE_WORKER_OK, result); |
| + was_called = false; |
| + |
| + // Notify storage of installations no longer happening. |
| + storage()->NotifyDoneInstallingRegistration(live_registration1); |
| + storage()->NotifyDoneInstallingRegistration(live_registration2); |
| + storage()->NotifyDoneInstallingRegistration(live_registration3); |
| + |
| + // Find a registration among installed ones. |
| + storage()->FindRegistrationForDocument( |
| + kDocumentUrl, |
| + MakeFindCallback(&was_called, &result, &found_registration)); |
| + base::RunLoop().RunUntilIdle(); |
| + ASSERT_TRUE(was_called); |
| + EXPECT_EQ(SERVICE_WORKER_OK, result); |
| + EXPECT_EQ(live_registration2, found_registration); |
| + was_called = false; |
| + found_registration = NULL; |
| +} |
| + |
| } // namespace content |