OLD | NEW |
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 "ppapi/proxy/ppapi_proxy_test.h" | 5 #include "ppapi/proxy/ppapi_proxy_test.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
10 #include "ipc/ipc_sync_channel.h" | 10 #include "ipc/ipc_sync_channel.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 TupleTypes<PpapiMsg_SupportsInterface::ReplyParam>::ValueTuple reply_data; | 132 TupleTypes<PpapiMsg_SupportsInterface::ReplyParam>::ValueTuple reply_data; |
133 EXPECT_TRUE(PpapiMsg_SupportsInterface::ReadReplyParam( | 133 EXPECT_TRUE(PpapiMsg_SupportsInterface::ReadReplyParam( |
134 reply_msg, &reply_data)); | 134 reply_msg, &reply_data)); |
135 | 135 |
136 sink().ClearMessages(); | 136 sink().ClearMessages(); |
137 return reply_data.a; | 137 return reply_data.a; |
138 } | 138 } |
139 | 139 |
140 // PluginProxyTestHarness ------------------------------------------------------ | 140 // PluginProxyTestHarness ------------------------------------------------------ |
141 | 141 |
142 PluginProxyTestHarness::PluginProxyTestHarness() { | 142 PluginProxyTestHarness::PluginProxyTestHarness() |
| 143 : plugin_globals_(PpapiGlobals::ForTest()) { |
143 } | 144 } |
144 | 145 |
145 PluginProxyTestHarness::~PluginProxyTestHarness() { | 146 PluginProxyTestHarness::~PluginProxyTestHarness() { |
146 } | 147 } |
147 | 148 |
148 Dispatcher* PluginProxyTestHarness::GetDispatcher() { | 149 Dispatcher* PluginProxyTestHarness::GetDispatcher() { |
149 return plugin_dispatcher_.get(); | 150 return plugin_dispatcher_.get(); |
150 } | 151 } |
151 | 152 |
152 void PluginProxyTestHarness::SetUpHarness() { | 153 void PluginProxyTestHarness::SetUpHarness() { |
153 // These must be first since the dispatcher set-up uses them. | 154 // These must be first since the dispatcher set-up uses them. |
| 155 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); |
154 resource_tracker().DidCreateInstance(pp_instance()); | 156 resource_tracker().DidCreateInstance(pp_instance()); |
155 | 157 |
156 plugin_dispatcher_.reset(new PluginDispatcher( | 158 plugin_dispatcher_.reset(new PluginDispatcher( |
157 base::Process::Current().handle(), | 159 base::Process::Current().handle(), |
158 &MockGetInterface)); | 160 &MockGetInterface)); |
159 plugin_dispatcher_->InitWithTestSink(&sink()); | 161 plugin_dispatcher_->InitWithTestSink(&sink()); |
160 plugin_dispatcher_->DidCreateInstance(pp_instance()); | 162 plugin_dispatcher_->DidCreateInstance(pp_instance()); |
161 } | 163 } |
162 | 164 |
163 void PluginProxyTestHarness::SetUpHarnessWithChannel( | 165 void PluginProxyTestHarness::SetUpHarnessWithChannel( |
164 const IPC::ChannelHandle& channel_handle, | 166 const IPC::ChannelHandle& channel_handle, |
165 base::MessageLoopProxy* ipc_message_loop, | 167 base::MessageLoopProxy* ipc_message_loop, |
166 base::WaitableEvent* shutdown_event, | 168 base::WaitableEvent* shutdown_event, |
167 bool is_client) { | 169 bool is_client) { |
168 // These must be first since the dispatcher set-up uses them. | 170 // These must be first since the dispatcher set-up uses them. |
| 171 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); |
169 resource_tracker().DidCreateInstance(pp_instance()); | 172 resource_tracker().DidCreateInstance(pp_instance()); |
170 plugin_delegate_mock_.Init(ipc_message_loop, shutdown_event); | 173 plugin_delegate_mock_.Init(ipc_message_loop, shutdown_event); |
171 | 174 |
172 plugin_dispatcher_.reset(new PluginDispatcher( | 175 plugin_dispatcher_.reset(new PluginDispatcher( |
173 base::Process::Current().handle(), | 176 base::Process::Current().handle(), |
174 &MockGetInterface)); | 177 &MockGetInterface)); |
175 plugin_dispatcher_->InitPluginWithChannel(&plugin_delegate_mock_, | 178 plugin_dispatcher_->InitPluginWithChannel(&plugin_delegate_mock_, |
176 channel_handle, | 179 channel_handle, |
177 is_client); | 180 is_client); |
178 plugin_dispatcher_->DidCreateInstance(pp_instance()); | 181 plugin_dispatcher_->DidCreateInstance(pp_instance()); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 void PluginProxyTest::SetUp() { | 244 void PluginProxyTest::SetUp() { |
242 SetUpHarness(); | 245 SetUpHarness(); |
243 } | 246 } |
244 | 247 |
245 void PluginProxyTest::TearDown() { | 248 void PluginProxyTest::TearDown() { |
246 TearDownHarness(); | 249 TearDownHarness(); |
247 } | 250 } |
248 | 251 |
249 // HostProxyTestHarness -------------------------------------------------------- | 252 // HostProxyTestHarness -------------------------------------------------------- |
250 | 253 |
251 HostProxyTestHarness::HostProxyTestHarness() { | 254 HostProxyTestHarness::HostProxyTestHarness() |
| 255 : host_globals_(PpapiGlobals::ForTest()) { |
252 } | 256 } |
253 | 257 |
254 HostProxyTestHarness::~HostProxyTestHarness() { | 258 HostProxyTestHarness::~HostProxyTestHarness() { |
255 } | 259 } |
256 | 260 |
257 Dispatcher* HostProxyTestHarness::GetDispatcher() { | 261 Dispatcher* HostProxyTestHarness::GetDispatcher() { |
258 return host_dispatcher_.get(); | 262 return host_dispatcher_.get(); |
259 } | 263 } |
260 | 264 |
261 void HostProxyTestHarness::SetUpHarness() { | 265 void HostProxyTestHarness::SetUpHarness() { |
| 266 // These must be first since the dispatcher set-up uses them. |
| 267 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); |
262 host_dispatcher_.reset(new HostDispatcher( | 268 host_dispatcher_.reset(new HostDispatcher( |
263 base::Process::Current().handle(), | 269 base::Process::Current().handle(), |
264 pp_module(), | 270 pp_module(), |
265 &MockGetInterface)); | 271 &MockGetInterface)); |
266 host_dispatcher_->InitWithTestSink(&sink()); | 272 host_dispatcher_->InitWithTestSink(&sink()); |
267 HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get()); | 273 HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get()); |
268 } | 274 } |
269 | 275 |
270 void HostProxyTestHarness::SetUpHarnessWithChannel( | 276 void HostProxyTestHarness::SetUpHarnessWithChannel( |
271 const IPC::ChannelHandle& channel_handle, | 277 const IPC::ChannelHandle& channel_handle, |
272 base::MessageLoopProxy* ipc_message_loop, | 278 base::MessageLoopProxy* ipc_message_loop, |
273 base::WaitableEvent* shutdown_event, | 279 base::WaitableEvent* shutdown_event, |
274 bool is_client) { | 280 bool is_client) { |
| 281 // These must be first since the dispatcher set-up uses them. |
| 282 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); |
275 delegate_mock_.Init(ipc_message_loop, shutdown_event); | 283 delegate_mock_.Init(ipc_message_loop, shutdown_event); |
| 284 |
276 host_dispatcher_.reset(new HostDispatcher( | 285 host_dispatcher_.reset(new HostDispatcher( |
277 base::Process::Current().handle(), | 286 base::Process::Current().handle(), |
278 pp_module(), | 287 pp_module(), |
279 &MockGetInterface)); | 288 &MockGetInterface)); |
280 ppapi::Preferences preferences; | 289 ppapi::Preferences preferences; |
281 host_dispatcher_->InitHostWithChannel(&delegate_mock_, channel_handle, | 290 host_dispatcher_->InitHostWithChannel(&delegate_mock_, channel_handle, |
282 is_client, preferences); | 291 is_client, preferences); |
283 HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get()); | 292 HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get()); |
284 } | 293 } |
285 | 294 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 } | 347 } |
339 | 348 |
340 void TwoWayTest::SetUp() { | 349 void TwoWayTest::SetUp() { |
341 base::Thread::Options options; | 350 base::Thread::Options options; |
342 options.message_loop_type = MessageLoop::TYPE_IO; | 351 options.message_loop_type = MessageLoop::TYPE_IO; |
343 io_thread_.StartWithOptions(options); | 352 io_thread_.StartWithOptions(options); |
344 plugin_thread_.Start(); | 353 plugin_thread_.Start(); |
345 | 354 |
346 IPC::ChannelHandle handle; | 355 IPC::ChannelHandle handle; |
347 handle.name = "TwoWayTestChannel"; | 356 handle.name = "TwoWayTestChannel"; |
348 | |
349 base::WaitableEvent remote_harness_set_up(true, false); | 357 base::WaitableEvent remote_harness_set_up(true, false); |
350 plugin_thread_.message_loop_proxy()->PostTask( | 358 plugin_thread_.message_loop_proxy()->PostTask( |
351 FROM_HERE, | 359 FROM_HERE, |
352 base::Bind(&SetUpRemoteHarness, | 360 base::Bind(&SetUpRemoteHarness, |
353 remote_harness_, | 361 remote_harness_, |
354 handle, | 362 handle, |
355 io_thread_.message_loop_proxy(), | 363 io_thread_.message_loop_proxy(), |
356 &shutdown_event_, | 364 &shutdown_event_, |
357 &remote_harness_set_up)); | 365 &remote_harness_set_up)); |
358 remote_harness_set_up.Wait(); | 366 remote_harness_set_up.Wait(); |
(...skipping 13 matching lines...) Expand all Loading... |
372 remote_harness_torn_down.Wait(); | 380 remote_harness_torn_down.Wait(); |
373 | 381 |
374 local_harness_->TearDownHarness(); | 382 local_harness_->TearDownHarness(); |
375 | 383 |
376 io_thread_.Stop(); | 384 io_thread_.Stop(); |
377 } | 385 } |
378 | 386 |
379 | 387 |
380 } // namespace proxy | 388 } // namespace proxy |
381 } // namespace ppapi | 389 } // namespace ppapi |
OLD | NEW |