| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 CHROME_BROWSER_RENDERER_HOST_MOCK_RENDER_PROCESS_HOST_H_ | 5 #ifndef CHROME_BROWSER_RENDERER_HOST_MOCK_RENDER_PROCESS_HOST_H_ |
| 6 #define CHROME_BROWSER_RENDERER_HOST_MOCK_RENDER_PROCESS_HOST_H_ | 6 #define CHROME_BROWSER_RENDERER_HOST_MOCK_RENDER_PROCESS_HOST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 // TODO(jam): remove this file when all files have been converted. |
| 10 #include "base/scoped_vector.h" | 10 #include "content/browser/renderer_host/mock_render_process_host.h" |
| 11 #include "chrome/browser/renderer_host/render_process_host.h" | |
| 12 #include "ipc/ipc_test_sink.h" | |
| 13 | |
| 14 class MockRenderProcessHostFactory; | |
| 15 class TransportDIB; | |
| 16 class URLRequestContextGetter; | |
| 17 | |
| 18 // A mock render process host that has no corresponding renderer process. All | |
| 19 // IPC messages are sent into the message sink for inspection by tests. | |
| 20 class MockRenderProcessHost : public RenderProcessHost { | |
| 21 public: | |
| 22 explicit MockRenderProcessHost(Profile* profile); | |
| 23 virtual ~MockRenderProcessHost(); | |
| 24 | |
| 25 // Provides access to all IPC messages that would have been sent to the | |
| 26 // renderer via this RenderProcessHost. | |
| 27 IPC::TestSink& sink() { return sink_; } | |
| 28 | |
| 29 // Provides tests access to the max page ID currently used for this process. | |
| 30 int max_page_id() const { return max_page_id_; } | |
| 31 | |
| 32 // Provides test access to how many times a bad message has been received. | |
| 33 int bad_msg_count() const { return bad_msg_count_; } | |
| 34 | |
| 35 // RenderProcessHost implementation (public portion). | |
| 36 virtual bool Init(bool is_accessibility_enabled, bool is_extensions_process); | |
| 37 virtual int GetNextRoutingID(); | |
| 38 virtual void CancelResourceRequests(int render_widget_id); | |
| 39 virtual void CrossSiteClosePageACK(const ViewMsg_ClosePage_Params& params); | |
| 40 virtual bool WaitForUpdateMsg(int render_widget_id, | |
| 41 const base::TimeDelta& max_delay, | |
| 42 IPC::Message* msg); | |
| 43 virtual void ReceivedBadMessage(); | |
| 44 virtual void WidgetRestored(); | |
| 45 virtual void WidgetHidden(); | |
| 46 virtual void ViewCreated(); | |
| 47 virtual void AddWord(const string16& word); | |
| 48 virtual void SendVisitedLinkTable(base::SharedMemory* table_memory); | |
| 49 virtual void AddVisitedLinks( | |
| 50 const VisitedLinkCommon::Fingerprints& visited_links); | |
| 51 virtual void ResetVisitedLinks(); | |
| 52 virtual bool FastShutdownIfPossible(); | |
| 53 virtual bool SendWithTimeout(IPC::Message* msg, int timeout_ms); | |
| 54 virtual base::ProcessHandle GetHandle(); | |
| 55 | |
| 56 virtual TransportDIB* GetTransportDIB(TransportDIB::Id dib_id); | |
| 57 | |
| 58 // IPC::Channel::Sender via RenderProcessHost. | |
| 59 virtual bool Send(IPC::Message* msg); | |
| 60 | |
| 61 // IPC::Channel::Listener via RenderProcessHost. | |
| 62 virtual bool OnMessageReceived(const IPC::Message& msg); | |
| 63 virtual void OnChannelConnected(int32 peer_pid); | |
| 64 | |
| 65 // Attaches the factory object so we can remove this object in its destructor | |
| 66 // and prevent MockRenderProcessHostFacotry from deleting it. | |
| 67 void SetFactory(const MockRenderProcessHostFactory* factory) { | |
| 68 factory_ = factory; | |
| 69 } | |
| 70 | |
| 71 private: | |
| 72 // Stores IPC messages that would have been sent to the renderer. | |
| 73 IPC::TestSink sink_; | |
| 74 TransportDIB* transport_dib_; | |
| 75 int bad_msg_count_; | |
| 76 const MockRenderProcessHostFactory* factory_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHost); | |
| 79 }; | |
| 80 | |
| 81 class MockRenderProcessHostFactory : public RenderProcessHostFactory { | |
| 82 public: | |
| 83 MockRenderProcessHostFactory(); | |
| 84 virtual ~MockRenderProcessHostFactory(); | |
| 85 | |
| 86 virtual RenderProcessHost* CreateRenderProcessHost(Profile* profile) const; | |
| 87 | |
| 88 // Removes the given MockRenderProcessHost from the MockRenderProcessHost list | |
| 89 // without deleting it. When a test deletes a MockRenderProcessHost, we need | |
| 90 // to remove it from |processes_| to prevent it from being deleted twice. | |
| 91 void Remove(MockRenderProcessHost* host) const; | |
| 92 | |
| 93 private: | |
| 94 // A list of MockRenderProcessHosts created by this object. This list is used | |
| 95 // for deleting all MockRenderProcessHosts that have not deleted by a test in | |
| 96 // the destructor and prevent them from being leaked. | |
| 97 mutable ScopedVector<MockRenderProcessHost> processes_; | |
| 98 | |
| 99 DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHostFactory); | |
| 100 }; | |
| 101 | 11 |
| 102 #endif // CHROME_BROWSER_RENDERER_HOST_MOCK_RENDER_PROCESS_HOST_H_ | 12 #endif // CHROME_BROWSER_RENDERER_HOST_MOCK_RENDER_PROCESS_HOST_H_ |
| OLD | NEW |