OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 }; | 76 }; |
77 | 77 |
78 // Test harness for the plugin side of the proxy. | 78 // Test harness for the plugin side of the proxy. |
79 class PluginProxyTestHarness : public ProxyTestHarnessBase { | 79 class PluginProxyTestHarness : public ProxyTestHarnessBase { |
80 public: | 80 public: |
81 PluginProxyTestHarness(); | 81 PluginProxyTestHarness(); |
82 virtual ~PluginProxyTestHarness(); | 82 virtual ~PluginProxyTestHarness(); |
83 | 83 |
84 PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); } | 84 PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); } |
85 PluginResourceTracker& resource_tracker() { | 85 PluginResourceTracker& resource_tracker() { |
86 return *plugin_globals_.plugin_resource_tracker(); | 86 return *plugin_globals_->plugin_resource_tracker(); |
87 } | 87 } |
88 PluginVarTracker& var_tracker() { | 88 PluginVarTracker& var_tracker() { |
89 return *plugin_globals_.plugin_var_tracker(); | 89 return *plugin_globals_->plugin_var_tracker(); |
90 } | 90 } |
91 | 91 |
92 // ProxyTestHarnessBase implementation. | 92 // ProxyTestHarnessBase implementation. |
93 virtual PpapiGlobals* GetGlobals() { return &plugin_globals_; } | 93 virtual PpapiGlobals* GetGlobals(); |
94 virtual Dispatcher* GetDispatcher(); | 94 virtual Dispatcher* GetDispatcher(); |
95 virtual void SetUpHarness(); | 95 virtual void SetUpHarness(); |
96 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, | 96 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, |
97 base::MessageLoopProxy* ipc_message_loop, | 97 base::MessageLoopProxy* ipc_message_loop, |
98 base::WaitableEvent* shutdown_event, | 98 base::WaitableEvent* shutdown_event, |
99 bool is_client); | 99 bool is_client); |
100 virtual void TearDownHarness(); | 100 virtual void TearDownHarness(); |
101 | 101 |
102 class PluginDelegateMock : public PluginDispatcher::PluginDelegate, | 102 class PluginDelegateMock : public PluginDispatcher::PluginDelegate, |
103 public PluginProxyDelegate { | 103 public PluginProxyDelegate { |
104 public: | 104 public: |
105 PluginDelegateMock() : ipc_message_loop_(NULL), shutdown_event_() {} | 105 PluginDelegateMock() : ipc_message_loop_(NULL), shutdown_event_() {} |
106 virtual ~PluginDelegateMock() {} | 106 virtual ~PluginDelegateMock() {} |
107 | 107 |
108 void Init(base::MessageLoopProxy* ipc_message_loop, | 108 void Init(base::MessageLoopProxy* ipc_message_loop, |
109 base::WaitableEvent* shutdown_event) { | 109 base::WaitableEvent* shutdown_event) { |
110 ipc_message_loop_ = ipc_message_loop; | 110 ipc_message_loop_ = ipc_message_loop; |
111 shutdown_event_ = shutdown_event; | 111 shutdown_event_ = shutdown_event; |
112 } | 112 } |
113 | 113 |
| 114 void set_browser_sender(IPC::Sender* browser_sender) { |
| 115 browser_sender_ = browser_sender; |
| 116 } |
| 117 |
114 // ProxyChannel::Delegate implementation. | 118 // ProxyChannel::Delegate implementation. |
115 virtual base::MessageLoopProxy* GetIPCMessageLoop() OVERRIDE; | 119 virtual base::MessageLoopProxy* GetIPCMessageLoop() OVERRIDE; |
116 virtual base::WaitableEvent* GetShutdownEvent() OVERRIDE; | 120 virtual base::WaitableEvent* GetShutdownEvent() OVERRIDE; |
117 virtual IPC::PlatformFileForTransit ShareHandleWithRemote( | 121 virtual IPC::PlatformFileForTransit ShareHandleWithRemote( |
118 base::PlatformFile handle, | 122 base::PlatformFile handle, |
119 const IPC::SyncChannel& /* channel */, | 123 const IPC::SyncChannel& /* channel */, |
120 bool should_close_source) OVERRIDE; | 124 bool should_close_source) OVERRIDE; |
121 | 125 |
122 // PluginDispatcher::PluginDelegate implementation. | 126 // PluginDispatcher::PluginDelegate implementation. |
123 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() OVERRIDE; | 127 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() OVERRIDE; |
124 virtual uint32 Register(PluginDispatcher* plugin_dispatcher) OVERRIDE; | 128 virtual uint32 Register(PluginDispatcher* plugin_dispatcher) OVERRIDE; |
125 virtual void Unregister(uint32 plugin_dispatcher_id) OVERRIDE; | 129 virtual void Unregister(uint32 plugin_dispatcher_id) OVERRIDE; |
126 | 130 |
127 // PluginPepperDelegate implementation. | 131 // PluginProxyDelegate implementation. |
128 virtual bool SendToBrowser(IPC::Message* msg) OVERRIDE; | 132 virtual bool SendToBrowser(IPC::Message* msg) OVERRIDE; |
129 virtual IPC::Sender* GetBrowserSender() OVERRIDE; | 133 virtual IPC::Sender* GetBrowserSender() OVERRIDE; |
130 virtual std::string GetUILanguage() OVERRIDE; | 134 virtual std::string GetUILanguage() OVERRIDE; |
131 virtual void PreCacheFont(const void* logfontw) OVERRIDE; | 135 virtual void PreCacheFont(const void* logfontw) OVERRIDE; |
132 virtual void SetActiveURL(const std::string& url) OVERRIDE; | 136 virtual void SetActiveURL(const std::string& url) OVERRIDE; |
133 | 137 |
134 private: | 138 private: |
135 base::MessageLoopProxy* ipc_message_loop_; // Weak | 139 base::MessageLoopProxy* ipc_message_loop_; // Weak |
136 base::WaitableEvent* shutdown_event_; // Weak | 140 base::WaitableEvent* shutdown_event_; // Weak |
137 std::set<PP_Instance> instance_id_set_; | 141 std::set<PP_Instance> instance_id_set_; |
| 142 IPC::Sender* browser_sender_; |
138 | 143 |
139 DISALLOW_COPY_AND_ASSIGN(PluginDelegateMock); | 144 DISALLOW_COPY_AND_ASSIGN(PluginDelegateMock); |
140 }; | 145 }; |
141 | 146 |
142 private: | 147 private: |
143 PluginGlobals plugin_globals_; | 148 scoped_ptr<PluginGlobals> plugin_globals_; |
144 | 149 |
145 scoped_ptr<PluginDispatcher> plugin_dispatcher_; | 150 scoped_ptr<PluginDispatcher> plugin_dispatcher_; |
146 PluginDelegateMock plugin_delegate_mock_; | 151 PluginDelegateMock plugin_delegate_mock_; |
147 }; | 152 }; |
148 | 153 |
149 class PluginProxyTest : public PluginProxyTestHarness, public testing::Test { | 154 class PluginProxyTest : public PluginProxyTestHarness, public testing::Test { |
150 public: | 155 public: |
151 PluginProxyTest(); | 156 PluginProxyTest(); |
152 virtual ~PluginProxyTest(); | 157 virtual ~PluginProxyTest(); |
153 | 158 |
154 // testing::Test implementation. | 159 // testing::Test implementation. |
155 virtual void SetUp(); | 160 virtual void SetUp(); |
156 virtual void TearDown(); | 161 virtual void TearDown(); |
157 private: | 162 private: |
158 MessageLoop message_loop_; | 163 MessageLoop message_loop_; |
159 }; | 164 }; |
160 | 165 |
161 class HostProxyTestHarness : public ProxyTestHarnessBase { | 166 class HostProxyTestHarness : public ProxyTestHarnessBase { |
162 public: | 167 public: |
163 HostProxyTestHarness(); | 168 HostProxyTestHarness(); |
164 virtual ~HostProxyTestHarness(); | 169 virtual ~HostProxyTestHarness(); |
165 | 170 |
166 HostDispatcher* host_dispatcher() { return host_dispatcher_.get(); } | 171 HostDispatcher* host_dispatcher() { return host_dispatcher_.get(); } |
167 ResourceTracker& resource_tracker() { | 172 ResourceTracker& resource_tracker() { |
168 return *host_globals_.GetResourceTracker(); | 173 return *host_globals_->GetResourceTracker(); |
169 } | 174 } |
170 VarTracker& var_tracker() { | 175 VarTracker& var_tracker() { |
171 return *host_globals_.GetVarTracker(); | 176 return *host_globals_->GetVarTracker(); |
172 } | 177 } |
173 | 178 |
174 // ProxyTestBase implementation. | 179 // ProxyTestBase implementation. |
175 virtual PpapiGlobals* GetGlobals() { return &host_globals_; } | 180 virtual PpapiGlobals* GetGlobals(); |
176 virtual Dispatcher* GetDispatcher(); | 181 virtual Dispatcher* GetDispatcher(); |
177 virtual void SetUpHarness(); | 182 virtual void SetUpHarness(); |
178 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, | 183 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, |
179 base::MessageLoopProxy* ipc_message_loop, | 184 base::MessageLoopProxy* ipc_message_loop, |
180 base::WaitableEvent* shutdown_event, | 185 base::WaitableEvent* shutdown_event, |
181 bool is_client); | 186 bool is_client); |
182 virtual void TearDownHarness(); | 187 virtual void TearDownHarness(); |
183 | 188 |
184 class DelegateMock : public ProxyChannel::Delegate { | 189 class DelegateMock : public ProxyChannel::Delegate { |
185 public: | 190 public: |
(...skipping 18 matching lines...) Expand all Loading... |
204 private: | 209 private: |
205 base::MessageLoopProxy* ipc_message_loop_; // Weak | 210 base::MessageLoopProxy* ipc_message_loop_; // Weak |
206 base::WaitableEvent* shutdown_event_; // Weak | 211 base::WaitableEvent* shutdown_event_; // Weak |
207 | 212 |
208 DISALLOW_COPY_AND_ASSIGN(DelegateMock); | 213 DISALLOW_COPY_AND_ASSIGN(DelegateMock); |
209 }; | 214 }; |
210 | 215 |
211 private: | 216 private: |
212 class MockSyncMessageStatusReceiver; | 217 class MockSyncMessageStatusReceiver; |
213 | 218 |
214 ppapi::TestGlobals host_globals_; | 219 scoped_ptr<ppapi::TestGlobals> host_globals_; |
215 scoped_ptr<HostDispatcher> host_dispatcher_; | 220 scoped_ptr<HostDispatcher> host_dispatcher_; |
216 DelegateMock delegate_mock_; | 221 DelegateMock delegate_mock_; |
217 | 222 |
218 scoped_ptr<MockSyncMessageStatusReceiver> status_receiver_; | 223 scoped_ptr<MockSyncMessageStatusReceiver> status_receiver_; |
219 }; | 224 }; |
220 | 225 |
221 class HostProxyTest : public HostProxyTestHarness, public testing::Test { | 226 class HostProxyTest : public HostProxyTestHarness, public testing::Test { |
222 public: | 227 public: |
223 HostProxyTest(); | 228 HostProxyTest(); |
224 virtual ~HostProxyTest(); | 229 virtual ~HostProxyTest(); |
(...skipping 18 matching lines...) Expand all Loading... |
243 HostProxyTestHarness& host() { return host_; } | 248 HostProxyTestHarness& host() { return host_; } |
244 PluginProxyTestHarness& plugin() { return plugin_; } | 249 PluginProxyTestHarness& plugin() { return plugin_; } |
245 PP_Module pp_module() const { return host_.pp_module(); } | 250 PP_Module pp_module() const { return host_.pp_module(); } |
246 PP_Instance pp_instance() const { return host_.pp_instance(); } | 251 PP_Instance pp_instance() const { return host_.pp_instance(); } |
247 TwoWayTestMode test_mode() { return test_mode_; } | 252 TwoWayTestMode test_mode() { return test_mode_; } |
248 | 253 |
249 // testing::Test implementation. | 254 // testing::Test implementation. |
250 virtual void SetUp(); | 255 virtual void SetUp(); |
251 virtual void TearDown(); | 256 virtual void TearDown(); |
252 | 257 |
| 258 protected: |
| 259 // Post a task to the thread where the remote harness lives. This |
| 260 // is typically used to test the state of the var tracker on the plugin |
| 261 // thread. This runs the task synchronously for convenience. |
| 262 void PostTaskOnRemoteHarness(const base::Closure& task); |
| 263 |
253 private: | 264 private: |
254 TwoWayTestMode test_mode_; | 265 TwoWayTestMode test_mode_; |
255 HostProxyTestHarness host_; | 266 HostProxyTestHarness host_; |
256 PluginProxyTestHarness plugin_; | 267 PluginProxyTestHarness plugin_; |
257 // In order to use sync IPC, we need to have an IO thread. | 268 // In order to use sync IPC, we need to have an IO thread. |
258 base::Thread io_thread_; | 269 base::Thread io_thread_; |
259 // The plugin side of the proxy runs on its own thread. | 270 // The plugin side of the proxy runs on its own thread. |
260 base::Thread plugin_thread_; | 271 base::Thread plugin_thread_; |
261 // The message loop for the main (host) thread. | 272 // The message loop for the main (host) thread. |
262 MessageLoop message_loop_; | 273 MessageLoop message_loop_; |
(...skipping 15 matching lines...) Expand all Loading... |
278 // EXPECT_VAR_IS_STRING("foo", my_var); | 289 // EXPECT_VAR_IS_STRING("foo", my_var); |
279 #define EXPECT_VAR_IS_STRING(str, var) { \ | 290 #define EXPECT_VAR_IS_STRING(str, var) { \ |
280 StringVar* sv = StringVar::FromPPVar(var); \ | 291 StringVar* sv = StringVar::FromPPVar(var); \ |
281 EXPECT_TRUE(sv); \ | 292 EXPECT_TRUE(sv); \ |
282 if (sv) \ | 293 if (sv) \ |
283 EXPECT_EQ(str, sv->value()); \ | 294 EXPECT_EQ(str, sv->value()); \ |
284 } | 295 } |
285 | 296 |
286 } // namespace proxy | 297 } // namespace proxy |
287 } // namespace ppapi | 298 } // namespace ppapi |
OLD | NEW |