OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" | 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 base::RunLoop().RunUntilIdle(); | 96 base::RunLoop().RunUntilIdle(); |
97 } | 97 } |
98 | 98 |
99 void Unregister(int64 provider_id, GURL pattern, uint32 expected_message) { | 99 void Unregister(int64 provider_id, GURL pattern, uint32 expected_message) { |
100 SendUnregister(provider_id, pattern); | 100 SendUnregister(provider_id, pattern); |
101 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( | 101 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( |
102 expected_message)); | 102 expected_message)); |
103 dispatcher_host_->ipc_sink()->ClearMessages(); | 103 dispatcher_host_->ipc_sink()->ClearMessages(); |
104 } | 104 } |
105 | 105 |
106 void SendGetRegistration(int64 provider_id, GURL document_url) { | |
107 dispatcher_host_->OnMessageReceived( | |
108 ServiceWorkerHostMsg_GetRegistration( | |
109 -1, -1, provider_id, document_url)); | |
110 base::RunLoop().RunUntilIdle(); | |
111 } | |
112 | |
113 void GetRegistration(int64 provider_id, | |
114 GURL document_url, | |
115 uint32 expected_message) { | |
116 SendGetRegistration(provider_id, document_url); | |
117 EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( | |
118 expected_message)); | |
119 dispatcher_host_->ipc_sink()->ClearMessages(); | |
120 } | |
121 | |
106 TestBrowserThreadBundle browser_thread_bundle_; | 122 TestBrowserThreadBundle browser_thread_bundle_; |
107 scoped_ptr<EmbeddedWorkerTestHelper> helper_; | 123 scoped_ptr<EmbeddedWorkerTestHelper> helper_; |
108 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_; | 124 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_; |
109 }; | 125 }; |
110 | 126 |
111 TEST_F(ServiceWorkerDispatcherHostTest, Register_SameOrigin) { | 127 TEST_F(ServiceWorkerDispatcherHostTest, Register_SameOrigin) { |
112 const int64 kProviderId = 99; // Dummy value | 128 const int64 kProviderId = 99; // Dummy value |
113 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 129 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
114 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | 130 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
115 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 131 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 // Deletion of the dispatcher_host should cause providers for that | 244 // Deletion of the dispatcher_host should cause providers for that |
229 // process to get deleted as well. | 245 // process to get deleted as well. |
230 dispatcher_host_->OnMessageReceived( | 246 dispatcher_host_->OnMessageReceived( |
231 ServiceWorkerHostMsg_ProviderCreated(kProviderId)); | 247 ServiceWorkerHostMsg_ProviderCreated(kProviderId)); |
232 EXPECT_TRUE(context()->GetProviderHost(kRenderProcessId, kProviderId)); | 248 EXPECT_TRUE(context()->GetProviderHost(kRenderProcessId, kProviderId)); |
233 EXPECT_TRUE(dispatcher_host_->HasOneRef()); | 249 EXPECT_TRUE(dispatcher_host_->HasOneRef()); |
234 dispatcher_host_ = NULL; | 250 dispatcher_host_ = NULL; |
235 EXPECT_FALSE(context()->GetProviderHost(kRenderProcessId, kProviderId)); | 251 EXPECT_FALSE(context()->GetProviderHost(kRenderProcessId, kProviderId)); |
236 } | 252 } |
237 | 253 |
254 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration) { | |
255 const int64 kProviderId = 99; // Dummy value | |
256 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | |
257 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | |
258 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | |
259 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); | |
260 context()->AddProviderHost(host.Pass()); | |
261 | |
262 GetRegistration(kProviderId, | |
263 GURL("http://www.example.com/"), | |
264 ServiceWorkerMsg_DidGetRegistration::ID); | |
265 } | |
266 | |
nhiroki
2014/09/10 04:07:22
How about testing a CrossOrigin case like others?
Kunihiko Sakamoto
2014/09/10 08:22:44
Done.
| |
267 TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_EarlyContextDeletion) { | |
268 helper_->ShutdownContext(); | |
269 | |
270 // Let the shutdown reach the simulated IO thread. | |
271 base::RunLoop().RunUntilIdle(); | |
272 | |
273 GetRegistration(-1, | |
274 GURL(), | |
275 ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); | |
276 } | |
277 | |
238 } // namespace content | 278 } // namespace content |
OLD | NEW |