OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/pepper/host_globals.h" | 6 #include "content/renderer/pepper/host_globals.h" |
7 #include "content/renderer/pepper/host_var_tracker.h" | 7 #include "content/renderer/pepper/host_var_tracker.h" |
8 #include "content/renderer/pepper/mock_resource.h" | 8 #include "content/renderer/pepper/mock_resource.h" |
9 #include "content/renderer/pepper/npapi_glue.h" | 9 #include "content/renderer/pepper/npapi_glue.h" |
10 #include "content/renderer/pepper/npobject_var.h" | 10 #include "content/renderer/pepper/npobject_var.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // in a NPObjectReleaser to free this ref when the test completes. | 49 // in a NPObjectReleaser to free this ref when the test completes. |
50 NPObject* NewTrackedNPObject() { | 50 NPObject* NewTrackedNPObject() { |
51 NPObject* object = new NPObject; | 51 NPObject* object = new NPObject; |
52 object->_class = &g_tracked_npclass; | 52 object->_class = &g_tracked_npclass; |
53 object->referenceCount = 1; | 53 object->referenceCount = 1; |
54 | 54 |
55 g_npobjects_alive++; | 55 g_npobjects_alive++; |
56 return object; | 56 return object; |
57 } | 57 } |
58 | 58 |
59 class ReleaseNPObject { | 59 struct ReleaseNPObject { |
60 public: | |
61 void operator()(NPObject* o) const { | 60 void operator()(NPObject* o) const { |
62 blink::WebBindings::releaseObject(o); | 61 blink::WebBindings::releaseObject(o); |
63 } | 62 } |
64 }; | 63 }; |
65 | 64 |
66 // Handles automatically releasing a reference to the NPObject on destruction. | 65 // Handles automatically releasing a reference to the NPObject on destruction. |
67 // It's assumed the input has a ref already taken. | 66 // It's assumed the input has a ref already taken. |
68 typedef scoped_ptr_malloc<NPObject, ReleaseNPObject> NPObjectReleaser; | 67 typedef scoped_ptr<NPObject, ReleaseNPObject> NPObjectReleaser; |
69 | 68 |
70 } // namespace | 69 } // namespace |
71 | 70 |
72 class HostVarTrackerTest : public PpapiUnittest { | 71 class HostVarTrackerTest : public PpapiUnittest { |
73 public: | 72 public: |
74 HostVarTrackerTest() { | 73 HostVarTrackerTest() { |
75 } | 74 } |
76 | 75 |
77 HostVarTracker& tracker() { | 76 HostVarTracker& tracker() { |
78 return *HostGlobals::Get()->host_var_tracker(); | 77 return *HostGlobals::Get()->host_var_tracker(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object1.value.as_id)); | 124 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object1.value.as_id)); |
126 | 125 |
127 // Releasing the resource should free the internal ref, and so making a new | 126 // Releasing the resource should free the internal ref, and so making a new |
128 // one now should generate a new ID. | 127 // one now should generate a new ID. |
129 PP_Var pp_object3 = NPObjectToPPVarForTest(instance(), npobject.get()); | 128 PP_Var pp_object3 = NPObjectToPPVarForTest(instance(), npobject.get()); |
130 EXPECT_NE(pp_object1.value.as_id, pp_object3.value.as_id); | 129 EXPECT_NE(pp_object1.value.as_id, pp_object3.value.as_id); |
131 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object3.value.as_id)); | 130 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object3.value.as_id)); |
132 } | 131 } |
133 | 132 |
134 } // namespace content | 133 } // namespace content |
OLD | NEW |