OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/process.h" | 6 #include "base/process.h" |
7 #include "ppapi/proxy/mock_resource.h" | 7 #include "ppapi/proxy/mock_resource.h" |
8 #include "ppapi/proxy/plugin_dispatcher.h" | 8 #include "ppapi/proxy/plugin_dispatcher.h" |
9 #include "ppapi/proxy/plugin_resource_tracker.h" | 9 #include "ppapi/proxy/plugin_resource_tracker.h" |
10 #include "ppapi/proxy/ppapi_messages.h" | 10 #include "ppapi/proxy/ppapi_messages.h" |
11 #include "ppapi/proxy/ppapi_proxy_test.h" | 11 #include "ppapi/proxy/ppapi_proxy_test.h" |
12 #include "ppapi/shared_impl/proxy_lock.h" | |
13 | 12 |
14 namespace ppapi { | 13 namespace ppapi { |
15 namespace proxy { | 14 namespace proxy { |
16 | 15 |
17 namespace { | 16 namespace { |
18 | 17 |
19 // Object so we know when a resource has been released. | 18 // Object so we know when a resource has been released. |
20 class TrackedMockResource : public MockResource { | 19 class TrackedMockResource : public MockResource { |
21 public: | 20 public: |
22 TrackedMockResource(const HostResource& serialized) | 21 TrackedMockResource(const HostResource& serialized) |
(...skipping 11 matching lines...) Expand all Loading... |
34 | 33 |
35 } // namespace | 34 } // namespace |
36 | 35 |
37 class PluginResourceTrackerTest : public PluginProxyTest { | 36 class PluginResourceTrackerTest : public PluginProxyTest { |
38 public: | 37 public: |
39 PluginResourceTrackerTest() {} | 38 PluginResourceTrackerTest() {} |
40 ~PluginResourceTrackerTest() {} | 39 ~PluginResourceTrackerTest() {} |
41 }; | 40 }; |
42 | 41 |
43 TEST_F(PluginResourceTrackerTest, PluginResourceForHostResource) { | 42 TEST_F(PluginResourceTrackerTest, PluginResourceForHostResource) { |
44 ProxyAutoLock lock; | |
45 | |
46 PP_Resource host_resource = 0x5678; | 43 PP_Resource host_resource = 0x5678; |
47 | 44 |
48 HostResource serialized; | 45 HostResource serialized; |
49 serialized.SetHostResource(pp_instance(), host_resource); | 46 serialized.SetHostResource(pp_instance(), host_resource); |
50 | 47 |
51 // When we haven't added an object, the return value should be 0. | 48 // When we haven't added an object, the return value should be 0. |
52 EXPECT_EQ(0, resource_tracker().PluginResourceForHostResource(serialized)); | 49 EXPECT_EQ(0, resource_tracker().PluginResourceForHostResource(serialized)); |
53 | 50 |
54 EXPECT_EQ(0, TrackedMockResource::tracked_alive_count); | 51 EXPECT_EQ(0, TrackedMockResource::tracked_alive_count); |
55 TrackedMockResource* object = new TrackedMockResource(serialized); | 52 TrackedMockResource* object = new TrackedMockResource(serialized); |
56 EXPECT_EQ(1, TrackedMockResource::tracked_alive_count); | 53 EXPECT_EQ(1, TrackedMockResource::tracked_alive_count); |
57 PP_Resource plugin_resource = object->GetReference(); | 54 PP_Resource plugin_resource = object->GetReference(); |
58 | 55 |
59 // Now that the object has been added, the return value should be the plugin | 56 // Now that the object has been added, the return value should be the plugin |
60 // resource ID we already got. | 57 // resource ID we already got. |
61 EXPECT_EQ(plugin_resource, | 58 EXPECT_EQ(plugin_resource, |
62 resource_tracker().PluginResourceForHostResource(serialized)); | 59 resource_tracker().PluginResourceForHostResource(serialized)); |
63 | 60 |
64 // Releasing the resource should have freed it. | 61 // Releasing the resource should have freed it. |
65 resource_tracker().ReleaseResource(plugin_resource); | 62 resource_tracker().ReleaseResource(plugin_resource); |
66 EXPECT_EQ(0, TrackedMockResource::tracked_alive_count); | 63 EXPECT_EQ(0, TrackedMockResource::tracked_alive_count); |
67 EXPECT_EQ(0, resource_tracker().PluginResourceForHostResource(serialized)); | 64 EXPECT_EQ(0, resource_tracker().PluginResourceForHostResource(serialized)); |
68 } | 65 } |
69 | 66 |
70 } // namespace proxy | 67 } // namespace proxy |
71 } // namespace ppapi | 68 } // namespace ppapi |
OLD | NEW |