| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 |
| 118 // MockEmbeddedWorkerInstanceClient. | 119 // MockEmbeddedWorkerInstanceClient. |
| 119 void RegisterMockInstanceClient( | 120 void RegisterMockInstanceClient( |
| 120 std::unique_ptr<MockEmbeddedWorkerInstanceClient> client); | 121 std::unique_ptr<MockEmbeddedWorkerInstanceClient> client); |
| 121 | 122 |
| 122 // Registers the dispatcher host for the process to a map managed by this test | 123 // Registers the dispatcher host for the process to a map managed by this test |
| 123 // helper. If there is a existing dispatcher host, it'll removed before adding | 124 // helper. If there is a existing dispatcher host, it'll removed before adding |
| 124 // to the map. This should be called before ServiceWorkerDispatcherHost::Init | 125 // to the map. This should be called before ServiceWorkerDispatcherHost::Init |
| 125 // because it internally calls ServiceWorkerContextCore::AddDispatcherHost. | 126 // because it internally calls ServiceWorkerContextCore::AddDispatcherHost. |
| 126 void RegisterMockDispatcherHost( | 127 void RegisterMockDispatcherHost( |
| 127 int process_id, | 128 int process_id, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 138 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>>* | 139 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>>* |
| 139 mock_instance_clients() { | 140 mock_instance_clients() { |
| 140 return &mock_instance_clients_; | 141 return &mock_instance_clients_; |
| 141 } | 142 } |
| 142 | 143 |
| 143 ServiceWorkerContextCore* context(); | 144 ServiceWorkerContextCore* context(); |
| 144 ServiceWorkerContextWrapper* context_wrapper() { return wrapper_.get(); } | 145 ServiceWorkerContextWrapper* context_wrapper() { return wrapper_.get(); } |
| 145 void ShutdownContext(); | 146 void ShutdownContext(); |
| 146 | 147 |
| 147 int GetNextThreadId() { return next_thread_id_++; } | 148 int GetNextThreadId() { return next_thread_id_++; } |
| 148 int GetNextProviderId() { return next_provider_id_++; } | |
| 149 | 149 |
| 150 int mock_render_process_id() const { return mock_render_process_id_; } | 150 int mock_render_process_id() const { return mock_render_process_id_; } |
| 151 MockRenderProcessHost* mock_render_process_host() { | 151 MockRenderProcessHost* mock_render_process_host() { |
| 152 return render_process_host_.get(); | 152 return render_process_host_.get(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 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() { |
| 156 return embedded_worker_id_service_worker_version_id_map_; | 156 return embedded_worker_id_service_worker_version_id_map_; |
| 157 } | 157 } |
| 158 | 158 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 171 // StartWorker IPC handler routed through MockEmbeddedWorkerInstanceClient. | 171 // StartWorker IPC handler routed through MockEmbeddedWorkerInstanceClient. |
| 172 // 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| |
| 173 // to MockServiceWorkerEventDispatcher by default. | 173 // to MockServiceWorkerEventDispatcher by default. |
| 174 virtual void OnStartWorker( | 174 virtual void OnStartWorker( |
| 175 int embedded_worker_id, | 175 int embedded_worker_id, |
| 176 int64_t service_worker_version_id, | 176 int64_t service_worker_version_id, |
| 177 const GURL& scope, | 177 const GURL& scope, |
| 178 const GURL& script_url, | 178 const GURL& script_url, |
| 179 bool pause_after_download, | 179 bool pause_after_download, |
| 180 mojom::ServiceWorkerEventDispatcherRequest request, | 180 mojom::ServiceWorkerEventDispatcherRequest request, |
| 181 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host); | 181 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, |
| 182 mojom::ServiceWorkerProviderClientInfoPtr provider_client_info); |
| 182 virtual void OnResumeAfterDownload(int embedded_worker_id); | 183 virtual void OnResumeAfterDownload(int embedded_worker_id); |
| 183 // StopWorker IPC handler routed through MockEmbeddedWorkerInstanceClient. | 184 // StopWorker IPC handler routed through MockEmbeddedWorkerInstanceClient. |
| 184 // This calls SimulateWorkerStopped() by default. | 185 // This calls SimulateWorkerStopped() by default. |
| 185 virtual void OnStopWorker(int embedded_worker_id); | 186 virtual void OnStopWorker(int embedded_worker_id); |
| 186 | 187 |
| 187 // On*Event handlers. By default they just return success via | 188 // On*Event handlers. By default they just return success via |
| 188 // SimulateSendReplyToBrowser. | 189 // SimulateSendReplyToBrowser. |
| 189 virtual void OnActivateEvent( | 190 virtual void OnActivateEvent( |
| 190 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback | 191 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback |
| 191 callback); | 192 callback); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 payments::mojom::PaymentRequestEventDataPtr data, | 243 payments::mojom::PaymentRequestEventDataPtr data, |
| 243 payments::mojom::PaymentAppResponseCallbackPtr response_callback, | 244 payments::mojom::PaymentAppResponseCallbackPtr response_callback, |
| 244 mojom::ServiceWorkerEventDispatcher::DispatchPaymentRequestEventCallback | 245 mojom::ServiceWorkerEventDispatcher::DispatchPaymentRequestEventCallback |
| 245 callback); | 246 callback); |
| 246 | 247 |
| 247 // These functions simulate sending an EmbeddedHostMsg message through the | 248 // These functions simulate sending an EmbeddedHostMsg message through the |
| 248 // legacy IPC system to the browser. | 249 // legacy IPC system to the browser. |
| 249 void SimulateWorkerReadyForInspection(int embedded_worker_id); | 250 void SimulateWorkerReadyForInspection(int embedded_worker_id); |
| 250 void SimulateWorkerScriptCached(int embedded_worker_id); | 251 void SimulateWorkerScriptCached(int embedded_worker_id); |
| 251 void SimulateWorkerScriptLoaded(int embedded_worker_id); | 252 void SimulateWorkerScriptLoaded(int embedded_worker_id); |
| 252 void SimulateWorkerThreadStarted(int thread_id, | 253 void SimulateWorkerThreadStarted(int thread_id, int embedded_worker_id); |
| 253 int embedded_worker_id, | |
| 254 int provider_id); | |
| 255 void SimulateWorkerScriptEvaluated(int embedded_worker_id, bool success); | 254 void SimulateWorkerScriptEvaluated(int embedded_worker_id, bool success); |
| 256 void SimulateWorkerStarted(int embedded_worker_id); | 255 void SimulateWorkerStarted(int embedded_worker_id); |
| 257 void SimulateWorkerStopped(int embedded_worker_id); | 256 void SimulateWorkerStopped(int embedded_worker_id); |
| 258 void SimulateSend(IPC::Message* message); | 257 void SimulateSend(IPC::Message* message); |
| 259 | 258 |
| 260 EmbeddedWorkerRegistry* registry(); | 259 EmbeddedWorkerRegistry* registry(); |
| 261 | 260 |
| 262 private: | 261 private: |
| 263 class MockServiceWorkerEventDispatcher; | 262 class MockServiceWorkerEventDispatcher; |
| 264 | 263 |
| 265 void OnStartWorkerStub( | 264 void OnStartWorkerStub( |
| 266 const EmbeddedWorkerStartParams& params, | 265 const EmbeddedWorkerStartParams& params, |
| 267 mojom::ServiceWorkerEventDispatcherRequest request, | 266 mojom::ServiceWorkerEventDispatcherRequest request, |
| 268 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host); | 267 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, |
| 268 mojom::ServiceWorkerProviderClientInfoPtr provider_client_info); |
| 269 void OnResumeAfterDownloadStub(int embedded_worker_id); | 269 void OnResumeAfterDownloadStub(int embedded_worker_id); |
| 270 void OnStopWorkerStub(int embedded_worker_id); | 270 void OnStopWorkerStub(int embedded_worker_id); |
| 271 void OnMessageToWorkerStub(int thread_id, | 271 void OnMessageToWorkerStub(int thread_id, |
| 272 int embedded_worker_id, | 272 int embedded_worker_id, |
| 273 const IPC::Message& message); | 273 const IPC::Message& message); |
| 274 void OnActivateEventStub( | 274 void OnActivateEventStub( |
| 275 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback | 275 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback |
| 276 callback); | 276 callback); |
| 277 void OnBackgroundFetchAbortEventStub( | 277 void OnBackgroundFetchAbortEventStub( |
| 278 const std::string& tag, | 278 const std::string& tag, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 | 335 |
| 336 scoped_refptr<ServiceWorkerContextWrapper> wrapper_; | 336 scoped_refptr<ServiceWorkerContextWrapper> wrapper_; |
| 337 | 337 |
| 338 IPC::TestSink sink_; | 338 IPC::TestSink sink_; |
| 339 | 339 |
| 340 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>> | 340 std::vector<std::unique_ptr<MockEmbeddedWorkerInstanceClient>> |
| 341 mock_instance_clients_; | 341 mock_instance_clients_; |
| 342 size_t mock_instance_clients_next_index_; | 342 size_t mock_instance_clients_next_index_; |
| 343 | 343 |
| 344 int next_thread_id_; | 344 int next_thread_id_; |
| 345 int next_provider_id_; | |
| 346 int mock_render_process_id_; | 345 int mock_render_process_id_; |
| 347 int new_mock_render_process_id_; | 346 int new_mock_render_process_id_; |
| 348 | 347 |
| 349 std::map<int /* process_id */, scoped_refptr<ServiceWorkerDispatcherHost>> | 348 std::map<int /* process_id */, scoped_refptr<ServiceWorkerDispatcherHost>> |
| 350 dispatcher_hosts_; | 349 dispatcher_hosts_; |
| 351 | 350 |
| 352 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_; |
| 353 std::map<int /* thread_id */, int /* embedded_worker_id */> | 352 std::map<int /* thread_id */, int /* embedded_worker_id */> |
| 354 thread_id_embedded_worker_id_map_; | 353 thread_id_embedded_worker_id_map_; |
| 355 | 354 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 373 std::unique_ptr<MockType> mock = | 372 std::unique_ptr<MockType> mock = |
| 374 base::MakeUnique<MockType>(std::forward<Args>(args)...); | 373 base::MakeUnique<MockType>(std::forward<Args>(args)...); |
| 375 MockType* mock_rawptr = mock.get(); | 374 MockType* mock_rawptr = mock.get(); |
| 376 RegisterMockInstanceClient(std::move(mock)); | 375 RegisterMockInstanceClient(std::move(mock)); |
| 377 return mock_rawptr; | 376 return mock_rawptr; |
| 378 } | 377 } |
| 379 | 378 |
| 380 } // namespace content | 379 } // namespace content |
| 381 | 380 |
| 382 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ | 381 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ |
| OLD | NEW |