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