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

Unified Diff: content/browser/service_worker/service_worker_version_unittest.cc

Issue 739383002: Don't drop messages/events send to a service worker that is stopping. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@termnate_sw
Patch Set: address nit Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/service_worker/service_worker_version.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/service_worker/service_worker_version_unittest.cc
diff --git a/content/browser/service_worker/service_worker_version_unittest.cc b/content/browser/service_worker/service_worker_version_unittest.cc
index 31225e963572de85d6919aa1767c42039edfc5ff..cd12a0cd4d0353be044a5758a6f3a7f82d8c5cf5 100644
--- a/content/browser/service_worker/service_worker_version_unittest.cc
+++ b/content/browser/service_worker/service_worker_version_unittest.cc
@@ -88,7 +88,9 @@ class MessageReceiverFromWorker : public EmbeddedWorkerInstance::Listener {
~MessageReceiverFromWorker() override { instance_->RemoveListener(this); }
void OnStarted() override { NOTREACHED(); }
- void OnStopped() override { NOTREACHED(); }
+ void OnStopped(EmbeddedWorkerInstance::Status old_status) override {
+ NOTREACHED();
+ }
bool OnMessageReceived(const IPC::Message& message) override {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(MessageReceiverFromWorker, message)
@@ -209,21 +211,43 @@ TEST_F(ServiceWorkerVersionTest, ConcurrentStartAndStop) {
// Call StopWorker() multiple times.
status1 = SERVICE_WORKER_ERROR_FAILED;
status2 = SERVICE_WORKER_ERROR_FAILED;
- status3 = SERVICE_WORKER_ERROR_FAILED;
version_->StopWorker(CreateReceiverOnCurrentThread(&status1));
version_->StopWorker(CreateReceiverOnCurrentThread(&status2));
- // Also try calling StartWorker while StopWorker is in queue.
+ EXPECT_EQ(ServiceWorkerVersion::STOPPING, version_->running_status());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(ServiceWorkerVersion::STOPPED, version_->running_status());
+
+ // All StopWorker should just succeed.
+ EXPECT_EQ(SERVICE_WORKER_OK, status1);
+ EXPECT_EQ(SERVICE_WORKER_OK, status2);
+
+ // Start worker again.
+ status1 = SERVICE_WORKER_ERROR_FAILED;
+ status2 = SERVICE_WORKER_ERROR_FAILED;
+ status3 = SERVICE_WORKER_ERROR_FAILED;
+
+ version_->StartWorker(CreateReceiverOnCurrentThread(&status1));
+
+ EXPECT_EQ(ServiceWorkerVersion::STARTING, version_->running_status());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(ServiceWorkerVersion::RUNNING, version_->running_status());
+
+ // Call StopWorker()
+ status2 = SERVICE_WORKER_ERROR_FAILED;
+ version_->StopWorker(CreateReceiverOnCurrentThread(&status2));
+
+ // And try calling StartWorker while StopWorker is in queue.
version_->StartWorker(CreateReceiverOnCurrentThread(&status3));
EXPECT_EQ(ServiceWorkerVersion::STOPPING, version_->running_status());
base::RunLoop().RunUntilIdle();
- EXPECT_EQ(ServiceWorkerVersion::STOPPED, version_->running_status());
+ EXPECT_EQ(ServiceWorkerVersion::RUNNING, version_->running_status());
- // All StopWorker should just succeed, while StartWorker fails.
+ // All should just succeed.
EXPECT_EQ(SERVICE_WORKER_OK, status1);
EXPECT_EQ(SERVICE_WORKER_OK, status2);
- EXPECT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, status3);
+ EXPECT_EQ(SERVICE_WORKER_OK, status3);
}
TEST_F(ServiceWorkerVersionTest, SendMessage) {
@@ -248,39 +272,11 @@ TEST_F(ServiceWorkerVersionTest, SendMessage) {
base::RunLoop().RunUntilIdle();
EXPECT_EQ(SERVICE_WORKER_OK, stop_status);
- // SendMessage should return START_WORKER_FAILED error since it tried to
- // start a worker while it was stopping.
- EXPECT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, msg_status);
-}
-
-TEST_F(ServiceWorkerVersionTest, ReSendMessageAfterStop) {
- EXPECT_EQ(ServiceWorkerVersion::STOPPED, version_->running_status());
-
- // Start the worker.
- ServiceWorkerStatusCode start_status = SERVICE_WORKER_ERROR_FAILED;
- version_->StartWorker(CreateReceiverOnCurrentThread(&start_status));
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(SERVICE_WORKER_OK, start_status);
- EXPECT_EQ(ServiceWorkerVersion::RUNNING, version_->running_status());
-
- // Stop the worker, and then send the message immediately.
- ServiceWorkerStatusCode msg_status = SERVICE_WORKER_ERROR_FAILED;
- ServiceWorkerStatusCode stop_status = SERVICE_WORKER_ERROR_FAILED;
- version_->StopWorker(CreateReceiverOnCurrentThread(&stop_status));
- version_->SendMessage(TestMsg_Message(),
- CreateReceiverOnCurrentThread(&msg_status));
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(SERVICE_WORKER_OK, stop_status);
-
- // SendMessage should return START_WORKER_FAILED error since it tried to
- // start a worker while it was stopping.
- EXPECT_EQ(SERVICE_WORKER_ERROR_START_WORKER_FAILED, msg_status);
-
- // Resend the message, which should succeed and restart the worker.
- version_->SendMessage(TestMsg_Message(),
- CreateReceiverOnCurrentThread(&msg_status));
- base::RunLoop().RunUntilIdle();
+ // SendMessage should return SERVICE_WORKER_OK since the worker should have
+ // been restarted to deliver the message.
EXPECT_EQ(SERVICE_WORKER_OK, msg_status);
+
+ // The worker should be now started again.
EXPECT_EQ(ServiceWorkerVersion::RUNNING, version_->running_status());
}
« no previous file with comments | « content/browser/service_worker/service_worker_version.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698