Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(943)

Side by Side Diff: ppapi/proxy/ppapi_proxy_test.h

Issue 6286070: Remove all uses of the global Dispatcher Get function. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/scoped_ptr.h" 5 #include "base/scoped_ptr.h"
6 #include "ipc/ipc_test_sink.h" 6 #include "ipc/ipc_test_sink.h"
7 #include "ppapi/c/pp_instance.h" 7 #include "ppapi/c/pp_instance.h"
8 #include "ppapi/proxy/host_dispatcher.h"
8 #include "ppapi/proxy/plugin_dispatcher.h" 9 #include "ppapi/proxy/plugin_dispatcher.h"
9 #include "ppapi/proxy/plugin_resource_tracker.h" 10 #include "ppapi/proxy/plugin_resource_tracker.h"
10 #include "ppapi/proxy/plugin_var_tracker.h" 11 #include "ppapi/proxy/plugin_var_tracker.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace pp { 14 namespace pp {
14 namespace proxy { 15 namespace proxy {
15 16
17 // Base class for plugin and host tests. Tests will not use this directly.
18 // Instead, use the Plugin or HostProxyTest.
19 class ProxyTestBase : public testing::Test {
20 public:
21 ProxyTestBase();
22 virtual ~ProxyTestBase();
23
24 PP_Module pp_module() const { return pp_module_; }
25 PP_Instance pp_instance() const { return pp_instance_; }
26 IPC::TestSink& sink() { return sink_; }
27
28 // Returns either the plugin or host dispatcher, depending on the test.
29 virtual Dispatcher* GetDispatcher() = 0;
30
31 // Implementation of GetInterface for the dispatcher. This will
32 // return NULL for all interfaces unless one is registered by calling
33 // RegisterTestInterface();
34 const void* GetInterface(const char* name);
35
36 // Allows the test to specify an interface implementation for a given
37 // interface name. This will be returned when any of the proxy logic
38 // requests a local interface.
39 void RegisterTestInterface(const char* name, const void* interface);
40
41 // Sends a "supports interface" message to the current dispatcher and returns
42 // true if it's supported. This is just for the convenience of tests.
43 bool SupportsInterface(const char* name);
44
45 private:
46 // Destination for IPC messages sent by the test.
47 IPC::TestSink sink_;
48
49 // The module and instance ID associated with the plugin dispatcher.
50 PP_Module pp_module_;
51 PP_Instance pp_instance_;
52
53 // Stores the data for GetInterface/RegisterTestInterface.
54 std::map<std::string, const void*> registered_interfaces_;
55 };
56
16 // Test harness for the plugin side of the proxy. 57 // Test harness for the plugin side of the proxy.
17 class PluginProxyTest : public testing::Test { 58 class PluginProxyTest : public ProxyTestBase {
18 public: 59 public:
19 PluginProxyTest(); 60 PluginProxyTest();
20 ~PluginProxyTest(); 61 virtual ~PluginProxyTest();
21
22 virtual void SetUp();
23 virtual void TearDown();
24
25 // The instance ID associated with the plugin dispatcher.
26 PP_Instance pp_instance() const { return pp_instance_; }
27 62
28 PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); } 63 PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); }
29
30 PluginResourceTracker& resource_tracker() { return resource_tracker_; } 64 PluginResourceTracker& resource_tracker() { return resource_tracker_; }
31 PluginVarTracker& var_tracker() { return var_tracker_; } 65 PluginVarTracker& var_tracker() { return var_tracker_; }
32 66
33 IPC::TestSink& sink() { return sink_; } 67 // ProxyTestBase implementation.
68 virtual Dispatcher* GetDispatcher();
69
70 // testing::Test implementation.
71 virtual void SetUp();
72 virtual void TearDown();
34 73
35 private: 74 private:
36 PluginResourceTracker resource_tracker_; 75 PluginResourceTracker resource_tracker_;
37 PluginVarTracker var_tracker_; 76 PluginVarTracker var_tracker_;
77 scoped_ptr<PluginDispatcher> plugin_dispatcher_;
78 };
38 79
39 PP_Instance pp_instance_; 80 class HostProxyTest : public ProxyTestBase {
40 scoped_ptr<PluginDispatcher> plugin_dispatcher_; 81 public:
82 HostProxyTest();
83 virtual ~HostProxyTest();
41 84
42 IPC::TestSink sink_; 85 HostDispatcher* host_dispatcher() { return host_dispatcher_.get(); }
86
87 // ProxyTestBase implementation.
88 virtual Dispatcher* GetDispatcher();
89
90 // testing::Test implementation.
91 virtual void SetUp();
92 virtual void TearDown();
93
94 private:
95 scoped_ptr<HostDispatcher> host_dispatcher_;
43 }; 96 };
44 97
45 } // namespace proxy 98 } // namespace proxy
46 } // namespace pp 99 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698