[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / content / public / test / mock_render_thread.h
blobb5e1550dea5c60d9c2b337af0456ddf5dd11c8f6
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_THREAD_H_
6 #define CONTENT_PUBLIC_TEST_MOCK_RENDER_THREAD_H_
8 #include "base/memory/shared_memory.h"
9 #include "base/observer_list.h"
10 #include "base/strings/string16.h"
11 #include "cc/test/test_shared_bitmap_manager.h"
12 #include "content/public/renderer/render_thread.h"
13 #include "ipc/ipc_test_sink.h"
14 #include "ipc/message_filter.h"
15 #include "third_party/WebKit/public/web/WebPopupType.h"
17 struct ViewHostMsg_CreateWindow_Params;
19 namespace IPC {
20 class MessageFilter;
21 class MessageReplyDeserializer;
24 namespace blink {
25 enum class WebSandboxFlags;
26 enum class WebTreeScopeType;
29 namespace content {
31 // This class is a very simple mock of RenderThread. It simulates an IPC channel
32 // which supports only three messages:
33 // ViewHostMsg_CreateWidget : sync message sent by the Widget.
34 // ViewHostMsg_CreateWindow : sync message sent by the Widget.
35 // ViewMsg_Close : async, send to the Widget.
36 class MockRenderThread : public RenderThread {
37 public:
38 MockRenderThread();
39 ~MockRenderThread() override;
41 // Provides access to the messages that have been received by this thread.
42 IPC::TestSink& sink() { return sink_; }
44 // RenderThread implementation:
45 bool Send(IPC::Message* msg) override;
46 IPC::SyncChannel* GetChannel() override;
47 std::string GetLocale() override;
48 IPC::SyncMessageFilter* GetSyncMessageFilter() override;
49 scoped_refptr<base::SingleThreadTaskRunner> GetIOMessageLoopProxy() override;
50 void AddRoute(int32 routing_id, IPC::Listener* listener) override;
51 void RemoveRoute(int32 routing_id) override;
52 int GenerateRoutingID() override;
53 void AddFilter(IPC::MessageFilter* filter) override;
54 void RemoveFilter(IPC::MessageFilter* filter) override;
55 void AddObserver(RenderProcessObserver* observer) override;
56 void RemoveObserver(RenderProcessObserver* observer) override;
57 void SetResourceDispatcherDelegate(
58 ResourceDispatcherDelegate* delegate) override;
59 void EnsureWebKitInitialized() override;
60 void RecordAction(const base::UserMetricsAction& action) override;
61 void RecordComputedAction(const std::string& action) override;
62 scoped_ptr<base::SharedMemory> HostAllocateSharedMemoryBuffer(
63 size_t buffer_size) override;
64 cc::SharedBitmapManager* GetSharedBitmapManager() override;
65 void RegisterExtension(v8::Extension* extension) override;
66 void ScheduleIdleHandler(int64 initial_delay_ms) override;
67 void IdleHandler() override;
68 int64 GetIdleNotificationDelayInMs() const override;
69 void SetIdleNotificationDelayInMs(
70 int64 idle_notification_delay_in_ms) override;
71 void UpdateHistograms(int sequence_number) override;
72 int PostTaskToAllWebWorkers(const base::Closure& closure) override;
73 bool ResolveProxy(const GURL& url, std::string* proxy_list) override;
74 base::WaitableEvent* GetShutdownEvent() override;
75 #if defined(OS_WIN)
76 void PreCacheFont(const LOGFONT& log_font) override;
77 void ReleaseCachedFonts() override;
78 #endif
79 IPC::AttachmentBroker* GetAttachmentBroker() override;
80 ServiceRegistry* GetServiceRegistry() override;
82 //////////////////////////////////////////////////////////////////////////
83 // The following functions are called by the test itself.
85 void set_routing_id(int32 id) {
86 routing_id_ = id;
89 void set_surface_id(int32 id) {
90 surface_id_ = id;
93 int32 opener_id() const {
94 return opener_id_;
97 void set_new_window_routing_id(int32 id) {
98 new_window_routing_id_ = id;
101 void set_new_frame_routing_id(int32 id) {
102 new_frame_routing_id_ = id;
105 // Simulates the Widget receiving a close message. This should result
106 // on releasing the internal reference counts and destroying the internal
107 // state.
108 void SendCloseMessage();
110 // Dispatches control messages to observers.
111 bool OnControlMessageReceived(const IPC::Message& msg);
113 base::ObserverList<RenderProcessObserver>& observers() { return observers_; }
115 protected:
116 // This function operates as a regular IPC listener. Subclasses
117 // overriding this should first delegate to this implementation.
118 virtual bool OnMessageReceived(const IPC::Message& msg);
120 // The Widget expects to be returned valid route_id.
121 void OnCreateWidget(int opener_id,
122 blink::WebPopupType popup_type,
123 int* route_id,
124 int* surface_id);
126 // The View expects to be returned a valid route_id different from its own.
127 // We do not keep track of the newly created widget in MockRenderThread,
128 // so it must be cleaned up on its own.
129 void OnCreateWindow(
130 const ViewHostMsg_CreateWindow_Params& params,
131 int* route_id,
132 int* main_frame_route_id,
133 int* surface_id,
134 int64* cloned_session_storage_namespace_id);
136 // The Frame expects to be returned a valid route_id different from its own.
137 void OnCreateChildFrame(int new_frame_routing_id,
138 blink::WebTreeScopeType scope,
139 const std::string& frame_name,
140 blink::WebSandboxFlags sandbox_flags,
141 int* new_render_frame_id);
143 #if defined(OS_WIN)
144 void OnDuplicateSection(base::SharedMemoryHandle renderer_handle,
145 base::SharedMemoryHandle* browser_handle);
146 #endif
148 IPC::TestSink sink_;
150 // Routing id what will be assigned to the Widget.
151 int32 routing_id_;
153 // Surface id what will be assigned to the Widget.
154 int32 surface_id_;
156 // Opener id reported by the Widget.
157 int32 opener_id_;
159 // Routing id that will be assigned to a CreateWindow Widget.
160 int32 new_window_routing_id_;
161 int32 new_window_main_frame_routing_id_;
162 int32 new_frame_routing_id_;
164 // The last known good deserializer for sync messages.
165 scoped_ptr<IPC::MessageReplyDeserializer> reply_deserializer_;
167 // A list of message filters added to this thread.
168 std::vector<scoped_refptr<IPC::MessageFilter> > filters_;
170 // Observers to notify.
171 base::ObserverList<RenderProcessObserver> observers_;
173 cc::TestSharedBitmapManager shared_bitmap_manager_;
176 } // namespace content
178 #endif // CONTENT_PUBLIC_TEST_MOCK_RENDER_THREAD_H_