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

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

Issue 2606593002: [ServiceWorker] Associate interfaces.
Patch Set: Fix unit tests Created 3 years, 11 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>
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/service_worker_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/associated_binding.h"
26 #include "net/http/http_response_info.h" 26 #include "net/http/http_response_info.h"
27 #include "services/service_manager/public/cpp/interface_provider.h" 27 #include "services/service_manager/public/cpp/interface_provider.h"
28 #include "services/service_manager/public/cpp/interface_registry.h" 28 #include "services/service_manager/public/cpp/interface_registry.h"
29 #include "services/service_manager/public/interfaces/interface_provider.mojom.h" 29 #include "services/service_manager/public/interfaces/interface_provider.mojom.h"
30 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "url/gurl.h" 31 #include "url/gurl.h"
32 32
33 class GURL; 33 class GURL;
34 34
35 namespace service_manager { 35 namespace service_manager {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 base::Time /* dispatch_event_time */)>; 73 base::Time /* dispatch_event_time */)>;
74 74
75 class MockEmbeddedWorkerInstanceClient 75 class MockEmbeddedWorkerInstanceClient
76 : public mojom::EmbeddedWorkerInstanceClient { 76 : public mojom::EmbeddedWorkerInstanceClient {
77 public: 77 public:
78 explicit MockEmbeddedWorkerInstanceClient( 78 explicit MockEmbeddedWorkerInstanceClient(
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 mojo::ScopedInterfaceEndpointHandle handle);
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 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request) override; 89 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request) override;
90 void StopWorker(const StopWorkerCallback& callback) override; 90 void StopWorker(const StopWorkerCallback& callback) override;
91 91
92 base::WeakPtr<EmbeddedWorkerTestHelper> helper_; 92 base::WeakPtr<EmbeddedWorkerTestHelper> helper_;
93 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_; 93 mojo::AssociatedBinding<mojom::EmbeddedWorkerInstanceClient> binding_;
94 94
95 base::Optional<int> embedded_worker_id_; 95 base::Optional<int> embedded_worker_id_;
96 96
97 private: 97 private:
98 DISALLOW_COPY_AND_ASSIGN(MockEmbeddedWorkerInstanceClient); 98 DISALLOW_COPY_AND_ASSIGN(MockEmbeddedWorkerInstanceClient);
99 }; 99 };
100 100
101 // If |user_data_directory| is empty, the context makes storage stuff in 101 // If |user_data_directory| is empty, the context makes storage stuff in
102 // memory. 102 // memory.
103 explicit EmbeddedWorkerTestHelper(const base::FilePath& user_data_directory); 103 explicit EmbeddedWorkerTestHelper(const base::FilePath& user_data_directory);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 const ServiceWorkerFetchRequest& request, 239 const ServiceWorkerFetchRequest& request,
240 mojom::FetchEventPreloadHandlePtr preload_handle, 240 mojom::FetchEventPreloadHandlePtr preload_handle,
241 const FetchCallback& callback); 241 const FetchCallback& callback);
242 void OnPushEventStub( 242 void OnPushEventStub(
243 const PushEventPayload& payload, 243 const PushEventPayload& payload,
244 const mojom::ServiceWorkerEventDispatcher::DispatchPushEventCallback& 244 const mojom::ServiceWorkerEventDispatcher::DispatchPushEventCallback&
245 callback); 245 callback);
246 246
247 MessagePortMessageFilter* NewMessagePortMessageFilter(); 247 MessagePortMessageFilter* NewMessagePortMessageFilter();
248 248
249 std::unique_ptr<service_manager::InterfaceRegistry> CreateInterfaceRegistry( 249 void OverrideRemoteAssociatedInterfaces(MockRenderProcessHost* rph);
250 MockRenderProcessHost* rph);
251 250
252 std::unique_ptr<TestBrowserContext> browser_context_; 251 std::unique_ptr<TestBrowserContext> browser_context_;
253 std::unique_ptr<MockRenderProcessHost> render_process_host_; 252 std::unique_ptr<MockRenderProcessHost> render_process_host_;
254 std::unique_ptr<MockRenderProcessHost> new_render_process_host_; 253 std::unique_ptr<MockRenderProcessHost> new_render_process_host_;
255 254
256 scoped_refptr<ServiceWorkerContextWrapper> wrapper_; 255 scoped_refptr<ServiceWorkerContextWrapper> wrapper_;
257 256
258 IPC::TestSink sink_; 257 IPC::TestSink sink_;
259 IPC::TestSink inner_sink_; 258 IPC::TestSink inner_sink_;
260 259
261 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>> 260 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>>
262 mock_instance_clients_; 261 mock_instance_clients_;
263 size_t mock_instance_clients_next_index_; 262 size_t mock_instance_clients_next_index_;
264 263
265 int next_thread_id_; 264 int next_thread_id_;
266 int mock_render_process_id_; 265 int mock_render_process_id_;
267 int new_mock_render_process_id_; 266 int new_mock_render_process_id_;
268 267
269 std::unique_ptr<service_manager::InterfaceRegistry>
270 render_process_interface_registry_;
271 std::unique_ptr<service_manager::InterfaceRegistry>
272 new_render_process_interface_registry_;
273
274 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_; 268 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_;
275 std::map<int /* thread_id */, int /* embedded_worker_id */> 269 std::map<int /* thread_id */, int /* embedded_worker_id */>
276 thread_id_embedded_worker_id_map_; 270 thread_id_embedded_worker_id_map_;
277 271
278 // Stores the InterfaceRegistry/InterfaceProviders that are associated with 272 // Stores the InterfaceRegistry/InterfaceProviders that are associated with
279 // each individual service worker. 273 // each individual service worker.
280 base::hash_map<int, InterfaceRegistryAndProvider> 274 base::hash_map<int, InterfaceRegistryAndProvider>
281 thread_id_service_registry_map_; 275 thread_id_service_registry_map_;
282 276
283 // Updated each time MessageToWorker message is received. 277 // Updated each time MessageToWorker message is received.
(...skipping 13 matching lines...) Expand all
297 std::unique_ptr<MockType> mock = 291 std::unique_ptr<MockType> mock =
298 base::MakeUnique<MockType>(std::forward<Args>(args)...); 292 base::MakeUnique<MockType>(std::forward<Args>(args)...);
299 MockType* mock_rawptr = mock.get(); 293 MockType* mock_rawptr = mock.get();
300 RegisterMockInstanceClient(std::move(mock)); 294 RegisterMockInstanceClient(std::move(mock));
301 return mock_rawptr; 295 return mock_rawptr;
302 } 296 }
303 297
304 } // namespace content 298 } // namespace content
305 299
306 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ 300 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698