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 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 EXPECT_EQ(SERVICE_WORKER_OK, status); | 514 EXPECT_EQ(SERVICE_WORKER_OK, status); |
515 ASSERT_EQ(3u, events_.size()); | 515 ASSERT_EQ(3u, events_.size()); |
516 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type); | 516 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type); |
517 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type); | 517 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type); |
518 EXPECT_EQ(STARTED, events_[2].type); | 518 EXPECT_EQ(STARTED, events_[2].type); |
519 | 519 |
520 // Tear down the worker. | 520 // Tear down the worker. |
521 worker->Stop(); | 521 worker->Stop(); |
522 } | 522 } |
523 | 523 |
524 class DontReceiveResumeAfterDownloadInstanceClient | |
525 : public EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient { | |
526 public: | |
527 explicit DontReceiveResumeAfterDownloadInstanceClient( | |
528 base::WeakPtr<EmbeddedWorkerTestHelper> helper) | |
529 : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {} | |
530 | |
531 private: | |
532 void ResumeAfterDownload() override { NOTREACHED(); } | |
falken
2017/01/18 01:12:06
Can you avoid the NOTREACHED by keeping state and
shimazu
2017/01/18 03:47:45
Thanks, done.
| |
533 }; | |
534 | |
524 TEST_F(EmbeddedWorkerInstanceTest, StopDuringPausedAfterDownload) { | 535 TEST_F(EmbeddedWorkerInstanceTest, StopDuringPausedAfterDownload) { |
525 const int64_t version_id = 55L; | 536 const int64_t version_id = 55L; |
526 const GURL scope("http://example.com/"); | 537 const GURL scope("http://example.com/"); |
527 const GURL url("http://example.com/worker.js"); | 538 const GURL url("http://example.com/worker.js"); |
528 | 539 |
540 helper_->RegisterMockInstanceClient( | |
541 base::MakeUnique<DontReceiveResumeAfterDownloadInstanceClient>( | |
542 helper_->AsWeakPtr())); | |
543 | |
529 std::unique_ptr<EmbeddedWorkerInstance> worker = | 544 std::unique_ptr<EmbeddedWorkerInstance> worker = |
530 embedded_worker_registry()->CreateWorker(); | 545 embedded_worker_registry()->CreateWorker(); |
531 worker->AddListener(this); | 546 worker->AddListener(this); |
532 | 547 |
533 // Run the start worker sequence until pause after download. | 548 // Run the start worker sequence until pause after download. |
534 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; | 549 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; |
535 | 550 |
536 std::unique_ptr<EmbeddedWorkerStartParams> params = | 551 std::unique_ptr<EmbeddedWorkerStartParams> params = |
537 CreateStartParams(version_id, scope, url); | 552 CreateStartParams(version_id, scope, url); |
538 params->pause_after_download = true; | 553 params->pause_after_download = true; |
539 worker->Start( | 554 worker->Start( |
540 std::move(params), CreateEventDispatcher(), | 555 std::move(params), CreateEventDispatcher(), |
541 base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing))); | 556 base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing))); |
542 base::RunLoop().RunUntilIdle(); | 557 base::RunLoop().RunUntilIdle(); |
543 | 558 |
544 // Make the worker stopping and attempt to send a resume after download | 559 // Make the worker stopping and attempt to send a resume after download |
545 // message. | 560 // message. |
546 worker->Stop(); | 561 worker->Stop(); |
547 worker->ResumeAfterDownload(); | 562 worker->ResumeAfterDownload(); |
548 base::RunLoop().RunUntilIdle(); | 563 base::RunLoop().RunUntilIdle(); |
549 | 564 |
550 // The resume after download message should not have been sent. | 565 // The resume after download message should not have been sent. |
551 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); | 566 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); |
552 EXPECT_FALSE(ipc_sink()->GetFirstMessageMatching( | |
553 EmbeddedWorkerMsg_ResumeAfterDownload::ID)); | |
554 } | 567 } |
555 | 568 |
556 TEST_F(EmbeddedWorkerInstanceTest, StopAfterSendingStartWorkerMessage) { | 569 TEST_F(EmbeddedWorkerInstanceTest, StopAfterSendingStartWorkerMessage) { |
557 const int64_t version_id = 55L; | 570 const int64_t version_id = 55L; |
558 const GURL scope("http://example.com/"); | 571 const GURL scope("http://example.com/"); |
559 const GURL url("http://example.com/worker.js"); | 572 const GURL url("http://example.com/worker.js"); |
560 | 573 |
561 helper_.reset(new StalledInStartWorkerHelper); | 574 helper_.reset(new StalledInStartWorkerHelper); |
562 std::unique_ptr<EmbeddedWorkerInstance> worker = | 575 std::unique_ptr<EmbeddedWorkerInstance> worker = |
563 embedded_worker_registry()->CreateWorker(); | 576 embedded_worker_registry()->CreateWorker(); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
719 | 732 |
720 // Worker should handle the sudden shutdown as detach. | 733 // Worker should handle the sudden shutdown as detach. |
721 ASSERT_EQ(3u, events_.size()); | 734 ASSERT_EQ(3u, events_.size()); |
722 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type); | 735 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type); |
723 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type); | 736 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type); |
724 EXPECT_EQ(DETACHED, events_[2].type); | 737 EXPECT_EQ(DETACHED, events_[2].type); |
725 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[2].status); | 738 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[2].status); |
726 } | 739 } |
727 | 740 |
728 } // namespace content | 741 } // namespace content |
OLD | NEW |