| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "content/browser/service_worker/embedded_worker_registry.h" | 7 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 8 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 8 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 9 #include "content/browser/service_worker/service_worker_context_core.h" | 9 #include "content/browser/service_worker/service_worker_context_core.h" |
| 10 #include "content/browser/service_worker/service_worker_registration.h" | 10 #include "content/browser/service_worker/service_worker_registration.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // --------------------------------------------------------------------------- | 26 // --------------------------------------------------------------------------- |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 static const int kRenderProcessId = 1; | 32 static const int kRenderProcessId = 1; |
| 33 | 33 |
| 34 class MessageReceiver : public EmbeddedWorkerTestHelper { | 34 class MessageReceiver : public EmbeddedWorkerTestHelper { |
| 35 public: | 35 public: |
| 36 MessageReceiver(ServiceWorkerContextCore* context) | 36 MessageReceiver() |
| 37 : EmbeddedWorkerTestHelper(context, kRenderProcessId), | 37 : EmbeddedWorkerTestHelper(kRenderProcessId), |
| 38 current_embedded_worker_id_(0) {} | 38 current_embedded_worker_id_(0) {} |
| 39 virtual ~MessageReceiver() {} | 39 virtual ~MessageReceiver() {} |
| 40 | 40 |
| 41 virtual bool OnMessageToWorker(int thread_id, | 41 virtual bool OnMessageToWorker(int thread_id, |
| 42 int embedded_worker_id, | 42 int embedded_worker_id, |
| 43 const IPC::Message& message) OVERRIDE { | 43 const IPC::Message& message) OVERRIDE { |
| 44 if (EmbeddedWorkerTestHelper::OnMessageToWorker( | 44 if (EmbeddedWorkerTestHelper::OnMessageToWorker( |
| 45 thread_id, embedded_worker_id, message)) { | 45 thread_id, embedded_worker_id, message)) { |
| 46 return true; | 46 return true; |
| 47 } | 47 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 } // namespace | 112 } // namespace |
| 113 | 113 |
| 114 class ServiceWorkerVersionTest : public testing::Test { | 114 class ServiceWorkerVersionTest : public testing::Test { |
| 115 protected: | 115 protected: |
| 116 ServiceWorkerVersionTest() | 116 ServiceWorkerVersionTest() |
| 117 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} | 117 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} |
| 118 | 118 |
| 119 virtual void SetUp() OVERRIDE { | 119 virtual void SetUp() OVERRIDE { |
| 120 context_.reset(new ServiceWorkerContextCore(base::FilePath(), NULL, NULL)); | 120 helper_.reset(new MessageReceiver()); |
| 121 helper_.reset(new MessageReceiver(context_.get())); | |
| 122 | 121 |
| 123 registration_ = new ServiceWorkerRegistration( | 122 registration_ = new ServiceWorkerRegistration( |
| 124 GURL("http://www.example.com/*"), | 123 GURL("http://www.example.com/*"), |
| 125 GURL("http://www.example.com/service_worker.js"), | 124 GURL("http://www.example.com/service_worker.js"), |
| 126 1L, context_->AsWeakPtr()); | 125 1L, |
| 126 helper_->context()->AsWeakPtr()); |
| 127 version_ = new ServiceWorkerVersion( | 127 version_ = new ServiceWorkerVersion( |
| 128 registration_, | 128 registration_, 1L, helper_->context()->AsWeakPtr()); |
| 129 1L, context_->AsWeakPtr()); | |
| 130 | 129 |
| 131 // Simulate adding one process to the worker. | 130 // Simulate adding one process to the worker. |
| 132 int embedded_worker_id = version_->embedded_worker()->embedded_worker_id(); | 131 int embedded_worker_id = version_->embedded_worker()->embedded_worker_id(); |
| 133 helper_->SimulateAddProcessToWorker(embedded_worker_id, kRenderProcessId); | 132 helper_->SimulateAddProcessToWorker(embedded_worker_id, kRenderProcessId); |
| 134 ASSERT_TRUE(version_->HasProcessToRun()); | 133 ASSERT_TRUE(version_->HasProcessToRun()); |
| 135 } | 134 } |
| 136 | 135 |
| 137 virtual void TearDown() OVERRIDE { | 136 virtual void TearDown() OVERRIDE { |
| 138 version_ = 0; | 137 version_ = 0; |
| 139 registration_ = 0; | 138 registration_ = 0; |
| 140 helper_.reset(); | 139 helper_.reset(); |
| 141 context_.reset(); | |
| 142 } | 140 } |
| 143 | 141 |
| 144 TestBrowserThreadBundle thread_bundle_; | 142 TestBrowserThreadBundle thread_bundle_; |
| 145 scoped_ptr<ServiceWorkerContextCore> context_; | |
| 146 scoped_ptr<MessageReceiver> helper_; | 143 scoped_ptr<MessageReceiver> helper_; |
| 147 scoped_refptr<ServiceWorkerRegistration> registration_; | 144 scoped_refptr<ServiceWorkerRegistration> registration_; |
| 148 scoped_refptr<ServiceWorkerVersion> version_; | 145 scoped_refptr<ServiceWorkerVersion> version_; |
| 149 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersionTest); | 146 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersionTest); |
| 150 }; | 147 }; |
| 151 | 148 |
| 152 TEST_F(ServiceWorkerVersionTest, ConcurrentStartAndStop) { | 149 TEST_F(ServiceWorkerVersionTest, ConcurrentStartAndStop) { |
| 153 // Call StartWorker() multiple times. | 150 // Call StartWorker() multiple times. |
| 154 ServiceWorkerStatusCode status1 = SERVICE_WORKER_ERROR_FAILED; | 151 ServiceWorkerStatusCode status1 = SERVICE_WORKER_ERROR_FAILED; |
| 155 ServiceWorkerStatusCode status2 = SERVICE_WORKER_ERROR_FAILED; | 152 ServiceWorkerStatusCode status2 = SERVICE_WORKER_ERROR_FAILED; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 // multiple times should be handled correctly. | 346 // multiple times should be handled correctly. |
| 350 ASSERT_TRUE(version_->HasProcessToRun()); | 347 ASSERT_TRUE(version_->HasProcessToRun()); |
| 351 | 348 |
| 352 // Removing the process again (so that # of AddProcess == # of RemoveProcess | 349 // Removing the process again (so that # of AddProcess == # of RemoveProcess |
| 353 // for the process) should remove all process references. | 350 // for the process) should remove all process references. |
| 354 version_->RemoveProcessFromWorker(another_process_id); | 351 version_->RemoveProcessFromWorker(another_process_id); |
| 355 ASSERT_FALSE(version_->HasProcessToRun()); | 352 ASSERT_FALSE(version_->HasProcessToRun()); |
| 356 } | 353 } |
| 357 | 354 |
| 358 } // namespace content | 355 } // namespace content |
| OLD | NEW |