| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 if (registration_) { | 187 if (registration_) { |
| 188 registration_->Shutdown(); | 188 registration_->Shutdown(); |
| 189 registration_ = NULL; | 189 registration_ = NULL; |
| 190 } | 190 } |
| 191 if (version_) { | 191 if (version_) { |
| 192 version_->Shutdown(); | 192 version_->Shutdown(); |
| 193 version_ = NULL; | 193 version_ = NULL; |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 | 196 |
| 197 void InstallTestHelper(const std::string& worker_url) { | |
| 198 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, | |
| 199 worker_url)); | |
| 200 | |
| 201 // Dispatch install on a worker. | |
| 202 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | |
| 203 base::RunLoop install_run_loop; | |
| 204 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 205 base::Bind(&self::InstallOnIOThread, this, | |
| 206 install_run_loop.QuitClosure(), | |
| 207 &status)); | |
| 208 install_run_loop.Run(); | |
| 209 ASSERT_EQ(SERVICE_WORKER_OK, status); | |
| 210 | |
| 211 // Stop the worker. | |
| 212 status = SERVICE_WORKER_ERROR_FAILED; | |
| 213 base::RunLoop stop_run_loop; | |
| 214 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 215 base::Bind(&self::StopOnIOThread, this, | |
| 216 stop_run_loop.QuitClosure(), | |
| 217 &status)); | |
| 218 stop_run_loop.Run(); | |
| 219 ASSERT_EQ(SERVICE_WORKER_OK, status); | |
| 220 } | |
| 221 | |
| 222 void SetUpRegistrationOnIOThread(const std::string& worker_url) { | 197 void SetUpRegistrationOnIOThread(const std::string& worker_url) { |
| 223 const int64 version_id = 1L; | 198 const int64 version_id = 1L; |
| 224 registration_ = new ServiceWorkerRegistration( | 199 registration_ = new ServiceWorkerRegistration( |
| 225 embedded_test_server()->GetURL("/*"), | 200 embedded_test_server()->GetURL("/*"), |
| 226 embedded_test_server()->GetURL(worker_url), | 201 embedded_test_server()->GetURL(worker_url), |
| 227 next_registration_id_++); | 202 next_registration_id_++); |
| 228 version_ = new ServiceWorkerVersion( | 203 version_ = new ServiceWorkerVersion( |
| 229 registration_, | 204 registration_, |
| 230 wrapper()->context()->embedded_worker_registry(), | 205 wrapper()->context()->embedded_worker_registry(), |
| 231 version_id); | 206 version_id); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 base::RunLoop start_run_loop; | 286 base::RunLoop start_run_loop; |
| 312 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 287 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 313 base::Bind(&self::StartOnIOThread, this, | 288 base::Bind(&self::StartOnIOThread, this, |
| 314 start_run_loop.QuitClosure(), | 289 start_run_loop.QuitClosure(), |
| 315 &status)); | 290 &status)); |
| 316 start_run_loop.Run(); | 291 start_run_loop.Run(); |
| 317 ASSERT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, status); | 292 ASSERT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, status); |
| 318 } | 293 } |
| 319 | 294 |
| 320 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, Install) { | 295 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, Install) { |
| 321 InstallTestHelper("/service_worker/worker.js"); | 296 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, |
| 322 } | 297 "/service_worker/worker.js")); |
| 323 | 298 |
| 324 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, | 299 // Dispatch install on a worker. |
| 325 InstallWithWaitUntil_Fulfilled) { | 300 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
| 326 InstallTestHelper("/service_worker/worker_install_fulfilled.js"); | 301 base::RunLoop install_run_loop; |
| 327 } | 302 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 303 base::Bind(&self::InstallOnIOThread, this, |
| 304 install_run_loop.QuitClosure(), |
| 305 &status)); |
| 306 install_run_loop.Run(); |
| 307 ASSERT_EQ(SERVICE_WORKER_OK, status); |
| 328 | 308 |
| 329 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, | 309 // Stop the worker. |
| 330 InstallWithWaitUntil_Rejected) { | 310 status = SERVICE_WORKER_ERROR_FAILED; |
| 331 // TODO(kinuko): This should also report back an error, but we | 311 base::RunLoop stop_run_loop; |
| 332 // don't have plumbing for it yet. | 312 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 333 InstallTestHelper("/service_worker/worker_install_rejected.js"); | 313 base::Bind(&self::StopOnIOThread, this, |
| 314 stop_run_loop.QuitClosure(), |
| 315 &status)); |
| 316 stop_run_loop.Run(); |
| 317 ASSERT_EQ(SERVICE_WORKER_OK, status); |
| 334 } | 318 } |
| 335 | 319 |
| 336 } // namespace content | 320 } // namespace content |
| OLD | NEW |