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/embedded_worker_test_helper.h" | 5 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/browser/service_worker/embedded_worker_instance.h" | 8 #include "content/browser/service_worker/embedded_worker_instance.h" |
9 #include "content/browser/service_worker/embedded_worker_registry.h" | 9 #include "content/browser/service_worker/embedded_worker_registry.h" |
10 #include "content/browser/service_worker/service_worker_context_core.h" | 10 #include "content/browser/service_worker/service_worker_context_core.h" |
11 #include "content/common/service_worker/embedded_worker_messages.h" | 11 #include "content/common/service_worker/embedded_worker_messages.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 EmbeddedWorkerTestHelper::EmbeddedWorkerTestHelper( | 16 EmbeddedWorkerTestHelper::EmbeddedWorkerTestHelper( |
17 ServiceWorkerContextCore* context) | 17 ServiceWorkerContextCore* context) |
18 : context_(context->AsWeakPtr()), | 18 : context_(context->AsWeakPtr()), |
19 next_thread_id_(0), | 19 next_thread_id_(0), |
20 weak_factory_(this) { | 20 weak_factory_(this) { |
21 } | 21 } |
22 | 22 |
23 EmbeddedWorkerTestHelper::~EmbeddedWorkerTestHelper() { | 23 EmbeddedWorkerTestHelper::~EmbeddedWorkerTestHelper() { |
24 } | 24 } |
25 | 25 |
| 26 int EmbeddedWorkerTestHelper::SimulateCreateWorker(int process_id) { |
| 27 scoped_ptr<EmbeddedWorkerInstance> worker = registry()->CreateWorker(); |
| 28 |
| 29 int embedded_worker_id = worker->embedded_worker_id(); |
| 30 SimulateAddProcess(embedded_worker_id, process_id); |
| 31 return embedded_worker_id; |
| 32 } |
| 33 |
26 void EmbeddedWorkerTestHelper::SimulateAddProcess( | 34 void EmbeddedWorkerTestHelper::SimulateAddProcess( |
27 int embedded_worker_id, | 35 int embedded_worker_id, |
28 int process_id) { | 36 int process_id) { |
29 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); | 37 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); |
30 ASSERT_TRUE(worker); | 38 ASSERT_TRUE(worker); |
31 registry()->AddChildProcessSender(process_id, this); | 39 registry()->AddChildProcessSender(process_id, this); |
32 worker->AddProcessReference(process_id); | 40 worker->AddProcessReference(process_id); |
33 } | 41 } |
34 | 42 |
35 void EmbeddedWorkerTestHelper::SimulateRemoveProcess( | 43 void EmbeddedWorkerTestHelper::SimulateRemoveProcess( |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 request_id, | 157 request_id, |
150 message)); | 158 message)); |
151 } | 159 } |
152 | 160 |
153 EmbeddedWorkerRegistry* EmbeddedWorkerTestHelper::registry() { | 161 EmbeddedWorkerRegistry* EmbeddedWorkerTestHelper::registry() { |
154 DCHECK(context_); | 162 DCHECK(context_); |
155 return context_->embedded_worker_registry(); | 163 return context_->embedded_worker_registry(); |
156 } | 164 } |
157 | 165 |
158 } // namespace content | 166 } // namespace content |
OLD | NEW |