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 "content/browser/service_worker/service_worker_process_manager.h" | 5 #include "content/browser/service_worker/service_worker_process_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 EXPECT_EQ(3u, instance_info.size()); | 210 EXPECT_EQ(3u, instance_info.size()); |
211 found = instance_info.find(kEmbeddedWorkerId3); | 211 found = instance_info.find(kEmbeddedWorkerId3); |
212 ASSERT_TRUE(found != instance_info.end()); | 212 ASSERT_TRUE(found != instance_info.end()); |
213 EXPECT_EQ(host2->GetID(), found->second.process_id); | 213 EXPECT_EQ(host2->GetID(), found->second.process_id); |
214 | 214 |
215 // The instance map should be updated by process release. | 215 // The instance map should be updated by process release. |
216 process_manager_->ReleaseWorkerProcess(kEmbeddedWorkerId3); | 216 process_manager_->ReleaseWorkerProcess(kEmbeddedWorkerId3); |
217 EXPECT_EQ(2, host1->worker_ref_count()); | 217 EXPECT_EQ(2, host1->worker_ref_count()); |
218 EXPECT_EQ(0, host2->worker_ref_count()); | 218 EXPECT_EQ(0, host2->worker_ref_count()); |
219 EXPECT_EQ(2u, instance_info.size()); | 219 EXPECT_EQ(2u, instance_info.size()); |
220 EXPECT_TRUE(ContainsKey(instance_info, kEmbeddedWorkerId1)); | 220 EXPECT_TRUE(base::ContainsKey(instance_info, kEmbeddedWorkerId1)); |
221 EXPECT_TRUE(ContainsKey(instance_info, kEmbeddedWorkerId2)); | 221 EXPECT_TRUE(base::ContainsKey(instance_info, kEmbeddedWorkerId2)); |
222 | 222 |
223 process_manager_->ReleaseWorkerProcess(kEmbeddedWorkerId1); | 223 process_manager_->ReleaseWorkerProcess(kEmbeddedWorkerId1); |
224 EXPECT_EQ(1, host1->worker_ref_count()); | 224 EXPECT_EQ(1, host1->worker_ref_count()); |
225 EXPECT_EQ(0, host2->worker_ref_count()); | 225 EXPECT_EQ(0, host2->worker_ref_count()); |
226 EXPECT_EQ(1u, instance_info.size()); | 226 EXPECT_EQ(1u, instance_info.size()); |
227 EXPECT_TRUE(ContainsKey(instance_info, kEmbeddedWorkerId2)); | 227 EXPECT_TRUE(base::ContainsKey(instance_info, kEmbeddedWorkerId2)); |
228 | 228 |
229 process_manager_->ReleaseWorkerProcess(kEmbeddedWorkerId2); | 229 process_manager_->ReleaseWorkerProcess(kEmbeddedWorkerId2); |
230 EXPECT_EQ(0, host1->worker_ref_count()); | 230 EXPECT_EQ(0, host1->worker_ref_count()); |
231 EXPECT_EQ(0, host2->worker_ref_count()); | 231 EXPECT_EQ(0, host2->worker_ref_count()); |
232 EXPECT_TRUE(instance_info.empty()); | 232 EXPECT_TRUE(instance_info.empty()); |
233 } | 233 } |
234 | 234 |
235 TEST_F(ServiceWorkerProcessManagerTest, AllocateWorkerProcess_InShutdown) { | 235 TEST_F(ServiceWorkerProcessManagerTest, AllocateWorkerProcess_InShutdown) { |
236 process_manager_->Shutdown(); | 236 process_manager_->Shutdown(); |
237 ASSERT_TRUE(process_manager_->IsShutdown()); | 237 ASSERT_TRUE(process_manager_->IsShutdown()); |
238 | 238 |
239 base::RunLoop run_loop; | 239 base::RunLoop run_loop; |
240 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; | 240 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; |
241 int process_id = -10; | 241 int process_id = -10; |
242 bool is_new_process = true; | 242 bool is_new_process = true; |
243 process_manager_->AllocateWorkerProcess( | 243 process_manager_->AllocateWorkerProcess( |
244 1, pattern_, script_url_, true /* can_use_existing_process */, | 244 1, pattern_, script_url_, true /* can_use_existing_process */, |
245 base::Bind(&DidAllocateWorkerProcess, run_loop.QuitClosure(), &status, | 245 base::Bind(&DidAllocateWorkerProcess, run_loop.QuitClosure(), &status, |
246 &process_id, &is_new_process)); | 246 &process_id, &is_new_process)); |
247 run_loop.Run(); | 247 run_loop.Run(); |
248 | 248 |
249 // Allocating a process in shutdown should abort. | 249 // Allocating a process in shutdown should abort. |
250 EXPECT_EQ(SERVICE_WORKER_ERROR_ABORT, status); | 250 EXPECT_EQ(SERVICE_WORKER_ERROR_ABORT, status); |
251 EXPECT_EQ(ChildProcessHost::kInvalidUniqueID, process_id); | 251 EXPECT_EQ(ChildProcessHost::kInvalidUniqueID, process_id); |
252 EXPECT_FALSE(is_new_process); | 252 EXPECT_FALSE(is_new_process); |
253 EXPECT_TRUE(process_manager_->instance_info_.empty()); | 253 EXPECT_TRUE(process_manager_->instance_info_.empty()); |
254 } | 254 } |
255 | 255 |
256 } // namespace content | 256 } // namespace content |
OLD | NEW |