summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy/ppapi_proxy_test.h
blob: 2c1ae1fb3299b20acdb53f0444bf773e158d1dbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <map>
#include <string>

#include "base/memory/scoped_ptr.h"
#include "ipc/ipc_test_sink.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/proxy/host_dispatcher.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_resource_tracker.h"
#include "ppapi/proxy/plugin_var_tracker.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace pp {
namespace proxy {

// Base class for plugin and host tests. Tests will not use this directly.
// Instead, use the Plugin or HostProxyTest.
class ProxyTestBase : public testing::Test {
 public:
  ProxyTestBase();
  virtual ~ProxyTestBase();

  PP_Module pp_module() const { return pp_module_; }
  PP_Instance pp_instance() const { return pp_instance_; }
  IPC::TestSink& sink() { return sink_; }

  // Returns either the plugin or host dispatcher, depending on the test.
  virtual Dispatcher* GetDispatcher() = 0;

  // Implementation of GetInterface for the dispatcher. This will
  // return NULL for all interfaces unless one is registered by calling
  // RegisterTestInterface();
  const void* GetInterface(const char* name);

  // Allows the test to specify an interface implementation for a given
  // interface name. This will be returned when any of the proxy logic
  // requests a local interface.
  void RegisterTestInterface(const char* name, const void* interface);

  // Sends a "supports interface" message to the current dispatcher and returns
  // true if it's supported. This is just for the convenience of tests.
  bool SupportsInterface(const char* name);

 private:
  // Destination for IPC messages sent by the test.
  IPC::TestSink sink_;

  // The module and instance ID associated with the plugin dispatcher.
  PP_Module pp_module_;
  PP_Instance pp_instance_;

  // Stores the data for GetInterface/RegisterTestInterface.
  std::map<std::string, const void*> registered_interfaces_;
};

// Test harness for the plugin side of the proxy.
class PluginProxyTest : public ProxyTestBase {
 public:
  PluginProxyTest();
  virtual ~PluginProxyTest();

  PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); }
  PluginResourceTracker& resource_tracker() { return resource_tracker_; }
  PluginVarTracker& var_tracker() { return var_tracker_; }

  // ProxyTestBase implementation.
  virtual Dispatcher* GetDispatcher();

  // testing::Test implementation.
  virtual void SetUp();
  virtual void TearDown();

 private:
  PluginResourceTracker resource_tracker_;
  PluginVarTracker var_tracker_;
  scoped_ptr<PluginDispatcher> plugin_dispatcher_;
};

class HostProxyTest : public ProxyTestBase {
 public:
  HostProxyTest();
  virtual ~HostProxyTest();

  HostDispatcher* host_dispatcher() { return host_dispatcher_.get(); }

  // ProxyTestBase implementation.
  virtual Dispatcher* GetDispatcher();

  // testing::Test implementation.
  virtual void SetUp();
  virtual void TearDown();

 private:
  scoped_ptr<HostDispatcher> host_dispatcher_;
};

}  // namespace proxy
}  // namespace pp