OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/basictypes.h" |
| 6 #include "base/compiler_specific.h" |
| 7 |
| 8 #include "webkit/plugins/npapi/test/plugin_npobject_identity_test.h" |
| 9 |
| 10 namespace { |
| 11 |
| 12 class NPThingy : public NPObject { |
| 13 public: |
| 14 NPThingy() : NPObject() {} |
| 15 |
| 16 static NPObject* Allocate(NPP npp, NPClass* npclass) { |
| 17 return new NPThingy(); |
| 18 } |
| 19 |
| 20 static void Deallocate(NPObject* npobject) { |
| 21 delete static_cast<NPThingy*>(npobject); |
| 22 } |
| 23 }; |
| 24 |
| 25 NPClass* GetNPThingyClass() { |
| 26 static NPClass plugin_class = { |
| 27 NP_CLASS_STRUCT_VERSION, |
| 28 NPThingy::Allocate, |
| 29 NPThingy::Deallocate, |
| 30 NULL, // Invalidate |
| 31 NULL, // HasMethod |
| 32 NULL, // Invoke |
| 33 NULL, // InvokeDefault |
| 34 NULL, // HasProperty |
| 35 NULL, // GetProperty |
| 36 NULL, // SetProperty |
| 37 NULL, // RemoveProperty |
| 38 }; |
| 39 return &plugin_class; |
| 40 } |
| 41 |
| 42 |
| 43 } // namespace |
| 44 |
| 45 namespace NPAPIClient { |
| 46 |
| 47 NPObjectIdentityTest::NPObjectIdentityTest(NPP id, NPNetscapeFuncs *host_functio
ns) |
| 48 : PluginTest(id, host_functions) { |
| 49 } |
| 50 |
| 51 NPError NPObjectIdentityTest::SetWindow(NPWindow* pNPWindow) { |
| 52 if (pNPWindow->window == NULL) |
| 53 return NPERR_NO_ERROR; |
| 54 |
| 55 NPIdentifier are_these_the_same_id = HostFunctions()->getstringidentifier("are
TheseTheSame"); |
| 56 |
| 57 // Get a function from window.areTheseTheSame. |
| 58 NPObject* window; |
| 59 HostFunctions()->getvalue(id(), NPNVWindowNPObject, &window); |
| 60 NPVariant func_var; |
| 61 HostFunctions()->getproperty(id(), window, are_these_the_same_id, &func_var); |
| 62 NPObject* func = NPVARIANT_TO_OBJECT(func_var); |
| 63 |
| 64 // Create a custom NPObject and pass it in both arguments to areTheseTheSame. |
| 65 NPObject* thingy = HostFunctions()->createobject(id(), GetNPThingyClass()); |
| 66 NPVariant func_args[2]; |
| 67 OBJECT_TO_NPVARIANT(thingy, func_args[0]); |
| 68 OBJECT_TO_NPVARIANT(thingy, func_args[1]); |
| 69 NPVariant were_the_same_var; |
| 70 HostFunctions()->invokeDefault(id(), func, (const NPVariant*)&func_args, 2, |
| 71 &were_the_same_var); |
| 72 |
| 73 // Confirm that JavaScript could see that the objects were the same. |
| 74 bool were_the_same = NPVARIANT_TO_BOOLEAN(were_the_same_var); |
| 75 if (!were_the_same) |
| 76 SetError("Identity was lost in passing from NPAPI into JavaScript."); |
| 77 |
| 78 // If this test failed, then we'd have crashed by now. |
| 79 SignalTestCompleted(); |
| 80 |
| 81 return NPERR_NO_ERROR; |
| 82 } |
| 83 |
| 84 } // namespace NPAPIClient |
OLD | NEW |