Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Unified Diff: webkit/plugins/npapi/test/plugin_npobject_identity_test.cc

Issue 7037027: Fixes Issues #5751 & #22631: NPObject identity (Closed)
Patch Set: hopefully added base url Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/plugins/npapi/test/plugin_npobject_identity_test.cc
diff --git a/webkit/plugins/npapi/test/plugin_npobject_identity_test.cc b/webkit/plugins/npapi/test/plugin_npobject_identity_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d6e2c38366f87f160d9ba14d4439d6d800806bd4
--- /dev/null
+++ b/webkit/plugins/npapi/test/plugin_npobject_identity_test.cc
@@ -0,0 +1,84 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+
+#include "webkit/plugins/npapi/test/plugin_npobject_identity_test.h"
+
+namespace {
+
+class NPThingy : public NPObject {
+ public:
+ NPThingy() : NPObject() {}
+
+ static NPObject* Allocate(NPP npp, NPClass* npclass) {
+ return new NPThingy();
+ }
+
+ static void Deallocate(NPObject* npobject) {
+ delete static_cast<NPThingy*>(npobject);
+ }
+};
+
+NPClass* GetNPThingyClass() {
+ static NPClass plugin_class = {
+ NP_CLASS_STRUCT_VERSION,
+ NPThingy::Allocate,
+ NPThingy::Deallocate,
+ NULL, // Invalidate
+ NULL, // HasMethod
+ NULL, // Invoke
+ NULL, // InvokeDefault
+ NULL, // HasProperty
+ NULL, // GetProperty
+ NULL, // SetProperty
+ NULL, // RemoveProperty
+ };
+ return &plugin_class;
+}
+
+
+} // namespace
+
+namespace NPAPIClient {
+
+NPObjectIdentityTest::NPObjectIdentityTest(NPP id, NPNetscapeFuncs *host_functions)
+ : PluginTest(id, host_functions) {
+}
+
+NPError NPObjectIdentityTest::SetWindow(NPWindow* pNPWindow) {
+ if (pNPWindow->window == NULL)
+ return NPERR_NO_ERROR;
+
+ NPIdentifier are_these_the_same_id = HostFunctions()->getstringidentifier("areTheseTheSame");
+
+ // Get a function from window.areTheseTheSame.
+ NPObject* window;
+ HostFunctions()->getvalue(id(), NPNVWindowNPObject, &window);
+ NPVariant func_var;
+ HostFunctions()->getproperty(id(), window, are_these_the_same_id, &func_var);
+ NPObject* func = NPVARIANT_TO_OBJECT(func_var);
+
+ // Create a custom NPObject and pass it in both arguments to areTheseTheSame.
+ NPObject* thingy = HostFunctions()->createobject(id(), GetNPThingyClass());
+ NPVariant func_args[2];
+ OBJECT_TO_NPVARIANT(thingy, func_args[0]);
+ OBJECT_TO_NPVARIANT(thingy, func_args[1]);
+ NPVariant were_the_same_var;
+ HostFunctions()->invokeDefault(id(), func, (const NPVariant*)&func_args, 2,
+ &were_the_same_var);
+
+ // Confirm that JavaScript could see that the objects were the same.
+ bool were_the_same = NPVARIANT_TO_BOOLEAN(were_the_same_var);
+ if (!were_the_same)
+ SetError("Identity was lost in passing from NPAPI into JavaScript.");
+
+ // If this test failed, then we'd have crashed by now.
+ SignalTestCompleted();
+
+ return NPERR_NO_ERROR;
+}
+
+} // namespace NPAPIClient
« no previous file with comments | « webkit/plugins/npapi/test/plugin_npobject_identity_test.h ('k') | webkit/plugins/npapi/test/plugin_test_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698