| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_RENDERER_HOST_MOCK_RENDER_PROCESS_HOST_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MOCK_RENDER_PROCESS_HOST_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MOCK_RENDER_PROCESS_HOST_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_MOCK_RENDER_PROCESS_HOST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 11 #include "content/browser/renderer_host/render_process_host.h" | 11 #include "content/public/browser/render_process_host.h" |
| 12 #include "content/public/browser/render_process_host_factory.h" |
| 12 #include "ipc/ipc_test_sink.h" | 13 #include "ipc/ipc_test_sink.h" |
| 13 | 14 |
| 14 class MockRenderProcessHostFactory; | 15 class MockRenderProcessHostFactory; |
| 15 class TransportDIB; | 16 class TransportDIB; |
| 16 | 17 |
| 17 // A mock render process host that has no corresponding renderer process. All | 18 // A mock render process host that has no corresponding renderer process. All |
| 18 // IPC messages are sent into the message sink for inspection by tests. | 19 // IPC messages are sent into the message sink for inspection by tests. |
| 19 class MockRenderProcessHost : public RenderProcessHost { | 20 class MockRenderProcessHost : public RenderProcessHost { |
| 20 public: | 21 public: |
| 21 explicit MockRenderProcessHost(content::BrowserContext* browser_context); | 22 explicit MockRenderProcessHost(content::BrowserContext* browser_context); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 39 virtual void CrossSiteSwapOutACK(const ViewMsg_SwapOut_Params& params); | 40 virtual void CrossSiteSwapOutACK(const ViewMsg_SwapOut_Params& params); |
| 40 virtual bool WaitForUpdateMsg(int render_widget_id, | 41 virtual bool WaitForUpdateMsg(int render_widget_id, |
| 41 const base::TimeDelta& max_delay, | 42 const base::TimeDelta& max_delay, |
| 42 IPC::Message* msg); | 43 IPC::Message* msg); |
| 43 virtual void ReceivedBadMessage(); | 44 virtual void ReceivedBadMessage(); |
| 44 virtual void WidgetRestored(); | 45 virtual void WidgetRestored(); |
| 45 virtual void WidgetHidden(); | 46 virtual void WidgetHidden(); |
| 46 virtual int VisibleWidgetCount() const; | 47 virtual int VisibleWidgetCount() const; |
| 47 virtual void AddWord(const string16& word); | 48 virtual void AddWord(const string16& word); |
| 48 virtual bool FastShutdownIfPossible(); | 49 virtual bool FastShutdownIfPossible(); |
| 50 virtual bool FastShutdownStarted() const; |
| 49 virtual void DumpHandles(); | 51 virtual void DumpHandles(); |
| 50 virtual base::ProcessHandle GetHandle(); | 52 virtual base::ProcessHandle GetHandle(); |
| 51 virtual TransportDIB* GetTransportDIB(TransportDIB::Id dib_id); | 53 virtual TransportDIB* GetTransportDIB(TransportDIB::Id dib_id); |
| 52 virtual void SetCompositingSurface( | 54 virtual void SetCompositingSurface( |
| 53 int render_widget_id, | 55 int render_widget_id, |
| 54 gfx::PluginWindowHandle compositing_surface); | 56 gfx::PluginWindowHandle compositing_surface); |
| 57 virtual int GetID() const; |
| 58 virtual bool HasConnection() const; |
| 59 virtual void SetIgnoreInputEvents(bool ignore_input_events); |
| 60 virtual bool IgnoreInputEvents() const; |
| 61 virtual void Attach(IPC::Channel::Listener* listener, int routing_id); |
| 62 virtual void Release(int listener_id); |
| 63 virtual void Cleanup(); |
| 64 virtual void ReportExpectingClose(int32 listener_id); |
| 65 virtual void AddPendingView(); |
| 66 virtual void RemovePendingView(); |
| 67 virtual void SetSuddenTerminationAllowed(bool allowed); |
| 68 virtual bool SuddenTerminationAllowed() const; |
| 69 virtual void UpdateMaxPageID(int32 page_id); |
| 70 virtual IPC::Channel::Listener* GetListenerByID(int routing_id); |
| 71 virtual content::BrowserContext* GetBrowserContext() const; |
| 72 virtual IPC::ChannelProxy* GetChannel(); |
| 73 virtual listeners_iterator ListenersIterator(); |
| 74 virtual bool FastShutdownForPageCount(size_t count); |
| 55 | 75 |
| 56 // IPC::Channel::Sender via RenderProcessHost. | 76 // IPC::Channel::Sender via RenderProcessHost. |
| 57 virtual bool Send(IPC::Message* msg); | 77 virtual bool Send(IPC::Message* msg); |
| 58 | 78 |
| 59 // IPC::Channel::Listener via RenderProcessHost. | 79 // IPC::Channel::Listener via RenderProcessHost. |
| 60 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 80 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
| 61 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 81 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
| 62 | 82 |
| 63 // Attaches the factory object so we can remove this object in its destructor | 83 // Attaches the factory object so we can remove this object in its destructor |
| 64 // and prevent MockRenderProcessHostFacotry from deleting it. | 84 // and prevent MockRenderProcessHostFacotry from deleting it. |
| 65 void SetFactory(const MockRenderProcessHostFactory* factory) { | 85 void SetFactory(const MockRenderProcessHostFactory* factory) { |
| 66 factory_ = factory; | 86 factory_ = factory; |
| 67 } | 87 } |
| 68 | 88 |
| 69 private: | 89 private: |
| 70 // Stores IPC messages that would have been sent to the renderer. | 90 // Stores IPC messages that would have been sent to the renderer. |
| 71 IPC::TestSink sink_; | 91 IPC::TestSink sink_; |
| 72 TransportDIB* transport_dib_; | 92 TransportDIB* transport_dib_; |
| 73 int bad_msg_count_; | 93 int bad_msg_count_; |
| 74 const MockRenderProcessHostFactory* factory_; | 94 const MockRenderProcessHostFactory* factory_; |
| 95 int id_; |
| 96 content::BrowserContext* browser_context_; |
| 97 int32 max_page_id_; |
| 98 |
| 99 IDMap<IPC::Channel::Listener> listeners_; |
| 100 bool fast_shutdown_started_; |
| 75 | 101 |
| 76 DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHost); | 102 DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHost); |
| 77 }; | 103 }; |
| 78 | 104 |
| 79 class MockRenderProcessHostFactory : public RenderProcessHostFactory { | 105 class MockRenderProcessHostFactory : public RenderProcessHostFactory { |
| 80 public: | 106 public: |
| 81 MockRenderProcessHostFactory(); | 107 MockRenderProcessHostFactory(); |
| 82 virtual ~MockRenderProcessHostFactory(); | 108 virtual ~MockRenderProcessHostFactory(); |
| 83 | 109 |
| 84 virtual RenderProcessHost* CreateRenderProcessHost( | 110 virtual RenderProcessHost* CreateRenderProcessHost( |
| 85 content::BrowserContext* browser_context) const OVERRIDE; | 111 content::BrowserContext* browser_context) const OVERRIDE; |
| 86 | 112 |
| 87 // Removes the given MockRenderProcessHost from the MockRenderProcessHost list | 113 // Removes the given MockRenderProcessHost from the MockRenderProcessHost list |
| 88 // without deleting it. When a test deletes a MockRenderProcessHost, we need | 114 // without deleting it. When a test deletes a MockRenderProcessHost, we need |
| 89 // to remove it from |processes_| to prevent it from being deleted twice. | 115 // to remove it from |processes_| to prevent it from being deleted twice. |
| 90 void Remove(MockRenderProcessHost* host) const; | 116 void Remove(MockRenderProcessHost* host) const; |
| 91 | 117 |
| 92 private: | 118 private: |
| 93 // A list of MockRenderProcessHosts created by this object. This list is used | 119 // A list of MockRenderProcessHosts created by this object. This list is used |
| 94 // for deleting all MockRenderProcessHosts that have not deleted by a test in | 120 // for deleting all MockRenderProcessHosts that have not deleted by a test in |
| 95 // the destructor and prevent them from being leaked. | 121 // the destructor and prevent them from being leaked. |
| 96 mutable ScopedVector<MockRenderProcessHost> processes_; | 122 mutable ScopedVector<MockRenderProcessHost> processes_; |
| 97 | 123 |
| 98 DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHostFactory); | 124 DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHostFactory); |
| 99 }; | 125 }; |
| 100 | 126 |
| 101 #endif // CONTENT_BROWSER_RENDERER_HOST_MOCK_RENDER_PROCESS_HOST_H_ | 127 #endif // CONTENT_BROWSER_RENDERER_HOST_MOCK_RENDER_PROCESS_HOST_H_ |
| OLD | NEW |