| Index: content/browser/service_worker/embedded_worker_instance_unittest.cc
|
| diff --git a/content/browser/service_worker/embedded_worker_instance_unittest.cc b/content/browser/service_worker/embedded_worker_instance_unittest.cc
|
| index c5f190eef42375c75139d573dcdd2827548c25b0..c2d753cbaed7087be894b6959c17a449b9c31651 100644
|
| --- a/content/browser/service_worker/embedded_worker_instance_unittest.cc
|
| +++ b/content/browser/service_worker/embedded_worker_instance_unittest.cc
|
| @@ -17,7 +17,18 @@
|
|
|
| namespace content {
|
|
|
| -static const int kRenderProcessId = 11;
|
| +namespace {
|
| +
|
| +const int kRenderProcessId = 11;
|
| +
|
| +void SaveStatusAndCall(ServiceWorkerStatusCode* out,
|
| + const base::Closure& callback,
|
| + ServiceWorkerStatusCode status) {
|
| + *out = status;
|
| + callback.Run();
|
| +}
|
| +
|
| +} // namespace
|
|
|
| class EmbeddedWorkerInstanceTest : public testing::Test {
|
| protected:
|
| @@ -30,6 +41,18 @@ class EmbeddedWorkerInstanceTest : public testing::Test {
|
|
|
| void TearDown() override { helper_.reset(); }
|
|
|
| + ServiceWorkerStatusCode StartWorker(EmbeddedWorkerInstance* worker,
|
| + int id, const GURL& pattern,
|
| + const GURL& url) {
|
| + ServiceWorkerStatusCode status;
|
| + base::RunLoop run_loop;
|
| + worker->Start(id, pattern, url, false,
|
| + base::Bind(&SaveStatusAndCall, &status,
|
| + run_loop.QuitClosure()));
|
| + run_loop.Run();
|
| + return status;
|
| + }
|
| +
|
| ServiceWorkerContextCore* context() { return helper_->context(); }
|
|
|
| EmbeddedWorkerRegistry* embedded_worker_registry() {
|
| @@ -46,13 +69,6 @@ class EmbeddedWorkerInstanceTest : public testing::Test {
|
| DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstanceTest);
|
| };
|
|
|
| -static void SaveStatusAndCall(ServiceWorkerStatusCode* out,
|
| - const base::Closure& callback,
|
| - ServiceWorkerStatusCode status) {
|
| - *out = status;
|
| - callback.Run();
|
| -}
|
| -
|
| TEST_F(EmbeddedWorkerInstanceTest, StartAndStop) {
|
| scoped_ptr<EmbeddedWorkerInstance> worker =
|
| embedded_worker_registry()->CreateWorker();
|
| @@ -99,6 +115,50 @@ TEST_F(EmbeddedWorkerInstanceTest, StartAndStop) {
|
| EmbeddedWorkerMsg_StopWorker::ID));
|
| }
|
|
|
| +TEST_F(EmbeddedWorkerInstanceTest, StopWhenDevToolsAttached) {
|
| + scoped_ptr<EmbeddedWorkerInstance> worker =
|
| + embedded_worker_registry()->CreateWorker();
|
| + EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
|
| +
|
| + const int64 service_worker_version_id = 55L;
|
| + const GURL pattern("http://example.com/");
|
| + const GURL url("http://example.com/worker.js");
|
| +
|
| + // Simulate adding one process to the pattern.
|
| + helper_->SimulateAddProcessToPattern(pattern, kRenderProcessId);
|
| +
|
| + // Start the worker and then call StopIfIdle().
|
| + EXPECT_EQ(SERVICE_WORKER_OK,
|
| + StartWorker(worker.get(), service_worker_version_id, pattern, url));
|
| + EXPECT_EQ(EmbeddedWorkerInstance::RUNNING, worker->status());
|
| + EXPECT_EQ(kRenderProcessId, worker->process_id());
|
| + worker->StopIfIdle();
|
| + EXPECT_EQ(EmbeddedWorkerInstance::STOPPING, worker->status());
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + // The worker must be stopped now.
|
| + EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
|
| +
|
| + // Set devtools_attached to true, and do the same.
|
| + worker->set_devtools_attached(true);
|
| +
|
| + EXPECT_EQ(SERVICE_WORKER_OK,
|
| + StartWorker(worker.get(), service_worker_version_id, pattern, url));
|
| + EXPECT_EQ(EmbeddedWorkerInstance::RUNNING, worker->status());
|
| + EXPECT_EQ(kRenderProcessId, worker->process_id());
|
| + worker->StopIfIdle();
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + // The worker must not be stopped this time.
|
| + EXPECT_EQ(EmbeddedWorkerInstance::RUNNING, worker->status());
|
| +
|
| + // Calling Stop() actually stops the worker regardless of whether devtools
|
| + // is attached or not.
|
| + EXPECT_EQ(SERVICE_WORKER_OK, worker->Stop());
|
| + base::RunLoop().RunUntilIdle();
|
| + EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
|
| +}
|
| +
|
| TEST_F(EmbeddedWorkerInstanceTest, InstanceDestroyedBeforeStartFinishes) {
|
| scoped_ptr<EmbeddedWorkerInstance> worker =
|
| embedded_worker_registry()->CreateWorker();
|
|
|