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 <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 int embedded_worker_id, | 84 int embedded_worker_id, |
85 int64 service_worker_version_id, | 85 int64 service_worker_version_id, |
86 const GURL& scope, | 86 const GURL& scope, |
87 const GURL& script_url, | 87 const GURL& script_url, |
88 bool pause_after_download) { | 88 bool pause_after_download) { |
89 if (pause_after_download) { | 89 if (pause_after_download) { |
90 SimulatePausedAfterDownload(embedded_worker_id); | 90 SimulatePausedAfterDownload(embedded_worker_id); |
91 return; | 91 return; |
92 } | 92 } |
93 SimulateWorkerReadyForInspection(embedded_worker_id); | 93 SimulateWorkerReadyForInspection(embedded_worker_id); |
94 SimulateWorkerScriptLoaded(embedded_worker_id); | 94 SimulateWorkerScriptLoaded(next_thread_id_++, embedded_worker_id); |
95 SimulateWorkerStarted(next_thread_id_++, embedded_worker_id); | 95 SimulateWorkerStarted(embedded_worker_id); |
96 } | 96 } |
97 | 97 |
98 void EmbeddedWorkerTestHelper::OnResumeAfterDownload(int embedded_worker_id) { | 98 void EmbeddedWorkerTestHelper::OnResumeAfterDownload(int embedded_worker_id) { |
99 SimulateWorkerReadyForInspection(embedded_worker_id); | 99 SimulateWorkerReadyForInspection(embedded_worker_id); |
100 SimulateWorkerScriptLoaded(embedded_worker_id); | 100 SimulateWorkerScriptLoaded(next_thread_id_++, embedded_worker_id); |
101 SimulateWorkerStarted(next_thread_id_++, embedded_worker_id); | 101 SimulateWorkerStarted(embedded_worker_id); |
102 } | 102 } |
103 | 103 |
104 void EmbeddedWorkerTestHelper::OnStopWorker(int embedded_worker_id) { | 104 void EmbeddedWorkerTestHelper::OnStopWorker(int embedded_worker_id) { |
105 // By default just notify the sender that the worker is stopped. | 105 // By default just notify the sender that the worker is stopped. |
106 SimulateWorkerStopped(embedded_worker_id); | 106 SimulateWorkerStopped(embedded_worker_id); |
107 } | 107 } |
108 | 108 |
109 bool EmbeddedWorkerTestHelper::OnMessageToWorker( | 109 bool EmbeddedWorkerTestHelper::OnMessageToWorker( |
110 int thread_id, | 110 int thread_id, |
111 int embedded_worker_id, | 111 int embedded_worker_id, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 165 |
166 void EmbeddedWorkerTestHelper::SimulateWorkerReadyForInspection( | 166 void EmbeddedWorkerTestHelper::SimulateWorkerReadyForInspection( |
167 int embedded_worker_id) { | 167 int embedded_worker_id) { |
168 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); | 168 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); |
169 ASSERT_TRUE(worker != NULL); | 169 ASSERT_TRUE(worker != NULL); |
170 registry()->OnWorkerReadyForInspection(worker->process_id(), | 170 registry()->OnWorkerReadyForInspection(worker->process_id(), |
171 embedded_worker_id); | 171 embedded_worker_id); |
172 } | 172 } |
173 | 173 |
174 void EmbeddedWorkerTestHelper::SimulateWorkerScriptLoaded( | 174 void EmbeddedWorkerTestHelper::SimulateWorkerScriptLoaded( |
175 int embedded_worker_id) { | 175 int thread_id, int embedded_worker_id) { |
176 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); | 176 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); |
177 ASSERT_TRUE(worker != NULL); | 177 ASSERT_TRUE(worker != NULL); |
178 registry()->OnWorkerScriptLoaded(worker->process_id(), embedded_worker_id); | 178 registry()->OnWorkerScriptLoaded( |
| 179 worker->process_id(), thread_id, embedded_worker_id); |
179 } | 180 } |
180 | 181 |
181 void EmbeddedWorkerTestHelper::SimulateWorkerStarted( | 182 void EmbeddedWorkerTestHelper::SimulateWorkerStarted( |
182 int thread_id, int embedded_worker_id) { | 183 int embedded_worker_id) { |
183 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); | 184 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); |
184 ASSERT_TRUE(worker != NULL); | 185 ASSERT_TRUE(worker != NULL); |
185 registry()->OnWorkerStarted( | 186 registry()->OnWorkerStarted( |
186 worker->process_id(), | 187 worker->process_id(), |
187 thread_id, | |
188 embedded_worker_id); | 188 embedded_worker_id); |
189 } | 189 } |
190 | 190 |
191 void EmbeddedWorkerTestHelper::SimulateWorkerStopped( | 191 void EmbeddedWorkerTestHelper::SimulateWorkerStopped( |
192 int embedded_worker_id) { | 192 int embedded_worker_id) { |
193 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); | 193 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); |
194 if (worker != NULL) | 194 if (worker != NULL) |
195 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); | 195 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); |
196 } | 196 } |
197 | 197 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 request_id, | 287 request_id, |
288 request)); | 288 request)); |
289 } | 289 } |
290 | 290 |
291 EmbeddedWorkerRegistry* EmbeddedWorkerTestHelper::registry() { | 291 EmbeddedWorkerRegistry* EmbeddedWorkerTestHelper::registry() { |
292 DCHECK(context()); | 292 DCHECK(context()); |
293 return context()->embedded_worker_registry(); | 293 return context()->embedded_worker_registry(); |
294 } | 294 } |
295 | 295 |
296 } // namespace content | 296 } // namespace content |
OLD | NEW |