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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
11 #include "content/public/browser/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 "content/public/browser/render_process_host_factory.h" |
13 #include "ipc/ipc_test_sink.h" | 13 #include "ipc/ipc_test_sink.h" |
14 | 14 |
15 class StoragePartition; | 15 class StoragePartition; |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 class MockRenderProcessHostFactory; | 19 class MockRenderProcessHostFactory; |
20 | 20 |
21 // A mock render process host that has no corresponding renderer process. All | 21 // A mock render process host that has no corresponding renderer process. All |
22 // IPC messages are sent into the message sink for inspection by tests. | 22 // IPC messages are sent into the message sink for inspection by tests. |
23 class MockRenderProcessHost : public RenderProcessHost { | 23 class MockRenderProcessHost : public RenderProcessHost { |
24 public: | 24 public: |
25 explicit MockRenderProcessHost(BrowserContext* browser_context); | 25 explicit MockRenderProcessHost(BrowserContext* browser_context); |
26 virtual ~MockRenderProcessHost(); | 26 ~MockRenderProcessHost() override; |
27 | 27 |
28 // Provides access to all IPC messages that would have been sent to the | 28 // Provides access to all IPC messages that would have been sent to the |
29 // renderer via this RenderProcessHost. | 29 // renderer via this RenderProcessHost. |
30 IPC::TestSink& sink() { return sink_; } | 30 IPC::TestSink& sink() { return sink_; } |
31 | 31 |
32 // Provides test access to how many times a bad message has been received. | 32 // Provides test access to how many times a bad message has been received. |
33 int bad_msg_count() const { return bad_msg_count_; } | 33 int bad_msg_count() const { return bad_msg_count_; } |
34 | 34 |
35 // RenderProcessHost implementation (public portion). | 35 // RenderProcessHost implementation (public portion). |
36 virtual void EnableSendQueue() override; | 36 void EnableSendQueue() override; |
37 virtual bool Init() override; | 37 bool Init() override; |
38 virtual int GetNextRoutingID() override; | 38 int GetNextRoutingID() override; |
39 virtual void AddRoute(int32 routing_id, IPC::Listener* listener) override; | 39 void AddRoute(int32 routing_id, IPC::Listener* listener) override; |
40 virtual void RemoveRoute(int32 routing_id) override; | 40 void RemoveRoute(int32 routing_id) override; |
41 virtual void AddObserver(RenderProcessHostObserver* observer) override; | 41 void AddObserver(RenderProcessHostObserver* observer) override; |
42 virtual void RemoveObserver(RenderProcessHostObserver* observer) override; | 42 void RemoveObserver(RenderProcessHostObserver* observer) override; |
43 virtual void ReceivedBadMessage() override; | 43 void ReceivedBadMessage() override; |
44 virtual void WidgetRestored() override; | 44 void WidgetRestored() override; |
45 virtual void WidgetHidden() override; | 45 void WidgetHidden() override; |
46 virtual int VisibleWidgetCount() const override; | 46 int VisibleWidgetCount() const override; |
47 virtual bool IsIsolatedGuest() const override; | 47 bool IsIsolatedGuest() const override; |
48 virtual StoragePartition* GetStoragePartition() const override; | 48 StoragePartition* GetStoragePartition() const override; |
49 virtual void AddWord(const base::string16& word); | 49 virtual void AddWord(const base::string16& word); |
50 virtual bool FastShutdownIfPossible() override; | 50 bool FastShutdownIfPossible() override; |
51 virtual bool FastShutdownStarted() const override; | 51 bool FastShutdownStarted() const override; |
52 virtual void DumpHandles() override; | 52 void DumpHandles() override; |
53 virtual base::ProcessHandle GetHandle() const override; | 53 base::ProcessHandle GetHandle() const override; |
54 virtual int GetID() const override; | 54 int GetID() const override; |
55 virtual bool HasConnection() const override; | 55 bool HasConnection() const override; |
56 virtual void SetIgnoreInputEvents(bool ignore_input_events) override; | 56 void SetIgnoreInputEvents(bool ignore_input_events) override; |
57 virtual bool IgnoreInputEvents() const override; | 57 bool IgnoreInputEvents() const override; |
58 virtual void Cleanup() override; | 58 void Cleanup() override; |
59 virtual void AddPendingView() override; | 59 void AddPendingView() override; |
60 virtual void RemovePendingView() override; | 60 void RemovePendingView() override; |
61 virtual void SetSuddenTerminationAllowed(bool allowed) override; | 61 void SetSuddenTerminationAllowed(bool allowed) override; |
62 virtual bool SuddenTerminationAllowed() const override; | 62 bool SuddenTerminationAllowed() const override; |
63 virtual BrowserContext* GetBrowserContext() const override; | 63 BrowserContext* GetBrowserContext() const override; |
64 virtual bool InSameStoragePartition( | 64 bool InSameStoragePartition(StoragePartition* partition) const override; |
65 StoragePartition* partition) const override; | 65 IPC::ChannelProxy* GetChannel() override; |
66 virtual IPC::ChannelProxy* GetChannel() override; | 66 void AddFilter(BrowserMessageFilter* filter) override; |
67 virtual void AddFilter(BrowserMessageFilter* filter) override; | 67 bool FastShutdownForPageCount(size_t count) override; |
68 virtual bool FastShutdownForPageCount(size_t count) override; | 68 base::TimeDelta GetChildProcessIdleTime() const override; |
69 virtual base::TimeDelta GetChildProcessIdleTime() const override; | 69 void ResumeRequestsForView(int route_id) override; |
70 virtual void ResumeRequestsForView(int route_id) override; | 70 void FilterURL(bool empty_allowed, GURL* url) override; |
71 virtual void FilterURL(bool empty_allowed, GURL* url) override; | |
72 #if defined(ENABLE_WEBRTC) | 71 #if defined(ENABLE_WEBRTC) |
73 virtual void EnableAecDump(const base::FilePath& file) override; | 72 void EnableAecDump(const base::FilePath& file) override; |
74 virtual void DisableAecDump() override; | 73 void DisableAecDump() override; |
75 virtual void SetWebRtcLogMessageCallback( | 74 void SetWebRtcLogMessageCallback( |
76 base::Callback<void(const std::string&)> callback) override; | 75 base::Callback<void(const std::string&)> callback) override; |
77 virtual WebRtcStopRtpDumpCallback StartRtpDump( | 76 WebRtcStopRtpDumpCallback StartRtpDump( |
78 bool incoming, | 77 bool incoming, |
79 bool outgoing, | 78 bool outgoing, |
80 const WebRtcRtpPacketCallback& packet_callback) override; | 79 const WebRtcRtpPacketCallback& packet_callback) override; |
81 #endif | 80 #endif |
82 virtual void ResumeDeferredNavigation(const GlobalRequestID& request_id) | 81 void ResumeDeferredNavigation(const GlobalRequestID& request_id) override; |
83 override; | 82 void NotifyTimezoneChange() override; |
84 virtual void NotifyTimezoneChange() override; | 83 ServiceRegistry* GetServiceRegistry() override; |
85 virtual ServiceRegistry* GetServiceRegistry() override; | |
86 | 84 |
87 // IPC::Sender via RenderProcessHost. | 85 // IPC::Sender via RenderProcessHost. |
88 virtual bool Send(IPC::Message* msg) override; | 86 bool Send(IPC::Message* msg) override; |
89 | 87 |
90 // IPC::Listener via RenderProcessHost. | 88 // IPC::Listener via RenderProcessHost. |
91 virtual bool OnMessageReceived(const IPC::Message& msg) override; | 89 bool OnMessageReceived(const IPC::Message& msg) override; |
92 virtual void OnChannelConnected(int32 peer_pid) override; | 90 void OnChannelConnected(int32 peer_pid) override; |
93 | 91 |
94 // Attaches the factory object so we can remove this object in its destructor | 92 // Attaches the factory object so we can remove this object in its destructor |
95 // and prevent MockRenderProcessHostFacotry from deleting it. | 93 // and prevent MockRenderProcessHostFacotry from deleting it. |
96 void SetFactory(const MockRenderProcessHostFactory* factory) { | 94 void SetFactory(const MockRenderProcessHostFactory* factory) { |
97 factory_ = factory; | 95 factory_ = factory; |
98 } | 96 } |
99 | 97 |
100 int GetActiveViewCount(); | 98 int GetActiveViewCount(); |
101 | 99 |
102 void set_is_isolated_guest(bool is_isolated_guest) { | 100 void set_is_isolated_guest(bool is_isolated_guest) { |
(...skipping 20 matching lines...) Expand all Loading... |
123 bool deletion_callback_called_; | 121 bool deletion_callback_called_; |
124 bool is_isolated_guest_; | 122 bool is_isolated_guest_; |
125 scoped_ptr<base::ProcessHandle> process_handle; | 123 scoped_ptr<base::ProcessHandle> process_handle; |
126 | 124 |
127 DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHost); | 125 DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHost); |
128 }; | 126 }; |
129 | 127 |
130 class MockRenderProcessHostFactory : public RenderProcessHostFactory { | 128 class MockRenderProcessHostFactory : public RenderProcessHostFactory { |
131 public: | 129 public: |
132 MockRenderProcessHostFactory(); | 130 MockRenderProcessHostFactory(); |
133 virtual ~MockRenderProcessHostFactory(); | 131 ~MockRenderProcessHostFactory() override; |
134 | 132 |
135 virtual RenderProcessHost* CreateRenderProcessHost( | 133 RenderProcessHost* CreateRenderProcessHost( |
136 BrowserContext* browser_context, | 134 BrowserContext* browser_context, |
137 SiteInstance* site_instance) const override; | 135 SiteInstance* site_instance) const override; |
138 | 136 |
139 // Removes the given MockRenderProcessHost from the MockRenderProcessHost list | 137 // Removes the given MockRenderProcessHost from the MockRenderProcessHost list |
140 // without deleting it. When a test deletes a MockRenderProcessHost, we need | 138 // without deleting it. When a test deletes a MockRenderProcessHost, we need |
141 // to remove it from |processes_| to prevent it from being deleted twice. | 139 // to remove it from |processes_| to prevent it from being deleted twice. |
142 void Remove(MockRenderProcessHost* host) const; | 140 void Remove(MockRenderProcessHost* host) const; |
143 | 141 |
144 private: | 142 private: |
145 // A list of MockRenderProcessHosts created by this object. This list is used | 143 // A list of MockRenderProcessHosts created by this object. This list is used |
146 // for deleting all MockRenderProcessHosts that have not deleted by a test in | 144 // for deleting all MockRenderProcessHosts that have not deleted by a test in |
147 // the destructor and prevent them from being leaked. | 145 // the destructor and prevent them from being leaked. |
148 mutable ScopedVector<MockRenderProcessHost> processes_; | 146 mutable ScopedVector<MockRenderProcessHost> processes_; |
149 | 147 |
150 DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHostFactory); | 148 DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHostFactory); |
151 }; | 149 }; |
152 | 150 |
153 } // namespace content | 151 } // namespace content |
154 | 152 |
155 #endif // CONTENT_PUBLIC_TEST_MOCK_RENDER_PROCESS_HOST_H_ | 153 #endif // CONTENT_PUBLIC_TEST_MOCK_RENDER_PROCESS_HOST_H_ |
OLD | NEW |