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

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

Issue 2746783002: [ServiceWorker] Mojofy InstallEvent of Service Worker (Closed)
Patch Set: Rebase and address falken, leon and mek's comments 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // also returns success for event messages (e.g. InstallEvent, FetchEvent). 59 // also returns success for event messages (e.g. InstallEvent, FetchEvent).
60 // 60 //
61 // Alternatively consumers can subclass this helper and override On*() 61 // Alternatively consumers can subclass this helper and override On*()
62 // methods to add their own logic/verification code. 62 // methods to add their own logic/verification code.
63 // 63 //
64 // See embedded_worker_instance_unittest.cc for example usages. 64 // See embedded_worker_instance_unittest.cc for example usages.
65 // 65 //
66 class EmbeddedWorkerTestHelper : public IPC::Sender, 66 class EmbeddedWorkerTestHelper : public IPC::Sender,
67 public IPC::Listener { 67 public IPC::Listener {
68 public: 68 public:
69 enum class Event { Activate }; 69 enum class Event { Install, Activate };
70 using FetchCallback = 70 using FetchCallback =
71 base::Callback<void(ServiceWorkerStatusCode, 71 base::Callback<void(ServiceWorkerStatusCode,
72 base::Time /* dispatch_event_time */)>; 72 base::Time /* dispatch_event_time */)>;
73 73
74 class MockEmbeddedWorkerInstanceClient 74 class MockEmbeddedWorkerInstanceClient
75 : public mojom::EmbeddedWorkerInstanceClient { 75 : public mojom::EmbeddedWorkerInstanceClient {
76 public: 76 public:
77 explicit MockEmbeddedWorkerInstanceClient( 77 explicit MockEmbeddedWorkerInstanceClient(
78 base::WeakPtr<EmbeddedWorkerTestHelper> helper); 78 base::WeakPtr<EmbeddedWorkerTestHelper> helper);
79 ~MockEmbeddedWorkerInstanceClient() override; 79 ~MockEmbeddedWorkerInstanceClient() override;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 DispatchBackgroundFetchFailEventCallback& callback); 206 DispatchBackgroundFetchFailEventCallback& callback);
207 virtual void OnBackgroundFetchedEvent( 207 virtual void OnBackgroundFetchedEvent(
208 const std::string& tag, 208 const std::string& tag,
209 const std::vector<BackgroundFetchSettledFetch>& fetches, 209 const std::vector<BackgroundFetchSettledFetch>& fetches,
210 const mojom::ServiceWorkerEventDispatcher:: 210 const mojom::ServiceWorkerEventDispatcher::
211 DispatchBackgroundFetchedEventCallback& callback); 211 DispatchBackgroundFetchedEventCallback& callback);
212 virtual void OnExtendableMessageEvent( 212 virtual void OnExtendableMessageEvent(
213 mojom::ExtendableMessageEventPtr event, 213 mojom::ExtendableMessageEventPtr event,
214 const mojom::ServiceWorkerEventDispatcher:: 214 const mojom::ServiceWorkerEventDispatcher::
215 DispatchExtendableMessageEventCallback& callback); 215 DispatchExtendableMessageEventCallback& callback);
216 virtual void OnInstallEvent(int embedded_worker_id, int request_id); 216 virtual void OnInstallEvent(
217 const mojom::ServiceWorkerEventDispatcher::DispatchInstallEventCallback&
218 callback);
217 virtual void OnFetchEvent(int embedded_worker_id, 219 virtual void OnFetchEvent(int embedded_worker_id,
218 int fetch_event_id, 220 int fetch_event_id,
219 const ServiceWorkerFetchRequest& request, 221 const ServiceWorkerFetchRequest& request,
220 mojom::FetchEventPreloadHandlePtr preload_handle, 222 mojom::FetchEventPreloadHandlePtr preload_handle,
221 const FetchCallback& callback); 223 const FetchCallback& callback);
222 virtual void OnNotificationClickEvent( 224 virtual void OnNotificationClickEvent(
223 const std::string& notification_id, 225 const std::string& notification_id,
224 const PlatformNotificationData& notification_data, 226 const PlatformNotificationData& notification_data,
225 int action_index, 227 int action_index,
226 const base::Optional<base::string16>& reply, 228 const base::Optional<base::string16>& reply,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 DispatchBackgroundFetchFailEventCallback& callback); 286 DispatchBackgroundFetchFailEventCallback& callback);
285 void OnBackgroundFetchedEventStub( 287 void OnBackgroundFetchedEventStub(
286 const std::string& tag, 288 const std::string& tag,
287 const std::vector<BackgroundFetchSettledFetch>& fetches, 289 const std::vector<BackgroundFetchSettledFetch>& fetches,
288 const mojom::ServiceWorkerEventDispatcher:: 290 const mojom::ServiceWorkerEventDispatcher::
289 DispatchBackgroundFetchedEventCallback& callback); 291 DispatchBackgroundFetchedEventCallback& callback);
290 void OnExtendableMessageEventStub( 292 void OnExtendableMessageEventStub(
291 mojom::ExtendableMessageEventPtr event, 293 mojom::ExtendableMessageEventPtr event,
292 const mojom::ServiceWorkerEventDispatcher:: 294 const mojom::ServiceWorkerEventDispatcher::
293 DispatchExtendableMessageEventCallback& callback); 295 DispatchExtendableMessageEventCallback& callback);
294 void OnInstallEventStub(int request_id); 296 void OnInstallEventStub(
297 const mojom::ServiceWorkerEventDispatcher::DispatchInstallEventCallback&
298 callback);
295 void OnFetchEventStub(int thread_id, 299 void OnFetchEventStub(int thread_id,
296 int fetch_event_id, 300 int fetch_event_id,
297 const ServiceWorkerFetchRequest& request, 301 const ServiceWorkerFetchRequest& request,
298 mojom::FetchEventPreloadHandlePtr preload_handle, 302 mojom::FetchEventPreloadHandlePtr preload_handle,
299 const FetchCallback& callback); 303 const FetchCallback& callback);
300 void OnNotificationClickEventStub( 304 void OnNotificationClickEventStub(
301 const std::string& notification_id, 305 const std::string& notification_id,
302 const PlatformNotificationData& notification_data, 306 const PlatformNotificationData& notification_data,
303 int action_index, 307 int action_index,
304 const base::Optional<base::string16>& reply, 308 const base::Optional<base::string16>& reply,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 348
345 std::unique_ptr<service_manager::InterfaceRegistry> 349 std::unique_ptr<service_manager::InterfaceRegistry>
346 render_process_interface_registry_; 350 render_process_interface_registry_;
347 std::unique_ptr<service_manager::InterfaceRegistry> 351 std::unique_ptr<service_manager::InterfaceRegistry>
348 new_render_process_interface_registry_; 352 new_render_process_interface_registry_;
349 353
350 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_;
351 std::map<int /* thread_id */, int /* embedded_worker_id */> 355 std::map<int /* thread_id */, int /* embedded_worker_id */>
352 thread_id_embedded_worker_id_map_; 356 thread_id_embedded_worker_id_map_;
353 357
354 // Updated each time MessageToWorker message is received.
355 int current_embedded_worker_id_;
356
357 std::vector<Event> events_; 358 std::vector<Event> events_;
358 359
359 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_; 360 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_;
360 361
361 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper); 362 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper);
362 }; 363 };
363 364
364 template <typename MockType, typename... Args> 365 template <typename MockType, typename... Args>
365 MockType* EmbeddedWorkerTestHelper::CreateAndRegisterMockInstanceClient( 366 MockType* EmbeddedWorkerTestHelper::CreateAndRegisterMockInstanceClient(
366 Args&&... args) { 367 Args&&... args) {
367 std::unique_ptr<MockType> mock = 368 std::unique_ptr<MockType> mock =
368 base::MakeUnique<MockType>(std::forward<Args>(args)...); 369 base::MakeUnique<MockType>(std::forward<Args>(args)...);
369 MockType* mock_rawptr = mock.get(); 370 MockType* mock_rawptr = mock.get();
370 RegisterMockInstanceClient(std::move(mock)); 371 RegisterMockInstanceClient(std::move(mock));
371 return mock_rawptr; 372 return mock_rawptr;
372 } 373 }
373 374
374 } // namespace content 375 } // namespace content
375 376
376 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ 377 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698