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" |
12 | 13 |
13 namespace ppapi { | 14 namespace ppapi { |
14 namespace proxy { | 15 namespace proxy { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // Object so we know when a resource has been released. | 19 // Object so we know when a resource has been released. |
19 class TrackedMockResource : public MockResource { | 20 class TrackedMockResource : public MockResource { |
20 public: | 21 public: |
21 TrackedMockResource(const HostResource& serialized) | 22 TrackedMockResource(const HostResource& serialized) |
(...skipping 11 matching lines...) Expand all Loading... |
33 | 34 |
34 } // namespace | 35 } // namespace |
35 | 36 |
36 class PluginResourceTrackerTest : public PluginProxyTest { | 37 class PluginResourceTrackerTest : public PluginProxyTest { |
37 public: | 38 public: |
38 PluginResourceTrackerTest() {} | 39 PluginResourceTrackerTest() {} |
39 ~PluginResourceTrackerTest() {} | 40 ~PluginResourceTrackerTest() {} |
40 }; | 41 }; |
41 | 42 |
42 TEST_F(PluginResourceTrackerTest, PluginResourceForHostResource) { | 43 TEST_F(PluginResourceTrackerTest, PluginResourceForHostResource) { |
| 44 ProxyAutoLock lock; |
| 45 |
43 PP_Resource host_resource = 0x5678; | 46 PP_Resource host_resource = 0x5678; |
44 | 47 |
45 HostResource serialized; | 48 HostResource serialized; |
46 serialized.SetHostResource(pp_instance(), host_resource); | 49 serialized.SetHostResource(pp_instance(), host_resource); |
47 | 50 |
48 // When we haven't added an object, the return value should be 0. | 51 // When we haven't added an object, the return value should be 0. |
49 EXPECT_EQ(0, resource_tracker().PluginResourceForHostResource(serialized)); | 52 EXPECT_EQ(0, resource_tracker().PluginResourceForHostResource(serialized)); |
50 | 53 |
51 EXPECT_EQ(0, TrackedMockResource::tracked_alive_count); | 54 EXPECT_EQ(0, TrackedMockResource::tracked_alive_count); |
52 TrackedMockResource* object = new TrackedMockResource(serialized); | 55 TrackedMockResource* object = new TrackedMockResource(serialized); |
53 EXPECT_EQ(1, TrackedMockResource::tracked_alive_count); | 56 EXPECT_EQ(1, TrackedMockResource::tracked_alive_count); |
54 PP_Resource plugin_resource = object->GetReference(); | 57 PP_Resource plugin_resource = object->GetReference(); |
55 | 58 |
56 // Now that the object has been added, the return value should be the plugin | 59 // Now that the object has been added, the return value should be the plugin |
57 // resource ID we already got. | 60 // resource ID we already got. |
58 EXPECT_EQ(plugin_resource, | 61 EXPECT_EQ(plugin_resource, |
59 resource_tracker().PluginResourceForHostResource(serialized)); | 62 resource_tracker().PluginResourceForHostResource(serialized)); |
60 | 63 |
61 // Releasing the resource should have freed it. | 64 // Releasing the resource should have freed it. |
62 resource_tracker().ReleaseResource(plugin_resource); | 65 resource_tracker().ReleaseResource(plugin_resource); |
63 EXPECT_EQ(0, TrackedMockResource::tracked_alive_count); | 66 EXPECT_EQ(0, TrackedMockResource::tracked_alive_count); |
64 EXPECT_EQ(0, resource_tracker().PluginResourceForHostResource(serialized)); | 67 EXPECT_EQ(0, resource_tracker().PluginResourceForHostResource(serialized)); |
65 } | 68 } |
66 | 69 |
67 } // namespace proxy | 70 } // namespace proxy |
68 } // namespace ppapi | 71 } // namespace ppapi |
OLD | NEW |