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::ServiceWorkerProviderClientInfoPtr provider_client_info) |
87 override; | 88 override; |
88 void StopWorker() override; | 89 void StopWorker() override; |
89 void ResumeAfterDownload() override; | 90 void ResumeAfterDownload() override; |
90 void AddMessageToConsole(blink::WebConsoleMessage::Level level, | 91 void AddMessageToConsole(blink::WebConsoleMessage::Level level, |
91 const std::string& message) override; | 92 const std::string& message) override; |
92 | 93 |
93 base::WeakPtr<EmbeddedWorkerTestHelper> helper_; | 94 base::WeakPtr<EmbeddedWorkerTestHelper> helper_; |
94 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_; | 95 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_; |
95 | 96 |
96 base::Optional<int> embedded_worker_id_; | 97 base::Optional<int> embedded_worker_id_; |
(...skipping 10 matching lines...) Expand all Loading... |
107 // Call this to simulate add/associate a process to a pattern. | 108 // Call this to simulate add/associate a process to a pattern. |
108 // This also registers this sender for the process. | 109 // This also registers this sender for the process. |
109 void SimulateAddProcessToPattern(const GURL& pattern, int process_id); | 110 void SimulateAddProcessToPattern(const GURL& pattern, int process_id); |
110 | 111 |
111 // IPC::Sender implementation. | 112 // IPC::Sender implementation. |
112 bool Send(IPC::Message* message) override; | 113 bool Send(IPC::Message* message) override; |
113 | 114 |
114 // IPC::Listener implementation. | 115 // IPC::Listener implementation. |
115 bool OnMessageReceived(const IPC::Message& msg) override; | 116 bool OnMessageReceived(const IPC::Message& msg) override; |
116 | 117 |
117 // Register a mojo endpoint object derived from | 118 // Registers a Mojo endpoint object derived from |
118 // MockEmbeddedWorkerInstanceClient. | 119 // MockEmbeddedWorkerInstanceClient. |
119 void RegisterMockInstanceClient( | 120 void RegisterMockInstanceClient( |
120 std::unique_ptr<MockEmbeddedWorkerInstanceClient> client); | 121 std::unique_ptr<MockEmbeddedWorkerInstanceClient> client); |
121 | 122 |
122 // Registers the dispatcher host for the process to a map managed by this test | 123 // Registers the dispatcher host for the process to a map managed by this test |
123 // helper. If there is a existing dispatcher host, it'll removed before adding | 124 // helper. If there is a existing dispatcher host, it'll removed before adding |
124 // to the map. This should be called before ServiceWorkerDispatcherHost::Init | 125 // to the map. This should be called before ServiceWorkerDispatcherHost::Init |
125 // because it internally calls ServiceWorkerContextCore::AddDispatcherHost. | 126 // because it internally calls ServiceWorkerContextCore::AddDispatcherHost. |
126 // If |dispatcher_host| is nullptr, this method just removes the existing | 127 // If |dispatcher_host| is nullptr, this method just removes the existing |
127 // dispatcher host from the map. | 128 // dispatcher host from the map. |
(...skipping 12 matching lines...) Expand all Loading... |
140 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>>* | 141 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>>* |
141 mock_instance_clients() { | 142 mock_instance_clients() { |
142 return &mock_instance_clients_; | 143 return &mock_instance_clients_; |
143 } | 144 } |
144 | 145 |
145 ServiceWorkerContextCore* context(); | 146 ServiceWorkerContextCore* context(); |
146 ServiceWorkerContextWrapper* context_wrapper() { return wrapper_.get(); } | 147 ServiceWorkerContextWrapper* context_wrapper() { return wrapper_.get(); } |
147 void ShutdownContext(); | 148 void ShutdownContext(); |
148 | 149 |
149 int GetNextThreadId() { return next_thread_id_++; } | 150 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::ServiceWorkerProviderClientInfoPtr provider_client_info); |
184 virtual void OnResumeAfterDownload(int embedded_worker_id); | 185 virtual void OnResumeAfterDownload(int embedded_worker_id); |
185 // StopWorker IPC handler routed through MockEmbeddedWorkerInstanceClient. | 186 // StopWorker IPC handler routed through MockEmbeddedWorkerInstanceClient. |
186 // This calls SimulateWorkerStopped() by default. | 187 // This calls SimulateWorkerStopped() by default. |
187 virtual void OnStopWorker(int embedded_worker_id); | 188 virtual void OnStopWorker(int embedded_worker_id); |
188 | 189 |
189 // On*Event handlers. By default they just return success via | 190 // On*Event handlers. By default they just return success via |
190 // SimulateSendReplyToBrowser. | 191 // SimulateSendReplyToBrowser. |
191 virtual void OnActivateEvent( | 192 virtual void OnActivateEvent( |
192 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback | 193 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback |
193 callback); | 194 callback); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 payments::mojom::PaymentRequestEventDataPtr data, | 245 payments::mojom::PaymentRequestEventDataPtr data, |
245 payments::mojom::PaymentAppResponseCallbackPtr response_callback, | 246 payments::mojom::PaymentAppResponseCallbackPtr response_callback, |
246 mojom::ServiceWorkerEventDispatcher::DispatchPaymentRequestEventCallback | 247 mojom::ServiceWorkerEventDispatcher::DispatchPaymentRequestEventCallback |
247 callback); | 248 callback); |
248 | 249 |
249 // These functions simulate sending an EmbeddedHostMsg message through the | 250 // These functions simulate sending an EmbeddedHostMsg message through the |
250 // legacy IPC system to the browser. | 251 // legacy IPC system to the browser. |
251 void SimulateWorkerReadyForInspection(int embedded_worker_id); | 252 void SimulateWorkerReadyForInspection(int embedded_worker_id); |
252 void SimulateWorkerScriptCached(int embedded_worker_id); | 253 void SimulateWorkerScriptCached(int embedded_worker_id); |
253 void SimulateWorkerScriptLoaded(int embedded_worker_id); | 254 void SimulateWorkerScriptLoaded(int embedded_worker_id); |
254 void SimulateWorkerThreadStarted(int thread_id, | 255 void SimulateWorkerThreadStarted(int thread_id, int embedded_worker_id); |
255 int embedded_worker_id, | |
256 int provider_id); | |
257 void SimulateWorkerScriptEvaluated(int embedded_worker_id, bool success); | 256 void SimulateWorkerScriptEvaluated(int embedded_worker_id, bool success); |
258 void SimulateWorkerStarted(int embedded_worker_id); | 257 void SimulateWorkerStarted(int embedded_worker_id); |
259 void SimulateWorkerStopped(int embedded_worker_id); | 258 void SimulateWorkerStopped(int embedded_worker_id); |
260 void SimulateSend(IPC::Message* message); | 259 void SimulateSend(IPC::Message* message); |
261 | 260 |
262 EmbeddedWorkerRegistry* registry(); | 261 EmbeddedWorkerRegistry* registry(); |
263 | 262 |
264 private: | 263 private: |
265 class MockServiceWorkerEventDispatcher; | 264 class MockServiceWorkerEventDispatcher; |
266 | 265 |
267 void OnStartWorkerStub( | 266 void OnStartWorkerStub( |
268 const EmbeddedWorkerStartParams& params, | 267 const EmbeddedWorkerStartParams& params, |
269 mojom::ServiceWorkerEventDispatcherRequest request, | 268 mojom::ServiceWorkerEventDispatcherRequest request, |
270 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host); | 269 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, |
| 270 mojom::ServiceWorkerProviderClientInfoPtr provider_client_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_; | |
348 int mock_render_process_id_; | 347 int mock_render_process_id_; |
349 int new_mock_render_process_id_; | 348 int new_mock_render_process_id_; |
350 | 349 |
351 std::map<int /* process_id */, scoped_refptr<ServiceWorkerDispatcherHost>> | 350 std::map<int /* process_id */, scoped_refptr<ServiceWorkerDispatcherHost>> |
352 dispatcher_hosts_; | 351 dispatcher_hosts_; |
353 | 352 |
354 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_; | 353 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_; |
355 std::map<int /* thread_id */, int /* embedded_worker_id */> | 354 std::map<int /* thread_id */, int /* embedded_worker_id */> |
356 thread_id_embedded_worker_id_map_; | 355 thread_id_embedded_worker_id_map_; |
357 | 356 |
(...skipping 17 matching lines...) Expand all Loading... |
375 std::unique_ptr<MockType> mock = | 374 std::unique_ptr<MockType> mock = |
376 base::MakeUnique<MockType>(std::forward<Args>(args)...); | 375 base::MakeUnique<MockType>(std::forward<Args>(args)...); |
377 MockType* mock_rawptr = mock.get(); | 376 MockType* mock_rawptr = mock.get(); |
378 RegisterMockInstanceClient(std::move(mock)); | 377 RegisterMockInstanceClient(std::move(mock)); |
379 return mock_rawptr; | 378 return mock_rawptr; |
380 } | 379 } |
381 | 380 |
382 } // namespace content | 381 } // namespace content |
383 | 382 |
384 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ | 383 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ |
OLD | NEW |