Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: content/renderer/pepper/host_var_tracker_unittest.cc

Issue 225903006: PPAPI: Run clang_format.py on content/renderer/pepper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 13 matching lines...) Expand all
24 // Tracked NPObjects ----------------------------------------------------------- 24 // Tracked NPObjects -----------------------------------------------------------
25 25
26 int g_npobjects_alive = 0; 26 int g_npobjects_alive = 0;
27 27
28 void TrackedClassDeallocate(NPObject* npobject) { 28 void TrackedClassDeallocate(NPObject* npobject) {
29 g_npobjects_alive--; 29 g_npobjects_alive--;
30 delete npobject; 30 delete npobject;
31 } 31 }
32 32
33 NPClass g_tracked_npclass = { 33 NPClass g_tracked_npclass = {
34 NP_CLASS_STRUCT_VERSION, 34 NP_CLASS_STRUCT_VERSION, NULL, &TrackedClassDeallocate, NULL, NULL, NULL,
35 NULL, 35 NULL, NULL, NULL, NULL, NULL, NULL, };
bbudge 2014/04/07 17:02:17 Kind of strange formatting.
36 &TrackedClassDeallocate,
37 NULL,
38 NULL,
39 NULL,
40 NULL,
41 NULL,
42 NULL,
43 NULL,
44 NULL,
45 NULL,
46 };
47 36
48 // Returns a new tracked NPObject with a refcount of 1. You'll want to put this 37 // Returns a new tracked NPObject with a refcount of 1. You'll want to put this
49 // in a NPObjectReleaser to free this ref when the test completes. 38 // in a NPObjectReleaser to free this ref when the test completes.
50 NPObject* NewTrackedNPObject() { 39 NPObject* NewTrackedNPObject() {
51 NPObject* object = new NPObject; 40 NPObject* object = new NPObject;
52 object->_class = &g_tracked_npclass; 41 object->_class = &g_tracked_npclass;
53 object->referenceCount = 1; 42 object->referenceCount = 1;
54 43
55 g_npobjects_alive++; 44 g_npobjects_alive++;
56 return object; 45 return object;
57 } 46 }
58 47
59 struct ReleaseNPObject { 48 struct ReleaseNPObject {
60 void operator()(NPObject* o) const { 49 void operator()(NPObject* o) const { blink::WebBindings::releaseObject(o); }
61 blink::WebBindings::releaseObject(o);
62 }
63 }; 50 };
64 51
65 // Handles automatically releasing a reference to the NPObject on destruction. 52 // Handles automatically releasing a reference to the NPObject on destruction.
66 // It's assumed the input has a ref already taken. 53 // It's assumed the input has a ref already taken.
67 typedef scoped_ptr<NPObject, ReleaseNPObject> NPObjectReleaser; 54 typedef scoped_ptr<NPObject, ReleaseNPObject> NPObjectReleaser;
68 55
69 } // namespace 56 } // namespace
70 57
71 class HostVarTrackerTest : public PpapiUnittest { 58 class HostVarTrackerTest : public PpapiUnittest {
72 public: 59 public:
73 HostVarTrackerTest() { 60 HostVarTrackerTest() {}
74 }
75 61
76 HostVarTracker& tracker() { 62 HostVarTracker& tracker() { return *HostGlobals::Get()->host_var_tracker(); }
77 return *HostGlobals::Get()->host_var_tracker();
78 }
79 }; 63 };
80 64
81 TEST_F(HostVarTrackerTest, DeleteObjectVarWithInstance) { 65 TEST_F(HostVarTrackerTest, DeleteObjectVarWithInstance) {
82 // Make a second instance (the test harness already creates & manages one). 66 // Make a second instance (the test harness already creates & manages one).
83 scoped_refptr<PepperPluginInstanceImpl> instance2( 67 scoped_refptr<PepperPluginInstanceImpl> instance2(
84 PepperPluginInstanceImpl::Create(NULL, module(), NULL, GURL())); 68 PepperPluginInstanceImpl::Create(NULL, module(), NULL, GURL()));
85 PP_Instance pp_instance2 = instance2->pp_instance(); 69 PP_Instance pp_instance2 = instance2->pp_instance();
86 70
87 // Make an object var. 71 // Make an object var.
88 NPObjectReleaser npobject(NewTrackedNPObject()); 72 NPObjectReleaser npobject(NewTrackedNPObject());
(...skipping 22 matching lines...) Expand all
111 // This ObjectVar must be released before we do NPObjectToPPVarForTest again 95 // This ObjectVar must be released before we do NPObjectToPPVarForTest again
112 // below so it gets freed and we get a new identifier. 96 // below so it gets freed and we get a new identifier.
113 { 97 {
114 scoped_refptr<NPObjectVar> check_object(NPObjectVar::FromPPVar(pp_object1)); 98 scoped_refptr<NPObjectVar> check_object(NPObjectVar::FromPPVar(pp_object1));
115 ASSERT_TRUE(check_object.get()); 99 ASSERT_TRUE(check_object.get());
116 EXPECT_EQ(instance()->pp_instance(), check_object->pp_instance()); 100 EXPECT_EQ(instance()->pp_instance(), check_object->pp_instance());
117 EXPECT_EQ(npobject.get(), check_object->np_object()); 101 EXPECT_EQ(npobject.get(), check_object->np_object());
118 } 102 }
119 103
120 // Remove both of the refs we made above. 104 // Remove both of the refs we made above.
121 ppapi::VarTracker* var_tracker = 105 ppapi::VarTracker* var_tracker = ppapi::PpapiGlobals::Get()->GetVarTracker();
122 ppapi::PpapiGlobals::Get()->GetVarTracker();
123 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object2.value.as_id)); 106 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object2.value.as_id));
124 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object1.value.as_id)); 107 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object1.value.as_id));
125 108
126 // Releasing the resource should free the internal ref, and so making a new 109 // Releasing the resource should free the internal ref, and so making a new
127 // one now should generate a new ID. 110 // one now should generate a new ID.
128 PP_Var pp_object3 = NPObjectToPPVarForTest(instance(), npobject.get()); 111 PP_Var pp_object3 = NPObjectToPPVarForTest(instance(), npobject.get());
129 EXPECT_NE(pp_object1.value.as_id, pp_object3.value.as_id); 112 EXPECT_NE(pp_object1.value.as_id, pp_object3.value.as_id);
130 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object3.value.as_id)); 113 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object3.value.as_id));
131 } 114 }
132 115
133 } // namespace content 116 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698