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

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

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