Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ppapi / proxy / plugin_dispatcher_unittest.cc
blob821ecad3799c3441408892e81697ffab7041ce54
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.
5 #include "base/memory/scoped_ptr.h"
6 #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"
12 namespace ppapi {
13 namespace proxy {
15 namespace {
17 bool received_create = false;
19 // Implement PPB_Audio since it's a relatively simple PPB interface and
20 // includes bidirectional communication.
21 PP_Resource Create(PP_Instance instance, PP_Resource config,
22 PPB_Audio_Callback audio_callback, void* user_data) {
23 received_create = true;
24 return 0;
26 PP_Bool IsAudio(PP_Resource resource) {
27 return PP_FALSE;
29 PP_Resource GetCurrentConfig(PP_Resource audio) {
30 return 0;
32 PP_Bool StartPlayback(PP_Resource audio) {
33 return PP_FALSE;
35 PP_Bool StopPlayback(PP_Resource audio) {
36 return PP_FALSE;
39 PPB_Audio dummy_audio_interface = {
40 &Create,
41 &IsAudio,
42 &GetCurrentConfig,
43 &StartPlayback,
44 &StopPlayback
47 PPP_Instance dummy_ppp_instance_interface = {};
49 } // namespace
51 class PluginDispatcherTest : public PluginProxyTest {
52 public:
53 PluginDispatcherTest() {}
55 bool HasTargetProxy(ApiID id) {
56 return !!plugin_dispatcher()->proxies_[id].get();
60 TEST_F(PluginDispatcherTest, SupportsInterface) {
61 RegisterTestInterface(PPB_AUDIO_INTERFACE, &dummy_audio_interface);
62 RegisterTestInterface(PPP_INSTANCE_INTERFACE, &dummy_ppp_instance_interface);
64 // Sending a request for a random interface should fail.
65 EXPECT_FALSE(SupportsInterface("Random interface"));
67 // Sending a request for a supported PPP interface should succeed.
68 EXPECT_TRUE(SupportsInterface(PPP_INSTANCE_INTERFACE));
71 TEST_F(PluginDispatcherTest, PPBCreation) {
72 // Sending a PPB message out of the blue should create a target proxy for
73 // that interface in the plugin.
74 EXPECT_FALSE(HasTargetProxy(API_ID_PPB_AUDIO));
75 PpapiMsg_PPBAudio_NotifyAudioStreamCreated audio_msg(
76 API_ID_PPB_AUDIO, HostResource(), 0,
77 ppapi::proxy::SerializedHandle(
78 ppapi::proxy::SerializedHandle::SOCKET),
79 ppapi::proxy::SerializedHandle(
80 ppapi::proxy::SerializedHandle::SHARED_MEMORY));
81 plugin_dispatcher()->OnMessageReceived(audio_msg);
82 EXPECT_TRUE(HasTargetProxy(API_ID_PPB_AUDIO));
85 } // namespace proxy
86 } // namespace ppapi