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.
4
5#ifndef CONTENT_RENDERER_PEPPER_MOCK_RENDERER_PPAPI_HOST_H_
6#define CONTENT_RENDERER_PEPPER_MOCK_RENDERER_PPAPI_HOST_H_
7
8#include "base/basictypes.h"
9#include "content/public/renderer/renderer_ppapi_host.h"
10#include "content/renderer/pepper/content_renderer_pepper_host_factory.h"
11#include "ppapi/host/ppapi_host.h"
12#include "ppapi/proxy/resource_message_test_sink.h"
13
14namespace content {
15class PluginModule;
16
17// A mock RendererPpapiHost for testing resource hosts. Messages sent by
18// resources through this will get added to the test sink.
19class MockRendererPpapiHost : public RendererPpapiHost {
20 public:
21  // This function takes the RenderView and instance that the mock resource
22  // host will be associated with.
23  MockRendererPpapiHost(RenderView* render_view,
24                        PP_Instance instance);
25  virtual ~MockRendererPpapiHost();
26
27  ppapi::proxy::ResourceMessageTestSink& sink() { return sink_; }
28  PP_Instance pp_instance() const { return pp_instance_; }
29
30  // Sets whether there is currently a user gesture. Defaults to false.
31  void set_has_user_gesture(bool gesture) { has_user_gesture_ = gesture; }
32
33  // RendererPpapiHost.
34  virtual ppapi::host::PpapiHost* GetPpapiHost() OVERRIDE;
35  virtual bool IsValidInstance(PP_Instance instance) const OVERRIDE;
36  virtual PepperPluginInstance* GetPluginInstance(
37      PP_Instance instance) const OVERRIDE;
38  virtual RenderView* GetRenderViewForInstance(
39      PP_Instance instance) const OVERRIDE;
40  virtual WebKit::WebPluginContainer* GetContainerForInstance(
41      PP_Instance instance) const OVERRIDE;
42  virtual base::ProcessId GetPluginPID() const OVERRIDE;
43  virtual bool HasUserGesture(PP_Instance instance) const OVERRIDE;
44  virtual int GetRoutingIDForWidget(PP_Instance instance) const OVERRIDE;
45  virtual gfx::Point PluginPointToRenderView(
46      PP_Instance instance,
47      const gfx::Point& pt) const OVERRIDE;
48  virtual IPC::PlatformFileForTransit ShareHandleWithRemote(
49      base::PlatformFile handle,
50      bool should_close_source) OVERRIDE;
51  virtual bool IsRunningInProcess() const OVERRIDE;
52  virtual void CreateBrowserResourceHost(
53      PP_Instance instance,
54      const IPC::Message& nested_msg,
55      const base::Callback<void(int)>& callback) const OVERRIDE;
56
57 private:
58  ppapi::proxy::ResourceMessageTestSink sink_;
59  ppapi::host::PpapiHost ppapi_host_;
60
61  RenderView* render_view_;
62  PP_Instance pp_instance_;
63
64  bool has_user_gesture_;
65
66  DISALLOW_COPY_AND_ASSIGN(MockRendererPpapiHost);
67};
68
69}  // namespace content
70
71#endif  // CONTENT_RENDERER_PEPPER_MOCK_RENDERER_PPAPI_HOST_H_
72