Chromium Code Reviews| 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 27 matching lines...) Expand all Loading... | |
| 38 | 38 |
| 39 void RunOnIOThread(const base::Closure& closure) { | 39 void RunOnIOThread(const base::Closure& closure) { |
| 40 base::RunLoop run_loop; | 40 base::RunLoop run_loop; |
| 41 BrowserThread::PostTask( | 41 BrowserThread::PostTask( |
| 42 BrowserThread::IO, FROM_HERE, | 42 BrowserThread::IO, FROM_HERE, |
| 43 base::Bind(&RunAndQuit, closure, run_loop.QuitClosure(), | 43 base::Bind(&RunAndQuit, closure, run_loop.QuitClosure(), |
| 44 base::MessageLoopProxy::current())); | 44 base::MessageLoopProxy::current())); |
| 45 run_loop.Run(); | 45 run_loop.Run(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void ReceiveFetchResult(BrowserThread::ID run_quit_thread, | |
| 49 const base::Closure& quit, | |
| 50 ServiceWorkerStatusCode* out_status, | |
| 51 ServiceWorkerFetchResponse* out_response, | |
| 52 ServiceWorkerStatusCode actual_status, | |
| 53 const ServiceWorkerFetchResponse& actual_response) { | |
| 54 *out_status = actual_status; | |
| 55 *out_response = actual_response; | |
| 56 if (!quit.is_null()) | |
| 57 BrowserThread::PostTask(run_quit_thread, FROM_HERE, quit); | |
| 58 } | |
| 59 | |
| 60 ServiceWorkerVersion::FetchCallback CreateFetchResponseReceiver( | |
| 61 BrowserThread::ID run_quit_thread, | |
| 62 const base::Closure& quit, | |
| 63 ServiceWorkerStatusCode* out_status, | |
| 64 ServiceWorkerFetchResponse* out_response) { | |
| 65 return base::Bind( | |
| 66 &ReceiveFetchResult, run_quit_thread, quit, out_status, out_response); | |
| 67 } | |
| 68 | |
| 69 | |
|
kinuko
2014/02/19 07:18:00
nit: extra empty line
falken
2014/02/19 07:30:01
Done.
| |
| 48 } // namespace | 70 } // namespace |
| 49 | 71 |
| 50 class ServiceWorkerBrowserTest : public ContentBrowserTest { | 72 class ServiceWorkerBrowserTest : public ContentBrowserTest { |
| 51 protected: | 73 protected: |
| 52 typedef ServiceWorkerBrowserTest self; | 74 typedef ServiceWorkerBrowserTest self; |
| 53 | 75 |
| 54 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 76 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 55 command_line->AppendSwitch(switches::kEnableServiceWorker); | 77 command_line->AppendSwitch(switches::kEnableServiceWorker); |
| 56 } | 78 } |
| 57 | 79 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 AssociateRendererProcessToWorker(version_->embedded_worker()); | 246 AssociateRendererProcessToWorker(version_->embedded_worker()); |
| 225 } | 247 } |
| 226 | 248 |
| 227 void StartOnIOThread(const base::Closure& done, | 249 void StartOnIOThread(const base::Closure& done, |
| 228 ServiceWorkerStatusCode* result) { | 250 ServiceWorkerStatusCode* result) { |
| 229 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 251 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 230 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); | 252 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); |
| 231 } | 253 } |
| 232 | 254 |
| 233 void InstallOnIOThread(const base::Closure& done, | 255 void InstallOnIOThread(const base::Closure& done, |
| 234 ServiceWorkerStatusCode* result) { | 256 ServiceWorkerStatusCode* result) { |
| 235 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 257 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 236 version_->DispatchInstallEvent( | 258 version_->DispatchInstallEvent( |
| 237 -1, CreateReceiver(BrowserThread::UI, done, result)); | 259 -1, CreateReceiver(BrowserThread::UI, done, result)); |
| 238 } | 260 } |
| 239 | 261 |
| 262 void FetchOnIOThread(const base::Closure& done, | |
| 263 ServiceWorkerStatusCode* result, | |
| 264 ServiceWorkerFetchResponse* message) { | |
| 265 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 266 ServiceWorkerFetchRequest request( | |
| 267 embedded_test_server()->GetURL("/service_worker/empty.html"), | |
| 268 "GET", | |
| 269 std::map<std::string, std::string>()); | |
| 270 version_->DispatchFetchEvent( | |
| 271 request, | |
| 272 CreateFetchResponseReceiver(BrowserThread::UI, done, result, message)); | |
| 273 } | |
| 274 | |
| 275 | |
| 240 void StopOnIOThread(const base::Closure& done, | 276 void StopOnIOThread(const base::Closure& done, |
| 241 ServiceWorkerStatusCode* result) { | 277 ServiceWorkerStatusCode* result) { |
| 242 ASSERT_TRUE(version_); | 278 ASSERT_TRUE(version_); |
| 243 version_->StopWorker(CreateReceiver(BrowserThread::UI, done, result)); | 279 version_->StopWorker(CreateReceiver(BrowserThread::UI, done, result)); |
| 244 } | 280 } |
| 245 | 281 |
| 246 protected: | 282 protected: |
| 247 int64 next_registration_id_; | 283 int64 next_registration_id_; |
| 248 scoped_refptr<ServiceWorkerRegistration> registration_; | 284 scoped_refptr<ServiceWorkerRegistration> registration_; |
| 249 scoped_refptr<ServiceWorkerVersion> version_; | 285 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"); | 354 InstallTestHelper("/service_worker/worker_install_fulfilled.js"); |
| 319 } | 355 } |
| 320 | 356 |
| 321 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, | 357 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, |
| 322 InstallWithWaitUntil_Rejected) { | 358 InstallWithWaitUntil_Rejected) { |
| 323 // TODO(kinuko): This should also report back an error, but we | 359 // TODO(kinuko): This should also report back an error, but we |
| 324 // don't have plumbing for it yet. | 360 // don't have plumbing for it yet. |
| 325 InstallTestHelper("/service_worker/worker_install_rejected.js"); | 361 InstallTestHelper("/service_worker/worker_install_rejected.js"); |
| 326 } | 362 } |
| 327 | 363 |
| 364 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, Fetch) { | |
| 365 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, | |
| 366 "/service_worker/worker.js")); | |
| 367 | |
| 368 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | |
| 369 ServiceWorkerFetchResponse response; | |
| 370 base::RunLoop fetch_run_loop; | |
| 371 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 372 base::Bind(&self::FetchOnIOThread, this, | |
| 373 fetch_run_loop.QuitClosure(), | |
| 374 &status, &response)); | |
| 375 fetch_run_loop.Run(); | |
| 376 ASSERT_EQ(SERVICE_WORKER_OK, status); | |
| 377 ASSERT_EQ(200, response.status_code); | |
| 378 ASSERT_EQ("OK", response.status_text); | |
| 379 ASSERT_EQ("GET", response.method); | |
| 380 std::map<std::string, std::string> expected_headers; | |
| 381 ASSERT_EQ(expected_headers, response.headers); | |
| 382 } | |
| 383 | |
| 328 } // namespace content | 384 } // namespace content |
| OLD | NEW |