| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "gpu/gpu_plugin/gpu_plugin.h" | |
| 6 #include "gpu/gpu_plugin/gpu_plugin_object.h" | |
| 7 #include "gpu/np_utils/np_object_mock.h" | |
| 8 #include "gpu/np_utils/np_plugin_object_factory_mock.h" | |
| 9 #include "gpu/np_utils/np_plugin_object_mock.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 #include "webkit/glue/plugins/nphostapi.h" | |
| 12 | |
| 13 #if defined(OS_LINUX) | |
| 14 #define INITIALIZE_PLUGIN_FUNCS , &plugin_funcs_ | |
| 15 #else | |
| 16 #define INITIALIZE_PLUGIN_FUNCS | |
| 17 #endif | |
| 18 | |
| 19 using np_utils::MockPluginObject; | |
| 20 using np_utils::PluginObject; | |
| 21 using testing::_; | |
| 22 using testing::DoAll; | |
| 23 using testing::NiceMock; | |
| 24 using testing::Return; | |
| 25 using testing::SetArgumentPointee; | |
| 26 using testing::StrictMock; | |
| 27 | |
| 28 namespace gpu_plugin { | |
| 29 | |
| 30 class GPUPluginTest : public testing::Test { | |
| 31 protected: | |
| 32 virtual void SetUp() { | |
| 33 memset(&npp_, 0, sizeof(npp_)); | |
| 34 memset(&browser_funcs_, 0, sizeof(browser_funcs_)); | |
| 35 memset(&plugin_funcs_, 0, sizeof(plugin_funcs_)); | |
| 36 | |
| 37 plugin_object_factory_ = new StrictMock<np_utils::MockPluginObjectFactory>; | |
| 38 | |
| 39 np_class_ = np_utils::NPGetClass<StrictMock<np_utils::MockNPObject> >(); | |
| 40 } | |
| 41 | |
| 42 virtual void TearDown() { | |
| 43 delete plugin_object_factory_; | |
| 44 } | |
| 45 | |
| 46 NPP_t npp_; | |
| 47 NPNetscapeFuncs browser_funcs_; | |
| 48 NPPluginFuncs plugin_funcs_; | |
| 49 np_utils::MockPluginObjectFactory* plugin_object_factory_; | |
| 50 const NPClass* np_class_; | |
| 51 }; | |
| 52 | |
| 53 TEST_F(GPUPluginTest, GetEntryPointsSetsNeededFunctionPointers) { | |
| 54 #if defined(OS_LINUX) | |
| 55 NPError error = gpu_plugin::NP_Initialize(&browser_funcs_, | |
| 56 &plugin_funcs_); | |
| 57 gpu_plugin::NP_Shutdown(); | |
| 58 #else | |
| 59 NPError error = gpu_plugin::NP_GetEntryPoints(&plugin_funcs_); | |
| 60 #endif | |
| 61 | |
| 62 EXPECT_EQ(NPERR_NO_ERROR, error); | |
| 63 EXPECT_TRUE(NULL != plugin_funcs_.newp); | |
| 64 EXPECT_TRUE(NULL != plugin_funcs_.destroy); | |
| 65 EXPECT_TRUE(NULL != plugin_funcs_.setwindow); | |
| 66 EXPECT_TRUE(NULL != plugin_funcs_.event); | |
| 67 EXPECT_TRUE(NULL != plugin_funcs_.getvalue); | |
| 68 EXPECT_TRUE(NULL != plugin_funcs_.setvalue); | |
| 69 } | |
| 70 | |
| 71 TEST_F(GPUPluginTest, CanInitializeAndShutdownPlugin) { | |
| 72 EXPECT_EQ(NPERR_NO_ERROR, | |
| 73 gpu_plugin::NP_Initialize(&browser_funcs_ INITIALIZE_PLUGIN_FUNCS)); | |
| 74 EXPECT_EQ(NPERR_NO_ERROR, gpu_plugin::NP_Shutdown()); | |
| 75 } | |
| 76 | |
| 77 TEST_F(GPUPluginTest, InitializeFailsIfBrowserFuncsIsNull) { | |
| 78 EXPECT_EQ(NPERR_INVALID_FUNCTABLE_ERROR, | |
| 79 gpu_plugin::NP_Initialize(NULL INITIALIZE_PLUGIN_FUNCS)); | |
| 80 } | |
| 81 | |
| 82 TEST_F(GPUPluginTest, InitializeFailsIfAlreadyInitialized) { | |
| 83 EXPECT_EQ(NPERR_NO_ERROR, | |
| 84 gpu_plugin::NP_Initialize(&browser_funcs_ INITIALIZE_PLUGIN_FUNCS)); | |
| 85 EXPECT_EQ(NPERR_GENERIC_ERROR, | |
| 86 gpu_plugin::NP_Initialize(&browser_funcs_ INITIALIZE_PLUGIN_FUNCS)); | |
| 87 EXPECT_EQ(NPERR_NO_ERROR, gpu_plugin::NP_Shutdown()); | |
| 88 } | |
| 89 | |
| 90 TEST_F(GPUPluginTest, ShutdownFailsIfNotInitialized) { | |
| 91 EXPECT_EQ(NPERR_GENERIC_ERROR, gpu_plugin::NP_Shutdown()); | |
| 92 } | |
| 93 | |
| 94 TEST_F(GPUPluginTest, NewReturnsErrorForInvalidInstance) { | |
| 95 gpu_plugin::NP_GetEntryPoints(&plugin_funcs_); | |
| 96 gpu_plugin::NP_Initialize(&browser_funcs_ INITIALIZE_PLUGIN_FUNCS); | |
| 97 | |
| 98 EXPECT_EQ(NPERR_INVALID_INSTANCE_ERROR, plugin_funcs_.newp( | |
| 99 const_cast<NPMIMEType>(GPUPluginObject::kPluginType), | |
| 100 NULL, 0, 0, NULL, NULL, NULL)); | |
| 101 | |
| 102 gpu_plugin::NP_Shutdown(); | |
| 103 } | |
| 104 | |
| 105 TEST_F(GPUPluginTest, GetValueReturnsErrorForInvalidInstance) { | |
| 106 gpu_plugin::NP_GetEntryPoints(&plugin_funcs_); | |
| 107 gpu_plugin::NP_Initialize(&browser_funcs_ INITIALIZE_PLUGIN_FUNCS); | |
| 108 | |
| 109 int* result = NULL; | |
| 110 EXPECT_EQ(NPERR_INVALID_INSTANCE_ERROR, plugin_funcs_.getvalue( | |
| 111 NULL, NPPVjavaClass, &result)); | |
| 112 | |
| 113 gpu_plugin::NP_Shutdown(); | |
| 114 } | |
| 115 | |
| 116 TEST_F(GPUPluginTest, DestroyReturnsErrorForInvalidInstance) { | |
| 117 gpu_plugin::NP_GetEntryPoints(&plugin_funcs_); | |
| 118 gpu_plugin::NP_Initialize(&browser_funcs_ INITIALIZE_PLUGIN_FUNCS); | |
| 119 | |
| 120 EXPECT_EQ(NPERR_INVALID_INSTANCE_ERROR, plugin_funcs_.destroy(NULL, NULL)); | |
| 121 | |
| 122 gpu_plugin::NP_Shutdown(); | |
| 123 } | |
| 124 | |
| 125 TEST_F(GPUPluginTest, SetWindowReturnsErrorForInvalidInstance) { | |
| 126 gpu_plugin::NP_GetEntryPoints(&plugin_funcs_); | |
| 127 gpu_plugin::NP_Initialize(&browser_funcs_ INITIALIZE_PLUGIN_FUNCS); | |
| 128 | |
| 129 EXPECT_EQ(NPERR_INVALID_INSTANCE_ERROR, plugin_funcs_.setwindow(NULL, NULL)); | |
| 130 | |
| 131 gpu_plugin::NP_Shutdown(); | |
| 132 } | |
| 133 | |
| 134 TEST_F(GPUPluginTest, HandleEventReturnsFalseForInvalidInstance) { | |
| 135 gpu_plugin::NP_GetEntryPoints(&plugin_funcs_); | |
| 136 gpu_plugin::NP_Initialize(&browser_funcs_ INITIALIZE_PLUGIN_FUNCS); | |
| 137 | |
| 138 EXPECT_EQ(0, plugin_funcs_.event(NULL, NULL)); | |
| 139 | |
| 140 gpu_plugin::NP_Shutdown(); | |
| 141 } | |
| 142 | |
| 143 TEST_F(GPUPluginTest, NewCreatesAPluginObjectAndInitializesIt) { | |
| 144 StrictMock<np_utils::MockPluginObject> plugin_object; | |
| 145 | |
| 146 EXPECT_CALL(*plugin_object_factory_, CreatePluginObject( | |
| 147 &npp_, const_cast<NPMIMEType>(GPUPluginObject::kPluginType))) | |
| 148 .WillOnce(Return(&plugin_object)); | |
| 149 | |
| 150 NPObject scriptable_object; | |
| 151 | |
| 152 EXPECT_CALL(plugin_object, New( | |
| 153 const_cast<NPMIMEType>(GPUPluginObject::kPluginType), | |
| 154 0, NULL, NULL, NULL)) | |
| 155 .WillOnce(Return(NPERR_NO_ERROR)); | |
| 156 | |
| 157 EXPECT_CALL(plugin_object, GetScriptableNPObject()) | |
| 158 .WillOnce(Return(&scriptable_object)); | |
| 159 | |
| 160 EXPECT_CALL(plugin_object, Destroy(static_cast<NPSavedData**>(NULL))) | |
| 161 .WillOnce(Return(NPERR_NO_ERROR)); | |
| 162 | |
| 163 EXPECT_CALL(plugin_object, Release()); | |
| 164 | |
| 165 gpu_plugin::NP_GetEntryPoints(&plugin_funcs_); | |
| 166 gpu_plugin::NP_Initialize(&browser_funcs_ INITIALIZE_PLUGIN_FUNCS); | |
| 167 | |
| 168 EXPECT_EQ(NPERR_NO_ERROR, plugin_funcs_.newp( | |
| 169 const_cast<NPMIMEType>(GPUPluginObject::kPluginType), | |
| 170 &npp_, 0, 0, NULL, NULL, NULL)); | |
| 171 | |
| 172 NPObject* result; | |
| 173 EXPECT_EQ(NPERR_NO_ERROR, plugin_funcs_.getvalue( | |
| 174 &npp_, NPPVpluginScriptableNPObject, &result)); | |
| 175 EXPECT_EQ(&scriptable_object, result); | |
| 176 | |
| 177 EXPECT_EQ(NPERR_NO_ERROR, plugin_funcs_.destroy(&npp_, NULL)); | |
| 178 | |
| 179 gpu_plugin::NP_Shutdown(); | |
| 180 } | |
| 181 | |
| 182 TEST_F(GPUPluginTest, NewFailsIfPluginObjectFactoryFails) { | |
| 183 EXPECT_CALL(*plugin_object_factory_, CreatePluginObject( | |
| 184 &npp_, const_cast<NPMIMEType>(GPUPluginObject::kPluginType))) | |
| 185 .WillOnce(Return(static_cast<PluginObject*>(NULL))); | |
| 186 | |
| 187 gpu_plugin::NP_GetEntryPoints(&plugin_funcs_); | |
| 188 gpu_plugin::NP_Initialize(&browser_funcs_ INITIALIZE_PLUGIN_FUNCS); | |
| 189 | |
| 190 EXPECT_EQ(NPERR_GENERIC_ERROR, plugin_funcs_.newp( | |
| 191 const_cast<NPMIMEType>(GPUPluginObject::kPluginType), | |
| 192 &npp_, 0, 0, NULL, NULL, NULL)); | |
| 193 | |
| 194 gpu_plugin::NP_Shutdown(); | |
| 195 } | |
| 196 | |
| 197 TEST_F(GPUPluginTest, SetWindowForwardsToPluginObject) { | |
| 198 StrictMock<MockPluginObject> plugin_object; | |
| 199 | |
| 200 EXPECT_CALL(*plugin_object_factory_, CreatePluginObject( | |
| 201 &npp_, const_cast<NPMIMEType>(GPUPluginObject::kPluginType))) | |
| 202 .WillOnce(Return(&plugin_object)); | |
| 203 | |
| 204 EXPECT_CALL(plugin_object, New( | |
| 205 const_cast<NPMIMEType>(GPUPluginObject::kPluginType), | |
| 206 0, NULL, NULL, NULL)) | |
| 207 .WillOnce(Return(NPERR_NO_ERROR)); | |
| 208 | |
| 209 NPWindow window = {0}; | |
| 210 | |
| 211 EXPECT_CALL(plugin_object, SetWindow(&window)) | |
| 212 .WillOnce(Return(NPERR_NO_ERROR)); | |
| 213 | |
| 214 EXPECT_CALL(plugin_object, Destroy(static_cast<NPSavedData**>(NULL))) | |
| 215 .WillOnce(Return(NPERR_NO_ERROR)); | |
| 216 | |
| 217 EXPECT_CALL(plugin_object, Release()); | |
| 218 | |
| 219 gpu_plugin::NP_GetEntryPoints(&plugin_funcs_); | |
| 220 gpu_plugin::NP_Initialize(&browser_funcs_ INITIALIZE_PLUGIN_FUNCS); | |
| 221 | |
| 222 EXPECT_EQ(NPERR_NO_ERROR, plugin_funcs_.newp( | |
| 223 const_cast<NPMIMEType>(GPUPluginObject::kPluginType), | |
| 224 &npp_, 0, 0, NULL, NULL, NULL)); | |
| 225 | |
| 226 EXPECT_EQ(NPERR_NO_ERROR, plugin_funcs_.setwindow(&npp_, &window)); | |
| 227 | |
| 228 EXPECT_EQ(NPERR_NO_ERROR, plugin_funcs_.destroy(&npp_, NULL)); | |
| 229 | |
| 230 gpu_plugin::NP_Shutdown(); | |
| 231 } | |
| 232 | |
| 233 TEST_F(GPUPluginTest, HandleEventForwardsToPluginObject) { | |
| 234 StrictMock<MockPluginObject> plugin_object; | |
| 235 | |
| 236 EXPECT_CALL(*plugin_object_factory_, CreatePluginObject( | |
| 237 &npp_, const_cast<NPMIMEType>(GPUPluginObject::kPluginType))) | |
| 238 .WillOnce(Return(&plugin_object)); | |
| 239 | |
| 240 EXPECT_CALL(plugin_object, New( | |
| 241 const_cast<NPMIMEType>(GPUPluginObject::kPluginType), | |
| 242 0, NULL, NULL, NULL)) | |
| 243 .WillOnce(Return(NPERR_NO_ERROR)); | |
| 244 | |
| 245 NPEvent event = {0}; | |
| 246 | |
| 247 EXPECT_CALL(plugin_object, HandleEvent(&event)) | |
| 248 .WillOnce(Return(7)); | |
| 249 | |
| 250 EXPECT_CALL(plugin_object, Destroy(static_cast<NPSavedData**>(NULL))) | |
| 251 .WillOnce(Return(NPERR_NO_ERROR)); | |
| 252 | |
| 253 EXPECT_CALL(plugin_object, Release()); | |
| 254 | |
| 255 gpu_plugin::NP_GetEntryPoints(&plugin_funcs_); | |
| 256 gpu_plugin::NP_Initialize(&browser_funcs_ INITIALIZE_PLUGIN_FUNCS); | |
| 257 | |
| 258 EXPECT_EQ(NPERR_NO_ERROR, plugin_funcs_.newp( | |
| 259 const_cast<NPMIMEType>(GPUPluginObject::kPluginType), | |
| 260 &npp_, 0, 0, NULL, NULL, NULL)); | |
| 261 | |
| 262 EXPECT_EQ(7, plugin_funcs_.event(&npp_, &event)); | |
| 263 | |
| 264 EXPECT_EQ(NPERR_NO_ERROR, plugin_funcs_.destroy(&npp_, NULL)); | |
| 265 | |
| 266 gpu_plugin::NP_Shutdown(); | |
| 267 } | |
| 268 | |
| 269 TEST_F(GPUPluginTest, GetValueReturnsErrorForUnknownVariable) { | |
| 270 StrictMock<MockPluginObject> plugin_object; | |
| 271 | |
| 272 EXPECT_CALL(*plugin_object_factory_, CreatePluginObject( | |
| 273 &npp_, const_cast<NPMIMEType>(GPUPluginObject::kPluginType))) | |
| 274 .WillOnce(Return(&plugin_object)); | |
| 275 | |
| 276 EXPECT_CALL(plugin_object, New( | |
| 277 const_cast<NPMIMEType>(GPUPluginObject::kPluginType), | |
| 278 0, NULL, NULL, NULL)) | |
| 279 .WillOnce(Return(NPERR_NO_ERROR)); | |
| 280 | |
| 281 EXPECT_CALL(plugin_object, Destroy(static_cast<NPSavedData**>(NULL))) | |
| 282 .WillOnce(Return(NPERR_NO_ERROR)); | |
| 283 | |
| 284 EXPECT_CALL(plugin_object, Release()); | |
| 285 | |
| 286 gpu_plugin::NP_GetEntryPoints(&plugin_funcs_); | |
| 287 gpu_plugin::NP_Initialize(&browser_funcs_ INITIALIZE_PLUGIN_FUNCS); | |
| 288 | |
| 289 EXPECT_EQ(NPERR_NO_ERROR, plugin_funcs_.newp( | |
| 290 const_cast<NPMIMEType>(GPUPluginObject::kPluginType), | |
| 291 &npp_, 0, 0, NULL, NULL, NULL)); | |
| 292 | |
| 293 int* result = NULL; | |
| 294 EXPECT_EQ(NPERR_GENERIC_ERROR, plugin_funcs_.getvalue( | |
| 295 &npp_, NPPVjavaClass, &result)); | |
| 296 | |
| 297 EXPECT_EQ(NPERR_NO_ERROR, plugin_funcs_.destroy(&npp_, NULL)); | |
| 298 | |
| 299 gpu_plugin::NP_Shutdown(); | |
| 300 } | |
| 301 | |
| 302 } // namespace gpu_plugin | |
| OLD | NEW |