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

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

Issue 2490623005: Remove InterfaceRegistry/Provider from service workers (Closed)
Patch Set: rebase/fix comment Created 4 years 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>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/containers/hash_tables.h" 15 #include "base/containers/hash_tables.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/optional.h" 18 #include "base/optional.h"
19 #include "base/time/time.h" 19 #include "base/time/time.h"
20 #include "content/common/service_worker/embedded_worker.mojom.h" 20 #include "content/common/service_worker/embedded_worker.mojom.h"
21 #include "content/common/service_worker/fetch_event_dispatcher.mojom.h" 21 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h"
22 #include "content/common/service_worker/service_worker_status_code.h" 22 #include "content/common/service_worker/service_worker_status_code.h"
23 #include "ipc/ipc_listener.h" 23 #include "ipc/ipc_listener.h"
24 #include "ipc/ipc_test_sink.h" 24 #include "ipc/ipc_test_sink.h"
25 #include "mojo/public/cpp/bindings/binding.h" 25 #include "mojo/public/cpp/bindings/binding.h"
26 #include "services/service_manager/public/cpp/interface_provider.h" 26 #include "services/service_manager/public/cpp/interface_provider.h"
27 #include "services/service_manager/public/cpp/interface_registry.h" 27 #include "services/service_manager/public/cpp/interface_registry.h"
28 #include "services/service_manager/public/interfaces/interface_provider.mojom.h" 28 #include "services/service_manager/public/interfaces/interface_provider.mojom.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
30 #include "url/gurl.h" 30 #include "url/gurl.h"
31 31
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 base::WeakPtr<EmbeddedWorkerTestHelper> helper); 79 base::WeakPtr<EmbeddedWorkerTestHelper> helper);
80 ~MockEmbeddedWorkerInstanceClient() override; 80 ~MockEmbeddedWorkerInstanceClient() override;
81 81
82 static void Bind(const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, 82 static void Bind(const base::WeakPtr<EmbeddedWorkerTestHelper>& helper,
83 mojom::EmbeddedWorkerInstanceClientRequest request); 83 mojom::EmbeddedWorkerInstanceClientRequest request);
84 84
85 protected: 85 protected:
86 // Implementation of mojo interfaces. 86 // Implementation of mojo interfaces.
87 void StartWorker( 87 void StartWorker(
88 const EmbeddedWorkerStartParams& params, 88 const EmbeddedWorkerStartParams& params,
89 service_manager::mojom::InterfaceProviderPtr browser_interfaces, 89 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request) override;
90 service_manager::mojom::InterfaceProviderRequest renderer_request)
91 override;
92 void StopWorker(const StopWorkerCallback& callback) override; 90 void StopWorker(const StopWorkerCallback& callback) override;
93 91
94 base::WeakPtr<EmbeddedWorkerTestHelper> helper_; 92 base::WeakPtr<EmbeddedWorkerTestHelper> helper_;
95 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_; 93 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_;
96 94
97 base::Optional<int> embedded_worker_id_; 95 base::Optional<int> embedded_worker_id_;
98 96
99 private: 97 private:
100 DISALLOW_COPY_AND_ASSIGN(MockEmbeddedWorkerInstanceClient); 98 DISALLOW_COPY_AND_ASSIGN(MockEmbeddedWorkerInstanceClient);
101 }; 99 };
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 virtual void OnResumeAfterDownload(int embedded_worker_id); 170 virtual void OnResumeAfterDownload(int embedded_worker_id);
173 virtual void OnStopWorker(int embedded_worker_id); 171 virtual void OnStopWorker(int embedded_worker_id);
174 virtual bool OnMessageToWorker(int thread_id, 172 virtual bool OnMessageToWorker(int thread_id,
175 int embedded_worker_id, 173 int embedded_worker_id,
176 const IPC::Message& message); 174 const IPC::Message& message);
177 175
178 // Called to setup mojo for a new embedded worker. Override to register 176 // Called to setup mojo for a new embedded worker. Override to register
179 // interfaces the worker should expose to the browser. 177 // interfaces the worker should expose to the browser.
180 virtual void OnSetupMojo( 178 virtual void OnSetupMojo(
181 int thread_id, 179 int thread_id,
182 service_manager::InterfaceRegistry* interface_registry); 180 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request);
183 181
184 // On*Event handlers. Called by the default implementation of 182 // On*Event handlers. Called by the default implementation of
185 // OnMessageToWorker when events are sent to the embedded 183 // OnMessageToWorker when events are sent to the embedded
186 // worker. By default they just return success via 184 // worker. By default they just return success via
187 // SimulateSendReplyToBrowser. 185 // SimulateSendReplyToBrowser.
188 virtual void OnActivateEvent(int embedded_worker_id, int request_id); 186 virtual void OnActivateEvent(int embedded_worker_id, int request_id);
189 virtual void OnExtendableMessageEvent(int embedded_worker_id, int request_id); 187 virtual void OnExtendableMessageEvent(int embedded_worker_id, int request_id);
190 virtual void OnInstallEvent(int embedded_worker_id, int request_id); 188 virtual void OnInstallEvent(int embedded_worker_id, int request_id);
191 virtual void OnFetchEvent(int embedded_worker_id, 189 virtual void OnFetchEvent(int embedded_worker_id,
192 int fetch_event_id, 190 int fetch_event_id,
(...skipping 16 matching lines...) Expand all
209 void SimulateSend(IPC::Message* message); 207 void SimulateSend(IPC::Message* message);
210 208
211 EmbeddedWorkerRegistry* registry(); 209 EmbeddedWorkerRegistry* registry();
212 210
213 private: 211 private:
214 using InterfaceRegistryAndProvider = 212 using InterfaceRegistryAndProvider =
215 std::pair<std::unique_ptr<service_manager::InterfaceRegistry>, 213 std::pair<std::unique_ptr<service_manager::InterfaceRegistry>,
216 std::unique_ptr<service_manager::InterfaceProvider>>; 214 std::unique_ptr<service_manager::InterfaceProvider>>;
217 215
218 class MockEmbeddedWorkerSetup; 216 class MockEmbeddedWorkerSetup;
219 class MockFetchEventDispatcher; 217 class MockServiceWorkerEventDispatcher;
220 218
221 void OnStartWorkerStub(const EmbeddedWorkerStartParams& params); 219 void OnStartWorkerStub(const EmbeddedWorkerStartParams& params);
222 void OnResumeAfterDownloadStub(int embedded_worker_id); 220 void OnResumeAfterDownloadStub(int embedded_worker_id);
223 void OnStopWorkerStub(int embedded_worker_id); 221 void OnStopWorkerStub(int embedded_worker_id);
224 void OnMessageToWorkerStub(int thread_id, 222 void OnMessageToWorkerStub(int thread_id,
225 int embedded_worker_id, 223 int embedded_worker_id,
226 const IPC::Message& message); 224 const IPC::Message& message);
227 void OnActivateEventStub(int request_id); 225 void OnActivateEventStub(int request_id);
228 void OnExtendableMessageEventStub( 226 void OnExtendableMessageEventStub(
229 int request_id, 227 int request_id,
230 const ServiceWorkerMsg_ExtendableMessageEvent_Params& params); 228 const ServiceWorkerMsg_ExtendableMessageEvent_Params& params);
231 void OnInstallEventStub(int request_id); 229 void OnInstallEventStub(int request_id);
232 void OnFetchEventStub(int thread_id, 230 void OnFetchEventStub(int thread_id,
233 int fetch_event_id, 231 int fetch_event_id,
234 const ServiceWorkerFetchRequest& request, 232 const ServiceWorkerFetchRequest& request,
235 mojom::FetchEventPreloadHandlePtr preload_handle, 233 mojom::FetchEventPreloadHandlePtr preload_handle,
236 const FetchCallback& callback); 234 const FetchCallback& callback);
237 void OnPushEventStub(int request_id, const PushEventPayload& payload); 235 void OnPushEventStub(int request_id, const PushEventPayload& payload);
238 void OnSetupMojoStub(
239 int thread_id,
240 service_manager::mojom::InterfaceProviderRequest services,
241 service_manager::mojom::InterfaceProviderPtr exposed_services);
242 236
243 MessagePortMessageFilter* NewMessagePortMessageFilter(); 237 MessagePortMessageFilter* NewMessagePortMessageFilter();
244 238
245 std::unique_ptr<service_manager::InterfaceRegistry> CreateInterfaceRegistry( 239 std::unique_ptr<service_manager::InterfaceRegistry> CreateInterfaceRegistry(
246 MockRenderProcessHost* rph); 240 MockRenderProcessHost* rph);
247 241
248 std::unique_ptr<TestBrowserContext> browser_context_; 242 std::unique_ptr<TestBrowserContext> browser_context_;
249 std::unique_ptr<MockRenderProcessHost> render_process_host_; 243 std::unique_ptr<MockRenderProcessHost> render_process_host_;
250 std::unique_ptr<MockRenderProcessHost> new_render_process_host_; 244 std::unique_ptr<MockRenderProcessHost> new_render_process_host_;
251 245
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 std::unique_ptr<MockType> mock = 287 std::unique_ptr<MockType> mock =
294 base::MakeUnique<MockType>(std::forward<Args>(args)...); 288 base::MakeUnique<MockType>(std::forward<Args>(args)...);
295 MockType* mock_rawptr = mock.get(); 289 MockType* mock_rawptr = mock.get();
296 RegisterMockInstanceClient(std::move(mock)); 290 RegisterMockInstanceClient(std::move(mock));
297 return mock_rawptr; 291 return mock_rawptr;
298 } 292 }
299 293
300 } // namespace content 294 } // namespace content
301 295
302 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ 296 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698