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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/test/test_timeouts.h" | 7 #include "base/test/test_timeouts.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "ppapi/c/dev/ppb_var_deprecated.h" | 9 #include "ppapi/c/dev/ppb_var_deprecated.h" |
10 #include "ppapi/c/dev/ppp_class_deprecated.h" | 10 #include "ppapi/c/dev/ppp_class_deprecated.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 // have a ref of our own. | 59 // have a ref of our own. |
60 printf("GetInstanceObject called\n"); | 60 printf("GetInstanceObject called\n"); |
61 plugin_var_deprecated_if()->AddRef(instance_obj); | 61 plugin_var_deprecated_if()->AddRef(instance_obj); |
62 return instance_obj; | 62 return instance_obj; |
63 } | 63 } |
64 | 64 |
65 PPP_Instance_Private ppp_instance_private_mock = { | 65 PPP_Instance_Private ppp_instance_private_mock = { |
66 &GetInstanceObject | 66 &GetInstanceObject |
67 }; | 67 }; |
68 | 68 |
69 // We need to pass in a |PPP_Class_Deprecated| to | |
70 // |PPB_Var_Deprecated->CreateObject| for a mock |Deallocate| method. | |
71 void Deallocate(void* object) { | |
72 } | |
73 | |
74 const PPP_Class_Deprecated ppp_class_deprecated_mock = { | |
75 NULL, // HasProperty | |
76 NULL, // HasMethod | |
77 NULL, // GetProperty | |
78 NULL, // GetAllPropertyNames | |
79 NULL, // SetProperty | |
80 NULL, // RemoveProperty | |
81 NULL, // Call | |
82 NULL, // Construct | |
83 &Deallocate | |
84 }; | |
85 | |
86 | |
69 // We need to mock PPP_Instance, so that we can create and destroy the pretend | 87 // We need to mock PPP_Instance, so that we can create and destroy the pretend |
70 // instance that PPP_Instance_Private uses. | 88 // instance that PPP_Instance_Private uses. |
71 PP_Bool DidCreate(PP_Instance /*instance*/, uint32_t /*argc*/, | 89 PP_Bool DidCreate(PP_Instance /*instance*/, uint32_t /*argc*/, |
72 const char* /*argn*/[], const char* /*argv*/[]) { | 90 const char* /*argn*/[], const char* /*argv*/[]) { |
73 // Create an object var. This should exercise the typical path for creating | 91 // Create an object var. This should exercise the typical path for creating |
74 // instance objects. | 92 // instance objects. |
75 instance_obj = | 93 instance_obj = |
76 plugin_var_deprecated_if()->CreateObject(kInstance, NULL, NULL); | 94 plugin_var_deprecated_if()->CreateObject(kInstance, |
95 &ppp_class_deprecated_mock, | |
96 NULL); | |
77 return PP_TRUE; | 97 return PP_TRUE; |
78 } | 98 } |
79 | 99 |
80 void DidDestroy(PP_Instance /*instance*/) { | 100 void DidDestroy(PP_Instance /*instance*/) { |
81 // Decrement the reference count for our instance object. It should be | 101 // Decrement the reference count for our instance object. It should be |
82 // deleted. | 102 // deleted. |
83 plugin_var_deprecated_if()->Release(instance_obj); | 103 plugin_var_deprecated_if()->Release(instance_obj); |
84 } | 104 } |
85 | 105 |
86 PPP_Instance_1_0 ppp_instance_mock = { &DidCreate, &DidDestroy }; | 106 PPP_Instance_1_0 ppp_instance_mock = { &DidCreate, &DidDestroy }; |
(...skipping 16 matching lines...) Expand all Loading... | |
103 NULL, // GetProperty | 123 NULL, // GetProperty |
104 NULL, // EnumerateProperties | 124 NULL, // EnumerateProperties |
105 NULL, // SetProperty | 125 NULL, // SetProperty |
106 NULL, // RemoveProperty | 126 NULL, // RemoveProperty |
107 NULL, // Call | 127 NULL, // Call |
108 NULL, // Construct | 128 NULL, // Construct |
109 NULL, // IsInstanceOf | 129 NULL, // IsInstanceOf |
110 &CreateObject | 130 &CreateObject |
111 }; | 131 }; |
112 | 132 |
113 } // namespace | |
114 | |
115 class PPP_Instance_Private_ProxyTest : public TwoWayTest { | 133 class PPP_Instance_Private_ProxyTest : public TwoWayTest { |
116 public: | 134 public: |
117 PPP_Instance_Private_ProxyTest() | 135 PPP_Instance_Private_ProxyTest() |
118 : TwoWayTest(TwoWayTest::TEST_PPP_INTERFACE) { | 136 : TwoWayTest(TwoWayTest::TEST_PPP_INTERFACE) { |
119 plugin().RegisterTestInterface(PPP_INSTANCE_PRIVATE_INTERFACE, | 137 plugin().RegisterTestInterface(PPP_INSTANCE_PRIVATE_INTERFACE, |
120 &ppp_instance_private_mock); | 138 &ppp_instance_private_mock); |
121 plugin().RegisterTestInterface(PPP_INSTANCE_INTERFACE_1_0, | 139 plugin().RegisterTestInterface(PPP_INSTANCE_INTERFACE_1_0, |
122 &ppp_instance_mock); | 140 &ppp_instance_mock); |
123 host().RegisterTestInterface(PPB_VAR_DEPRECATED_INTERFACE, | 141 host().RegisterTestInterface(PPB_VAR_DEPRECATED_INTERFACE, |
124 &ppb_var_deprecated_mock); | 142 &ppb_var_deprecated_mock); |
125 } | 143 } |
126 }; | 144 }; |
127 | 145 |
146 void GetRefCountForObject(PluginProxyTestHarness* plugin_harness, | |
147 PP_Var instance_obj, | |
148 int32_t* out_ref_count) { | |
149 *out_ref_count = | |
150 plugin_harness->var_tracker().GetRefCountForObject(instance_obj); | |
151 } | |
152 | |
153 void GetHostObjectId(PluginProxyTestHarness* plugin_harness, | |
154 PP_Var instance_obj, | |
155 int32_t* out_id) { | |
156 *out_id = | |
157 plugin_harness->var_tracker().GetHostObject(instance_obj).value.as_id; | |
158 } | |
159 | |
160 } // namespace | |
161 | |
128 TEST_F(PPP_Instance_Private_ProxyTest, PPPInstancePrivate) { | 162 TEST_F(PPP_Instance_Private_ProxyTest, PPPInstancePrivate) { |
129 // This test controls its own instance; we can't use the one that | 163 // This test controls its own instance; we can't use the one that |
130 // PluginProxyTestHarness provides. | 164 // PluginProxyTestHarness provides. |
131 ASSERT_NE(kInstance, pp_instance()); | 165 ASSERT_NE(kInstance, pp_instance()); |
132 HostDispatcher::SetForInstance(kInstance, host().host_dispatcher()); | 166 HostDispatcher::SetForInstance(kInstance, host().host_dispatcher()); |
133 | 167 |
134 // This file-local global is used by the PPP_Instance mock above in order to | 168 // This file-local global is used by the PPP_Instance mock above in order to |
135 // access PPB_Var_Deprecated. | 169 // access PPB_Var_Deprecated. |
136 plugin_dispatcher = plugin().plugin_dispatcher(); | 170 plugin_dispatcher = plugin().plugin_dispatcher(); |
137 | 171 |
138 // Grab the host-side proxy for PPP_Instance and PPP_Instance_Private. | 172 // Grab the host-side proxy for PPP_Instance and PPP_Instance_Private. |
139 const PPP_Instance_Private* ppp_instance_private = | 173 const PPP_Instance_Private* ppp_instance_private = |
140 static_cast<const PPP_Instance_Private*>( | 174 static_cast<const PPP_Instance_Private*>( |
141 host().host_dispatcher()->GetProxiedInterface( | 175 host().host_dispatcher()->GetProxiedInterface( |
142 PPP_INSTANCE_PRIVATE_INTERFACE)); | 176 PPP_INSTANCE_PRIVATE_INTERFACE)); |
143 const PPP_Instance_1_1* ppp_instance = static_cast<const PPP_Instance_1_1*>( | 177 const PPP_Instance_1_1* ppp_instance = static_cast<const PPP_Instance_1_1*>( |
144 host().host_dispatcher()->GetProxiedInterface( | 178 host().host_dispatcher()->GetProxiedInterface( |
145 PPP_INSTANCE_INTERFACE_1_1)); | 179 PPP_INSTANCE_INTERFACE_1_1)); |
146 | 180 |
147 // Initialize an Instance, so that the plugin-side machinery will work | 181 // Initialize an Instance, so that the plugin-side machinery will work |
148 // properly. | 182 // properly. |
149 EXPECT_EQ(PP_TRUE, ppp_instance->DidCreate(kInstance, 0, NULL, NULL)); | 183 EXPECT_EQ(PP_TRUE, ppp_instance->DidCreate(kInstance, 0, NULL, NULL)); |
150 | 184 |
151 // Check the plugin-side reference count. | 185 // Check the plugin-side reference count. |
152 EXPECT_EQ(1, plugin().var_tracker().GetRefCountForObject(instance_obj)); | 186 int32_t ref_count = 0; |
187 PostTaskOnRemoteHarness(base::Bind(GetRefCountForObject, | |
188 &plugin(), instance_obj, &ref_count)); | |
189 EXPECT_EQ(1, ref_count); | |
dmichael (off chromium)
2012/09/17 15:27:29
This is fine, but I'd also be okay with just disab
raymes
2012/09/18 21:29:15
Done.
| |
153 // Check the host-side var exists with the expected id and has 1 refcount (the | 190 // Check the host-side var exists with the expected id and has 1 refcount (the |
154 // refcount on behalf of the plugin). | 191 // refcount on behalf of the plugin). |
155 int32 expected_host_id = | 192 int32 expected_host_id = 0; |
156 plugin().var_tracker().GetHostObject(instance_obj).value.as_id; | 193 PostTaskOnRemoteHarness(base::Bind(GetHostObjectId, |
194 &plugin(), instance_obj, | |
195 &expected_host_id)); | |
157 Var* host_var = host().var_tracker().GetVar(expected_host_id); | 196 Var* host_var = host().var_tracker().GetVar(expected_host_id); |
158 ASSERT_TRUE(host_var); | 197 ASSERT_TRUE(host_var); |
159 EXPECT_EQ( | 198 EXPECT_EQ( |
160 1, | 199 1, |
161 host().var_tracker().GetRefCountForObject(GetPPVarNoAddRef(host_var))); | 200 host().var_tracker().GetRefCountForObject(GetPPVarNoAddRef(host_var))); |
162 | 201 |
163 // Call from the browser side to get the instance object. | 202 // Call from the browser side to get the instance object. |
164 PP_Var host_pp_var = ppp_instance_private->GetInstanceObject(kInstance); | 203 PP_Var host_pp_var = ppp_instance_private->GetInstanceObject(kInstance); |
165 EXPECT_EQ(instance_obj.type, host_pp_var.type); | 204 EXPECT_EQ(instance_obj.type, host_pp_var.type); |
166 EXPECT_EQ(host_pp_var.value.as_id, expected_host_id); | 205 EXPECT_EQ(host_pp_var.value.as_id, expected_host_id); |
167 EXPECT_EQ(1, plugin().var_tracker().GetRefCountForObject(instance_obj)); | 206 ref_count = 0; |
207 PostTaskOnRemoteHarness(base::Bind(GetRefCountForObject, | |
208 &plugin(), instance_obj, &ref_count)); | |
209 EXPECT_EQ(1, ref_count); | |
168 // A reference is passed to the browser, which we consume here. | 210 // A reference is passed to the browser, which we consume here. |
169 host().var_tracker().ReleaseVar(host_pp_var); | 211 host().var_tracker().ReleaseVar(host_pp_var); |
170 EXPECT_EQ(1, host().var_tracker().GetRefCountForObject(host_pp_var)); | 212 EXPECT_EQ(1, host().var_tracker().GetRefCountForObject(host_pp_var)); |
171 | 213 |
172 // The plugin is going away; generally, so will all references to its instance | 214 // The plugin is going away; generally, so will all references to its instance |
173 // object. | 215 // object. |
174 host().var_tracker().ReleaseVar(host_pp_var); | 216 host().var_tracker().ReleaseVar(host_pp_var); |
175 // Destroy the instance. DidDestroy above decrements the reference count for | 217 // Destroy the instance. DidDestroy above decrements the reference count for |
176 // instance_obj, so it should also be destroyed. | 218 // instance_obj, so it should also be destroyed. |
177 ppp_instance->DidDestroy(kInstance); | 219 ppp_instance->DidDestroy(kInstance); |
178 EXPECT_EQ(-1, plugin().var_tracker().GetRefCountForObject(instance_obj)); | 220 ref_count = 0; |
221 PostTaskOnRemoteHarness(base::Bind(GetRefCountForObject, | |
222 &plugin(), instance_obj, &ref_count)); | |
223 EXPECT_EQ(-1, ref_count); | |
179 EXPECT_EQ(-1, host().var_tracker().GetRefCountForObject(host_pp_var)); | 224 EXPECT_EQ(-1, host().var_tracker().GetRefCountForObject(host_pp_var)); |
180 } | 225 } |
181 | 226 |
182 } // namespace proxy | 227 } // namespace proxy |
183 } // namespace ppapi | 228 } // namespace ppapi |
184 | 229 |
OLD | NEW |