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 "webkit/plugins/ppapi/ppapi_unittest.h" | 5 #include "webkit/plugins/ppapi/ppapi_unittest.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "ppapi/c/pp_var.h" | 8 #include "ppapi/c/pp_var.h" |
9 #include "ppapi/c/ppp_instance.h" | 9 #include "ppapi/c/ppp_instance.h" |
10 #include "third_party/npapi/bindings/npruntime.h" | 10 #include "third_party/npapi/bindings/npruntime.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
12 #include "webkit/plugins/ppapi/host_globals.h" | |
13 #include "webkit/plugins/ppapi/mock_plugin_delegate.h" | 12 #include "webkit/plugins/ppapi/mock_plugin_delegate.h" |
14 #include "webkit/plugins/ppapi/mock_resource.h" | 13 #include "webkit/plugins/ppapi/mock_resource.h" |
15 #include "webkit/plugins/ppapi/npapi_glue.h" | 14 #include "webkit/plugins/ppapi/npapi_glue.h" |
16 #include "webkit/plugins/ppapi/npobject_var.h" | 15 #include "webkit/plugins/ppapi/npobject_var.h" |
17 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 16 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
18 #include "webkit/plugins/ppapi/resource_tracker.h" | 17 #include "webkit/plugins/ppapi/resource_tracker.h" |
19 | 18 |
20 using ppapi::NPObjectVar; | 19 using ppapi::NPObjectVar; |
21 | 20 |
22 namespace webkit { | 21 namespace webkit { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 71 |
73 } // namespace | 72 } // namespace |
74 | 73 |
75 // ResourceTrackerTest --------------------------------------------------------- | 74 // ResourceTrackerTest --------------------------------------------------------- |
76 | 75 |
77 class ResourceTrackerTest : public PpapiUnittest { | 76 class ResourceTrackerTest : public PpapiUnittest { |
78 public: | 77 public: |
79 ResourceTrackerTest() { | 78 ResourceTrackerTest() { |
80 } | 79 } |
81 | 80 |
82 ResourceTracker& tracker() { | 81 virtual void SetUp() { |
83 return *HostGlobals::Get()->host_resource_tracker(); | 82 // The singleton override must be installed before the generic setup because |
| 83 // that creates an instance, etc. which uses the tracker. |
| 84 ResourceTracker::SetSingletonOverride(&tracker_); |
| 85 PpapiUnittest::SetUp(); |
84 } | 86 } |
| 87 virtual void TearDown() { |
| 88 // Must do normal tear down before clearing the override for the same rason |
| 89 // as the SetUp. |
| 90 PpapiUnittest::TearDown(); |
| 91 ResourceTracker::ClearSingletonOverride(); |
| 92 } |
| 93 |
| 94 ResourceTracker& tracker() { return tracker_; } |
| 95 |
| 96 private: |
| 97 ResourceTracker tracker_; |
85 }; | 98 }; |
86 | 99 |
87 TEST_F(ResourceTrackerTest, DeleteObjectVarWithInstance) { | 100 TEST_F(ResourceTrackerTest, DeleteObjectVarWithInstance) { |
88 // Make a second instance (the test harness already creates & manages one). | 101 // Make a second instance (the test harness already creates & manages one). |
89 scoped_refptr<PluginInstance> instance2( | 102 scoped_refptr<PluginInstance> instance2( |
90 PluginInstance::Create1_0(delegate(), module(), | 103 PluginInstance::Create1_0(delegate(), module(), |
91 GetMockInterface(PPP_INSTANCE_INTERFACE_1_0))); | 104 GetMockInterface(PPP_INSTANCE_INTERFACE_1_0))); |
92 PP_Instance pp_instance2 = instance2->pp_instance(); | 105 PP_Instance pp_instance2 = instance2->pp_instance(); |
93 | 106 |
94 // Make an object var. | 107 // Make an object var. |
(...skipping 23 matching lines...) Expand all Loading... |
118 // This ObjectVar must be released before we do NPObjectToPPVar again | 131 // This ObjectVar must be released before we do NPObjectToPPVar again |
119 // below so it gets freed and we get a new identifier. | 132 // below so it gets freed and we get a new identifier. |
120 { | 133 { |
121 scoped_refptr<NPObjectVar> check_object(NPObjectVar::FromPPVar(pp_object1)); | 134 scoped_refptr<NPObjectVar> check_object(NPObjectVar::FromPPVar(pp_object1)); |
122 ASSERT_TRUE(check_object.get()); | 135 ASSERT_TRUE(check_object.get()); |
123 EXPECT_EQ(instance()->pp_instance(), check_object->pp_instance()); | 136 EXPECT_EQ(instance()->pp_instance(), check_object->pp_instance()); |
124 EXPECT_EQ(npobject.get(), check_object->np_object()); | 137 EXPECT_EQ(npobject.get(), check_object->np_object()); |
125 } | 138 } |
126 | 139 |
127 // Remove both of the refs we made above. | 140 // Remove both of the refs we made above. |
128 ::ppapi::VarTracker* var_tracker = | 141 ::ppapi::VarTracker* var_tracker = tracker().GetVarTracker(); |
129 ::ppapi::PpapiGlobals::Get()->GetVarTracker(); | |
130 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object2.value.as_id)); | 142 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object2.value.as_id)); |
131 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object1.value.as_id)); | 143 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object1.value.as_id)); |
132 | 144 |
133 // Releasing the resource should free the internal ref, and so making a new | 145 // Releasing the resource should free the internal ref, and so making a new |
134 // one now should generate a new ID. | 146 // one now should generate a new ID. |
135 PP_Var pp_object3 = NPObjectToPPVar(instance(), npobject.get()); | 147 PP_Var pp_object3 = NPObjectToPPVar(instance(), npobject.get()); |
136 EXPECT_NE(pp_object1.value.as_id, pp_object3.value.as_id); | 148 EXPECT_NE(pp_object1.value.as_id, pp_object3.value.as_id); |
137 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object3.value.as_id)); | 149 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object3.value.as_id)); |
138 } | 150 } |
139 | 151 |
140 } // namespace ppapi | 152 } // namespace ppapi |
141 } // namespace webkit | 153 } // namespace webkit |
OLD | NEW |