Skip to content

Commit

Permalink
Add test that service workers stay alive after handling a push event.
Browse files Browse the repository at this point in the history
Facebook relies on this implementation detail. Until we can support their use
case with a proper API/functionality we should make sure we don't break them.

BUG=517817

Review URL: https://codereview.chromium.org/1286103003

Cr-Commit-Position: refs/heads/master@{#342986}
  • Loading branch information
mfalken authored and Commit bot committed Aug 12, 2015
1 parent 1454d7f commit 4df847a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions content/browser/service_worker/service_worker_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ class CONTENT_EXPORT ServiceWorkerVersion
TimeoutStartingWorker);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest,
TimeoutWorkerInEvent);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StayAliveAfterPush);

class Metrics;
class PingController;
Expand Down
18 changes: 18 additions & 0 deletions content/browser/service_worker/service_worker_version_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,24 @@ TEST_F(ServiceWorkerVersionTest, IdleTimeout) {
EXPECT_LT(idle_time, version_->idle_time_);
}

// Test that the worker stays alive for some time after
// receiving a push event.
// TODO(falken): Remove this test once Facebook doesn't rely on the behavior:
// crbug.com/519993
TEST_F(ServiceWorkerVersionTest, StayAliveAfterPush) {
const base::TimeDelta kTenSeconds = base::TimeDelta::FromSeconds(10);
ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
version_->DispatchPushEvent(CreateReceiverOnCurrentThread(&status),
std::string());
base::RunLoop().RunUntilIdle();

// Pretend we've been idle for 10 seconds and fire the timeout code.
version_->idle_time_ = base::TimeTicks::Now() - kTenSeconds;
version_->OnTimeoutTimer();
EXPECT_EQ(ServiceWorkerVersion::RUNNING, version_->running_status());
}

TEST_F(ServiceWorkerVersionTest, SetDevToolsAttached) {
ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
version_->StartWorker(CreateReceiverOnCurrentThread(&status));
Expand Down

0 comments on commit 4df847a

Please sign in to comment.