[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 5 | #include "ipc/ipc_message_utils.h" |
| 6 | #include "ppapi/c/ppb_audio.h" |
| 7 | #include "ppapi/c/ppp_instance.h" |
| 8 | #include "ppapi/proxy/ppapi_messages.h" |
| 9 | #include "ppapi/proxy/ppapi_proxy_test.h" |
| 10 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 11 | namespace ppapi { |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 12 | namespace proxy { |
| 13 | |
| 14 | namespace { |
| 15 | |
| 16 | bool received_create = false; |
| 17 | |
| 18 | // Implement PPB_Audio since it's a relatively simple PPB interface and |
| 19 | // includes bidirectional communication. |
| 20 | PP_Resource Create(PP_Instance instance, PP_Resource config, |
| 21 | PPB_Audio_Callback audio_callback, void* user_data) { |
| 22 | received_create = true; |
| 23 | return 0; |
| 24 | } |
| 25 | PP_Bool IsAudio(PP_Resource resource) { |
| 26 | return PP_FALSE; |
| 27 | } |
| 28 | PP_Resource GetCurrentConfig(PP_Resource audio) { |
| 29 | return 0; |
| 30 | } |
| 31 | PP_Bool StartPlayback(PP_Resource audio) { |
| 32 | return PP_FALSE; |
| 33 | } |
| 34 | PP_Bool StopPlayback(PP_Resource audio) { |
| 35 | return PP_FALSE; |
| 36 | } |
| 37 | |
| 38 | PPB_Audio dummy_audio_interface = { |
| 39 | &Create, |
| 40 | &IsAudio, |
| 41 | &GetCurrentConfig, |
| 42 | &StartPlayback, |
| 43 | &StopPlayback |
| 44 | }; |
| 45 | |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 46 | PPP_Instance dummy_ppp_instance_interface = {}; |
| 47 | |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 48 | } // namespace |
| 49 | |
| 50 | class PluginDispatcherTest : public PluginProxyTest { |
| 51 | public: |
| 52 | PluginDispatcherTest() {} |
| 53 | |
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 54 | bool HasTargetProxy(ApiID id) { |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 55 | return !!plugin_dispatcher()->proxies_[id].get(); |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 56 | } |
| 57 | }; |
| 58 | |
| 59 | TEST_F(PluginDispatcherTest, SupportsInterface) { |
| 60 | RegisterTestInterface(PPB_AUDIO_INTERFACE, &dummy_audio_interface); |
[email protected] | 912f3d6c | 2011-06-29 18:26:36 | [diff] [blame] | 61 | RegisterTestInterface(PPP_INSTANCE_INTERFACE, &dummy_ppp_instance_interface); |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 62 | |
| 63 | // Sending a request for a random interface should fail. |
kareng | 1c62eeb | 2014-11-08 16:35:03 | [diff] [blame] | 64 | EXPECT_FALSE(SupportsInterface("Random interface")); |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 65 | |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 66 | // Sending a request for a supported PPP interface should succeed. |
kareng | 1c62eeb | 2014-11-08 16:35:03 | [diff] [blame] | 67 | EXPECT_TRUE(SupportsInterface(PPP_INSTANCE_INTERFACE)); |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | TEST_F(PluginDispatcherTest, PPBCreation) { |
| 71 | // Sending a PPB message out of the blue should create a target proxy for |
| 72 | // that interface in the plugin. |
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 73 | EXPECT_FALSE(HasTargetProxy(API_ID_PPB_AUDIO)); |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 74 | PpapiMsg_PPBAudio_NotifyAudioStreamCreated audio_msg( |
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 75 | API_ID_PPB_AUDIO, HostResource(), 0, |
Alexandr Ilin | 20f2841c | 2018-06-01 11:56:18 | [diff] [blame] | 76 | ppapi::proxy::SerializedHandle(ppapi::proxy::SerializedHandle::SOCKET), |
[email protected] | 246fc49 | 2012-08-27 20:28:18 | [diff] [blame] | 77 | ppapi::proxy::SerializedHandle( |
Alexandr Ilin | 20f2841c | 2018-06-01 11:56:18 | [diff] [blame] | 78 | ppapi::proxy::SerializedHandle::SHARED_MEMORY_REGION)); |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 79 | plugin_dispatcher()->OnMessageReceived(audio_msg); |
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 80 | EXPECT_TRUE(HasTargetProxy(API_ID_PPB_AUDIO)); |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | } // namespace proxy |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 84 | } // namespace ppapi |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 85 | |