blob: 56f563bd9309ff6d9439f6e512c143655ac5222a [file] [log] [blame]
[email protected]465faa22011-02-08 16:31:461// 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]3b63f8f42011-03-28 01:54:155#include "base/memory/scoped_ptr.h"
[email protected]465faa22011-02-08 16:31:466#include "ipc/ipc_message_utils.h"
7#include "ppapi/c/ppb_audio.h"
8#include "ppapi/c/ppp_instance.h"
9#include "ppapi/proxy/ppapi_messages.h"
10#include "ppapi/proxy/ppapi_proxy_test.h"
11
[email protected]4d2efd22011-08-18 21:58:0212namespace ppapi {
[email protected]465faa22011-02-08 16:31:4613namespace proxy {
14
15namespace {
16
17bool received_create = false;
18
19// Implement PPB_Audio since it's a relatively simple PPB interface and
20// includes bidirectional communication.
21PP_Resource Create(PP_Instance instance, PP_Resource config,
22 PPB_Audio_Callback audio_callback, void* user_data) {
23 received_create = true;
24 return 0;
25}
26PP_Bool IsAudio(PP_Resource resource) {
27 return PP_FALSE;
28}
29PP_Resource GetCurrentConfig(PP_Resource audio) {
30 return 0;
31}
32PP_Bool StartPlayback(PP_Resource audio) {
33 return PP_FALSE;
34}
35PP_Bool StopPlayback(PP_Resource audio) {
36 return PP_FALSE;
37}
38
39PPB_Audio dummy_audio_interface = {
40 &Create,
41 &IsAudio,
42 &GetCurrentConfig,
43 &StartPlayback,
44 &StopPlayback
45};
46
[email protected]912f3d6c2011-06-29 18:26:3647PPP_Instance dummy_ppp_instance_interface = {};
48
[email protected]465faa22011-02-08 16:31:4649} // namespace
50
51class PluginDispatcherTest : public PluginProxyTest {
52 public:
53 PluginDispatcherTest() {}
54
55 bool HasTargetProxy(InterfaceID id) {
56 return !!plugin_dispatcher()->target_proxies_[id].get();
57 }
58};
59
60TEST_F(PluginDispatcherTest, SupportsInterface) {
61 RegisterTestInterface(PPB_AUDIO_INTERFACE, &dummy_audio_interface);
[email protected]912f3d6c2011-06-29 18:26:3662 RegisterTestInterface(PPP_INSTANCE_INTERFACE, &dummy_ppp_instance_interface);
[email protected]465faa22011-02-08 16:31:4663
64 // Sending a request for a random interface should fail.
65 EXPECT_FALSE(SupportsInterface("Random interface"));
66
67 // Sending a request for a PPB interface should fail even though we've
68 // registered it as existing in the GetInterface function (the plugin proxy
69 // should only respond to PPP interfaces when asked if it supports them).
70 EXPECT_FALSE(SupportsInterface(PPB_AUDIO_INTERFACE));
71
72 // Sending a request for a supported PPP interface should succeed.
73 EXPECT_TRUE(SupportsInterface(PPP_INSTANCE_INTERFACE));
74}
75
76TEST_F(PluginDispatcherTest, PPBCreation) {
77 // Sending a PPB message out of the blue should create a target proxy for
78 // that interface in the plugin.
79 EXPECT_FALSE(HasTargetProxy(INTERFACE_ID_PPB_AUDIO));
80 PpapiMsg_PPBAudio_NotifyAudioStreamCreated audio_msg(
81 INTERFACE_ID_PPB_AUDIO, HostResource(), 0,
82 IPC::PlatformFileForTransit(), base::SharedMemoryHandle(), 0);
83 plugin_dispatcher()->OnMessageReceived(audio_msg);
84 EXPECT_TRUE(HasTargetProxy(INTERFACE_ID_PPB_AUDIO));
85}
86
87} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:0288} // namespace ppapi
[email protected]465faa22011-02-08 16:31:4689