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/embedded_worker_instance.h" | 5 #include "content/browser/service_worker/embedded_worker_instance.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, worker->status()); | 214 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, worker->status()); |
215 run_loop.Run(); | 215 run_loop.Run(); |
216 EXPECT_EQ(SERVICE_WORKER_OK, status); | 216 EXPECT_EQ(SERVICE_WORKER_OK, status); |
217 | 217 |
218 // The 'WorkerStarted' message should have been sent by | 218 // The 'WorkerStarted' message should have been sent by |
219 // EmbeddedWorkerTestHelper. | 219 // EmbeddedWorkerTestHelper. |
220 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status()); | 220 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status()); |
221 EXPECT_EQ(helper_->mock_render_process_id(), worker->process_id()); | 221 EXPECT_EQ(helper_->mock_render_process_id(), worker->process_id()); |
222 | 222 |
223 // Stop the worker. | 223 // Stop the worker. |
224 EXPECT_EQ(SERVICE_WORKER_OK, worker->Stop()); | 224 EXPECT_TRUE(worker->Stop()); |
225 EXPECT_EQ(EmbeddedWorkerStatus::STOPPING, worker->status()); | 225 EXPECT_EQ(EmbeddedWorkerStatus::STOPPING, worker->status()); |
226 base::RunLoop().RunUntilIdle(); | 226 base::RunLoop().RunUntilIdle(); |
227 | 227 |
228 // The 'WorkerStopped' message should have been sent by | 228 // The 'WorkerStopped' message should have been sent by |
229 // EmbeddedWorkerTestHelper. | 229 // EmbeddedWorkerTestHelper. |
230 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); | 230 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); |
231 | 231 |
232 if (!is_mojo_enabled()) { | 232 if (!is_mojo_enabled()) { |
233 // Verify that we've sent two messages via chromium IPC to start and | 233 // Verify that we've sent two messages via chromium IPC to start and |
234 // terminate the worker. | 234 // terminate the worker. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 CreateStartParams(service_worker_version_id, pattern, url); | 276 CreateStartParams(service_worker_version_id, pattern, url); |
277 worker->Start( | 277 worker->Start( |
278 std::move(params), CreateEventDispatcher(), | 278 std::move(params), CreateEventDispatcher(), |
279 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); | 279 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); |
280 run_loop.Run(); | 280 run_loop.Run(); |
281 EXPECT_EQ(SERVICE_WORKER_OK, status); | 281 EXPECT_EQ(SERVICE_WORKER_OK, status); |
282 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status()); | 282 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status()); |
283 // The worker should be using the default render process. | 283 // The worker should be using the default render process. |
284 EXPECT_EQ(helper_->mock_render_process_id(), worker->process_id()); | 284 EXPECT_EQ(helper_->mock_render_process_id(), worker->process_id()); |
285 | 285 |
286 EXPECT_EQ(SERVICE_WORKER_OK, worker->Stop()); | 286 EXPECT_TRUE(worker->Stop()); |
287 base::RunLoop().RunUntilIdle(); | 287 base::RunLoop().RunUntilIdle(); |
288 } | 288 } |
289 | 289 |
290 // Fail twice. | 290 // Fail twice. |
291 context()->UpdateVersionFailureCount(service_worker_version_id, | 291 context()->UpdateVersionFailureCount(service_worker_version_id, |
292 SERVICE_WORKER_ERROR_FAILED); | 292 SERVICE_WORKER_ERROR_FAILED); |
293 context()->UpdateVersionFailureCount(service_worker_version_id, | 293 context()->UpdateVersionFailureCount(service_worker_version_id, |
294 SERVICE_WORKER_ERROR_FAILED); | 294 SERVICE_WORKER_ERROR_FAILED); |
295 | 295 |
296 { | 296 { |
297 // Start again. | 297 // Start again. |
298 ServiceWorkerStatusCode status; | 298 ServiceWorkerStatusCode status; |
299 base::RunLoop run_loop; | 299 base::RunLoop run_loop; |
300 std::unique_ptr<EmbeddedWorkerStartParams> params = | 300 std::unique_ptr<EmbeddedWorkerStartParams> params = |
301 CreateStartParams(service_worker_version_id, pattern, url); | 301 CreateStartParams(service_worker_version_id, pattern, url); |
302 worker->Start( | 302 worker->Start( |
303 std::move(params), CreateEventDispatcher(), | 303 std::move(params), CreateEventDispatcher(), |
304 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); | 304 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); |
305 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, worker->status()); | 305 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, worker->status()); |
306 run_loop.Run(); | 306 run_loop.Run(); |
307 EXPECT_EQ(SERVICE_WORKER_OK, status); | 307 EXPECT_EQ(SERVICE_WORKER_OK, status); |
308 | 308 |
309 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status()); | 309 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status()); |
310 // The worker should be using the new render process. | 310 // The worker should be using the new render process. |
311 EXPECT_EQ(helper_->new_render_process_id(), worker->process_id()); | 311 EXPECT_EQ(helper_->new_render_process_id(), worker->process_id()); |
312 EXPECT_EQ(SERVICE_WORKER_OK, worker->Stop()); | 312 EXPECT_TRUE(worker->Stop()); |
313 base::RunLoop().RunUntilIdle(); | 313 base::RunLoop().RunUntilIdle(); |
314 } | 314 } |
315 } | 315 } |
316 | 316 |
317 TEST_P(EmbeddedWorkerInstanceTestP, StopWhenDevToolsAttached) { | 317 TEST_P(EmbeddedWorkerInstanceTestP, StopWhenDevToolsAttached) { |
318 std::unique_ptr<EmbeddedWorkerInstance> worker = | 318 std::unique_ptr<EmbeddedWorkerInstance> worker = |
319 embedded_worker_registry()->CreateWorker(); | 319 embedded_worker_registry()->CreateWorker(); |
320 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); | 320 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); |
321 | 321 |
322 const int64_t service_worker_version_id = 55L; | 322 const int64_t service_worker_version_id = 55L; |
(...skipping 24 matching lines...) Expand all Loading... |
347 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status()); | 347 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status()); |
348 EXPECT_EQ(helper_->mock_render_process_id(), worker->process_id()); | 348 EXPECT_EQ(helper_->mock_render_process_id(), worker->process_id()); |
349 worker->StopIfIdle(); | 349 worker->StopIfIdle(); |
350 base::RunLoop().RunUntilIdle(); | 350 base::RunLoop().RunUntilIdle(); |
351 | 351 |
352 // The worker must not be stopped this time. | 352 // The worker must not be stopped this time. |
353 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status()); | 353 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status()); |
354 | 354 |
355 // Calling Stop() actually stops the worker regardless of whether devtools | 355 // Calling Stop() actually stops the worker regardless of whether devtools |
356 // is attached or not. | 356 // is attached or not. |
357 EXPECT_EQ(SERVICE_WORKER_OK, worker->Stop()); | 357 EXPECT_TRUE(worker->Stop()); |
358 base::RunLoop().RunUntilIdle(); | 358 base::RunLoop().RunUntilIdle(); |
359 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); | 359 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); |
360 } | 360 } |
361 | 361 |
362 // Test that the removal of a worker from the registry doesn't remove | 362 // Test that the removal of a worker from the registry doesn't remove |
363 // other workers in the same process. | 363 // other workers in the same process. |
364 TEST_P(EmbeddedWorkerInstanceTestP, RemoveWorkerInSharedProcess) { | 364 TEST_P(EmbeddedWorkerInstanceTestP, RemoveWorkerInSharedProcess) { |
365 std::unique_ptr<EmbeddedWorkerInstance> worker1 = | 365 std::unique_ptr<EmbeddedWorkerInstance> worker1 = |
366 embedded_worker_registry()->CreateWorker(); | 366 embedded_worker_registry()->CreateWorker(); |
367 std::unique_ptr<EmbeddedWorkerInstance> worker2 = | 367 std::unique_ptr<EmbeddedWorkerInstance> worker2 = |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); | 513 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); |
514 EXPECT_EQ(ChildProcessHost::kInvalidUniqueID, worker->process_id()); | 514 EXPECT_EQ(ChildProcessHost::kInvalidUniqueID, worker->process_id()); |
515 | 515 |
516 // The start callback should not be aborted by stop (see a comment on the dtor | 516 // The start callback should not be aborted by stop (see a comment on the dtor |
517 // of EmbeddedWorkerInstance::StartTask). | 517 // of EmbeddedWorkerInstance::StartTask). |
518 EXPECT_EQ(SERVICE_WORKER_ERROR_MAX_VALUE, status); | 518 EXPECT_EQ(SERVICE_WORKER_ERROR_MAX_VALUE, status); |
519 | 519 |
520 // "PROCESS_ALLOCATED" event should not be recorded. | 520 // "PROCESS_ALLOCATED" event should not be recorded. |
521 ASSERT_EQ(1u, events_.size()); | 521 ASSERT_EQ(1u, events_.size()); |
522 EXPECT_EQ(DETACHED, events_[0].type); | 522 EXPECT_EQ(DETACHED, events_[0].type); |
523 if (is_mojo_enabled()) { | 523 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[0].status); |
524 // STOPPING should be recorded here because EmbeddedWorkerInstance must be | |
525 // detached while executing RunUntilIdle. | |
526 EXPECT_EQ(EmbeddedWorkerStatus::STOPPING, events_[0].status); | |
527 } else { | |
528 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[0].status); | |
529 } | |
530 events_.clear(); | 524 events_.clear(); |
531 | 525 |
532 // Restart the worker. | 526 // Restart the worker. |
533 status = SERVICE_WORKER_ERROR_MAX_VALUE; | 527 status = SERVICE_WORKER_ERROR_MAX_VALUE; |
534 std::unique_ptr<base::RunLoop> run_loop(new base::RunLoop); | 528 std::unique_ptr<base::RunLoop> run_loop(new base::RunLoop); |
535 params = CreateStartParams(version_id, scope, url); | 529 params = CreateStartParams(version_id, scope, url); |
536 worker->Start( | 530 worker->Start( |
537 std::move(params), CreateEventDispatcher(), | 531 std::move(params), CreateEventDispatcher(), |
538 base::Bind(&SaveStatusAndCall, &status, run_loop->QuitClosure())); | 532 base::Bind(&SaveStatusAndCall, &status, run_loop->QuitClosure())); |
539 run_loop->Run(); | 533 run_loop->Run(); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type); | 770 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type); |
777 EXPECT_EQ(DETACHED, events_[2].type); | 771 EXPECT_EQ(DETACHED, events_[2].type); |
778 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[2].status); | 772 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[2].status); |
779 } | 773 } |
780 | 774 |
781 INSTANTIATE_TEST_CASE_P(EmbeddedWorkerInstanceTest, | 775 INSTANTIATE_TEST_CASE_P(EmbeddedWorkerInstanceTest, |
782 EmbeddedWorkerInstanceTestP, | 776 EmbeddedWorkerInstanceTestP, |
783 ::testing::Values(false, true)); | 777 ::testing::Values(false, true)); |
784 | 778 |
785 } // namespace content | 779 } // namespace content |
OLD | NEW |