Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: content/browser/service_worker/embedded_worker_instance_unittest.cc

Issue 2630273002: ServiceWorker: mojofy ResumeAfterDownload and AddMessageToConsole (Closed)
Patch Set: Incorporating falken@ and dcheng@ comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 bool* is_resume_after_download_called)
530 : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper),
531 is_resume_after_download_called_(is_resume_after_download_called) {}
532
533 private:
534 void ResumeAfterDownload() override {
535 *is_resume_after_download_called_ = true;
536 }
537
538 bool* const is_resume_after_download_called_;
falken 2017/01/18 03:57:38 nit: "was_" seems like better grammar
shimazu 2017/01/18 05:00:46 Done.
539 };
540
524 TEST_F(EmbeddedWorkerInstanceTest, StopDuringPausedAfterDownload) { 541 TEST_F(EmbeddedWorkerInstanceTest, StopDuringPausedAfterDownload) {
525 const int64_t version_id = 55L; 542 const int64_t version_id = 55L;
526 const GURL scope("http://example.com/"); 543 const GURL scope("http://example.com/");
527 const GURL url("http://example.com/worker.js"); 544 const GURL url("http://example.com/worker.js");
528 545
546 bool is_resume_after_download_called = false;
547 helper_->RegisterMockInstanceClient(
548 base::MakeUnique<DontReceiveResumeAfterDownloadInstanceClient>(
549 helper_->AsWeakPtr(), &is_resume_after_download_called));
550
529 std::unique_ptr<EmbeddedWorkerInstance> worker = 551 std::unique_ptr<EmbeddedWorkerInstance> worker =
530 embedded_worker_registry()->CreateWorker(); 552 embedded_worker_registry()->CreateWorker();
531 worker->AddListener(this); 553 worker->AddListener(this);
532 554
533 // Run the start worker sequence until pause after download. 555 // Run the start worker sequence until pause after download.
534 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; 556 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
535 557
536 std::unique_ptr<EmbeddedWorkerStartParams> params = 558 std::unique_ptr<EmbeddedWorkerStartParams> params =
537 CreateStartParams(version_id, scope, url); 559 CreateStartParams(version_id, scope, url);
538 params->pause_after_download = true; 560 params->pause_after_download = true;
539 worker->Start( 561 worker->Start(
540 std::move(params), CreateEventDispatcher(), 562 std::move(params), CreateEventDispatcher(),
541 base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing))); 563 base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing)));
542 base::RunLoop().RunUntilIdle(); 564 base::RunLoop().RunUntilIdle();
543 565
544 // Make the worker stopping and attempt to send a resume after download 566 // Make the worker stopping and attempt to send a resume after download
545 // message. 567 // message.
546 worker->Stop(); 568 worker->Stop();
547 worker->ResumeAfterDownload(); 569 worker->ResumeAfterDownload();
548 base::RunLoop().RunUntilIdle(); 570 base::RunLoop().RunUntilIdle();
549 571
550 // The resume after download message should not have been sent. 572 // The resume after download message should not have been sent.
551 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status()); 573 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
552 EXPECT_FALSE(ipc_sink()->GetFirstMessageMatching( 574 EXPECT_FALSE(is_resume_after_download_called);
553 EmbeddedWorkerMsg_ResumeAfterDownload::ID));
554 } 575 }
555 576
556 TEST_F(EmbeddedWorkerInstanceTest, StopAfterSendingStartWorkerMessage) { 577 TEST_F(EmbeddedWorkerInstanceTest, StopAfterSendingStartWorkerMessage) {
557 const int64_t version_id = 55L; 578 const int64_t version_id = 55L;
558 const GURL scope("http://example.com/"); 579 const GURL scope("http://example.com/");
559 const GURL url("http://example.com/worker.js"); 580 const GURL url("http://example.com/worker.js");
560 581
561 helper_.reset(new StalledInStartWorkerHelper); 582 helper_.reset(new StalledInStartWorkerHelper);
562 std::unique_ptr<EmbeddedWorkerInstance> worker = 583 std::unique_ptr<EmbeddedWorkerInstance> worker =
563 embedded_worker_registry()->CreateWorker(); 584 embedded_worker_registry()->CreateWorker();
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 740
720 // Worker should handle the sudden shutdown as detach. 741 // Worker should handle the sudden shutdown as detach.
721 ASSERT_EQ(3u, events_.size()); 742 ASSERT_EQ(3u, events_.size());
722 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type); 743 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type);
723 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type); 744 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type);
724 EXPECT_EQ(DETACHED, events_[2].type); 745 EXPECT_EQ(DETACHED, events_[2].type);
725 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[2].status); 746 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[2].status);
726 } 747 }
727 748
728 } // namespace content 749 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698