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

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

Issue 2678733002: [ServiceWorker] Mojofy ActivateEvent of Service Worker (Closed)
Patch Set: Just rebase Created 3 years, 10 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
« no previous file with comments | « no previous file | content/browser/service_worker/embedded_worker_test_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // also returns success for event messages (e.g. InstallEvent, FetchEvent). 57 // also returns success for event messages (e.g. InstallEvent, FetchEvent).
58 // 58 //
59 // Alternatively consumers can subclass this helper and override On*() 59 // Alternatively consumers can subclass this helper and override On*()
60 // methods to add their own logic/verification code. 60 // methods to add their own logic/verification code.
61 // 61 //
62 // See embedded_worker_instance_unittest.cc for example usages. 62 // See embedded_worker_instance_unittest.cc for example usages.
63 // 63 //
64 class EmbeddedWorkerTestHelper : public IPC::Sender, 64 class EmbeddedWorkerTestHelper : public IPC::Sender,
65 public IPC::Listener { 65 public IPC::Listener {
66 public: 66 public:
67 enum class Event { Activate };
67 using FetchCallback = 68 using FetchCallback =
68 base::Callback<void(ServiceWorkerStatusCode, 69 base::Callback<void(ServiceWorkerStatusCode,
69 base::Time /* dispatch_event_time */)>; 70 base::Time /* dispatch_event_time */)>;
70 71
71 class MockEmbeddedWorkerInstanceClient 72 class MockEmbeddedWorkerInstanceClient
72 : public mojom::EmbeddedWorkerInstanceClient { 73 : public mojom::EmbeddedWorkerInstanceClient {
73 public: 74 public:
74 explicit MockEmbeddedWorkerInstanceClient( 75 explicit MockEmbeddedWorkerInstanceClient(
75 base::WeakPtr<EmbeddedWorkerTestHelper> helper); 76 base::WeakPtr<EmbeddedWorkerTestHelper> helper);
76 ~MockEmbeddedWorkerInstanceClient() override; 77 ~MockEmbeddedWorkerInstanceClient() override;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 std::unique_ptr<MockEmbeddedWorkerInstanceClient> client); 119 std::unique_ptr<MockEmbeddedWorkerInstanceClient> client);
119 120
120 template <typename MockType, typename... Args> 121 template <typename MockType, typename... Args>
121 MockType* CreateAndRegisterMockInstanceClient(Args&&... args); 122 MockType* CreateAndRegisterMockInstanceClient(Args&&... args);
122 123
123 // IPC sink for EmbeddedWorker messages. 124 // IPC sink for EmbeddedWorker messages.
124 IPC::TestSink* ipc_sink() { return &sink_; } 125 IPC::TestSink* ipc_sink() { return &sink_; }
125 // Inner IPC sink for script context messages sent via EmbeddedWorker. 126 // Inner IPC sink for script context messages sent via EmbeddedWorker.
126 IPC::TestSink* inner_ipc_sink() { return &inner_sink_; } 127 IPC::TestSink* inner_ipc_sink() { return &inner_sink_; }
127 128
129 std::vector<Event>* dispatched_events() { return &events_; }
130
128 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>>* 131 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>>*
129 mock_instance_clients() { 132 mock_instance_clients() {
130 return &mock_instance_clients_; 133 return &mock_instance_clients_;
131 } 134 }
132 135
133 ServiceWorkerContextCore* context(); 136 ServiceWorkerContextCore* context();
134 ServiceWorkerContextWrapper* context_wrapper() { return wrapper_.get(); } 137 ServiceWorkerContextWrapper* context_wrapper() { return wrapper_.get(); }
135 void ShutdownContext(); 138 void ShutdownContext();
136 139
137 int GetNextThreadId() { return next_thread_id_++; } 140 int GetNextThreadId() { return next_thread_id_++; }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // The legacy IPC message handler. This passes the messages to their 178 // The legacy IPC message handler. This passes the messages to their
176 // respective On*Event handler by default. 179 // respective On*Event handler by default.
177 virtual bool OnMessageToWorker(int thread_id, 180 virtual bool OnMessageToWorker(int thread_id,
178 int embedded_worker_id, 181 int embedded_worker_id,
179 const IPC::Message& message); 182 const IPC::Message& message);
180 183
181 // On*Event handlers. Called by the default implementation of 184 // On*Event handlers. Called by the default implementation of
182 // OnMessageToWorker when events are sent to the embedded 185 // OnMessageToWorker when events are sent to the embedded
183 // worker. By default they just return success via 186 // worker. By default they just return success via
184 // SimulateSendReplyToBrowser. 187 // SimulateSendReplyToBrowser.
185 virtual void OnActivateEvent(int embedded_worker_id, int request_id); 188 virtual void OnActivateEvent(
189 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback&
190 callback);
186 virtual void OnExtendableMessageEvent( 191 virtual void OnExtendableMessageEvent(
187 mojom::ExtendableMessageEventPtr event, 192 mojom::ExtendableMessageEventPtr event,
188 const mojom::ServiceWorkerEventDispatcher:: 193 const mojom::ServiceWorkerEventDispatcher::
189 DispatchExtendableMessageEventCallback& callback); 194 DispatchExtendableMessageEventCallback& callback);
190 virtual void OnInstallEvent(int embedded_worker_id, int request_id); 195 virtual void OnInstallEvent(int embedded_worker_id, int request_id);
191 virtual void OnFetchEvent(int embedded_worker_id, 196 virtual void OnFetchEvent(int embedded_worker_id,
192 int fetch_event_id, 197 int fetch_event_id,
193 const ServiceWorkerFetchRequest& request, 198 const ServiceWorkerFetchRequest& request,
194 mojom::FetchEventPreloadHandlePtr preload_handle, 199 mojom::FetchEventPreloadHandlePtr preload_handle,
195 const FetchCallback& callback); 200 const FetchCallback& callback);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 class MockServiceWorkerEventDispatcher; 236 class MockServiceWorkerEventDispatcher;
232 237
233 void OnStartWorkerStub(const EmbeddedWorkerStartParams& params, 238 void OnStartWorkerStub(const EmbeddedWorkerStartParams& params,
234 mojom::ServiceWorkerEventDispatcherRequest request); 239 mojom::ServiceWorkerEventDispatcherRequest request);
235 void OnResumeAfterDownloadStub(int embedded_worker_id); 240 void OnResumeAfterDownloadStub(int embedded_worker_id);
236 void OnStopWorkerStub( 241 void OnStopWorkerStub(
237 const mojom::EmbeddedWorkerInstanceClient::StopWorkerCallback& callback); 242 const mojom::EmbeddedWorkerInstanceClient::StopWorkerCallback& callback);
238 void OnMessageToWorkerStub(int thread_id, 243 void OnMessageToWorkerStub(int thread_id,
239 int embedded_worker_id, 244 int embedded_worker_id,
240 const IPC::Message& message); 245 const IPC::Message& message);
241 void OnActivateEventStub(int request_id); 246 void OnActivateEventStub(
247 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback&
248 callback);
242 void OnExtendableMessageEventStub( 249 void OnExtendableMessageEventStub(
243 mojom::ExtendableMessageEventPtr event, 250 mojom::ExtendableMessageEventPtr event,
244 const mojom::ServiceWorkerEventDispatcher:: 251 const mojom::ServiceWorkerEventDispatcher::
245 DispatchExtendableMessageEventCallback& callback); 252 DispatchExtendableMessageEventCallback& callback);
246 void OnInstallEventStub(int request_id); 253 void OnInstallEventStub(int request_id);
247 void OnFetchEventStub(int thread_id, 254 void OnFetchEventStub(int thread_id,
248 int fetch_event_id, 255 int fetch_event_id,
249 const ServiceWorkerFetchRequest& request, 256 const ServiceWorkerFetchRequest& request,
250 mojom::FetchEventPreloadHandlePtr preload_handle, 257 mojom::FetchEventPreloadHandlePtr preload_handle,
251 const FetchCallback& callback); 258 const FetchCallback& callback);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 std::unique_ptr<service_manager::InterfaceRegistry> 302 std::unique_ptr<service_manager::InterfaceRegistry>
296 new_render_process_interface_registry_; 303 new_render_process_interface_registry_;
297 304
298 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_; 305 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_;
299 std::map<int /* thread_id */, int /* embedded_worker_id */> 306 std::map<int /* thread_id */, int /* embedded_worker_id */>
300 thread_id_embedded_worker_id_map_; 307 thread_id_embedded_worker_id_map_;
301 308
302 // Updated each time MessageToWorker message is received. 309 // Updated each time MessageToWorker message is received.
303 int current_embedded_worker_id_; 310 int current_embedded_worker_id_;
304 311
312 std::vector<Event> events_;
313
305 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_; 314 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_;
306 315
307 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper); 316 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper);
308 }; 317 };
309 318
310 template <typename MockType, typename... Args> 319 template <typename MockType, typename... Args>
311 MockType* EmbeddedWorkerTestHelper::CreateAndRegisterMockInstanceClient( 320 MockType* EmbeddedWorkerTestHelper::CreateAndRegisterMockInstanceClient(
312 Args&&... args) { 321 Args&&... args) {
313 std::unique_ptr<MockType> mock = 322 std::unique_ptr<MockType> mock =
314 base::MakeUnique<MockType>(std::forward<Args>(args)...); 323 base::MakeUnique<MockType>(std::forward<Args>(args)...);
315 MockType* mock_rawptr = mock.get(); 324 MockType* mock_rawptr = mock.get();
316 RegisterMockInstanceClient(std::move(mock)); 325 RegisterMockInstanceClient(std::move(mock));
317 return mock_rawptr; 326 return mock_rawptr;
318 } 327 }
319 328
320 } // namespace content 329 } // namespace content
321 330
322 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ 331 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/embedded_worker_test_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698