| 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 } // namespace |
| 147 |
| 148 // TODO(raymes): This #ifdef is only here because we check the state of the |
| 149 // plugin globals on the main thread, rather than the plugin thread which causes |
| 150 // the thread checker to fail. Once ENABLE_PEPPER_THREADING is the default, |
| 151 // this will be safe to do anyway, so we can remove this. |
| 152 #ifdef ENABLE_PEPPER_THREADING |
| 128 TEST_F(PPP_Instance_Private_ProxyTest, PPPInstancePrivate) { | 153 TEST_F(PPP_Instance_Private_ProxyTest, PPPInstancePrivate) { |
| 154 #else |
| 155 TEST_F(PPP_Instance_Private_ProxyTest, DISABLED_PPPInstancePrivate) { |
| 156 #endif |
| 129 // This test controls its own instance; we can't use the one that | 157 // This test controls its own instance; we can't use the one that |
| 130 // PluginProxyTestHarness provides. | 158 // PluginProxyTestHarness provides. |
| 131 ASSERT_NE(kInstance, pp_instance()); | 159 ASSERT_NE(kInstance, pp_instance()); |
| 132 HostDispatcher::SetForInstance(kInstance, host().host_dispatcher()); | 160 HostDispatcher::SetForInstance(kInstance, host().host_dispatcher()); |
| 133 | 161 |
| 134 // This file-local global is used by the PPP_Instance mock above in order to | 162 // This file-local global is used by the PPP_Instance mock above in order to |
| 135 // access PPB_Var_Deprecated. | 163 // access PPB_Var_Deprecated. |
| 136 plugin_dispatcher = plugin().plugin_dispatcher(); | 164 plugin_dispatcher = plugin().plugin_dispatcher(); |
| 137 | 165 |
| 138 // Grab the host-side proxy for PPP_Instance and PPP_Instance_Private. | 166 // Grab the host-side proxy for PPP_Instance and PPP_Instance_Private. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 // Destroy the instance. DidDestroy above decrements the reference count for | 203 // Destroy the instance. DidDestroy above decrements the reference count for |
| 176 // instance_obj, so it should also be destroyed. | 204 // instance_obj, so it should also be destroyed. |
| 177 ppp_instance->DidDestroy(kInstance); | 205 ppp_instance->DidDestroy(kInstance); |
| 178 EXPECT_EQ(-1, plugin().var_tracker().GetRefCountForObject(instance_obj)); | 206 EXPECT_EQ(-1, plugin().var_tracker().GetRefCountForObject(instance_obj)); |
| 179 EXPECT_EQ(-1, host().var_tracker().GetRefCountForObject(host_pp_var)); | 207 EXPECT_EQ(-1, host().var_tracker().GetRefCountForObject(host_pp_var)); |
| 180 } | 208 } |
| 181 | 209 |
| 182 } // namespace proxy | 210 } // namespace proxy |
| 183 } // namespace ppapi | 211 } // namespace ppapi |
| 184 | 212 |
| OLD | NEW |