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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 base::WeakPtr<EmbeddedWorkerTestHelper> helper); | 74 base::WeakPtr<EmbeddedWorkerTestHelper> helper); |
75 ~MockEmbeddedWorkerInstanceClient() override; | 75 ~MockEmbeddedWorkerInstanceClient() override; |
76 | 76 |
77 static void Bind(const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, | 77 static void Bind(const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, |
78 mojo::ScopedMessagePipeHandle request); | 78 mojo::ScopedMessagePipeHandle request); |
79 | 79 |
80 protected: | 80 protected: |
81 // Implementation of mojo interfaces. | 81 // Implementation of mojo interfaces. |
82 void StartWorker( | 82 void StartWorker( |
83 const EmbeddedWorkerStartParams& params, | 83 const EmbeddedWorkerStartParams& params, |
84 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request) override; | 84 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, |
85 void StopWorker(const StopWorkerCallback& callback) override; | 85 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host) |
86 override; | |
87 void StopWorker() override; | |
86 void ResumeAfterDownload() override; | 88 void ResumeAfterDownload() override; |
87 void AddMessageToConsole(blink::WebConsoleMessage::Level level, | 89 void AddMessageToConsole(blink::WebConsoleMessage::Level level, |
88 const std::string& message) override; | 90 const std::string& message) override; |
89 | 91 |
90 base::WeakPtr<EmbeddedWorkerTestHelper> helper_; | 92 base::WeakPtr<EmbeddedWorkerTestHelper> helper_; |
91 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_; | 93 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_; |
92 | 94 |
93 base::Optional<int> embedded_worker_id_; | 95 base::Optional<int> embedded_worker_id_; |
94 | 96 |
95 private: | 97 private: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>>* | 131 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>>* |
130 mock_instance_clients() { | 132 mock_instance_clients() { |
131 return &mock_instance_clients_; | 133 return &mock_instance_clients_; |
132 } | 134 } |
133 | 135 |
134 ServiceWorkerContextCore* context(); | 136 ServiceWorkerContextCore* context(); |
135 ServiceWorkerContextWrapper* context_wrapper() { return wrapper_.get(); } | 137 ServiceWorkerContextWrapper* context_wrapper() { return wrapper_.get(); } |
136 void ShutdownContext(); | 138 void ShutdownContext(); |
137 | 139 |
138 int GetNextThreadId() { return next_thread_id_++; } | 140 int GetNextThreadId() { return next_thread_id_++; } |
141 int GetNextProviderId() { return next_provider_id_++; } | |
139 | 142 |
140 int mock_render_process_id() const { return mock_render_process_id_; } | 143 int mock_render_process_id() const { return mock_render_process_id_; } |
141 MockRenderProcessHost* mock_render_process_host() { | 144 MockRenderProcessHost* mock_render_process_host() { |
142 return render_process_host_.get(); | 145 return render_process_host_.get(); |
143 } | 146 } |
144 | 147 |
145 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map() { | 148 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map() { |
146 return embedded_worker_id_service_worker_version_id_map_; | 149 return embedded_worker_id_service_worker_version_id_map_; |
147 } | 150 } |
148 | 151 |
(...skipping 11 matching lines...) Expand all Loading... | |
160 protected: | 163 protected: |
161 // StartWorker IPC handler routed through MockEmbeddedWorkerInstanceClient. | 164 // StartWorker IPC handler routed through MockEmbeddedWorkerInstanceClient. |
162 // This simulates each legacy IPC sent from the renderer and binds |request| | 165 // This simulates each legacy IPC sent from the renderer and binds |request| |
163 // to MockServiceWorkerEventDispatcher by default. | 166 // to MockServiceWorkerEventDispatcher by default. |
164 virtual void OnStartWorker( | 167 virtual void OnStartWorker( |
165 int embedded_worker_id, | 168 int embedded_worker_id, |
166 int64_t service_worker_version_id, | 169 int64_t service_worker_version_id, |
167 const GURL& scope, | 170 const GURL& scope, |
168 const GURL& script_url, | 171 const GURL& script_url, |
169 bool pause_after_download, | 172 bool pause_after_download, |
170 mojom::ServiceWorkerEventDispatcherRequest request); | 173 mojom::ServiceWorkerEventDispatcherRequest request, |
174 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host); | |
171 virtual void OnResumeAfterDownload(int embedded_worker_id); | 175 virtual void OnResumeAfterDownload(int embedded_worker_id); |
172 // StopWorker IPC handler routed through MockEmbeddedWorkerInstanceClient. | 176 // StopWorker IPC handler routed through MockEmbeddedWorkerInstanceClient. |
173 // This calls StopWorkerCallback by default. | 177 // This calls SimulateWorkerStopped(embedded_worker_id) by default. |
falken
2017/04/12 14:30:18
nit: can just say SimulateWorkerStopped()
leonhsl(Using Gerrit)
2017/04/13 03:10:49
Done.
| |
174 virtual void OnStopWorker( | 178 virtual void OnStopWorker(int embedded_worker_id); |
175 const mojom::EmbeddedWorkerInstanceClient::StopWorkerCallback& callback); | |
176 // The legacy IPC message handler. This passes the messages to their | 179 // The legacy IPC message handler. This passes the messages to their |
177 // respective On*Event handler by default. | 180 // respective On*Event handler by default. |
178 virtual bool OnMessageToWorker(int thread_id, | 181 virtual bool OnMessageToWorker(int thread_id, |
179 int embedded_worker_id, | 182 int embedded_worker_id, |
180 const IPC::Message& message); | 183 const IPC::Message& message); |
181 | 184 |
182 // On*Event handlers. Called by the default implementation of | 185 // On*Event handlers. Called by the default implementation of |
183 // OnMessageToWorker when events are sent to the embedded | 186 // OnMessageToWorker when events are sent to the embedded |
184 // worker. By default they just return success via | 187 // worker. By default they just return success via |
185 // SimulateSendReplyToBrowser. | 188 // SimulateSendReplyToBrowser. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 payments::mojom::PaymentAppRequestPtr data, | 238 payments::mojom::PaymentAppRequestPtr data, |
236 payments::mojom::PaymentAppResponseCallbackPtr response_callback, | 239 payments::mojom::PaymentAppResponseCallbackPtr response_callback, |
237 const mojom::ServiceWorkerEventDispatcher:: | 240 const mojom::ServiceWorkerEventDispatcher:: |
238 DispatchPaymentRequestEventCallback& callback); | 241 DispatchPaymentRequestEventCallback& callback); |
239 | 242 |
240 // These functions simulate sending an EmbeddedHostMsg message through the | 243 // These functions simulate sending an EmbeddedHostMsg message through the |
241 // legacy IPC system to the browser. | 244 // legacy IPC system to the browser. |
242 void SimulateWorkerReadyForInspection(int embedded_worker_id); | 245 void SimulateWorkerReadyForInspection(int embedded_worker_id); |
243 void SimulateWorkerScriptCached(int embedded_worker_id); | 246 void SimulateWorkerScriptCached(int embedded_worker_id); |
244 void SimulateWorkerScriptLoaded(int embedded_worker_id); | 247 void SimulateWorkerScriptLoaded(int embedded_worker_id); |
245 void SimulateWorkerThreadStarted(int thread_id, int embedded_worker_id); | 248 void SimulateWorkerThreadStarted(int thread_id, |
249 int embedded_worker_id, | |
250 int provider_id); | |
246 void SimulateWorkerScriptEvaluated(int embedded_worker_id, bool success); | 251 void SimulateWorkerScriptEvaluated(int embedded_worker_id, bool success); |
247 void SimulateWorkerStarted(int embedded_worker_id); | 252 void SimulateWorkerStarted(int embedded_worker_id); |
248 void SimulateWorkerStopped(int embedded_worker_id); | 253 void SimulateWorkerStopped(int embedded_worker_id); |
249 void SimulateSend(IPC::Message* message); | 254 void SimulateSend(IPC::Message* message); |
250 | 255 |
251 EmbeddedWorkerRegistry* registry(); | 256 EmbeddedWorkerRegistry* registry(); |
252 | 257 |
253 private: | 258 private: |
254 class MockServiceWorkerEventDispatcher; | 259 class MockServiceWorkerEventDispatcher; |
255 | 260 |
256 void OnStartWorkerStub(const EmbeddedWorkerStartParams& params, | 261 void OnStartWorkerStub( |
257 mojom::ServiceWorkerEventDispatcherRequest request); | 262 const EmbeddedWorkerStartParams& params, |
263 mojom::ServiceWorkerEventDispatcherRequest request, | |
264 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host); | |
258 void OnResumeAfterDownloadStub(int embedded_worker_id); | 265 void OnResumeAfterDownloadStub(int embedded_worker_id); |
259 void OnStopWorkerStub( | 266 void OnStopWorkerStub(int embedded_worker_id); |
260 const mojom::EmbeddedWorkerInstanceClient::StopWorkerCallback& callback); | |
261 void OnMessageToWorkerStub(int thread_id, | 267 void OnMessageToWorkerStub(int thread_id, |
262 int embedded_worker_id, | 268 int embedded_worker_id, |
263 const IPC::Message& message); | 269 const IPC::Message& message); |
264 void OnActivateEventStub( | 270 void OnActivateEventStub( |
265 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback& | 271 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback& |
266 callback); | 272 callback); |
267 void OnBackgroundFetchAbortEventStub( | 273 void OnBackgroundFetchAbortEventStub( |
268 const std::string& tag, | 274 const std::string& tag, |
269 const mojom::ServiceWorkerEventDispatcher:: | 275 const mojom::ServiceWorkerEventDispatcher:: |
270 DispatchBackgroundFetchAbortEventCallback& callback); | 276 DispatchBackgroundFetchAbortEventCallback& callback); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 scoped_refptr<ServiceWorkerContextWrapper> wrapper_; | 328 scoped_refptr<ServiceWorkerContextWrapper> wrapper_; |
323 | 329 |
324 IPC::TestSink sink_; | 330 IPC::TestSink sink_; |
325 IPC::TestSink inner_sink_; | 331 IPC::TestSink inner_sink_; |
326 | 332 |
327 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>> | 333 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>> |
328 mock_instance_clients_; | 334 mock_instance_clients_; |
329 size_t mock_instance_clients_next_index_; | 335 size_t mock_instance_clients_next_index_; |
330 | 336 |
331 int next_thread_id_; | 337 int next_thread_id_; |
338 int next_provider_id_; | |
332 int mock_render_process_id_; | 339 int mock_render_process_id_; |
333 int new_mock_render_process_id_; | 340 int new_mock_render_process_id_; |
334 | 341 |
335 std::map<int /* process_id */, scoped_refptr<ServiceWorkerDispatcherHost>> | 342 std::map<int /* process_id */, scoped_refptr<ServiceWorkerDispatcherHost>> |
336 dispatcher_hosts_; | 343 dispatcher_hosts_; |
337 | 344 |
338 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_; | 345 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_; |
339 std::map<int /* thread_id */, int /* embedded_worker_id */> | 346 std::map<int /* thread_id */, int /* embedded_worker_id */> |
340 thread_id_embedded_worker_id_map_; | 347 thread_id_embedded_worker_id_map_; |
341 | 348 |
349 std::map< | |
350 int /* embedded_worker_id */, | |
351 mojom::EmbeddedWorkerInstanceHostAssociatedPtr /* instance_host_ptr */> | |
352 embedded_worker_id_instance_host_ptr_map_; | |
353 | |
342 // Updated each time MessageToWorker message is received. | 354 // Updated each time MessageToWorker message is received. |
343 int current_embedded_worker_id_; | 355 int current_embedded_worker_id_; |
344 | 356 |
345 std::vector<Event> events_; | 357 std::vector<Event> events_; |
346 | 358 |
347 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_; | 359 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_; |
348 | 360 |
349 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper); | 361 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper); |
350 }; | 362 }; |
351 | 363 |
352 template <typename MockType, typename... Args> | 364 template <typename MockType, typename... Args> |
353 MockType* EmbeddedWorkerTestHelper::CreateAndRegisterMockInstanceClient( | 365 MockType* EmbeddedWorkerTestHelper::CreateAndRegisterMockInstanceClient( |
354 Args&&... args) { | 366 Args&&... args) { |
355 std::unique_ptr<MockType> mock = | 367 std::unique_ptr<MockType> mock = |
356 base::MakeUnique<MockType>(std::forward<Args>(args)...); | 368 base::MakeUnique<MockType>(std::forward<Args>(args)...); |
357 MockType* mock_rawptr = mock.get(); | 369 MockType* mock_rawptr = mock.get(); |
358 RegisterMockInstanceClient(std::move(mock)); | 370 RegisterMockInstanceClient(std::move(mock)); |
359 return mock_rawptr; | 371 return mock_rawptr; |
360 } | 372 } |
361 | 373 |
362 } // namespace content | 374 } // namespace content |
363 | 375 |
364 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ | 376 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ |
OLD | NEW |