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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 int64 service_worker_version_id, | 88 int64 service_worker_version_id, |
89 const GURL& scope, | 89 const GURL& scope, |
90 const GURL& script_url, | 90 const GURL& script_url, |
91 bool pause_after_download) { | 91 bool pause_after_download) { |
92 if (pause_after_download) { | 92 if (pause_after_download) { |
93 SimulatePausedAfterDownload(embedded_worker_id); | 93 SimulatePausedAfterDownload(embedded_worker_id); |
94 return; | 94 return; |
95 } | 95 } |
96 SimulateWorkerReadyForInspection(embedded_worker_id); | 96 SimulateWorkerReadyForInspection(embedded_worker_id); |
97 SimulateWorkerScriptLoaded(next_thread_id_++, embedded_worker_id); | 97 SimulateWorkerScriptLoaded(next_thread_id_++, embedded_worker_id); |
| 98 SimulateWorkerScriptEvaluated(embedded_worker_id); |
98 SimulateWorkerStarted(embedded_worker_id); | 99 SimulateWorkerStarted(embedded_worker_id); |
99 } | 100 } |
100 | 101 |
101 void EmbeddedWorkerTestHelper::OnResumeAfterDownload(int embedded_worker_id) { | 102 void EmbeddedWorkerTestHelper::OnResumeAfterDownload(int embedded_worker_id) { |
102 SimulateWorkerReadyForInspection(embedded_worker_id); | 103 SimulateWorkerReadyForInspection(embedded_worker_id); |
103 SimulateWorkerScriptLoaded(next_thread_id_++, embedded_worker_id); | 104 SimulateWorkerScriptLoaded(next_thread_id_++, embedded_worker_id); |
| 105 SimulateWorkerScriptEvaluated(embedded_worker_id); |
104 SimulateWorkerStarted(embedded_worker_id); | 106 SimulateWorkerStarted(embedded_worker_id); |
105 } | 107 } |
106 | 108 |
107 void EmbeddedWorkerTestHelper::OnStopWorker(int embedded_worker_id) { | 109 void EmbeddedWorkerTestHelper::OnStopWorker(int embedded_worker_id) { |
108 // By default just notify the sender that the worker is stopped. | 110 // By default just notify the sender that the worker is stopped. |
109 SimulateWorkerStopped(embedded_worker_id); | 111 SimulateWorkerStopped(embedded_worker_id); |
110 } | 112 } |
111 | 113 |
112 bool EmbeddedWorkerTestHelper::OnMessageToWorker( | 114 bool EmbeddedWorkerTestHelper::OnMessageToWorker( |
113 int thread_id, | 115 int thread_id, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 } | 178 } |
177 | 179 |
178 void EmbeddedWorkerTestHelper::SimulateWorkerScriptLoaded( | 180 void EmbeddedWorkerTestHelper::SimulateWorkerScriptLoaded( |
179 int thread_id, int embedded_worker_id) { | 181 int thread_id, int embedded_worker_id) { |
180 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); | 182 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); |
181 ASSERT_TRUE(worker != NULL); | 183 ASSERT_TRUE(worker != NULL); |
182 registry()->OnWorkerScriptLoaded( | 184 registry()->OnWorkerScriptLoaded( |
183 worker->process_id(), thread_id, embedded_worker_id); | 185 worker->process_id(), thread_id, embedded_worker_id); |
184 } | 186 } |
185 | 187 |
| 188 void EmbeddedWorkerTestHelper::SimulateWorkerScriptEvaluated( |
| 189 int embedded_worker_id) { |
| 190 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); |
| 191 ASSERT_TRUE(worker != NULL); |
| 192 registry()->OnWorkerScriptEvaluated( |
| 193 worker->process_id(), embedded_worker_id, true /* success */); |
| 194 } |
| 195 |
186 void EmbeddedWorkerTestHelper::SimulateWorkerStarted( | 196 void EmbeddedWorkerTestHelper::SimulateWorkerStarted( |
187 int embedded_worker_id) { | 197 int embedded_worker_id) { |
188 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); | 198 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); |
189 ASSERT_TRUE(worker != NULL); | 199 ASSERT_TRUE(worker != NULL); |
190 registry()->OnWorkerStarted( | 200 registry()->OnWorkerStarted( |
191 worker->process_id(), | 201 worker->process_id(), |
192 embedded_worker_id); | 202 embedded_worker_id); |
193 } | 203 } |
194 | 204 |
195 void EmbeddedWorkerTestHelper::SimulateWorkerStopped( | 205 void EmbeddedWorkerTestHelper::SimulateWorkerStopped( |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 request_id, | 301 request_id, |
292 request)); | 302 request)); |
293 } | 303 } |
294 | 304 |
295 EmbeddedWorkerRegistry* EmbeddedWorkerTestHelper::registry() { | 305 EmbeddedWorkerRegistry* EmbeddedWorkerTestHelper::registry() { |
296 DCHECK(context()); | 306 DCHECK(context()); |
297 return context()->embedded_worker_registry(); | 307 return context()->embedded_worker_registry(); |
298 } | 308 } |
299 | 309 |
300 } // namespace content | 310 } // namespace content |
OLD | NEW |