Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / public / test / mock_render_process_host.h
blobed6b797545148b405ec3b693247ea89da328de62
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_TEST_MOCK_RENDER_PROCESS_HOST_H_
6 #define CONTENT_PUBLIC_TEST_MOCK_RENDER_PROCESS_HOST_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_vector.h"
10 #include "base/observer_list.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/render_process_host_factory.h"
13 #include "ipc/ipc_test_sink.h"
15 class StoragePartition;
17 namespace content {
19 class MockRenderProcessHostFactory;
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.
23 class MockRenderProcessHost : public RenderProcessHost {
24 public:
25 explicit MockRenderProcessHost(BrowserContext* browser_context);
26 ~MockRenderProcessHost() override;
28 // Provides access to all IPC messages that would have been sent to the
29 // renderer via this RenderProcessHost.
30 IPC::TestSink& sink() { return sink_; }
32 // Provides test access to how many times a bad message has been received.
33 int bad_msg_count() const { return bad_msg_count_; }
35 // Provides tests a way to simulate this render process crashing.
36 void SimulateCrash();
38 // RenderProcessHost implementation (public portion).
39 void EnableSendQueue() override;
40 bool Init() override;
41 int GetNextRoutingID() override;
42 void AddRoute(int32 routing_id, IPC::Listener* listener) override;
43 void RemoveRoute(int32 routing_id) override;
44 void AddObserver(RenderProcessHostObserver* observer) override;
45 void RemoveObserver(RenderProcessHostObserver* observer) override;
46 void ShutdownForBadMessage() override;
47 void WidgetRestored() override;
48 void WidgetHidden() override;
49 int VisibleWidgetCount() const override;
50 bool IsIsolatedGuest() const override;
51 StoragePartition* GetStoragePartition() const override;
52 virtual void AddWord(const base::string16& word);
53 bool Shutdown(int exit_code, bool wait) override;
54 bool FastShutdownIfPossible() override;
55 bool FastShutdownStarted() const override;
56 void DumpHandles() override;
57 base::ProcessHandle GetHandle() const override;
58 int GetID() const override;
59 bool HasConnection() const override;
60 void SetIgnoreInputEvents(bool ignore_input_events) override;
61 bool IgnoreInputEvents() const override;
62 void Cleanup() override;
63 void AddPendingView() override;
64 void RemovePendingView() override;
65 void SetSuddenTerminationAllowed(bool allowed) override;
66 bool SuddenTerminationAllowed() const override;
67 BrowserContext* GetBrowserContext() const override;
68 bool InSameStoragePartition(StoragePartition* partition) const override;
69 IPC::ChannelProxy* GetChannel() override;
70 void AddFilter(BrowserMessageFilter* filter) override;
71 bool FastShutdownForPageCount(size_t count) override;
72 base::TimeDelta GetChildProcessIdleTime() const override;
73 void ResumeRequestsForView(int route_id) override;
74 void FilterURL(bool empty_allowed, GURL* url) override;
75 #if defined(ENABLE_WEBRTC)
76 void EnableAecDump(const base::FilePath& file) override;
77 void DisableAecDump() override;
78 void SetWebRtcLogMessageCallback(
79 base::Callback<void(const std::string&)> callback) override;
80 WebRtcStopRtpDumpCallback StartRtpDump(
81 bool incoming,
82 bool outgoing,
83 const WebRtcRtpPacketCallback& packet_callback) override;
84 #endif
85 void ResumeDeferredNavigation(const GlobalRequestID& request_id) override;
86 void NotifyTimezoneChange() override;
87 ServiceRegistry* GetServiceRegistry() override;
88 const base::TimeTicks& GetInitTimeForNavigationMetrics() const override;
89 bool SubscribeUniformEnabled() const override;
90 void OnAddSubscription(unsigned int target) override;
91 void OnRemoveSubscription(unsigned int target) override;
92 void SendUpdateValueState(
93 unsigned int target, const gpu::ValueState& state) override;
94 #if defined(ENABLE_BROWSER_CDMS)
95 media::BrowserCdm* GetBrowserCdm(int render_frame_id,
96 int cdm_id) const override;
97 #endif
99 // IPC::Sender via RenderProcessHost.
100 bool Send(IPC::Message* msg) override;
102 // IPC::Listener via RenderProcessHost.
103 bool OnMessageReceived(const IPC::Message& msg) override;
104 void OnChannelConnected(int32 peer_pid) override;
106 // Attaches the factory object so we can remove this object in its destructor
107 // and prevent MockRenderProcessHostFacotry from deleting it.
108 void SetFactory(const MockRenderProcessHostFactory* factory) {
109 factory_ = factory;
112 void set_is_isolated_guest(bool is_isolated_guest) {
113 is_isolated_guest_ = is_isolated_guest;
116 void SetProcessHandle(scoped_ptr<base::ProcessHandle> new_handle) {
117 process_handle = new_handle.Pass();
120 void GetAudioOutputControllers(
121 const GetAudioOutputControllersCallback& callback) const override {}
123 private:
124 // Stores IPC messages that would have been sent to the renderer.
125 IPC::TestSink sink_;
126 int bad_msg_count_;
127 const MockRenderProcessHostFactory* factory_;
128 int id_;
129 BrowserContext* browser_context_;
130 ObserverList<RenderProcessHostObserver> observers_;
132 IDMap<RenderWidgetHost> render_widget_hosts_;
133 int prev_routing_id_;
134 IDMap<IPC::Listener> listeners_;
135 bool fast_shutdown_started_;
136 bool deletion_callback_called_;
137 bool is_isolated_guest_;
138 scoped_ptr<base::ProcessHandle> process_handle;
140 DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHost);
143 class MockRenderProcessHostFactory : public RenderProcessHostFactory {
144 public:
145 MockRenderProcessHostFactory();
146 ~MockRenderProcessHostFactory() override;
148 RenderProcessHost* CreateRenderProcessHost(
149 BrowserContext* browser_context,
150 SiteInstance* site_instance) const override;
152 // Removes the given MockRenderProcessHost from the MockRenderProcessHost list
153 // without deleting it. When a test deletes a MockRenderProcessHost, we need
154 // to remove it from |processes_| to prevent it from being deleted twice.
155 void Remove(MockRenderProcessHost* host) const;
157 private:
158 // A list of MockRenderProcessHosts created by this object. This list is used
159 // for deleting all MockRenderProcessHosts that have not deleted by a test in
160 // the destructor and prevent them from being leaked.
161 mutable ScopedVector<MockRenderProcessHost> processes_;
163 DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHostFactory);
166 } // namespace content
168 #endif // CONTENT_PUBLIC_TEST_MOCK_RENDER_PROCESS_HOST_H_