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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 ~MockEmbeddedWorkerInstanceClient() override; | 76 ~MockEmbeddedWorkerInstanceClient() override; |
77 | 77 |
78 static void Bind(const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, | 78 static void Bind(const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, |
79 mojo::ScopedMessagePipeHandle request); | 79 mojo::ScopedMessagePipeHandle request); |
80 | 80 |
81 protected: | 81 protected: |
82 // Implementation of mojo interfaces. | 82 // Implementation of mojo interfaces. |
83 void StartWorker( | 83 void StartWorker( |
84 const EmbeddedWorkerStartParams& params, | 84 const EmbeddedWorkerStartParams& params, |
85 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, | 85 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, |
86 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, | 86 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host) |
87 mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info) | |
88 override; | 87 override; |
89 void StopWorker() override; | 88 void StopWorker() override; |
90 void ResumeAfterDownload() override; | 89 void ResumeAfterDownload() override; |
91 void AddMessageToConsole(blink::WebConsoleMessage::Level level, | 90 void AddMessageToConsole(blink::WebConsoleMessage::Level level, |
92 const std::string& message) override; | 91 const std::string& message) override; |
93 | 92 |
94 base::WeakPtr<EmbeddedWorkerTestHelper> helper_; | 93 base::WeakPtr<EmbeddedWorkerTestHelper> helper_; |
95 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_; | 94 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_; |
96 | 95 |
97 base::Optional<int> embedded_worker_id_; | 96 base::Optional<int> embedded_worker_id_; |
(...skipping 10 matching lines...) Expand all Loading... |
108 // Call this to simulate add/associate a process to a pattern. | 107 // Call this to simulate add/associate a process to a pattern. |
109 // This also registers this sender for the process. | 108 // This also registers this sender for the process. |
110 void SimulateAddProcessToPattern(const GURL& pattern, int process_id); | 109 void SimulateAddProcessToPattern(const GURL& pattern, int process_id); |
111 | 110 |
112 // IPC::Sender implementation. | 111 // IPC::Sender implementation. |
113 bool Send(IPC::Message* message) override; | 112 bool Send(IPC::Message* message) override; |
114 | 113 |
115 // IPC::Listener implementation. | 114 // IPC::Listener implementation. |
116 bool OnMessageReceived(const IPC::Message& msg) override; | 115 bool OnMessageReceived(const IPC::Message& msg) override; |
117 | 116 |
118 // Registers a Mojo endpoint object derived from | 117 // Register a mojo endpoint object derived from |
119 // MockEmbeddedWorkerInstanceClient. | 118 // MockEmbeddedWorkerInstanceClient. |
120 void RegisterMockInstanceClient( | 119 void RegisterMockInstanceClient( |
121 std::unique_ptr<MockEmbeddedWorkerInstanceClient> client); | 120 std::unique_ptr<MockEmbeddedWorkerInstanceClient> client); |
122 | 121 |
123 // Registers the dispatcher host for the process to a map managed by this test | 122 // Registers the dispatcher host for the process to a map managed by this test |
124 // helper. If there is a existing dispatcher host, it'll removed before adding | 123 // helper. If there is a existing dispatcher host, it'll removed before adding |
125 // to the map. This should be called before ServiceWorkerDispatcherHost::Init | 124 // to the map. This should be called before ServiceWorkerDispatcherHost::Init |
126 // because it internally calls ServiceWorkerContextCore::AddDispatcherHost. | 125 // because it internally calls ServiceWorkerContextCore::AddDispatcherHost. |
127 // If |dispatcher_host| is nullptr, this method just removes the existing | 126 // If |dispatcher_host| is nullptr, this method just removes the existing |
128 // dispatcher host from the map. | 127 // dispatcher host from the map. |
(...skipping 12 matching lines...) Expand all Loading... |
141 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>>* | 140 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>>* |
142 mock_instance_clients() { | 141 mock_instance_clients() { |
143 return &mock_instance_clients_; | 142 return &mock_instance_clients_; |
144 } | 143 } |
145 | 144 |
146 ServiceWorkerContextCore* context(); | 145 ServiceWorkerContextCore* context(); |
147 ServiceWorkerContextWrapper* context_wrapper() { return wrapper_.get(); } | 146 ServiceWorkerContextWrapper* context_wrapper() { return wrapper_.get(); } |
148 void ShutdownContext(); | 147 void ShutdownContext(); |
149 | 148 |
150 int GetNextThreadId() { return next_thread_id_++; } | 149 int GetNextThreadId() { return next_thread_id_++; } |
| 150 int GetNextProviderId() { return next_provider_id_++; } |
151 | 151 |
152 int mock_render_process_id() const { return mock_render_process_id_; } | 152 int mock_render_process_id() const { return mock_render_process_id_; } |
153 MockRenderProcessHost* mock_render_process_host() { | 153 MockRenderProcessHost* mock_render_process_host() { |
154 return render_process_host_.get(); | 154 return render_process_host_.get(); |
155 } | 155 } |
156 | 156 |
157 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map() { | 157 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map() { |
158 return embedded_worker_id_service_worker_version_id_map_; | 158 return embedded_worker_id_service_worker_version_id_map_; |
159 } | 159 } |
160 | 160 |
(...skipping 12 matching lines...) Expand all Loading... |
173 // StartWorker IPC handler routed through MockEmbeddedWorkerInstanceClient. | 173 // StartWorker IPC handler routed through MockEmbeddedWorkerInstanceClient. |
174 // This simulates each legacy IPC sent from the renderer and binds |request| | 174 // This simulates each legacy IPC sent from the renderer and binds |request| |
175 // to MockServiceWorkerEventDispatcher by default. | 175 // to MockServiceWorkerEventDispatcher by default. |
176 virtual void OnStartWorker( | 176 virtual void OnStartWorker( |
177 int embedded_worker_id, | 177 int embedded_worker_id, |
178 int64_t service_worker_version_id, | 178 int64_t service_worker_version_id, |
179 const GURL& scope, | 179 const GURL& scope, |
180 const GURL& script_url, | 180 const GURL& script_url, |
181 bool pause_after_download, | 181 bool pause_after_download, |
182 mojom::ServiceWorkerEventDispatcherRequest request, | 182 mojom::ServiceWorkerEventDispatcherRequest request, |
183 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, | 183 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host); |
184 mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info); | |
185 virtual void OnResumeAfterDownload(int embedded_worker_id); | 184 virtual void OnResumeAfterDownload(int embedded_worker_id); |
186 // StopWorker IPC handler routed through MockEmbeddedWorkerInstanceClient. | 185 // StopWorker IPC handler routed through MockEmbeddedWorkerInstanceClient. |
187 // This calls SimulateWorkerStopped() by default. | 186 // This calls SimulateWorkerStopped() by default. |
188 virtual void OnStopWorker(int embedded_worker_id); | 187 virtual void OnStopWorker(int embedded_worker_id); |
189 | 188 |
190 // On*Event handlers. By default they just return success via | 189 // On*Event handlers. By default they just return success via |
191 // SimulateSendReplyToBrowser. | 190 // SimulateSendReplyToBrowser. |
192 virtual void OnActivateEvent( | 191 virtual void OnActivateEvent( |
193 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback | 192 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback |
194 callback); | 193 callback); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 payments::mojom::PaymentRequestEventDataPtr data, | 244 payments::mojom::PaymentRequestEventDataPtr data, |
246 payments::mojom::PaymentAppResponseCallbackPtr response_callback, | 245 payments::mojom::PaymentAppResponseCallbackPtr response_callback, |
247 mojom::ServiceWorkerEventDispatcher::DispatchPaymentRequestEventCallback | 246 mojom::ServiceWorkerEventDispatcher::DispatchPaymentRequestEventCallback |
248 callback); | 247 callback); |
249 | 248 |
250 // These functions simulate sending an EmbeddedHostMsg message through the | 249 // These functions simulate sending an EmbeddedHostMsg message through the |
251 // legacy IPC system to the browser. | 250 // legacy IPC system to the browser. |
252 void SimulateWorkerReadyForInspection(int embedded_worker_id); | 251 void SimulateWorkerReadyForInspection(int embedded_worker_id); |
253 void SimulateWorkerScriptCached(int embedded_worker_id); | 252 void SimulateWorkerScriptCached(int embedded_worker_id); |
254 void SimulateWorkerScriptLoaded(int embedded_worker_id); | 253 void SimulateWorkerScriptLoaded(int embedded_worker_id); |
255 void SimulateWorkerThreadStarted(int thread_id, int embedded_worker_id); | 254 void SimulateWorkerThreadStarted(int thread_id, |
| 255 int embedded_worker_id, |
| 256 int provider_id); |
256 void SimulateWorkerScriptEvaluated(int embedded_worker_id, bool success); | 257 void SimulateWorkerScriptEvaluated(int embedded_worker_id, bool success); |
257 void SimulateWorkerStarted(int embedded_worker_id); | 258 void SimulateWorkerStarted(int embedded_worker_id); |
258 void SimulateWorkerStopped(int embedded_worker_id); | 259 void SimulateWorkerStopped(int embedded_worker_id); |
259 void SimulateSend(IPC::Message* message); | 260 void SimulateSend(IPC::Message* message); |
260 | 261 |
261 EmbeddedWorkerRegistry* registry(); | 262 EmbeddedWorkerRegistry* registry(); |
262 | 263 |
263 private: | 264 private: |
264 class MockServiceWorkerEventDispatcher; | 265 class MockServiceWorkerEventDispatcher; |
265 | 266 |
266 void OnStartWorkerStub( | 267 void OnStartWorkerStub( |
267 const EmbeddedWorkerStartParams& params, | 268 const EmbeddedWorkerStartParams& params, |
268 mojom::ServiceWorkerEventDispatcherRequest request, | 269 mojom::ServiceWorkerEventDispatcherRequest request, |
269 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, | 270 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host); |
270 mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info); | |
271 void OnResumeAfterDownloadStub(int embedded_worker_id); | 271 void OnResumeAfterDownloadStub(int embedded_worker_id); |
272 void OnStopWorkerStub(int embedded_worker_id); | 272 void OnStopWorkerStub(int embedded_worker_id); |
273 void OnMessageToWorkerStub(int thread_id, | 273 void OnMessageToWorkerStub(int thread_id, |
274 int embedded_worker_id, | 274 int embedded_worker_id, |
275 const IPC::Message& message); | 275 const IPC::Message& message); |
276 void OnActivateEventStub( | 276 void OnActivateEventStub( |
277 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback | 277 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback |
278 callback); | 278 callback); |
279 void OnBackgroundFetchAbortEventStub( | 279 void OnBackgroundFetchAbortEventStub( |
280 const std::string& tag, | 280 const std::string& tag, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 337 |
338 scoped_refptr<ServiceWorkerContextWrapper> wrapper_; | 338 scoped_refptr<ServiceWorkerContextWrapper> wrapper_; |
339 | 339 |
340 IPC::TestSink sink_; | 340 IPC::TestSink sink_; |
341 | 341 |
342 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>> | 342 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>> |
343 mock_instance_clients_; | 343 mock_instance_clients_; |
344 size_t mock_instance_clients_next_index_; | 344 size_t mock_instance_clients_next_index_; |
345 | 345 |
346 int next_thread_id_; | 346 int next_thread_id_; |
| 347 int next_provider_id_; |
347 int mock_render_process_id_; | 348 int mock_render_process_id_; |
348 int new_mock_render_process_id_; | 349 int new_mock_render_process_id_; |
349 | 350 |
350 std::map<int /* process_id */, scoped_refptr<ServiceWorkerDispatcherHost>> | 351 std::map<int /* process_id */, scoped_refptr<ServiceWorkerDispatcherHost>> |
351 dispatcher_hosts_; | 352 dispatcher_hosts_; |
352 | 353 |
353 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_; | 354 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_; |
354 std::map<int /* thread_id */, int /* embedded_worker_id */> | 355 std::map<int /* thread_id */, int /* embedded_worker_id */> |
355 thread_id_embedded_worker_id_map_; | 356 thread_id_embedded_worker_id_map_; |
356 | 357 |
(...skipping 17 matching lines...) Expand all Loading... |
374 std::unique_ptr<MockType> mock = | 375 std::unique_ptr<MockType> mock = |
375 base::MakeUnique<MockType>(std::forward<Args>(args)...); | 376 base::MakeUnique<MockType>(std::forward<Args>(args)...); |
376 MockType* mock_rawptr = mock.get(); | 377 MockType* mock_rawptr = mock.get(); |
377 RegisterMockInstanceClient(std::move(mock)); | 378 RegisterMockInstanceClient(std::move(mock)); |
378 return mock_rawptr; | 379 return mock_rawptr; |
379 } | 380 } |
380 | 381 |
381 } // namespace content | 382 } // namespace content |
382 | 383 |
383 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ | 384 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ |
OLD | NEW |