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

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

Issue 1710903002: Revert of service worker: use 200 OK for update requests even in the no update case (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // A helper to simulate the start worker sequence is stalled in a worker 111 // A helper to simulate the start worker sequence is stalled in a worker
112 // process. 112 // process.
113 class StalledInStartWorkerHelper : public EmbeddedWorkerTestHelper { 113 class StalledInStartWorkerHelper : public EmbeddedWorkerTestHelper {
114 public: 114 public:
115 StalledInStartWorkerHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {} 115 StalledInStartWorkerHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {}
116 ~StalledInStartWorkerHelper() override{}; 116 ~StalledInStartWorkerHelper() override{};
117 117
118 void OnStartWorker(int embedded_worker_id, 118 void OnStartWorker(int embedded_worker_id,
119 int64_t service_worker_version_id, 119 int64_t service_worker_version_id,
120 const GURL& scope, 120 const GURL& scope,
121 const GURL& script_url, 121 const GURL& script_url) override {
122 bool pause_after_download) override {
123 if (force_stall_in_start_) { 122 if (force_stall_in_start_) {
124 // Do nothing to simulate a stall in the worker process. 123 // Do nothing to simulate a stall in the worker process.
125 return; 124 return;
126 } 125 }
127 EmbeddedWorkerTestHelper::OnStartWorker(embedded_worker_id, 126 EmbeddedWorkerTestHelper::OnStartWorker(
128 service_worker_version_id, scope, 127 embedded_worker_id, service_worker_version_id, scope, script_url);
129 script_url, pause_after_download);
130 } 128 }
131 129
132 void set_force_stall_in_start(bool force_stall_in_start) { 130 void set_force_stall_in_start(bool force_stall_in_start) {
133 force_stall_in_start_ = force_stall_in_start; 131 force_stall_in_start_ = force_stall_in_start;
134 } 132 }
135 133
136 private: 134 private:
137 bool force_stall_in_start_ = true; 135 bool force_stall_in_start_ = true;
138 }; 136 };
139 137
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 EXPECT_EQ(SERVICE_WORKER_OK, status); 464 EXPECT_EQ(SERVICE_WORKER_OK, status);
467 ASSERT_EQ(3u, events_.size()); 465 ASSERT_EQ(3u, events_.size());
468 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type); 466 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type);
469 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type); 467 EXPECT_EQ(START_WORKER_MESSAGE_SENT, events_[1].type);
470 EXPECT_EQ(STARTED, events_[2].type); 468 EXPECT_EQ(STARTED, events_[2].type);
471 469
472 // Tear down the worker. 470 // Tear down the worker.
473 worker->Stop(); 471 worker->Stop();
474 } 472 }
475 473
476 TEST_F(EmbeddedWorkerInstanceTest, StopDuringPausedAfterDownload) {
477 const int64_t version_id = 55L;
478 const GURL scope("http://example.com/");
479 const GURL url("http://example.com/worker.js");
480
481 scoped_ptr<EmbeddedWorkerInstance> worker =
482 embedded_worker_registry()->CreateWorker();
483 worker->AddListener(this);
484
485 // Run the start worker sequence until pause after download.
486 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
487 worker->Start(version_id, scope, url, base::Bind(&SaveStatusAndCall, &status,
488 base::Bind(base::DoNothing)),
489 true /* pause_after_download */);
490 base::RunLoop().RunUntilIdle();
491
492 // Make the worker stopping and attempt to send a resume after download
493 // message.
494 worker->Stop();
495 worker->ResumeAfterDownload();
496 base::RunLoop().RunUntilIdle();
497
498 // The resume after download message should not have been sent.
499 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
500 EXPECT_FALSE(ipc_sink()->GetFirstMessageMatching(
501 EmbeddedWorkerMsg_ResumeAfterDownload::ID));
502 }
503
504 TEST_F(EmbeddedWorkerInstanceTest, StopAfterSendingStartWorkerMessage) { 474 TEST_F(EmbeddedWorkerInstanceTest, StopAfterSendingStartWorkerMessage) {
505 const int64_t version_id = 55L; 475 const int64_t version_id = 55L;
506 const GURL scope("http://example.com/"); 476 const GURL scope("http://example.com/");
507 const GURL url("http://example.com/worker.js"); 477 const GURL url("http://example.com/worker.js");
508 478
509 helper_.reset(new StalledInStartWorkerHelper); 479 helper_.reset(new StalledInStartWorkerHelper);
510 scoped_ptr<EmbeddedWorkerInstance> worker = 480 scoped_ptr<EmbeddedWorkerInstance> worker =
511 embedded_worker_registry()->CreateWorker(); 481 embedded_worker_registry()->CreateWorker();
512 worker->AddListener(this); 482 worker->AddListener(this);
513 483
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 583
614 // The callback should have run, and we should have got an OnStopped message. 584 // The callback should have run, and we should have got an OnStopped message.
615 EXPECT_EQ(SERVICE_WORKER_ERROR_IPC_FAILED, status); 585 EXPECT_EQ(SERVICE_WORKER_ERROR_IPC_FAILED, status);
616 ASSERT_EQ(2u, events_.size()); 586 ASSERT_EQ(2u, events_.size());
617 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type); 587 EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type);
618 EXPECT_EQ(STOPPED, events_[1].type); 588 EXPECT_EQ(STOPPED, events_[1].type);
619 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, events_[1].status); 589 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, events_[1].status);
620 } 590 }
621 591
622 } // namespace content 592 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698