Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ppapi / proxy / interface_list_unittest.cc
blob902a0a18a4a113d7f2bb9b8e49721094e7c39f3e
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 "base/hash.h"
6 #include "ppapi/c/ppb_core.h"
7 #include "ppapi/proxy/interface_list.h"
8 #include "ppapi/proxy/ppapi_proxy_test.h"
10 namespace ppapi {
11 namespace proxy {
13 class InterfaceListTest : public PluginProxyTest {
14 public:
15 // Wrapper function so we can use the private InterfaceList::AddPPB.
16 void AddPPB(InterfaceList* list,
17 const char* iface_name, void* iface_addr, Permission perm) {
18 list->AddPPB(iface_name, iface_addr, perm);
21 // Wrapper function so we can use the private
22 // InterfaceList::HashInterfaceName.
23 int HashInterfaceName(const std::string& name) {
24 return InterfaceList::HashInterfaceName(name);
28 // Tests looking up a stable interface.
29 TEST_F(InterfaceListTest, Stable) {
30 InterfaceList list;
31 ASSERT_TRUE(list.GetInterfaceForPPB(PPB_CORE_INTERFACE_1_0) != NULL);
32 ASSERT_TRUE(list.GetInterfaceForPPB("FakeUnknownInterface") == NULL);
35 // Tests that dev channel restrictions work properly.
36 TEST_F(InterfaceListTest, DevChannel) {
37 InterfaceList list;
38 // "Dev channel" interface.
39 static const char* dev_channel_iface_name = "TestDevChannelInterface";
40 void* dev_channel_iface_addr = (void*)0xdeadbeef;
41 // "Dev" interface
42 static const char* dev_iface_name = "TestDevInterface";
43 void* dev_iface_addr = (void*)0xcafefade;
45 AddPPB(&list, dev_channel_iface_name, dev_channel_iface_addr,
46 PERMISSION_DEV_CHANNEL);
47 AddPPB(&list, dev_iface_name, dev_iface_addr, PERMISSION_DEV);
49 InterfaceList::SetProcessGlobalPermissions(
50 PpapiPermissions(PERMISSION_NONE));
51 ASSERT_TRUE(list.GetInterfaceForPPB(dev_channel_iface_name) == NULL);
52 ASSERT_TRUE(list.GetInterfaceForPPB(dev_iface_name) == NULL);
54 InterfaceList::SetProcessGlobalPermissions(
55 PpapiPermissions(PERMISSION_DEV_CHANNEL));
56 ASSERT_TRUE(list.GetInterfaceForPPB(dev_channel_iface_name) ==
57 dev_channel_iface_addr);
58 ASSERT_TRUE(list.GetInterfaceForPPB(dev_iface_name) == NULL);
60 InterfaceList::SetProcessGlobalPermissions(
61 PpapiPermissions(PERMISSION_DEV));
62 ASSERT_TRUE(list.GetInterfaceForPPB(dev_channel_iface_name) == NULL);
63 ASSERT_TRUE(list.GetInterfaceForPPB(dev_iface_name) == dev_iface_addr);
65 InterfaceList::SetProcessGlobalPermissions(
66 PpapiPermissions(PERMISSION_DEV | PERMISSION_DEV_CHANNEL));
67 ASSERT_TRUE(list.GetInterfaceForPPB(dev_channel_iface_name) ==
68 dev_channel_iface_addr);
69 ASSERT_TRUE(list.GetInterfaceForPPB(dev_iface_name) == dev_iface_addr);
72 // Test that the hash function provided by base::Hash is unchanged. This is so
73 // that we will generate correct values when logging interface use to UMA.
74 TEST_F(InterfaceListTest, InterfaceHash) {
75 EXPECT_EQ(612625164, HashInterfaceName("PPB_InputEvent;1.0"));
76 EXPECT_EQ(79708274, HashInterfaceName("PPB_TCPSocket;1.1"));
79 } // namespace proxy
80 } // namespace ppapi