OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "content/browser/service_worker/embedded_worker_instance.h" | 9 #include "content/browser/service_worker/embedded_worker_instance.h" |
10 #include "content/browser/service_worker/embedded_worker_registry.h" | 10 #include "content/browser/service_worker/embedded_worker_registry.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 AssociateRendererProcessToWorker(version_->embedded_worker()); | 224 AssociateRendererProcessToWorker(version_->embedded_worker()); |
225 } | 225 } |
226 | 226 |
227 void StartOnIOThread(const base::Closure& done, | 227 void StartOnIOThread(const base::Closure& done, |
228 ServiceWorkerStatusCode* result) { | 228 ServiceWorkerStatusCode* result) { |
229 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 229 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
230 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); | 230 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); |
231 } | 231 } |
232 | 232 |
233 void InstallOnIOThread(const base::Closure& done, | 233 void InstallOnIOThread(const base::Closure& done, |
234 ServiceWorkerStatusCode* result) { | 234 ServiceWorkerStatusCode* result) { |
nhiroki
2014/02/14 09:03:21
indent-nit.
falken
2014/02/19 05:32:19
Done.
| |
235 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 235 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
236 version_->DispatchInstallEvent( | 236 version_->DispatchInstallEvent( |
237 -1, CreateReceiver(BrowserThread::UI, done, result)); | 237 -1, CreateReceiver(BrowserThread::UI, done, result)); |
238 } | 238 } |
239 | 239 |
240 void FetchOnIOThread(const base::Closure& done, | |
241 ServiceWorkerStatusCode* result) { | |
nhiroki
2014/02/14 09:03:21
ditto.
falken
2014/02/19 05:32:19
Done.
| |
242 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
243 ServiceWorkerFetchRequest request( | |
244 embedded_test_server()->GetURL("/service_worker/empty.html"), | |
245 "GET", | |
246 std::map<std::string, std::string>()); | |
247 // TODO(falken): Actually receive and test the ServiceWorkerFetchResponse. | |
248 version_->DispatchFetchEvent( | |
249 request, CreateReceiver(BrowserThread::UI, done, result)); | |
250 } | |
251 | |
252 | |
240 void StopOnIOThread(const base::Closure& done, | 253 void StopOnIOThread(const base::Closure& done, |
241 ServiceWorkerStatusCode* result) { | 254 ServiceWorkerStatusCode* result) { |
242 ASSERT_TRUE(version_); | 255 ASSERT_TRUE(version_); |
243 version_->StopWorker(CreateReceiver(BrowserThread::UI, done, result)); | 256 version_->StopWorker(CreateReceiver(BrowserThread::UI, done, result)); |
244 } | 257 } |
245 | 258 |
246 protected: | 259 protected: |
247 int64 next_registration_id_; | 260 int64 next_registration_id_; |
248 scoped_refptr<ServiceWorkerRegistration> registration_; | 261 scoped_refptr<ServiceWorkerRegistration> registration_; |
249 scoped_refptr<ServiceWorkerVersion> version_; | 262 scoped_refptr<ServiceWorkerVersion> version_; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 InstallTestHelper("/service_worker/worker_install_fulfilled.js"); | 331 InstallTestHelper("/service_worker/worker_install_fulfilled.js"); |
319 } | 332 } |
320 | 333 |
321 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, | 334 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, |
322 InstallWithWaitUntil_Rejected) { | 335 InstallWithWaitUntil_Rejected) { |
323 // TODO(kinuko): This should also report back an error, but we | 336 // TODO(kinuko): This should also report back an error, but we |
324 // don't have plumbing for it yet. | 337 // don't have plumbing for it yet. |
325 InstallTestHelper("/service_worker/worker_install_rejected.js"); | 338 InstallTestHelper("/service_worker/worker_install_rejected.js"); |
326 } | 339 } |
327 | 340 |
341 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, Fetch) { | |
342 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, | |
343 "/service_worker/worker.js")); | |
344 | |
345 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | |
346 base::RunLoop fetch_run_loop; | |
347 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
348 base::Bind(&self::FetchOnIOThread, this, | |
349 fetch_run_loop.QuitClosure(), | |
350 &status)); | |
351 fetch_run_loop.Run(); | |
352 ASSERT_EQ(SERVICE_WORKER_OK, status); | |
353 } | |
354 | |
328 } // namespace content | 355 } // namespace content |
OLD | NEW |