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

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

Issue 2746783002: [ServiceWorker] Mojofy InstallEvent of Service Worker (Closed)
Patch Set: Created 3 years, 9 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // also returns success for event messages (e.g. InstallEvent, FetchEvent). 58 // also returns success for event messages (e.g. InstallEvent, FetchEvent).
59 // 59 //
60 // Alternatively consumers can subclass this helper and override On*() 60 // Alternatively consumers can subclass this helper and override On*()
61 // methods to add their own logic/verification code. 61 // methods to add their own logic/verification code.
62 // 62 //
63 // See embedded_worker_instance_unittest.cc for example usages. 63 // See embedded_worker_instance_unittest.cc for example usages.
64 // 64 //
65 class EmbeddedWorkerTestHelper : public IPC::Sender, 65 class EmbeddedWorkerTestHelper : public IPC::Sender,
66 public IPC::Listener { 66 public IPC::Listener {
67 public: 67 public:
68 enum class Event { Activate }; 68 enum class Event { Install, Activate };
69 using FetchCallback = 69 using FetchCallback =
70 base::Callback<void(ServiceWorkerStatusCode, 70 base::Callback<void(ServiceWorkerStatusCode,
71 base::Time /* dispatch_event_time */)>; 71 base::Time /* dispatch_event_time */)>;
72 72
73 class MockEmbeddedWorkerInstanceClient 73 class MockEmbeddedWorkerInstanceClient
74 : public mojom::EmbeddedWorkerInstanceClient { 74 : public mojom::EmbeddedWorkerInstanceClient {
75 public: 75 public:
76 explicit MockEmbeddedWorkerInstanceClient( 76 explicit MockEmbeddedWorkerInstanceClient(
77 base::WeakPtr<EmbeddedWorkerTestHelper> helper); 77 base::WeakPtr<EmbeddedWorkerTestHelper> helper);
78 ~MockEmbeddedWorkerInstanceClient() override; 78 ~MockEmbeddedWorkerInstanceClient() override;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback&
191 callback); 191 callback);
192 virtual void OnExtendableMessageEvent( 192 virtual void OnExtendableMessageEvent(
193 mojom::ExtendableMessageEventPtr event, 193 mojom::ExtendableMessageEventPtr event,
194 const mojom::ServiceWorkerEventDispatcher:: 194 const mojom::ServiceWorkerEventDispatcher::
195 DispatchExtendableMessageEventCallback& callback); 195 DispatchExtendableMessageEventCallback& callback);
196 virtual void OnInstallEvent(int embedded_worker_id, int request_id); 196 virtual void OnInstallEvent(
197 const mojom::ServiceWorkerEventDispatcher::DispatchInstallEventCallback&
198 callback);
197 virtual void OnFetchEvent(int embedded_worker_id, 199 virtual void OnFetchEvent(int embedded_worker_id,
198 int fetch_event_id, 200 int fetch_event_id,
199 const ServiceWorkerFetchRequest& request, 201 const ServiceWorkerFetchRequest& request,
200 mojom::FetchEventPreloadHandlePtr preload_handle, 202 mojom::FetchEventPreloadHandlePtr preload_handle,
201 const FetchCallback& callback); 203 const FetchCallback& callback);
202 virtual void OnNotificationClickEvent( 204 virtual void OnNotificationClickEvent(
203 const std::string& notification_id, 205 const std::string& notification_id,
204 const PlatformNotificationData& notification_data, 206 const PlatformNotificationData& notification_data,
205 int action_index, 207 int action_index,
206 const base::Optional<base::string16>& reply, 208 const base::Optional<base::string16>& reply,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 void OnMessageToWorkerStub(int thread_id, 246 void OnMessageToWorkerStub(int thread_id,
245 int embedded_worker_id, 247 int embedded_worker_id,
246 const IPC::Message& message); 248 const IPC::Message& message);
247 void OnActivateEventStub( 249 void OnActivateEventStub(
248 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback& 250 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback&
249 callback); 251 callback);
250 void OnExtendableMessageEventStub( 252 void OnExtendableMessageEventStub(
251 mojom::ExtendableMessageEventPtr event, 253 mojom::ExtendableMessageEventPtr event,
252 const mojom::ServiceWorkerEventDispatcher:: 254 const mojom::ServiceWorkerEventDispatcher::
253 DispatchExtendableMessageEventCallback& callback); 255 DispatchExtendableMessageEventCallback& callback);
254 void OnInstallEventStub(int request_id); 256 void OnInstallEventStub(
257 const mojom::ServiceWorkerEventDispatcher::DispatchInstallEventCallback&
258 callback);
255 void OnFetchEventStub(int thread_id, 259 void OnFetchEventStub(int thread_id,
256 int fetch_event_id, 260 int fetch_event_id,
257 const ServiceWorkerFetchRequest& request, 261 const ServiceWorkerFetchRequest& request,
258 mojom::FetchEventPreloadHandlePtr preload_handle, 262 mojom::FetchEventPreloadHandlePtr preload_handle,
259 const FetchCallback& callback); 263 const FetchCallback& callback);
260 void OnNotificationClickEventStub( 264 void OnNotificationClickEventStub(
261 const std::string& notification_id, 265 const std::string& notification_id,
262 const PlatformNotificationData& notification_data, 266 const PlatformNotificationData& notification_data,
263 int action_index, 267 int action_index,
264 const base::Optional<base::string16>& reply, 268 const base::Optional<base::string16>& reply,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 307
304 std::unique_ptr<service_manager::InterfaceRegistry> 308 std::unique_ptr<service_manager::InterfaceRegistry>
305 render_process_interface_registry_; 309 render_process_interface_registry_;
306 std::unique_ptr<service_manager::InterfaceRegistry> 310 std::unique_ptr<service_manager::InterfaceRegistry>
307 new_render_process_interface_registry_; 311 new_render_process_interface_registry_;
308 312
309 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_; 313 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_;
310 std::map<int /* thread_id */, int /* embedded_worker_id */> 314 std::map<int /* thread_id */, int /* embedded_worker_id */>
311 thread_id_embedded_worker_id_map_; 315 thread_id_embedded_worker_id_map_;
312 316
313 // Updated each time MessageToWorker message is received.
314 int current_embedded_worker_id_;
315
316 std::vector<Event> events_; 317 std::vector<Event> events_;
317 318
318 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_; 319 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_;
319 320
320 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper); 321 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper);
321 }; 322 };
322 323
323 template <typename MockType, typename... Args> 324 template <typename MockType, typename... Args>
324 MockType* EmbeddedWorkerTestHelper::CreateAndRegisterMockInstanceClient( 325 MockType* EmbeddedWorkerTestHelper::CreateAndRegisterMockInstanceClient(
325 Args&&... args) { 326 Args&&... args) {
326 std::unique_ptr<MockType> mock = 327 std::unique_ptr<MockType> mock =
327 base::MakeUnique<MockType>(std::forward<Args>(args)...); 328 base::MakeUnique<MockType>(std::forward<Args>(args)...);
328 MockType* mock_rawptr = mock.get(); 329 MockType* mock_rawptr = mock.get();
329 RegisterMockInstanceClient(std::move(mock)); 330 RegisterMockInstanceClient(std::move(mock));
330 return mock_rawptr; 331 return mock_rawptr;
331 } 332 }
332 333
333 } // namespace content 334 } // namespace content
334 335
335 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ 336 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698