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

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 shimazu's comment #33 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // also returns success for event messages (e.g. InstallEvent, FetchEvent). 55 // also returns success for event messages (e.g. InstallEvent, FetchEvent).
56 // 56 //
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 { Install, Activate };
66 using FetchCallback = 66 using FetchCallback =
67 base::Callback<void(ServiceWorkerStatusCode, 67 base::Callback<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;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 const 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 const mojom::ServiceWorkerEventDispatcher::
214 DispatchExtendableMessageEventCallback& callback); 214 DispatchExtendableMessageEventCallback& callback);
215 virtual void OnInstallEvent(int embedded_worker_id, int request_id); 215 virtual void OnInstallEvent(
216 const mojom::ServiceWorkerEventDispatcher::DispatchInstallEventCallback&
217 callback);
216 virtual void OnFetchEvent(int embedded_worker_id, 218 virtual void OnFetchEvent(int embedded_worker_id,
217 int fetch_event_id, 219 int fetch_event_id,
218 const ServiceWorkerFetchRequest& request, 220 const ServiceWorkerFetchRequest& request,
219 mojom::FetchEventPreloadHandlePtr preload_handle, 221 mojom::FetchEventPreloadHandlePtr preload_handle,
220 const FetchCallback& callback); 222 const FetchCallback& callback);
221 virtual void OnNotificationClickEvent( 223 virtual void OnNotificationClickEvent(
222 const std::string& notification_id, 224 const std::string& notification_id,
223 const PlatformNotificationData& notification_data, 225 const PlatformNotificationData& notification_data,
224 int action_index, 226 int action_index,
225 const base::Optional<base::string16>& reply, 227 const base::Optional<base::string16>& reply,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 DispatchBackgroundFetchFailEventCallback& callback); 288 DispatchBackgroundFetchFailEventCallback& callback);
287 void OnBackgroundFetchedEventStub( 289 void OnBackgroundFetchedEventStub(
288 const std::string& tag, 290 const std::string& tag,
289 const std::vector<BackgroundFetchSettledFetch>& fetches, 291 const std::vector<BackgroundFetchSettledFetch>& fetches,
290 const mojom::ServiceWorkerEventDispatcher:: 292 const mojom::ServiceWorkerEventDispatcher::
291 DispatchBackgroundFetchedEventCallback& callback); 293 DispatchBackgroundFetchedEventCallback& callback);
292 void OnExtendableMessageEventStub( 294 void OnExtendableMessageEventStub(
293 mojom::ExtendableMessageEventPtr event, 295 mojom::ExtendableMessageEventPtr event,
294 const mojom::ServiceWorkerEventDispatcher:: 296 const mojom::ServiceWorkerEventDispatcher::
295 DispatchExtendableMessageEventCallback& callback); 297 DispatchExtendableMessageEventCallback& callback);
296 void OnInstallEventStub(int request_id); 298 void OnInstallEventStub(
299 const mojom::ServiceWorkerEventDispatcher::DispatchInstallEventCallback&
300 callback);
297 void OnFetchEventStub(int thread_id, 301 void OnFetchEventStub(int thread_id,
298 int fetch_event_id, 302 int fetch_event_id,
299 const ServiceWorkerFetchRequest& request, 303 const ServiceWorkerFetchRequest& request,
300 mojom::FetchEventPreloadHandlePtr preload_handle, 304 mojom::FetchEventPreloadHandlePtr preload_handle,
301 const FetchCallback& callback); 305 const FetchCallback& callback);
302 void OnNotificationClickEventStub( 306 void OnNotificationClickEventStub(
303 const std::string& notification_id, 307 const std::string& notification_id,
304 const PlatformNotificationData& notification_data, 308 const PlatformNotificationData& notification_data,
305 int action_index, 309 int action_index,
306 const base::Optional<base::string16>& reply, 310 const base::Optional<base::string16>& reply,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 348
345 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_; 349 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_;
346 std::map<int /* thread_id */, int /* embedded_worker_id */> 350 std::map<int /* thread_id */, int /* embedded_worker_id */>
347 thread_id_embedded_worker_id_map_; 351 thread_id_embedded_worker_id_map_;
348 352
349 std::map< 353 std::map<
350 int /* embedded_worker_id */, 354 int /* embedded_worker_id */,
351 mojom::EmbeddedWorkerInstanceHostAssociatedPtr /* instance_host_ptr */> 355 mojom::EmbeddedWorkerInstanceHostAssociatedPtr /* instance_host_ptr */>
352 embedded_worker_id_instance_host_ptr_map_; 356 embedded_worker_id_instance_host_ptr_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