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

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

Issue 2779763004: Create ServiceWorkerProviderHost before starting worker (Closed)
Patch Set: Fix ForeignFetchRequestHandlerTest.InitializeHandler_TimeoutBehaviorForServiceWorker Created 3 years, 6 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 ~MockEmbeddedWorkerInstanceClient() override; 76 ~MockEmbeddedWorkerInstanceClient() override;
77 77
78 static void Bind(const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, 78 static void Bind(const base::WeakPtr<EmbeddedWorkerTestHelper>& helper,
79 mojo::ScopedMessagePipeHandle request); 79 mojo::ScopedMessagePipeHandle request);
80 80
81 protected: 81 protected:
82 // Implementation of mojo interfaces. 82 // Implementation of mojo interfaces.
83 void StartWorker( 83 void StartWorker(
84 const EmbeddedWorkerStartParams& params, 84 const EmbeddedWorkerStartParams& params,
85 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, 85 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request,
86 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host) 86 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host,
87 mojom::ServiceWorkerProviderClientInfoPtr provider_client_info)
87 override; 88 override;
88 void StopWorker() override; 89 void StopWorker() override;
89 void ResumeAfterDownload() override; 90 void ResumeAfterDownload() override;
90 void AddMessageToConsole(blink::WebConsoleMessage::Level level, 91 void AddMessageToConsole(blink::WebConsoleMessage::Level level,
91 const std::string& message) override; 92 const std::string& message) override;
92 93
93 base::WeakPtr<EmbeddedWorkerTestHelper> helper_; 94 base::WeakPtr<EmbeddedWorkerTestHelper> helper_;
94 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_; 95 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_;
95 96
96 base::Optional<int> embedded_worker_id_; 97 base::Optional<int> embedded_worker_id_;
(...skipping 10 matching lines...) Expand all
107 // Call this to simulate add/associate a process to a pattern. 108 // Call this to simulate add/associate a process to a pattern.
108 // This also registers this sender for the process. 109 // This also registers this sender for the process.
109 void SimulateAddProcessToPattern(const GURL& pattern, int process_id); 110 void SimulateAddProcessToPattern(const GURL& pattern, int process_id);
110 111
111 // IPC::Sender implementation. 112 // IPC::Sender implementation.
112 bool Send(IPC::Message* message) override; 113 bool Send(IPC::Message* message) override;
113 114
114 // IPC::Listener implementation. 115 // IPC::Listener implementation.
115 bool OnMessageReceived(const IPC::Message& msg) override; 116 bool OnMessageReceived(const IPC::Message& msg) override;
116 117
117 // Register a mojo endpoint object derived from 118 // Registers a mojo endpoint object derived from
falken 2017/06/06 14:06:33 while you're here: Mojo.
shimazu 2017/06/12 06:08:12 Done.
118 // MockEmbeddedWorkerInstanceClient. 119 // MockEmbeddedWorkerInstanceClient.
119 void RegisterMockInstanceClient( 120 void RegisterMockInstanceClient(
120 std::unique_ptr<MockEmbeddedWorkerInstanceClient> client); 121 std::unique_ptr<MockEmbeddedWorkerInstanceClient> client);
121 122
123 // Registers the dispatcher host for the process to a map managed by this test
124 // helper. If there is a existing dispatcher host, it'll removed before adding
125 // to the map. This should be called before ServiceWorkerDispatcher::Init
falken 2017/06/06 14:06:33 ServiceWorkerDispatcherHost::Init?
shimazu 2017/06/12 06:08:12 Done.
126 // because it internally calls ServiceWorkerContextCore::AddDispatcherHost.
127 void RegisterMockDispatcherHost(
128 int process_id,
129 scoped_refptr<ServiceWorkerDispatcherHost> dispatcher_host);
130
122 template <typename MockType, typename... Args> 131 template <typename MockType, typename... Args>
123 MockType* CreateAndRegisterMockInstanceClient(Args&&... args); 132 MockType* CreateAndRegisterMockInstanceClient(Args&&... args);
124 133
125 // IPC sink for EmbeddedWorker messages. 134 // IPC sink for EmbeddedWorker messages.
126 IPC::TestSink* ipc_sink() { return &sink_; } 135 IPC::TestSink* ipc_sink() { return &sink_; }
127 136
128 std::vector<Event>* dispatched_events() { return &events_; } 137 std::vector<Event>* dispatched_events() { return &events_; }
129 138
130 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>>* 139 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>>*
131 mock_instance_clients() { 140 mock_instance_clients() {
132 return &mock_instance_clients_; 141 return &mock_instance_clients_;
133 } 142 }
134 143
135 ServiceWorkerContextCore* context(); 144 ServiceWorkerContextCore* context();
136 ServiceWorkerContextWrapper* context_wrapper() { return wrapper_.get(); } 145 ServiceWorkerContextWrapper* context_wrapper() { return wrapper_.get(); }
137 void ShutdownContext(); 146 void ShutdownContext();
138 147
139 int GetNextThreadId() { return next_thread_id_++; } 148 int GetNextThreadId() { return next_thread_id_++; }
140 int GetNextProviderId() { return next_provider_id_++; }
141 149
142 int mock_render_process_id() const { return mock_render_process_id_; } 150 int mock_render_process_id() const { return mock_render_process_id_; }
143 MockRenderProcessHost* mock_render_process_host() { 151 MockRenderProcessHost* mock_render_process_host() {
144 return render_process_host_.get(); 152 return render_process_host_.get();
145 } 153 }
146 154
147 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map() { 155 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map() {
148 return embedded_worker_id_service_worker_version_id_map_; 156 return embedded_worker_id_service_worker_version_id_map_;
149 } 157 }
150 158
(...skipping 12 matching lines...) Expand all
163 // StartWorker IPC handler routed through MockEmbeddedWorkerInstanceClient. 171 // StartWorker IPC handler routed through MockEmbeddedWorkerInstanceClient.
164 // This simulates each legacy IPC sent from the renderer and binds |request| 172 // This simulates each legacy IPC sent from the renderer and binds |request|
165 // to MockServiceWorkerEventDispatcher by default. 173 // to MockServiceWorkerEventDispatcher by default.
166 virtual void OnStartWorker( 174 virtual void OnStartWorker(
167 int embedded_worker_id, 175 int embedded_worker_id,
168 int64_t service_worker_version_id, 176 int64_t service_worker_version_id,
169 const GURL& scope, 177 const GURL& scope,
170 const GURL& script_url, 178 const GURL& script_url,
171 bool pause_after_download, 179 bool pause_after_download,
172 mojom::ServiceWorkerEventDispatcherRequest request, 180 mojom::ServiceWorkerEventDispatcherRequest request,
173 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host); 181 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host,
182 mojom::ServiceWorkerProviderClientInfoPtr provider_client_info);
174 virtual void OnResumeAfterDownload(int embedded_worker_id); 183 virtual void OnResumeAfterDownload(int embedded_worker_id);
175 // StopWorker IPC handler routed through MockEmbeddedWorkerInstanceClient. 184 // StopWorker IPC handler routed through MockEmbeddedWorkerInstanceClient.
176 // This calls SimulateWorkerStopped() by default. 185 // This calls SimulateWorkerStopped() by default.
177 virtual void OnStopWorker(int embedded_worker_id); 186 virtual void OnStopWorker(int embedded_worker_id);
178 187
179 // On*Event handlers. By default they just return success via 188 // On*Event handlers. By default they just return success via
180 // SimulateSendReplyToBrowser. 189 // SimulateSendReplyToBrowser.
181 virtual void OnActivateEvent( 190 virtual void OnActivateEvent(
182 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback 191 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback
183 callback); 192 callback);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 payments::mojom::PaymentAppRequestPtr data, 243 payments::mojom::PaymentAppRequestPtr data,
235 payments::mojom::PaymentAppResponseCallbackPtr response_callback, 244 payments::mojom::PaymentAppResponseCallbackPtr response_callback,
236 mojom::ServiceWorkerEventDispatcher::DispatchPaymentRequestEventCallback 245 mojom::ServiceWorkerEventDispatcher::DispatchPaymentRequestEventCallback
237 callback); 246 callback);
238 247
239 // These functions simulate sending an EmbeddedHostMsg message through the 248 // These functions simulate sending an EmbeddedHostMsg message through the
240 // legacy IPC system to the browser. 249 // legacy IPC system to the browser.
241 void SimulateWorkerReadyForInspection(int embedded_worker_id); 250 void SimulateWorkerReadyForInspection(int embedded_worker_id);
242 void SimulateWorkerScriptCached(int embedded_worker_id); 251 void SimulateWorkerScriptCached(int embedded_worker_id);
243 void SimulateWorkerScriptLoaded(int embedded_worker_id); 252 void SimulateWorkerScriptLoaded(int embedded_worker_id);
244 void SimulateWorkerThreadStarted(int thread_id, 253 void SimulateWorkerThreadStarted(int thread_id, int embedded_worker_id);
245 int embedded_worker_id,
246 int provider_id);
247 void SimulateWorkerScriptEvaluated(int embedded_worker_id, bool success); 254 void SimulateWorkerScriptEvaluated(int embedded_worker_id, bool success);
248 void SimulateWorkerStarted(int embedded_worker_id); 255 void SimulateWorkerStarted(int embedded_worker_id);
249 void SimulateWorkerStopped(int embedded_worker_id); 256 void SimulateWorkerStopped(int embedded_worker_id);
250 void SimulateSend(IPC::Message* message); 257 void SimulateSend(IPC::Message* message);
251 258
252 EmbeddedWorkerRegistry* registry(); 259 EmbeddedWorkerRegistry* registry();
253 260
254 private: 261 private:
255 class MockServiceWorkerEventDispatcher; 262 class MockServiceWorkerEventDispatcher;
256 263
257 void OnStartWorkerStub( 264 void OnStartWorkerStub(
258 const EmbeddedWorkerStartParams& params, 265 const EmbeddedWorkerStartParams& params,
259 mojom::ServiceWorkerEventDispatcherRequest request, 266 mojom::ServiceWorkerEventDispatcherRequest request,
260 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host); 267 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host,
268 mojom::ServiceWorkerProviderClientInfoPtr provider_client_info);
261 void OnResumeAfterDownloadStub(int embedded_worker_id); 269 void OnResumeAfterDownloadStub(int embedded_worker_id);
262 void OnStopWorkerStub(int embedded_worker_id); 270 void OnStopWorkerStub(int embedded_worker_id);
263 void OnMessageToWorkerStub(int thread_id, 271 void OnMessageToWorkerStub(int thread_id,
264 int embedded_worker_id, 272 int embedded_worker_id,
265 const IPC::Message& message); 273 const IPC::Message& message);
266 void OnActivateEventStub( 274 void OnActivateEventStub(
267 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback 275 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback
268 callback); 276 callback);
269 void OnBackgroundFetchAbortEventStub( 277 void OnBackgroundFetchAbortEventStub(
270 const std::string& tag, 278 const std::string& tag,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 335
328 scoped_refptr<ServiceWorkerContextWrapper> wrapper_; 336 scoped_refptr<ServiceWorkerContextWrapper> wrapper_;
329 337
330 IPC::TestSink sink_; 338 IPC::TestSink sink_;
331 339
332 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>> 340 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>>
333 mock_instance_clients_; 341 mock_instance_clients_;
334 size_t mock_instance_clients_next_index_; 342 size_t mock_instance_clients_next_index_;
335 343
336 int next_thread_id_; 344 int next_thread_id_;
337 int next_provider_id_;
338 int mock_render_process_id_; 345 int mock_render_process_id_;
339 int new_mock_render_process_id_; 346 int new_mock_render_process_id_;
340 347
341 std::map<int /* process_id */, scoped_refptr<ServiceWorkerDispatcherHost>> 348 std::map<int /* process_id */, scoped_refptr<ServiceWorkerDispatcherHost>>
342 dispatcher_hosts_; 349 dispatcher_hosts_;
343 350
344 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_; 351 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_;
345 std::map<int /* thread_id */, int /* embedded_worker_id */> 352 std::map<int /* thread_id */, int /* embedded_worker_id */>
346 thread_id_embedded_worker_id_map_; 353 thread_id_embedded_worker_id_map_;
347 354
(...skipping 17 matching lines...) Expand all
365 std::unique_ptr<MockType> mock = 372 std::unique_ptr<MockType> mock =
366 base::MakeUnique<MockType>(std::forward<Args>(args)...); 373 base::MakeUnique<MockType>(std::forward<Args>(args)...);
367 MockType* mock_rawptr = mock.get(); 374 MockType* mock_rawptr = mock.get();
368 RegisterMockInstanceClient(std::move(mock)); 375 RegisterMockInstanceClient(std::move(mock));
369 return mock_rawptr; 376 return mock_rawptr;
370 } 377 }
371 378
372 } // namespace content 379 } // namespace content
373 380
374 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ 381 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698