Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(979)

Side by Side Diff: content/browser/service_worker/embedded_worker_test_helper.h

Issue 2824193002: Enable use_once_callback for //content/common/*.mojom (Closed)
Patch Set: push_messaging fix Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // Alternatively consumers can subclass this helper and override On*() 57 // Alternatively consumers can subclass this helper and override On*()
58 // methods to add their own logic/verification code. 58 // methods to add their own logic/verification code.
59 // 59 //
60 // See embedded_worker_instance_unittest.cc for example usages. 60 // See embedded_worker_instance_unittest.cc for example usages.
61 // 61 //
62 class EmbeddedWorkerTestHelper : public IPC::Sender, 62 class EmbeddedWorkerTestHelper : public IPC::Sender,
63 public IPC::Listener { 63 public IPC::Listener {
64 public: 64 public:
65 enum class Event { Activate }; 65 enum class Event { Activate };
66 using FetchCallback = 66 using FetchCallback =
67 base::Callback<void(ServiceWorkerStatusCode, 67 base::OnceCallback<void(ServiceWorkerStatusCode,
68 base::Time /* dispatch_event_time */)>; 68 base::Time /* dispatch_event_time */)>;
69 69
70 class MockEmbeddedWorkerInstanceClient 70 class MockEmbeddedWorkerInstanceClient
71 : public mojom::EmbeddedWorkerInstanceClient { 71 : public mojom::EmbeddedWorkerInstanceClient {
72 public: 72 public:
73 explicit MockEmbeddedWorkerInstanceClient( 73 explicit MockEmbeddedWorkerInstanceClient(
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);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // respective On*Event handler by default. 180 // respective On*Event handler by default.
181 virtual bool OnMessageToWorker(int thread_id, 181 virtual bool OnMessageToWorker(int thread_id,
182 int embedded_worker_id, 182 int embedded_worker_id,
183 const IPC::Message& message); 183 const IPC::Message& message);
184 184
185 // On*Event handlers. Called by the default implementation of 185 // On*Event handlers. Called by the default implementation of
186 // OnMessageToWorker when events are sent to the embedded 186 // OnMessageToWorker when events are sent to the embedded
187 // worker. By default they just return success via 187 // worker. By default they just return success via
188 // SimulateSendReplyToBrowser. 188 // SimulateSendReplyToBrowser.
189 virtual void OnActivateEvent( 189 virtual void OnActivateEvent(
190 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback& 190 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback
191 callback); 191 callback);
192 virtual void OnBackgroundFetchAbortEvent( 192 virtual void OnBackgroundFetchAbortEvent(
193 const std::string& tag, 193 const std::string& tag,
194 const mojom::ServiceWorkerEventDispatcher:: 194 mojom::ServiceWorkerEventDispatcher::
195 DispatchBackgroundFetchAbortEventCallback& callback); 195 DispatchBackgroundFetchAbortEventCallback callback);
196 virtual void OnBackgroundFetchClickEvent( 196 virtual void OnBackgroundFetchClickEvent(
197 const std::string& tag, 197 const std::string& tag,
198 mojom::BackgroundFetchState state, 198 mojom::BackgroundFetchState state,
199 const mojom::ServiceWorkerEventDispatcher:: 199 mojom::ServiceWorkerEventDispatcher::
200 DispatchBackgroundFetchClickEventCallback& callback); 200 DispatchBackgroundFetchClickEventCallback callback);
201 virtual void OnBackgroundFetchFailEvent( 201 virtual void OnBackgroundFetchFailEvent(
202 const std::string& tag, 202 const std::string& tag,
203 const std::vector<BackgroundFetchSettledFetch>& fetches, 203 const std::vector<BackgroundFetchSettledFetch>& fetches,
204 const mojom::ServiceWorkerEventDispatcher:: 204 mojom::ServiceWorkerEventDispatcher::
205 DispatchBackgroundFetchFailEventCallback& callback); 205 DispatchBackgroundFetchFailEventCallback callback);
206 virtual void OnBackgroundFetchedEvent( 206 virtual void OnBackgroundFetchedEvent(
207 const std::string& tag, 207 const std::string& tag,
208 const std::vector<BackgroundFetchSettledFetch>& fetches, 208 const std::vector<BackgroundFetchSettledFetch>& fetches,
209 const mojom::ServiceWorkerEventDispatcher:: 209 mojom::ServiceWorkerEventDispatcher::
210 DispatchBackgroundFetchedEventCallback& callback); 210 DispatchBackgroundFetchedEventCallback callback);
211 virtual void OnExtendableMessageEvent( 211 virtual void OnExtendableMessageEvent(
212 mojom::ExtendableMessageEventPtr event, 212 mojom::ExtendableMessageEventPtr event,
213 const mojom::ServiceWorkerEventDispatcher:: 213 mojom::ServiceWorkerEventDispatcher::
214 DispatchExtendableMessageEventCallback& callback); 214 DispatchExtendableMessageEventCallback callback);
215 virtual void OnInstallEvent(int embedded_worker_id, int request_id); 215 virtual void OnInstallEvent(int embedded_worker_id, int request_id);
216 virtual void OnFetchEvent(int embedded_worker_id, 216 virtual void OnFetchEvent(int embedded_worker_id,
217 int fetch_event_id, 217 int fetch_event_id,
218 const ServiceWorkerFetchRequest& request, 218 const ServiceWorkerFetchRequest& request,
219 mojom::FetchEventPreloadHandlePtr preload_handle, 219 mojom::FetchEventPreloadHandlePtr preload_handle,
220 const FetchCallback& callback); 220 FetchCallback callback);
221 virtual void OnNotificationClickEvent( 221 virtual void OnNotificationClickEvent(
222 const std::string& notification_id, 222 const std::string& notification_id,
223 const PlatformNotificationData& notification_data, 223 const PlatformNotificationData& notification_data,
224 int action_index, 224 int action_index,
225 const base::Optional<base::string16>& reply, 225 const base::Optional<base::string16>& reply,
226 const mojom::ServiceWorkerEventDispatcher:: 226 mojom::ServiceWorkerEventDispatcher::
227 DispatchNotificationClickEventCallback& callback); 227 DispatchNotificationClickEventCallback callback);
228 virtual void OnNotificationCloseEvent( 228 virtual void OnNotificationCloseEvent(
229 const std::string& notification_id, 229 const std::string& notification_id,
230 const PlatformNotificationData& notification_data, 230 const PlatformNotificationData& notification_data,
231 const mojom::ServiceWorkerEventDispatcher:: 231 mojom::ServiceWorkerEventDispatcher::
232 DispatchNotificationCloseEventCallback& callback); 232 DispatchNotificationCloseEventCallback callback);
233 virtual void OnPushEvent( 233 virtual void OnPushEvent(
234 const PushEventPayload& payload, 234 const PushEventPayload& payload,
235 const mojom::ServiceWorkerEventDispatcher::DispatchPushEventCallback& 235 mojom::ServiceWorkerEventDispatcher::DispatchPushEventCallback callback);
236 callback);
237 virtual void OnPaymentRequestEvent( 236 virtual void OnPaymentRequestEvent(
238 payments::mojom::PaymentAppRequestPtr data, 237 payments::mojom::PaymentAppRequestPtr data,
239 payments::mojom::PaymentAppResponseCallbackPtr response_callback, 238 payments::mojom::PaymentAppResponseCallbackPtr response_callback,
240 const mojom::ServiceWorkerEventDispatcher:: 239 mojom::ServiceWorkerEventDispatcher::DispatchPaymentRequestEventCallback
241 DispatchPaymentRequestEventCallback& callback); 240 callback);
242 241
243 // These functions simulate sending an EmbeddedHostMsg message through the 242 // These functions simulate sending an EmbeddedHostMsg message through the
244 // legacy IPC system to the browser. 243 // legacy IPC system to the browser.
245 void SimulateWorkerReadyForInspection(int embedded_worker_id); 244 void SimulateWorkerReadyForInspection(int embedded_worker_id);
246 void SimulateWorkerScriptCached(int embedded_worker_id); 245 void SimulateWorkerScriptCached(int embedded_worker_id);
247 void SimulateWorkerScriptLoaded(int embedded_worker_id); 246 void SimulateWorkerScriptLoaded(int embedded_worker_id);
248 void SimulateWorkerThreadStarted(int thread_id, 247 void SimulateWorkerThreadStarted(int thread_id,
249 int embedded_worker_id, 248 int embedded_worker_id,
250 int provider_id); 249 int provider_id);
251 void SimulateWorkerScriptEvaluated(int embedded_worker_id, bool success); 250 void SimulateWorkerScriptEvaluated(int embedded_worker_id, bool success);
252 void SimulateWorkerStarted(int embedded_worker_id); 251 void SimulateWorkerStarted(int embedded_worker_id);
253 void SimulateWorkerStopped(int embedded_worker_id); 252 void SimulateWorkerStopped(int embedded_worker_id);
254 void SimulateSend(IPC::Message* message); 253 void SimulateSend(IPC::Message* message);
255 254
256 EmbeddedWorkerRegistry* registry(); 255 EmbeddedWorkerRegistry* registry();
257 256
258 private: 257 private:
259 class MockServiceWorkerEventDispatcher; 258 class MockServiceWorkerEventDispatcher;
260 259
261 void OnStartWorkerStub( 260 void OnStartWorkerStub(
262 const EmbeddedWorkerStartParams& params, 261 const EmbeddedWorkerStartParams& params,
263 mojom::ServiceWorkerEventDispatcherRequest request, 262 mojom::ServiceWorkerEventDispatcherRequest request,
264 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host); 263 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host);
265 void OnResumeAfterDownloadStub(int embedded_worker_id); 264 void OnResumeAfterDownloadStub(int embedded_worker_id);
266 void OnStopWorkerStub(int embedded_worker_id); 265 void OnStopWorkerStub(int embedded_worker_id);
267 void OnMessageToWorkerStub(int thread_id, 266 void OnMessageToWorkerStub(int thread_id,
268 int embedded_worker_id, 267 int embedded_worker_id,
269 const IPC::Message& message); 268 const IPC::Message& message);
270 void OnActivateEventStub( 269 void OnActivateEventStub(
271 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback& 270 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback
272 callback); 271 callback);
273 void OnBackgroundFetchAbortEventStub( 272 void OnBackgroundFetchAbortEventStub(
274 const std::string& tag, 273 const std::string& tag,
275 const mojom::ServiceWorkerEventDispatcher:: 274 mojom::ServiceWorkerEventDispatcher::
276 DispatchBackgroundFetchAbortEventCallback& callback); 275 DispatchBackgroundFetchAbortEventCallback callback);
277 void OnBackgroundFetchClickEventStub( 276 void OnBackgroundFetchClickEventStub(
278 const std::string& tag, 277 const std::string& tag,
279 mojom::BackgroundFetchState state, 278 mojom::BackgroundFetchState state,
280 const mojom::ServiceWorkerEventDispatcher:: 279 mojom::ServiceWorkerEventDispatcher::
281 DispatchBackgroundFetchClickEventCallback& callback); 280 DispatchBackgroundFetchClickEventCallback callback);
282 void OnBackgroundFetchFailEventStub( 281 void OnBackgroundFetchFailEventStub(
283 const std::string& tag, 282 const std::string& tag,
284 const std::vector<BackgroundFetchSettledFetch>& fetches, 283 const std::vector<BackgroundFetchSettledFetch>& fetches,
285 const mojom::ServiceWorkerEventDispatcher:: 284 mojom::ServiceWorkerEventDispatcher::
286 DispatchBackgroundFetchFailEventCallback& callback); 285 DispatchBackgroundFetchFailEventCallback callback);
287 void OnBackgroundFetchedEventStub( 286 void OnBackgroundFetchedEventStub(
288 const std::string& tag, 287 const std::string& tag,
289 const std::vector<BackgroundFetchSettledFetch>& fetches, 288 const std::vector<BackgroundFetchSettledFetch>& fetches,
290 const mojom::ServiceWorkerEventDispatcher:: 289 mojom::ServiceWorkerEventDispatcher::
291 DispatchBackgroundFetchedEventCallback& callback); 290 DispatchBackgroundFetchedEventCallback callback);
292 void OnExtendableMessageEventStub( 291 void OnExtendableMessageEventStub(
293 mojom::ExtendableMessageEventPtr event, 292 mojom::ExtendableMessageEventPtr event,
294 const mojom::ServiceWorkerEventDispatcher:: 293 mojom::ServiceWorkerEventDispatcher::
295 DispatchExtendableMessageEventCallback& callback); 294 DispatchExtendableMessageEventCallback callback);
296 void OnInstallEventStub(int request_id); 295 void OnInstallEventStub(int request_id);
297 void OnFetchEventStub(int thread_id, 296 void OnFetchEventStub(int thread_id,
298 int fetch_event_id, 297 int fetch_event_id,
299 const ServiceWorkerFetchRequest& request, 298 const ServiceWorkerFetchRequest& request,
300 mojom::FetchEventPreloadHandlePtr preload_handle, 299 mojom::FetchEventPreloadHandlePtr preload_handle,
301 const FetchCallback& callback); 300 FetchCallback callback);
302 void OnNotificationClickEventStub( 301 void OnNotificationClickEventStub(
303 const std::string& notification_id, 302 const std::string& notification_id,
304 const PlatformNotificationData& notification_data, 303 const PlatformNotificationData& notification_data,
305 int action_index, 304 int action_index,
306 const base::Optional<base::string16>& reply, 305 const base::Optional<base::string16>& reply,
307 const mojom::ServiceWorkerEventDispatcher:: 306 mojom::ServiceWorkerEventDispatcher::
308 DispatchNotificationClickEventCallback& callback); 307 DispatchNotificationClickEventCallback callback);
309 void OnNotificationCloseEventStub( 308 void OnNotificationCloseEventStub(
310 const std::string& notification_id, 309 const std::string& notification_id,
311 const PlatformNotificationData& notification_data, 310 const PlatformNotificationData& notification_data,
312 const mojom::ServiceWorkerEventDispatcher:: 311 mojom::ServiceWorkerEventDispatcher::
313 DispatchNotificationCloseEventCallback& callback); 312 DispatchNotificationCloseEventCallback callback);
314 void OnPushEventStub( 313 void OnPushEventStub(
315 const PushEventPayload& payload, 314 const PushEventPayload& payload,
316 const mojom::ServiceWorkerEventDispatcher::DispatchPushEventCallback& 315 mojom::ServiceWorkerEventDispatcher::DispatchPushEventCallback callback);
317 callback);
318 void OnPaymentRequestEventStub( 316 void OnPaymentRequestEventStub(
319 payments::mojom::PaymentAppRequestPtr data, 317 payments::mojom::PaymentAppRequestPtr data,
320 payments::mojom::PaymentAppResponseCallbackPtr response_callback, 318 payments::mojom::PaymentAppResponseCallbackPtr response_callback,
321 const mojom::ServiceWorkerEventDispatcher:: 319 mojom::ServiceWorkerEventDispatcher::DispatchPaymentRequestEventCallback
322 DispatchPaymentRequestEventCallback& callback); 320 callback);
323 321
324 std::unique_ptr<TestBrowserContext> browser_context_; 322 std::unique_ptr<TestBrowserContext> browser_context_;
325 std::unique_ptr<MockRenderProcessHost> render_process_host_; 323 std::unique_ptr<MockRenderProcessHost> render_process_host_;
326 std::unique_ptr<MockRenderProcessHost> new_render_process_host_; 324 std::unique_ptr<MockRenderProcessHost> new_render_process_host_;
327 325
328 scoped_refptr<ServiceWorkerContextWrapper> wrapper_; 326 scoped_refptr<ServiceWorkerContextWrapper> wrapper_;
329 327
330 IPC::TestSink sink_; 328 IPC::TestSink sink_;
331 IPC::TestSink inner_sink_; 329 IPC::TestSink inner_sink_;
332 330
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 std::unique_ptr<MockType> mock = 365 std::unique_ptr<MockType> mock =
368 base::MakeUnique<MockType>(std::forward<Args>(args)...); 366 base::MakeUnique<MockType>(std::forward<Args>(args)...);
369 MockType* mock_rawptr = mock.get(); 367 MockType* mock_rawptr = mock.get();
370 RegisterMockInstanceClient(std::move(mock)); 368 RegisterMockInstanceClient(std::move(mock));
371 return mock_rawptr; 369 return mock_rawptr;
372 } 370 }
373 371
374 } // namespace content 372 } // namespace content
375 373
376 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ 374 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698