| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_PUBLIC_TEST_MOCK_RENDER_PROCESS_HOST_H_ | 5 #ifndef CONTENT_PUBLIC_TEST_MOCK_RENDER_PROCESS_HOST_H_ |
| 6 #define CONTENT_PUBLIC_TEST_MOCK_RENDER_PROCESS_HOST_H_ | 6 #define CONTENT_PUBLIC_TEST_MOCK_RENDER_PROCESS_HOST_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 namespace content { | 26 namespace content { |
| 27 | 27 |
| 28 class MockRenderProcessHostFactory; | 28 class MockRenderProcessHostFactory; |
| 29 class RenderWidgetHost; | 29 class RenderWidgetHost; |
| 30 | 30 |
| 31 // A mock render process host that has no corresponding renderer process. All | 31 // A mock render process host that has no corresponding renderer process. All |
| 32 // IPC messages are sent into the message sink for inspection by tests. | 32 // IPC messages are sent into the message sink for inspection by tests. |
| 33 class MockRenderProcessHost : public RenderProcessHost { | 33 class MockRenderProcessHost : public RenderProcessHost { |
| 34 public: | 34 public: |
| 35 using InterfaceBinder = base::Callback<void(mojo::ScopedMessagePipeHandle)>; |
| 36 |
| 35 explicit MockRenderProcessHost(BrowserContext* browser_context); | 37 explicit MockRenderProcessHost(BrowserContext* browser_context); |
| 36 ~MockRenderProcessHost() override; | 38 ~MockRenderProcessHost() override; |
| 37 | 39 |
| 38 // Provides access to all IPC messages that would have been sent to the | 40 // Provides access to all IPC messages that would have been sent to the |
| 39 // renderer via this RenderProcessHost. | 41 // renderer via this RenderProcessHost. |
| 40 IPC::TestSink& sink() { return sink_; } | 42 IPC::TestSink& sink() { return sink_; } |
| 41 | 43 |
| 42 // Provides test access to how many times a bad message has been received. | 44 // Provides test access to how many times a bad message has been received. |
| 43 int bad_msg_count() const { return bad_msg_count_; } | 45 int bad_msg_count() const { return bad_msg_count_; } |
| 44 | 46 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 bool StopWebRTCEventLog() override; | 94 bool StopWebRTCEventLog() override; |
| 93 void SetWebRtcLogMessageCallback( | 95 void SetWebRtcLogMessageCallback( |
| 94 base::Callback<void(const std::string&)> callback) override; | 96 base::Callback<void(const std::string&)> callback) override; |
| 95 void ClearWebRtcLogMessageCallback() override; | 97 void ClearWebRtcLogMessageCallback() override; |
| 96 WebRtcStopRtpDumpCallback StartRtpDump( | 98 WebRtcStopRtpDumpCallback StartRtpDump( |
| 97 bool incoming, | 99 bool incoming, |
| 98 bool outgoing, | 100 bool outgoing, |
| 99 const WebRtcRtpPacketCallback& packet_callback) override; | 101 const WebRtcRtpPacketCallback& packet_callback) override; |
| 100 #endif | 102 #endif |
| 101 void ResumeDeferredNavigation(const GlobalRequestID& request_id) override; | 103 void ResumeDeferredNavigation(const GlobalRequestID& request_id) override; |
| 102 service_manager::InterfaceProvider* GetRemoteInterfaces() override; | 104 void BindInterface(const std::string& interface_name, |
| 105 mojo::ScopedMessagePipeHandle interface_pipe) override; |
| 103 std::unique_ptr<base::SharedPersistentMemoryAllocator> TakeMetricsAllocator() | 106 std::unique_ptr<base::SharedPersistentMemoryAllocator> TakeMetricsAllocator() |
| 104 override; | 107 override; |
| 105 const base::TimeTicks& GetInitTimeForNavigationMetrics() const override; | 108 const base::TimeTicks& GetInitTimeForNavigationMetrics() const override; |
| 106 bool IsProcessBackgrounded() const override; | 109 bool IsProcessBackgrounded() const override; |
| 107 size_t GetWorkerRefCount() const override; | 110 size_t GetWorkerRefCount() const override; |
| 108 void IncrementServiceWorkerRefCount() override; | 111 void IncrementServiceWorkerRefCount() override; |
| 109 void DecrementServiceWorkerRefCount() override; | 112 void DecrementServiceWorkerRefCount() override; |
| 110 void IncrementSharedWorkerRefCount() override; | 113 void IncrementSharedWorkerRefCount() override; |
| 111 void DecrementSharedWorkerRefCount() override; | 114 void DecrementSharedWorkerRefCount() override; |
| 112 void ForceReleaseWorkerRefCounts() override; | 115 void ForceReleaseWorkerRefCounts() override; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 138 is_process_backgrounded_ = is_process_backgrounded; | 141 is_process_backgrounded_ = is_process_backgrounded; |
| 139 } | 142 } |
| 140 | 143 |
| 141 void SetProcessHandle(std::unique_ptr<base::ProcessHandle> new_handle) { | 144 void SetProcessHandle(std::unique_ptr<base::ProcessHandle> new_handle) { |
| 142 process_handle = std::move(new_handle); | 145 process_handle = std::move(new_handle); |
| 143 } | 146 } |
| 144 | 147 |
| 145 void GetAudioOutputControllers( | 148 void GetAudioOutputControllers( |
| 146 const GetAudioOutputControllersCallback& callback) const override {} | 149 const GetAudioOutputControllersCallback& callback) const override {} |
| 147 | 150 |
| 148 void SetRemoteInterfaces( | 151 void OverrideBinderForTesting(const std::string& interface_name, |
| 149 std::unique_ptr<service_manager::InterfaceProvider> remote_interfaces) { | 152 const InterfaceBinder& binder); |
| 150 remote_interfaces_ = std::move(remote_interfaces); | |
| 151 } | |
| 152 | 153 |
| 153 private: | 154 private: |
| 154 // Stores IPC messages that would have been sent to the renderer. | 155 // Stores IPC messages that would have been sent to the renderer. |
| 155 IPC::TestSink sink_; | 156 IPC::TestSink sink_; |
| 156 int bad_msg_count_; | 157 int bad_msg_count_; |
| 157 const MockRenderProcessHostFactory* factory_; | 158 const MockRenderProcessHostFactory* factory_; |
| 158 int id_; | 159 int id_; |
| 159 bool has_connection_; | 160 bool has_connection_; |
| 160 BrowserContext* browser_context_; | 161 BrowserContext* browser_context_; |
| 161 base::ObserverList<RenderProcessHostObserver> observers_; | 162 base::ObserverList<RenderProcessHostObserver> observers_; |
| 162 | 163 |
| 163 IDMap<RenderWidgetHost*> render_widget_hosts_; | 164 IDMap<RenderWidgetHost*> render_widget_hosts_; |
| 164 int prev_routing_id_; | 165 int prev_routing_id_; |
| 165 IDMap<IPC::Listener*> listeners_; | 166 IDMap<IPC::Listener*> listeners_; |
| 166 bool fast_shutdown_started_; | 167 bool fast_shutdown_started_; |
| 167 bool deletion_callback_called_; | 168 bool deletion_callback_called_; |
| 168 bool is_for_guests_only_; | 169 bool is_for_guests_only_; |
| 169 bool is_process_backgrounded_; | 170 bool is_process_backgrounded_; |
| 170 std::unique_ptr<base::ProcessHandle> process_handle; | 171 std::unique_ptr<base::ProcessHandle> process_handle; |
| 171 int worker_ref_count_; | 172 int worker_ref_count_; |
| 172 std::unique_ptr<service_manager::InterfaceProvider> remote_interfaces_; | |
| 173 std::unique_ptr<mojo::AssociatedInterfacePtr<mojom::Renderer>> | 173 std::unique_ptr<mojo::AssociatedInterfacePtr<mojom::Renderer>> |
| 174 renderer_interface_; | 174 renderer_interface_; |
| 175 std::map<std::string, InterfaceBinder> binder_overrides_; |
| 175 | 176 |
| 176 DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHost); | 177 DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHost); |
| 177 }; | 178 }; |
| 178 | 179 |
| 179 class MockRenderProcessHostFactory : public RenderProcessHostFactory { | 180 class MockRenderProcessHostFactory : public RenderProcessHostFactory { |
| 180 public: | 181 public: |
| 181 MockRenderProcessHostFactory(); | 182 MockRenderProcessHostFactory(); |
| 182 ~MockRenderProcessHostFactory() override; | 183 ~MockRenderProcessHostFactory() override; |
| 183 | 184 |
| 184 RenderProcessHost* CreateRenderProcessHost( | 185 RenderProcessHost* CreateRenderProcessHost( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 195 // for deleting all MockRenderProcessHosts that have not deleted by a test in | 196 // for deleting all MockRenderProcessHosts that have not deleted by a test in |
| 196 // the destructor and prevent them from being leaked. | 197 // the destructor and prevent them from being leaked. |
| 197 mutable std::vector<std::unique_ptr<MockRenderProcessHost>> processes_; | 198 mutable std::vector<std::unique_ptr<MockRenderProcessHost>> processes_; |
| 198 | 199 |
| 199 DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHostFactory); | 200 DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHostFactory); |
| 200 }; | 201 }; |
| 201 | 202 |
| 202 } // namespace content | 203 } // namespace content |
| 203 | 204 |
| 204 #endif // CONTENT_PUBLIC_TEST_MOCK_RENDER_PROCESS_HOST_H_ | 205 #endif // CONTENT_PUBLIC_TEST_MOCK_RENDER_PROCESS_HOST_H_ |
| OLD | NEW |