Chromium Code Reviews| Index: content/browser/service_worker/service_worker_dispatcher_host_unittest.cc |
| diff --git a/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc b/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc |
| index fe7cfa376e0966c946f6c3b68bbd5d2bf2cf7fa0..f763df89aff729b834fe55a2453843c7af096b9f 100644 |
| --- a/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc |
| +++ b/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc |
| @@ -103,6 +103,22 @@ class ServiceWorkerDispatcherHostTest : public testing::Test { |
| dispatcher_host_->ipc_sink()->ClearMessages(); |
| } |
| + void SendGetRegistration(int64 provider_id, GURL document_url) { |
| + dispatcher_host_->OnMessageReceived( |
| + ServiceWorkerHostMsg_GetRegistration( |
| + -1, -1, provider_id, document_url)); |
| + base::RunLoop().RunUntilIdle(); |
| + } |
| + |
| + void GetRegistration(int64 provider_id, |
| + GURL document_url, |
| + uint32 expected_message) { |
| + SendGetRegistration(provider_id, document_url); |
| + EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( |
| + expected_message)); |
| + dispatcher_host_->ipc_sink()->ClearMessages(); |
| + } |
| + |
| TestBrowserThreadBundle browser_thread_bundle_; |
| scoped_ptr<EmbeddedWorkerTestHelper> helper_; |
| scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_; |
| @@ -235,4 +251,28 @@ TEST_F(ServiceWorkerDispatcherHostTest, ProviderCreatedAndDestroyed) { |
| EXPECT_FALSE(context()->GetProviderHost(kRenderProcessId, kProviderId)); |
| } |
| +TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration) { |
| + const int64 kProviderId = 99; // Dummy value |
| + scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
| + kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
| + host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
| + base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); |
| + context()->AddProviderHost(host.Pass()); |
| + |
| + GetRegistration(kProviderId, |
| + GURL("http://www.example.com/"), |
| + ServiceWorkerMsg_DidGetRegistration::ID); |
| +} |
| + |
|
nhiroki
2014/09/10 04:07:22
How about testing a CrossOrigin case like others?
Kunihiko Sakamoto
2014/09/10 08:22:44
Done.
|
| +TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_EarlyContextDeletion) { |
| + helper_->ShutdownContext(); |
| + |
| + // Let the shutdown reach the simulated IO thread. |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + GetRegistration(-1, |
| + GURL(), |
| + ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); |
| +} |
| + |
| } // namespace content |