| 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> |
| 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/scoped_ptr_hash_map.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 "content/common/mojo/service_registry_impl.h" | 18 #include "content/common/mojo/service_registry_impl.h" |
| 19 #include "ipc/ipc_listener.h" | 19 #include "ipc/ipc_listener.h" |
| 20 #include "ipc/ipc_test_sink.h" | 20 #include "ipc/ipc_test_sink.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 23 | 23 |
| 24 class GURL; | 24 class GURL; |
| 25 struct EmbeddedWorkerMsg_StartWorker_Params; | 25 struct EmbeddedWorkerMsg_StartWorker_Params; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 const GURL& scope, | 113 const GURL& scope, |
| 114 const GURL& script_url, | 114 const GURL& script_url, |
| 115 bool pause_after_download); | 115 bool pause_after_download); |
| 116 virtual void OnResumeAfterDownload(int embedded_worker_id); | 116 virtual void OnResumeAfterDownload(int embedded_worker_id); |
| 117 virtual void OnStopWorker(int embedded_worker_id); | 117 virtual void OnStopWorker(int embedded_worker_id); |
| 118 virtual bool OnMessageToWorker(int thread_id, | 118 virtual bool OnMessageToWorker(int thread_id, |
| 119 int embedded_worker_id, | 119 int embedded_worker_id, |
| 120 const IPC::Message& message); | 120 const IPC::Message& message); |
| 121 | 121 |
| 122 // Called to setup mojo for a new embedded worker. Override to register | 122 // Called to setup mojo for a new embedded worker. Override to register |
| 123 // services the worker should expose to the browser. | 123 // interfaces the worker should expose to the browser. |
| 124 virtual void OnSetupMojo(ServiceRegistry* service_registry); | 124 virtual void OnSetupMojo(shell::InterfaceRegistry* interface_registry); |
| 125 | 125 |
| 126 // On*Event handlers. Called by the default implementation of | 126 // On*Event handlers. Called by the default implementation of |
| 127 // OnMessageToWorker when events are sent to the embedded | 127 // OnMessageToWorker when events are sent to the embedded |
| 128 // worker. By default they just return success via | 128 // worker. By default they just return success via |
| 129 // SimulateSendReplyToBrowser. | 129 // SimulateSendReplyToBrowser. |
| 130 virtual void OnActivateEvent(int embedded_worker_id, int request_id); | 130 virtual void OnActivateEvent(int embedded_worker_id, int request_id); |
| 131 virtual void OnExtendableMessageEvent(int embedded_worker_id, int request_id); | 131 virtual void OnExtendableMessageEvent(int embedded_worker_id, int request_id); |
| 132 virtual void OnInstallEvent(int embedded_worker_id, int request_id); | 132 virtual void OnInstallEvent(int embedded_worker_id, int request_id); |
| 133 virtual void OnFetchEvent(int embedded_worker_id, | 133 virtual void OnFetchEvent(int embedded_worker_id, |
| 134 int request_id, | 134 int request_id, |
| 135 const ServiceWorkerFetchRequest& request); | 135 const ServiceWorkerFetchRequest& request); |
| 136 virtual void OnPushEvent(int embedded_worker_id, | 136 virtual void OnPushEvent(int embedded_worker_id, |
| 137 int request_id, | 137 int request_id, |
| 138 const PushEventPayload& payload); | 138 const PushEventPayload& payload); |
| 139 | 139 |
| 140 // These functions simulate sending an EmbeddedHostMsg message to the | 140 // These functions simulate sending an EmbeddedHostMsg message to the |
| 141 // browser. | 141 // browser. |
| 142 void SimulateWorkerReadyForInspection(int embedded_worker_id); | 142 void SimulateWorkerReadyForInspection(int embedded_worker_id); |
| 143 void SimulateWorkerScriptCached(int embedded_worker_id); | 143 void SimulateWorkerScriptCached(int embedded_worker_id); |
| 144 void SimulateWorkerScriptLoaded(int embedded_worker_id); | 144 void SimulateWorkerScriptLoaded(int embedded_worker_id); |
| 145 void SimulateWorkerThreadStarted(int thread_id, int embedded_worker_id); | 145 void SimulateWorkerThreadStarted(int thread_id, int embedded_worker_id); |
| 146 void SimulateWorkerScriptEvaluated(int embedded_worker_id, bool success); | 146 void SimulateWorkerScriptEvaluated(int embedded_worker_id, bool success); |
| 147 void SimulateWorkerStarted(int embedded_worker_id); | 147 void SimulateWorkerStarted(int embedded_worker_id); |
| 148 void SimulateWorkerStopped(int embedded_worker_id); | 148 void SimulateWorkerStopped(int embedded_worker_id); |
| 149 void SimulateSend(IPC::Message* message); | 149 void SimulateSend(IPC::Message* message); |
| 150 | 150 |
| 151 EmbeddedWorkerRegistry* registry(); | 151 EmbeddedWorkerRegistry* registry(); |
| 152 | 152 |
| 153 private: | 153 private: |
| 154 using InterfaceRegistryAndProvider = |
| 155 std::pair<std::unique_ptr<shell::InterfaceRegistry>, |
| 156 std::unique_ptr<shell::InterfaceProvider>>; |
| 157 |
| 154 class MockEmbeddedWorkerSetup; | 158 class MockEmbeddedWorkerSetup; |
| 155 | 159 |
| 156 void OnStartWorkerStub(const EmbeddedWorkerMsg_StartWorker_Params& params); | 160 void OnStartWorkerStub(const EmbeddedWorkerMsg_StartWorker_Params& params); |
| 157 void OnResumeAfterDownloadStub(int embedded_worker_id); | 161 void OnResumeAfterDownloadStub(int embedded_worker_id); |
| 158 void OnStopWorkerStub(int embedded_worker_id); | 162 void OnStopWorkerStub(int embedded_worker_id); |
| 159 void OnMessageToWorkerStub(int thread_id, | 163 void OnMessageToWorkerStub(int thread_id, |
| 160 int embedded_worker_id, | 164 int embedded_worker_id, |
| 161 const IPC::Message& message); | 165 const IPC::Message& message); |
| 162 void OnActivateEventStub(int request_id); | 166 void OnActivateEventStub(int request_id); |
| 163 void OnExtendableMessageEventStub( | 167 void OnExtendableMessageEventStub( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 181 IPC::TestSink sink_; | 185 IPC::TestSink sink_; |
| 182 IPC::TestSink inner_sink_; | 186 IPC::TestSink inner_sink_; |
| 183 | 187 |
| 184 int next_thread_id_; | 188 int next_thread_id_; |
| 185 int mock_render_process_id_; | 189 int mock_render_process_id_; |
| 186 | 190 |
| 187 std::unique_ptr<shell::InterfaceRegistry> render_process_interface_registry_; | 191 std::unique_ptr<shell::InterfaceRegistry> render_process_interface_registry_; |
| 188 | 192 |
| 189 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_; | 193 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_; |
| 190 | 194 |
| 191 // Stores the ServiceRegistries that are associated with each individual | 195 // Stores the InterfaceRegistry/InterfaceProviders that are associated with |
| 192 // service worker. | 196 // each individual service worker. |
| 193 base::ScopedPtrHashMap<int, std::unique_ptr<ServiceRegistryImpl>> | 197 base::hash_map<int, InterfaceRegistryAndProvider> |
| 194 thread_id_service_registry_map_; | 198 thread_id_service_registry_map_; |
| 195 | 199 |
| 196 // Updated each time MessageToWorker message is received. | 200 // Updated each time MessageToWorker message is received. |
| 197 int current_embedded_worker_id_; | 201 int current_embedded_worker_id_; |
| 198 | 202 |
| 199 std::vector<scoped_refptr<MessagePortMessageFilter>> | 203 std::vector<scoped_refptr<MessagePortMessageFilter>> |
| 200 message_port_message_filters_; | 204 message_port_message_filters_; |
| 201 | 205 |
| 202 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_; | 206 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_; |
| 203 | 207 |
| 204 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper); | 208 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper); |
| 205 }; | 209 }; |
| 206 | 210 |
| 207 } // namespace content | 211 } // namespace content |
| 208 | 212 |
| 209 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ | 213 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ |
| OLD | NEW |