1 // Copyright (c) 2013 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 "ppapi/c/ppb_core.h"
6 #include "ppapi/proxy/interface_list.h"
7 #include "ppapi/proxy/ppapi_proxy_test.h"
12 class InterfaceListTest
: public PluginProxyTest
{
14 // Wrapper function so we can use the private InterfaceList::AddPPB.
15 void AddPPB(InterfaceList
* list
,
16 const char* iface_name
, void* iface_addr
, Permission perm
) {
17 list
->AddPPB(iface_name
, iface_addr
, perm
);
21 // Tests looking up a stable interface.
22 TEST_F(InterfaceListTest
, Stable
) {
24 ASSERT_TRUE(list
.GetInterfaceForPPB(PPB_CORE_INTERFACE_1_0
) != NULL
);
25 ASSERT_TRUE(list
.GetInterfaceForPPB("FakeUnknownInterface") == NULL
);
28 // Tests that dev channel restrictions work properly.
29 TEST_F(InterfaceListTest
, DevChannel
) {
31 // "Dev channel" interface.
32 static const char* dev_channel_iface_name
= "TestDevChannelInterface";
33 void* dev_channel_iface_addr
= (void*)0xdeadbeef;
35 static const char* dev_iface_name
= "TestDevInterface";
36 void* dev_iface_addr
= (void*)0xcafefade;
38 AddPPB(&list
, dev_channel_iface_name
, dev_channel_iface_addr
,
39 PERMISSION_DEV_CHANNEL
);
40 AddPPB(&list
, dev_iface_name
, dev_iface_addr
, PERMISSION_DEV
);
42 InterfaceList::SetProcessGlobalPermissions(
43 PpapiPermissions(PERMISSION_NONE
));
44 ASSERT_TRUE(list
.GetInterfaceForPPB(dev_channel_iface_name
) == NULL
);
45 ASSERT_TRUE(list
.GetInterfaceForPPB(dev_iface_name
) == NULL
);
47 InterfaceList::SetProcessGlobalPermissions(
48 PpapiPermissions(PERMISSION_DEV_CHANNEL
));
49 ASSERT_TRUE(list
.GetInterfaceForPPB(dev_channel_iface_name
) ==
50 dev_channel_iface_addr
);
51 ASSERT_TRUE(list
.GetInterfaceForPPB(dev_iface_name
) == NULL
);
53 InterfaceList::SetProcessGlobalPermissions(
54 PpapiPermissions(PERMISSION_DEV
));
55 ASSERT_TRUE(list
.GetInterfaceForPPB(dev_channel_iface_name
) == NULL
);
56 ASSERT_TRUE(list
.GetInterfaceForPPB(dev_iface_name
) == dev_iface_addr
);
58 InterfaceList::SetProcessGlobalPermissions(
59 PpapiPermissions(PERMISSION_DEV
| PERMISSION_DEV_CHANNEL
));
60 ASSERT_TRUE(list
.GetInterfaceForPPB(dev_channel_iface_name
) ==
61 dev_channel_iface_addr
);
62 ASSERT_TRUE(list
.GetInterfaceForPPB(dev_iface_name
) == dev_iface_addr
);