[email protected] | 7309756 | 2012-01-12 19:38:55 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ppapi/proxy/ppapi_proxy_test.h" |
| 6 | |
tzik | a0f614d | 2016-03-08 00:35:15 | [diff] [blame] | 7 | #include <tuple> |
[email protected] | b75673fe | 2012-10-17 17:59:14 | [diff] [blame] | 8 | |
[email protected] | 1f6581c | 2011-10-04 23:10:15 | [diff] [blame] | 9 | #include "base/bind.h" |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 10 | #include "base/bind_helpers.h" |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 11 | #include "base/location.h" |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 12 | #include "base/observer_list.h" |
rvargas | 079d184 | 2014-10-17 22:32:16 | [diff] [blame] | 13 | #include "base/process/process_handle.h" |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 14 | #include "base/run_loop.h" |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 15 | #include "base/single_thread_task_runner.h" |
gab | b19326e | 2016-05-11 18:10:31 | [diff] [blame] | 16 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 17 | #include "ipc/ipc_sync_channel.h" |
dmichael | 6b328f3d | 2014-09-29 23:49:02 | [diff] [blame] | 18 | #include "ipc/message_filter.h" |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 19 | #include "ppapi/c/pp_errors.h" |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 20 | #include "ppapi/c/private/ppb_proxy_private.h" |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 21 | #include "ppapi/proxy/ppapi_messages.h" |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 22 | #include "ppapi/proxy/ppb_message_loop_proxy.h" |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 23 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 24 | namespace ppapi { |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 25 | namespace proxy { |
| 26 | |
| 27 | namespace { |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 28 | // HostDispatcher requires a PPB_Proxy_Private, so we always provide a fallback |
| 29 | // do-nothing implementation. |
| 30 | void PluginCrashed(PP_Module module) { |
| 31 | NOTREACHED(); |
| 32 | }; |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 33 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 34 | PP_Instance GetInstanceForResource(PP_Resource resource) { |
| 35 | // If a test relies on this, we need to implement it. |
| 36 | NOTREACHED(); |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | void SetReserveInstanceIDCallback(PP_Module module, |
| 41 | PP_Bool (*is_seen)(PP_Module, PP_Instance)) { |
| 42 | // This function gets called in HostDispatcher's constructor. We simply don't |
| 43 | // worry about Instance uniqueness in tests, so we can ignore the call. |
| 44 | } |
| 45 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 46 | void AddRefModule(PP_Module module) {} |
| 47 | void ReleaseModule(PP_Module module) {} |
[email protected] | fa4dd291 | 2011-10-17 21:23:29 | [diff] [blame] | 48 | PP_Bool IsInModuleDestructor(PP_Module module) { return PP_FALSE; } |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 49 | |
[email protected] | fa4dd291 | 2011-10-17 21:23:29 | [diff] [blame] | 50 | PPB_Proxy_Private ppb_proxy_private = { |
| 51 | &PluginCrashed, |
| 52 | &GetInstanceForResource, |
| 53 | &SetReserveInstanceIDCallback, |
[email protected] | fa4dd291 | 2011-10-17 21:23:29 | [diff] [blame] | 54 | &AddRefModule, |
| 55 | &ReleaseModule, |
| 56 | &IsInModuleDestructor |
| 57 | }; |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 58 | |
| 59 | // We allow multiple harnesses at a time to respond to 'GetInterface' calls. |
| 60 | // We assume that only 1 harness's GetInterface function will ever support a |
| 61 | // given interface name. In practice, there will either be only 1 GetInterface |
| 62 | // handler (for PluginProxyTest or HostProxyTest), or there will be only 2 |
| 63 | // GetInterface handlers (for TwoWayTest). In the latter case, one handler is |
| 64 | // for the PluginProxyTestHarness and should only respond for PPP interfaces, |
| 65 | // and the other handler is for the HostProxyTestHarness which should only |
| 66 | // ever respond for PPB interfaces. |
Trent Apted | a250ec3ab | 2018-08-19 08:52:19 | [diff] [blame] | 67 | base::ObserverList<ProxyTestHarnessBase>::Unchecked get_interface_handlers_; |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 68 | |
| 69 | const void* MockGetInterface(const char* name) { |
dcheng | 9fae5022 | 2016-10-14 03:21:04 | [diff] [blame] | 70 | for (auto& observer : get_interface_handlers_) { |
| 71 | const void* interface = observer.GetInterface(name); |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 72 | if (interface) |
| 73 | return interface; |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 74 | } |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 75 | if (strcmp(name, PPB_PROXY_PRIVATE_INTERFACE) == 0) |
| 76 | return &ppb_proxy_private; |
| 77 | return NULL; |
| 78 | } |
| 79 | |
| 80 | void SetUpRemoteHarness(ProxyTestHarnessBase* harness, |
| 81 | const IPC::ChannelHandle& handle, |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 82 | base::SingleThreadTaskRunner* ipc_task_runner, |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 83 | base::WaitableEvent* shutdown_event, |
| 84 | base::WaitableEvent* harness_set_up) { |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 85 | harness->SetUpHarnessWithChannel(handle, ipc_task_runner, shutdown_event, |
| 86 | false); |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 87 | harness_set_up->Signal(); |
| 88 | } |
| 89 | |
| 90 | void TearDownRemoteHarness(ProxyTestHarnessBase* harness, |
| 91 | base::WaitableEvent* harness_torn_down) { |
| 92 | harness->TearDownHarness(); |
| 93 | harness_torn_down->Signal(); |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 94 | } |
| 95 | |
[email protected] | d57fd38 | 2012-09-19 00:55:42 | [diff] [blame] | 96 | void RunTaskOnRemoteHarness(const base::Closure& task, |
| 97 | base::WaitableEvent* task_complete) { |
| 98 | task.Run(); |
| 99 | task_complete->Signal(); |
| 100 | } |
| 101 | |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 102 | } // namespace |
| 103 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 104 | // ProxyTestHarnessBase -------------------------------------------------------- |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 105 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 106 | ProxyTestHarnessBase::ProxyTestHarnessBase() : pp_module_(0x98765), |
| 107 | pp_instance_(0x12345) { |
| 108 | get_interface_handlers_.AddObserver(this); |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 109 | } |
| 110 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 111 | ProxyTestHarnessBase::~ProxyTestHarnessBase() { |
| 112 | get_interface_handlers_.RemoveObserver(this); |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 113 | } |
| 114 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 115 | const void* ProxyTestHarnessBase::GetInterface(const char* name) { |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 116 | return registered_interfaces_[name]; |
| 117 | } |
| 118 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 119 | void ProxyTestHarnessBase::RegisterTestInterface(const char* name, |
[email protected] | 99ff993 | 2011-09-07 14:14:54 | [diff] [blame] | 120 | const void* test_interface) { |
| 121 | registered_interfaces_[name] = test_interface; |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 122 | } |
| 123 | |
kareng | 1c62eeb | 2014-11-08 16:35:03 | [diff] [blame] | 124 | bool ProxyTestHarnessBase::SupportsInterface(const char* name) { |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 125 | sink().ClearMessages(); |
| 126 | |
| 127 | // IPC doesn't actually write to this when we send a message manually |
| 128 | // not actually using IPC. |
| 129 | bool unused_result = false; |
kareng | 1c62eeb | 2014-11-08 16:35:03 | [diff] [blame] | 130 | PpapiMsg_SupportsInterface msg(name, &unused_result); |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 131 | GetDispatcher()->OnMessageReceived(msg); |
| 132 | |
| 133 | const IPC::Message* reply_msg = |
| 134 | sink().GetUniqueMessageMatching(IPC_REPLY_ID); |
| 135 | EXPECT_TRUE(reply_msg); |
| 136 | if (!reply_msg) |
| 137 | return false; |
| 138 | |
mdempsky | 390ab1e | 2016-03-07 22:18:35 | [diff] [blame] | 139 | PpapiMsg_SupportsInterface::ReplyParam reply_data; |
kareng | 1c62eeb | 2014-11-08 16:35:03 | [diff] [blame] | 140 | EXPECT_TRUE(PpapiMsg_SupportsInterface::ReadReplyParam( |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 141 | reply_msg, &reply_data)); |
| 142 | |
| 143 | sink().ClearMessages(); |
tzik | a0f614d | 2016-03-08 00:35:15 | [diff] [blame] | 144 | return std::get<0>(reply_data); |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 145 | } |
| 146 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 147 | // PluginProxyTestHarness ------------------------------------------------------ |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 148 | |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 149 | PluginProxyTestHarness::PluginProxyTestHarness( |
| 150 | GlobalsConfiguration globals_config) |
| 151 | : globals_config_(globals_config) { |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 152 | } |
| 153 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 154 | PluginProxyTestHarness::~PluginProxyTestHarness() { |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 155 | } |
| 156 | |
[email protected] | d57fd38 | 2012-09-19 00:55:42 | [diff] [blame] | 157 | PpapiGlobals* PluginProxyTestHarness::GetGlobals() { |
| 158 | return plugin_globals_.get(); |
| 159 | } |
| 160 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 161 | Dispatcher* PluginProxyTestHarness::GetDispatcher() { |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 162 | return plugin_dispatcher_.get(); |
| 163 | } |
| 164 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 165 | void PluginProxyTestHarness::SetUpHarness() { |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 166 | // These must be first since the dispatcher set-up uses them. |
dmichael | b11ca7b | 2015-04-02 16:59:40 | [diff] [blame] | 167 | CreatePluginGlobals(nullptr /* ipc_task_runner */); |
[email protected] | b73c659 | 2013-03-30 17:08:13 | [diff] [blame] | 168 | // Some of the methods called during set-up check that the lock is held. |
| 169 | ProxyAutoLock lock; |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 170 | |
[email protected] | 794d83cd | 2011-10-20 19:09:20 | [diff] [blame] | 171 | resource_tracker().DidCreateInstance(pp_instance()); |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 172 | |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 173 | plugin_dispatcher_.reset(new PluginDispatcher( |
[email protected] | bc2eeb4 | 2012-05-02 22:35:53 | [diff] [blame] | 174 | &MockGetInterface, |
[email protected] | 195d4cde | 2012-10-02 18:12:41 | [diff] [blame] | 175 | PpapiPermissions(), |
[email protected] | bc2eeb4 | 2012-05-02 22:35:53 | [diff] [blame] | 176 | false)); |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 177 | plugin_dispatcher_->InitWithTestSink(&sink()); |
[email protected] | d57fd38 | 2012-09-19 00:55:42 | [diff] [blame] | 178 | // The plugin proxy delegate is needed for |
| 179 | // |PluginProxyDelegate::GetBrowserSender| which is used |
| 180 | // in |ResourceCreationProxy::GetConnection| to get the channel to the |
| 181 | // browser. In this case we just use the |plugin_dispatcher_| as the channel |
| 182 | // for test purposes. |
| 183 | plugin_delegate_mock_.set_browser_sender(plugin_dispatcher_.get()); |
dmichael | fee3a51 | 2014-09-18 21:32:13 | [diff] [blame] | 184 | PluginGlobals::Get()->SetPluginProxyDelegate(&plugin_delegate_mock_); |
[email protected] | 22fdaa6 | 2012-11-30 01:55:44 | [diff] [blame] | 185 | plugin_dispatcher_->DidCreateInstance(pp_instance()); |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 186 | } |
| 187 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 188 | void PluginProxyTestHarness::SetUpHarnessWithChannel( |
| 189 | const IPC::ChannelHandle& channel_handle, |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 190 | base::SingleThreadTaskRunner* ipc_task_runner, |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 191 | base::WaitableEvent* shutdown_event, |
| 192 | bool is_client) { |
| 193 | // These must be first since the dispatcher set-up uses them. |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 194 | CreatePluginGlobals(ipc_task_runner); |
[email protected] | b73c659 | 2013-03-30 17:08:13 | [diff] [blame] | 195 | // Some of the methods called during set-up check that the lock is held. |
| 196 | ProxyAutoLock lock; |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 197 | |
[email protected] | 794d83cd | 2011-10-20 19:09:20 | [diff] [blame] | 198 | resource_tracker().DidCreateInstance(pp_instance()); |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 199 | plugin_delegate_mock_.Init(ipc_task_runner, shutdown_event); |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 200 | |
| 201 | plugin_dispatcher_.reset(new PluginDispatcher( |
[email protected] | bc2eeb4 | 2012-05-02 22:35:53 | [diff] [blame] | 202 | &MockGetInterface, |
[email protected] | 195d4cde | 2012-10-02 18:12:41 | [diff] [blame] | 203 | PpapiPermissions(), |
[email protected] | bc2eeb4 | 2012-05-02 22:35:53 | [diff] [blame] | 204 | false)); |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 205 | plugin_dispatcher_->InitPluginWithChannel(&plugin_delegate_mock_, |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 206 | base::kNullProcessId, |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 207 | channel_handle, |
| 208 | is_client); |
[email protected] | 22fdaa6 | 2012-11-30 01:55:44 | [diff] [blame] | 209 | plugin_delegate_mock_.set_browser_sender(plugin_dispatcher_.get()); |
dmichael | fee3a51 | 2014-09-18 21:32:13 | [diff] [blame] | 210 | PluginGlobals::Get()->SetPluginProxyDelegate(&plugin_delegate_mock_); |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 211 | plugin_dispatcher_->DidCreateInstance(pp_instance()); |
| 212 | } |
| 213 | |
| 214 | void PluginProxyTestHarness::TearDownHarness() { |
[email protected] | b73c659 | 2013-03-30 17:08:13 | [diff] [blame] | 215 | { |
| 216 | // Some of the methods called during tear-down check that the lock is held. |
| 217 | ProxyAutoLock lock; |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 218 | |
[email protected] | b73c659 | 2013-03-30 17:08:13 | [diff] [blame] | 219 | plugin_dispatcher_->DidDestroyInstance(pp_instance()); |
| 220 | plugin_dispatcher_.reset(); |
| 221 | |
| 222 | resource_tracker().DidDeleteInstance(pp_instance()); |
| 223 | } |
[email protected] | d57fd38 | 2012-09-19 00:55:42 | [diff] [blame] | 224 | plugin_globals_.reset(); |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 225 | } |
| 226 | |
dmichael | b11ca7b | 2015-04-02 16:59:40 | [diff] [blame] | 227 | void PluginProxyTestHarness::CreatePluginGlobals( |
| 228 | const scoped_refptr<base::TaskRunner>& ipc_task_runner) { |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 229 | if (globals_config_ == PER_THREAD_GLOBALS) { |
dmichael | b11ca7b | 2015-04-02 16:59:40 | [diff] [blame] | 230 | plugin_globals_.reset(new PluginGlobals(PpapiGlobals::PerThreadForTest(), |
| 231 | ipc_task_runner)); |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 232 | PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); |
| 233 | } else { |
dmichael | b11ca7b | 2015-04-02 16:59:40 | [diff] [blame] | 234 | plugin_globals_.reset(new PluginGlobals(ipc_task_runner)); |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | |
skyostil | 12262cf | 2015-05-21 14:49:31 | [diff] [blame] | 238 | base::SingleThreadTaskRunner* |
| 239 | PluginProxyTestHarness::PluginDelegateMock::GetIPCTaskRunner() { |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 240 | return ipc_task_runner_; |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | base::WaitableEvent* |
| 244 | PluginProxyTestHarness::PluginDelegateMock::GetShutdownEvent() { |
| 245 | return shutdown_event_; |
| 246 | } |
| 247 | |
[email protected] | f0ecb55 | 2012-05-11 22:09:11 | [diff] [blame] | 248 | IPC::PlatformFileForTransit |
| 249 | PluginProxyTestHarness::PluginDelegateMock::ShareHandleWithRemote( |
| 250 | base::PlatformFile handle, |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 251 | base::ProcessId /* remote_pid */, |
[email protected] | f0ecb55 | 2012-05-11 22:09:11 | [diff] [blame] | 252 | bool should_close_source) { |
erikchen | 09b4003 | 2016-04-06 18:51:55 | [diff] [blame] | 253 | return IPC::GetPlatformFileForTransit(handle, |
| 254 | should_close_source); |
[email protected] | f0ecb55 | 2012-05-11 22:09:11 | [diff] [blame] | 255 | } |
| 256 | |
erikchen | 4fc32d5 | 2015-06-02 02:16:38 | [diff] [blame] | 257 | base::SharedMemoryHandle |
| 258 | PluginProxyTestHarness::PluginDelegateMock::ShareSharedMemoryHandleWithRemote( |
| 259 | const base::SharedMemoryHandle& handle, |
erikchen | fc29ad99 | 2015-06-04 20:44:18 | [diff] [blame] | 260 | base::ProcessId /* remote_pid */) { |
| 261 | return base::SharedMemory::DuplicateHandle(handle); |
erikchen | 4fc32d5 | 2015-06-02 02:16:38 | [diff] [blame] | 262 | } |
| 263 | |
Alexandr Ilin | c7d975f | 2018-06-01 09:25:41 | [diff] [blame] | 264 | base::UnsafeSharedMemoryRegion PluginProxyTestHarness::PluginDelegateMock:: |
| 265 | ShareUnsafeSharedMemoryRegionWithRemote( |
| 266 | const base::UnsafeSharedMemoryRegion& region, |
| 267 | base::ProcessId /* remote_pid */) { |
| 268 | return region.Duplicate(); |
| 269 | } |
| 270 | |
| 271 | base::ReadOnlySharedMemoryRegion PluginProxyTestHarness::PluginDelegateMock:: |
| 272 | ShareReadOnlySharedMemoryRegionWithRemote( |
| 273 | const base::ReadOnlySharedMemoryRegion& region, |
| 274 | base::ProcessId /* remote_pid */) { |
| 275 | return region.Duplicate(); |
| 276 | } |
| 277 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 278 | std::set<PP_Instance>* |
| 279 | PluginProxyTestHarness::PluginDelegateMock::GetGloballySeenInstanceIDSet() { |
| 280 | return &instance_id_set_; |
| 281 | } |
| 282 | |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 283 | uint32_t PluginProxyTestHarness::PluginDelegateMock::Register( |
[email protected] | 6fc87e0 | 2011-12-20 19:18:45 | [diff] [blame] | 284 | PluginDispatcher* plugin_dispatcher) { |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | void PluginProxyTestHarness::PluginDelegateMock::Unregister( |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 289 | uint32_t plugin_dispatcher_id) {} |
[email protected] | 6fc87e0 | 2011-12-20 19:18:45 | [diff] [blame] | 290 | |
[email protected] | 93df81e | 2012-08-10 22:22:46 | [diff] [blame] | 291 | IPC::Sender* PluginProxyTestHarness::PluginDelegateMock::GetBrowserSender() { |
[email protected] | d57fd38 | 2012-09-19 00:55:42 | [diff] [blame] | 292 | return browser_sender_; |
[email protected] | 93df81e | 2012-08-10 22:22:46 | [diff] [blame] | 293 | } |
| 294 | |
[email protected] | 2306303a | 2012-06-11 18:10:37 | [diff] [blame] | 295 | std::string PluginProxyTestHarness::PluginDelegateMock::GetUILanguage() { |
| 296 | return std::string("en-US"); |
| 297 | } |
| 298 | |
mgiuca | 8ca5918 | 2015-07-08 02:10:21 | [diff] [blame] | 299 | void PluginProxyTestHarness::PluginDelegateMock::PreCacheFontForFlash( |
[email protected] | 6fc87e0 | 2011-12-20 19:18:45 | [diff] [blame] | 300 | const void* logfontw) { |
[email protected] | 373a95a | 2011-07-01 16:58:14 | [diff] [blame] | 301 | } |
[email protected] | 7f801d8 | 2011-07-08 23:30:11 | [diff] [blame] | 302 | |
[email protected] | 72a1072 | 2012-06-27 19:30:58 | [diff] [blame] | 303 | void PluginProxyTestHarness::PluginDelegateMock::SetActiveURL( |
| 304 | const std::string& url) { |
| 305 | } |
| 306 | |
[email protected] | 1d14806 | 2013-07-25 20:25:45 | [diff] [blame] | 307 | PP_Resource PluginProxyTestHarness::PluginDelegateMock::CreateBrowserFont( |
| 308 | Connection connection, |
| 309 | PP_Instance instance, |
| 310 | const PP_BrowserFont_Trusted_Description& desc, |
| 311 | const Preferences& prefs) { |
| 312 | return 0; |
| 313 | } |
| 314 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 315 | // PluginProxyTest ------------------------------------------------------------- |
| 316 | |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 317 | PluginProxyTest::PluginProxyTest() : PluginProxyTestHarness(SINGLETON_GLOBALS) { |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | PluginProxyTest::~PluginProxyTest() { |
| 321 | } |
| 322 | |
| 323 | void PluginProxyTest::SetUp() { |
| 324 | SetUpHarness(); |
| 325 | } |
| 326 | |
| 327 | void PluginProxyTest::TearDown() { |
| 328 | TearDownHarness(); |
| 329 | } |
| 330 | |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 331 | // PluginProxyMultiThreadTest -------------------------------------------------- |
| 332 | |
| 333 | PluginProxyMultiThreadTest::PluginProxyMultiThreadTest() { |
| 334 | } |
| 335 | |
| 336 | PluginProxyMultiThreadTest::~PluginProxyMultiThreadTest() { |
| 337 | } |
| 338 | |
| 339 | void PluginProxyMultiThreadTest::RunTest() { |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 340 | main_thread_task_runner_ = PpapiGlobals::Get()->GetMainThreadMessageLoop(); |
| 341 | ASSERT_EQ(main_thread_task_runner_.get(), |
| 342 | base::ThreadTaskRunnerHandle::Get().get()); |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 343 | nested_main_thread_message_loop_.reset(new base::RunLoop()); |
| 344 | |
| 345 | secondary_thread_.reset(new base::DelegateSimpleThread( |
| 346 | this, "PluginProxyMultiThreadTest")); |
| 347 | |
| 348 | { |
| 349 | ProxyAutoLock auto_lock; |
| 350 | |
| 351 | // MessageLoopResource assumes that the proxy lock has been acquired. |
| 352 | secondary_thread_message_loop_ = new MessageLoopResource(pp_instance()); |
| 353 | |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 354 | ASSERT_EQ(PP_OK, |
| 355 | secondary_thread_message_loop_->PostWork( |
| 356 | PP_MakeCompletionCallback( |
| 357 | &PluginProxyMultiThreadTest::InternalSetUpTestOnSecondaryThread, |
| 358 | this), |
| 359 | 0)); |
| 360 | } |
| 361 | |
| 362 | SetUpTestOnMainThread(); |
| 363 | |
| 364 | secondary_thread_->Start(); |
| 365 | nested_main_thread_message_loop_->Run(); |
| 366 | secondary_thread_->Join(); |
| 367 | |
| 368 | { |
| 369 | ProxyAutoLock auto_lock; |
| 370 | |
| 371 | // The destruction requires a valid PpapiGlobals instance, so we should |
| 372 | // explicitly release it. |
| 373 | secondary_thread_message_loop_ = NULL; |
| 374 | } |
| 375 | |
| 376 | secondary_thread_.reset(NULL); |
| 377 | nested_main_thread_message_loop_.reset(NULL); |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 378 | main_thread_task_runner_ = NULL; |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | void PluginProxyMultiThreadTest::CheckOnThread(ThreadType thread_type) { |
| 382 | ProxyAutoLock auto_lock; |
| 383 | if (thread_type == MAIN_THREAD) { |
| 384 | ASSERT_TRUE(MessageLoopResource::GetCurrent()->is_main_thread_loop()); |
| 385 | } else { |
| 386 | ASSERT_EQ(secondary_thread_message_loop_.get(), |
| 387 | MessageLoopResource::GetCurrent()); |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | void PluginProxyMultiThreadTest::PostQuitForMainThread() { |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 392 | main_thread_task_runner_->PostTask( |
| 393 | FROM_HERE, base::Bind(&PluginProxyMultiThreadTest::QuitNestedLoop, |
| 394 | base::Unretained(this))); |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | void PluginProxyMultiThreadTest::PostQuitForSecondaryThread() { |
| 398 | ProxyAutoLock auto_lock; |
| 399 | secondary_thread_message_loop_->PostQuit(PP_TRUE); |
| 400 | } |
| 401 | |
| 402 | void PluginProxyMultiThreadTest::Run() { |
| 403 | ProxyAutoLock auto_lock; |
| 404 | ASSERT_EQ(PP_OK, secondary_thread_message_loop_->AttachToCurrentThread()); |
| 405 | ASSERT_EQ(PP_OK, secondary_thread_message_loop_->Run()); |
[email protected] | 1b77701 | 2013-07-15 20:42:38 | [diff] [blame] | 406 | secondary_thread_message_loop_->DetachFromThread(); |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | void PluginProxyMultiThreadTest::QuitNestedLoop() { |
| 410 | nested_main_thread_message_loop_->Quit(); |
| 411 | } |
| 412 | |
| 413 | // static |
| 414 | void PluginProxyMultiThreadTest::InternalSetUpTestOnSecondaryThread( |
| 415 | void* user_data, |
| 416 | int32_t result) { |
| 417 | EXPECT_EQ(PP_OK, result); |
| 418 | PluginProxyMultiThreadTest* thiz = |
| 419 | static_cast<PluginProxyMultiThreadTest*>(user_data); |
| 420 | thiz->CheckOnThread(SECONDARY_THREAD); |
| 421 | thiz->SetUpTestOnSecondaryThread(); |
| 422 | } |
| 423 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 424 | // HostProxyTestHarness -------------------------------------------------------- |
| 425 | |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 426 | HostProxyTestHarness::HostProxyTestHarness(GlobalsConfiguration globals_config) |
dmichael | 6b328f3d | 2014-09-29 23:49:02 | [diff] [blame] | 427 | : globals_config_(globals_config) { |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | HostProxyTestHarness::~HostProxyTestHarness() { |
| 431 | } |
| 432 | |
[email protected] | d57fd38 | 2012-09-19 00:55:42 | [diff] [blame] | 433 | PpapiGlobals* HostProxyTestHarness::GetGlobals() { |
| 434 | return host_globals_.get(); |
| 435 | } |
| 436 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 437 | Dispatcher* HostProxyTestHarness::GetDispatcher() { |
| 438 | return host_dispatcher_.get(); |
| 439 | } |
| 440 | |
| 441 | void HostProxyTestHarness::SetUpHarness() { |
[email protected] | 7309756 | 2012-01-12 19:38:55 | [diff] [blame] | 442 | // These must be first since the dispatcher set-up uses them. |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 443 | CreateHostGlobals(); |
| 444 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 445 | host_dispatcher_.reset(new HostDispatcher( |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 446 | pp_module(), |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 447 | &MockGetInterface, |
[email protected] | 73e20db | 2012-12-12 22:27:06 | [diff] [blame] | 448 | PpapiPermissions::AllPermissions())); |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 449 | host_dispatcher_->InitWithTestSink(&sink()); |
| 450 | HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get()); |
| 451 | } |
| 452 | |
| 453 | void HostProxyTestHarness::SetUpHarnessWithChannel( |
| 454 | const IPC::ChannelHandle& channel_handle, |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 455 | base::SingleThreadTaskRunner* ipc_task_runner, |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 456 | base::WaitableEvent* shutdown_event, |
| 457 | bool is_client) { |
[email protected] | 7309756 | 2012-01-12 19:38:55 | [diff] [blame] | 458 | // These must be first since the dispatcher set-up uses them. |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 459 | CreateHostGlobals(); |
| 460 | |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 461 | delegate_mock_.Init(ipc_task_runner, shutdown_event); |
[email protected] | 7309756 | 2012-01-12 19:38:55 | [diff] [blame] | 462 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 463 | host_dispatcher_.reset(new HostDispatcher( |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 464 | pp_module(), |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 465 | &MockGetInterface, |
[email protected] | 73e20db | 2012-12-12 22:27:06 | [diff] [blame] | 466 | PpapiPermissions::AllPermissions())); |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 467 | ppapi::Preferences preferences; |
Hajime Hoshi | 5959c54f | 2019-01-09 01:42:12 | [diff] [blame^] | 468 | host_dispatcher_->InitHostWithChannel(&delegate_mock_, base::kNullProcessId, |
| 469 | channel_handle, is_client, preferences, |
| 470 | base::ThreadTaskRunnerHandle::Get()); |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 471 | HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get()); |
| 472 | } |
| 473 | |
| 474 | void HostProxyTestHarness::TearDownHarness() { |
| 475 | HostDispatcher::RemoveForInstance(pp_instance()); |
| 476 | host_dispatcher_.reset(); |
[email protected] | d57fd38 | 2012-09-19 00:55:42 | [diff] [blame] | 477 | host_globals_.reset(); |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 478 | } |
| 479 | |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 480 | void HostProxyTestHarness::CreateHostGlobals() { |
dmichael | bd96c1e | 2015-02-12 00:58:08 | [diff] [blame] | 481 | disable_locking_.reset(new ProxyLock::LockingDisablerForTest); |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 482 | if (globals_config_ == PER_THREAD_GLOBALS) { |
| 483 | host_globals_.reset(new TestGlobals(PpapiGlobals::PerThreadForTest())); |
| 484 | PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); |
| 485 | } else { |
| 486 | host_globals_.reset(new TestGlobals()); |
| 487 | } |
| 488 | } |
| 489 | |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 490 | base::SingleThreadTaskRunner* |
| 491 | HostProxyTestHarness::DelegateMock::GetIPCTaskRunner() { |
| 492 | return ipc_task_runner_; |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | base::WaitableEvent* HostProxyTestHarness::DelegateMock::GetShutdownEvent() { |
| 496 | return shutdown_event_; |
| 497 | } |
| 498 | |
[email protected] | f0ecb55 | 2012-05-11 22:09:11 | [diff] [blame] | 499 | IPC::PlatformFileForTransit |
| 500 | HostProxyTestHarness::DelegateMock::ShareHandleWithRemote( |
| 501 | base::PlatformFile handle, |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 502 | base::ProcessId /* remote_pid */, |
[email protected] | f0ecb55 | 2012-05-11 22:09:11 | [diff] [blame] | 503 | bool should_close_source) { |
erikchen | 09b4003 | 2016-04-06 18:51:55 | [diff] [blame] | 504 | return IPC::GetPlatformFileForTransit(handle, |
| 505 | should_close_source); |
[email protected] | f0ecb55 | 2012-05-11 22:09:11 | [diff] [blame] | 506 | } |
| 507 | |
erikchen | 4fc32d5 | 2015-06-02 02:16:38 | [diff] [blame] | 508 | base::SharedMemoryHandle |
| 509 | HostProxyTestHarness::DelegateMock::ShareSharedMemoryHandleWithRemote( |
| 510 | const base::SharedMemoryHandle& handle, |
erikchen | fc29ad99 | 2015-06-04 20:44:18 | [diff] [blame] | 511 | base::ProcessId /*remote_pid*/) { |
| 512 | return base::SharedMemory::DuplicateHandle(handle); |
erikchen | 4fc32d5 | 2015-06-02 02:16:38 | [diff] [blame] | 513 | } |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 514 | |
Alexandr Ilin | c7d975f | 2018-06-01 09:25:41 | [diff] [blame] | 515 | base::UnsafeSharedMemoryRegion |
| 516 | HostProxyTestHarness::DelegateMock::ShareUnsafeSharedMemoryRegionWithRemote( |
| 517 | const base::UnsafeSharedMemoryRegion& region, |
| 518 | base::ProcessId /*remote_pid*/) { |
| 519 | return region.Duplicate(); |
| 520 | } |
| 521 | |
| 522 | base::ReadOnlySharedMemoryRegion |
| 523 | HostProxyTestHarness::DelegateMock::ShareReadOnlySharedMemoryRegionWithRemote( |
| 524 | const base::ReadOnlySharedMemoryRegion& region, |
| 525 | base::ProcessId /*remote_pid*/) { |
| 526 | return region.Duplicate(); |
| 527 | } |
| 528 | |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 529 | // HostProxyTest --------------------------------------------------------------- |
| 530 | |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 531 | HostProxyTest::HostProxyTest() : HostProxyTestHarness(SINGLETON_GLOBALS) { |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | HostProxyTest::~HostProxyTest() { |
| 535 | } |
| 536 | |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 537 | void HostProxyTest::SetUp() { |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 538 | SetUpHarness(); |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | void HostProxyTest::TearDown() { |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 542 | TearDownHarness(); |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 543 | } |
| 544 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 545 | // TwoWayTest --------------------------------------------------------------- |
| 546 | |
| 547 | TwoWayTest::TwoWayTest(TwoWayTest::TwoWayTestMode test_mode) |
| 548 | : test_mode_(test_mode), |
[email protected] | 7ef6b79b | 2013-01-17 02:38:24 | [diff] [blame] | 549 | host_(ProxyTestHarnessBase::PER_THREAD_GLOBALS), |
| 550 | plugin_(ProxyTestHarnessBase::PER_THREAD_GLOBALS), |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 551 | io_thread_("TwoWayTest_IOThread"), |
| 552 | plugin_thread_("TwoWayTest_PluginThread"), |
| 553 | remote_harness_(NULL), |
| 554 | local_harness_(NULL), |
gab | f40c0a5e | 2016-06-01 20:10:46 | [diff] [blame] | 555 | channel_created_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 556 | base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 557 | shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 558 | base::WaitableEvent::InitialState::NOT_SIGNALED) { |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 559 | if (test_mode == TEST_PPP_INTERFACE) { |
| 560 | remote_harness_ = &plugin_; |
| 561 | local_harness_ = &host_; |
| 562 | } else { |
| 563 | remote_harness_ = &host_; |
| 564 | local_harness_ = &plugin_; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | TwoWayTest::~TwoWayTest() { |
| 569 | shutdown_event_.Signal(); |
| 570 | } |
| 571 | |
| 572 | void TwoWayTest::SetUp() { |
| 573 | base::Thread::Options options; |
[email protected] | d2881d8 | 2013-05-06 19:23:08 | [diff] [blame] | 574 | options.message_loop_type = base::MessageLoop::TYPE_IO; |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 575 | io_thread_.StartWithOptions(options); |
| 576 | plugin_thread_.Start(); |
| 577 | |
sammc | 9bf370c | 2016-11-14 03:29:08 | [diff] [blame] | 578 | mojo::MessagePipe pipe; |
gab | f40c0a5e | 2016-06-01 20:10:46 | [diff] [blame] | 579 | base::WaitableEvent remote_harness_set_up( |
| 580 | base::WaitableEvent::ResetPolicy::MANUAL, |
| 581 | base::WaitableEvent::InitialState::NOT_SIGNALED); |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 582 | plugin_thread_.task_runner()->PostTask( |
sammc | 9bf370c | 2016-11-14 03:29:08 | [diff] [blame] | 583 | FROM_HERE, |
| 584 | base::Bind(&SetUpRemoteHarness, remote_harness_, pipe.handle0.release(), |
| 585 | base::RetainedRef(io_thread_.task_runner()), &shutdown_event_, |
| 586 | &remote_harness_set_up)); |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 587 | remote_harness_set_up.Wait(); |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 588 | local_harness_->SetUpHarnessWithChannel( |
sammc | 9bf370c | 2016-11-14 03:29:08 | [diff] [blame] | 589 | pipe.handle1.release(), io_thread_.task_runner().get(), &shutdown_event_, |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 590 | true); // is_client |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | void TwoWayTest::TearDown() { |
gab | f40c0a5e | 2016-06-01 20:10:46 | [diff] [blame] | 594 | base::WaitableEvent remote_harness_torn_down( |
| 595 | base::WaitableEvent::ResetPolicy::MANUAL, |
| 596 | base::WaitableEvent::InitialState::NOT_SIGNALED); |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 597 | plugin_thread_.task_runner()->PostTask( |
| 598 | FROM_HERE, base::Bind(&TearDownRemoteHarness, remote_harness_, |
| 599 | &remote_harness_torn_down)); |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 600 | remote_harness_torn_down.Wait(); |
| 601 | |
| 602 | local_harness_->TearDownHarness(); |
| 603 | |
| 604 | io_thread_.Stop(); |
| 605 | } |
| 606 | |
[email protected] | d57fd38 | 2012-09-19 00:55:42 | [diff] [blame] | 607 | void TwoWayTest::PostTaskOnRemoteHarness(const base::Closure& task) { |
gab | f40c0a5e | 2016-06-01 20:10:46 | [diff] [blame] | 608 | base::WaitableEvent task_complete( |
| 609 | base::WaitableEvent::ResetPolicy::MANUAL, |
| 610 | base::WaitableEvent::InitialState::NOT_SIGNALED); |
skyostil | 23490d4 | 2015-06-12 12:54:26 | [diff] [blame] | 611 | plugin_thread_.task_runner()->PostTask( |
| 612 | FROM_HERE, base::Bind(&RunTaskOnRemoteHarness, task, &task_complete)); |
[email protected] | d57fd38 | 2012-09-19 00:55:42 | [diff] [blame] | 613 | task_complete.Wait(); |
| 614 | } |
| 615 | |
| 616 | |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 617 | } // namespace proxy |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 618 | } // namespace ppapi |