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_RENDERER_PEPPER_MOCK_RENDERER_PPAPI_HOST_H_
6 #define CONTENT_RENDERER_PEPPER_MOCK_RENDERER_PPAPI_HOST_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "content/public/renderer/renderer_ppapi_host.h"
11 #include "content/renderer/pepper/content_renderer_pepper_host_factory.h"
12 #include "ppapi/host/ppapi_host.h"
13 #include "ppapi/proxy/resource_message_test_sink.h"
16 class FakePepperPluginInstance
;
19 // A mock RendererPpapiHost for testing resource hosts. Messages sent by
20 // resources through this will get added to the test sink.
21 class MockRendererPpapiHost
: public RendererPpapiHost
{
23 // This function takes the RenderView and instance that the mock resource
24 // host will be associated with.
25 MockRendererPpapiHost(RenderView
* render_view
, PP_Instance instance
);
26 ~MockRendererPpapiHost() override
;
28 ppapi::proxy::ResourceMessageTestSink
& sink() { return sink_
; }
29 PP_Instance
pp_instance() const { return pp_instance_
; }
31 // Sets whether there is currently a user gesture. Defaults to false.
32 void set_has_user_gesture(bool gesture
) { has_user_gesture_
= gesture
; }
35 ppapi::host::PpapiHost
* GetPpapiHost() override
;
36 bool IsValidInstance(PP_Instance instance
) const override
;
37 PepperPluginInstance
* GetPluginInstance(PP_Instance instance
) const override
;
38 RenderFrame
* GetRenderFrameForInstance(PP_Instance instance
) const override
;
39 RenderView
* GetRenderViewForInstance(PP_Instance instance
) const override
;
40 blink::WebPluginContainer
* GetContainerForInstance(
41 PP_Instance instance
) const override
;
42 base::ProcessId
GetPluginPID() const override
;
43 bool HasUserGesture(PP_Instance instance
) const override
;
44 int GetRoutingIDForWidget(PP_Instance instance
) const override
;
45 gfx::Point
PluginPointToRenderFrame(PP_Instance instance
,
46 const gfx::Point
& pt
) const override
;
47 IPC::PlatformFileForTransit
ShareHandleWithRemote(
48 base::PlatformFile handle
,
49 bool should_close_source
) override
;
50 base::SharedMemoryHandle
ShareSharedMemoryHandleWithRemote(
51 const base::SharedMemoryHandle
& handle
) override
;
52 bool IsRunningInProcess() const override
;
53 std::string
GetPluginName() const override
;
54 void SetToExternalPluginHost() override
;
55 void CreateBrowserResourceHosts(
57 const std::vector
<IPC::Message
>& nested_msgs
,
58 const base::Callback
<void(const std::vector
<int>&)>& callback
)
60 GURL
GetDocumentURL(PP_Instance instance
) const override
;
63 ppapi::proxy::ResourceMessageTestSink sink_
;
64 ppapi::host::PpapiHost ppapi_host_
;
66 RenderView
* render_view_
;
67 PP_Instance pp_instance_
;
69 bool has_user_gesture_
;
71 scoped_ptr
<FakePepperPluginInstance
> plugin_instance_
;
73 DISALLOW_COPY_AND_ASSIGN(MockRendererPpapiHost
);
76 } // namespace content
78 #endif // CONTENT_RENDERER_PEPPER_MOCK_RENDERER_PPAPI_HOST_H_