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

Side by Side Diff: webkit/plugins/npapi/test/plugin_delete_plugin_in_deallocate_test.cc

Issue 7806020: Add DeletePluginInDeallocate UI test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Correct Copyright header. Created 9 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "webkit/plugins/npapi/test/plugin_delete_plugin_in_deallocate_test.h"
6
7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h"
9
10 namespace {
11
12 NPAPIClient::DeletePluginInDeallocateTest* g_signalling_instance_ = NULL;
13
14 class DeletePluginInDeallocateTestNPObject : public NPObject {
15 public:
16 DeletePluginInDeallocateTestNPObject()
17 : NPObject(), id_(NULL), host_functions_(NULL), deallocate_count_(0) {}
18
19 static NPObject* Allocate(NPP npp, NPClass* npclass) {
20 return new DeletePluginInDeallocateTestNPObject();
21 }
22
23 static void Deallocate(NPObject* npobject) {
24 DeletePluginInDeallocateTestNPObject* object =
25 reinterpret_cast<DeletePluginInDeallocateTestNPObject*>(npobject);
26 ++object->deallocate_count_;
27
28 // Call window.deletePlugin to tear-down our plugin from inside deallocate.
29 if (object->deallocate_count_ == 1) {
30 NPIdentifier delete_id =
31 object->host_functions_->getstringidentifier("deletePlugin");
32 NPObject* window_obj = NULL;
33 object->host_functions_->getvalue(object->id_, NPNVWindowNPObject,
34 &window_obj);
35 NPVariant rv;
36 object->host_functions_->invoke(object->id_, window_obj, delete_id, NULL,
37 0, &rv);
38 }
39 }
40
41 NPP id_;
42 NPNetscapeFuncs* host_functions_;
43 int deallocate_count_;
44 };
45
46 NPClass* GetDeletePluginInDeallocateTestClass() {
47 static NPClass plugin_class = {
48 NP_CLASS_STRUCT_VERSION,
49 DeletePluginInDeallocateTestNPObject::Allocate,
50 DeletePluginInDeallocateTestNPObject::Deallocate,
51 NULL, // Invalidate
52 NULL, // HasMethod
53 NULL, // Invoke
54 NULL, // InvokeDefault
55 NULL, // HasProperty
56 NULL, // GetProperty
57 NULL, // SetProperty
58 NULL, // RemoveProperty
59 };
60 return &plugin_class;
61 }
62
63 } // namespace
64
65 namespace NPAPIClient {
66
67 DeletePluginInDeallocateTest::DeletePluginInDeallocateTest(
68 NPP id, NPNetscapeFuncs* host_functions)
69 : PluginTest(id, host_functions), npobject_(NULL), test_started_(false) {
70 }
71
72 NPError DeletePluginInDeallocateTest::SetWindow(NPWindow* pNPWindow) {
73 if (pNPWindow->window == NULL)
74 return NPERR_NO_ERROR;
75
76 // Ensure that we run the test once, even if SetWindow is called again.
77 if (test_started_)
78 return NPERR_NO_ERROR;
79 test_started_ = true;
80
81 // Because of http://crbug.com/94829, we have to have a second plugin
82 // instance that we can use to signal completion.
83 if (test_id() == "signaller") {
84 g_signalling_instance_ = this;
85 return NPERR_NO_ERROR;
86 }
87
88 // Create a custom NPObject and give our Id and the Netscape function table.
89 npobject_ = HostFunctions()->createobject(
90 id(), GetDeletePluginInDeallocateTestClass());
91 DeletePluginInDeallocateTestNPObject* test_object =
92 reinterpret_cast<DeletePluginInDeallocateTestNPObject*>(npobject_);
93 test_object->id_ = id();
94 test_object->host_functions_ = HostFunctions();
95
96 // Fetch the window script object for our page.
97 NPObject* window = NULL;
98 HostFunctions()->getvalue(id(), NPNVWindowNPObject, &window);
99
100 // Pass it to the window.setTestObject function, which will later release it.
101 NPIdentifier set_test_object_id =
102 HostFunctions()->getstringidentifier("setTestObject");
103 NPVariant func_var;
104 NULL_TO_NPVARIANT(func_var);
105 HostFunctions()->getproperty(id(), window, set_test_object_id, &func_var);
106
107 NPObject* func = NPVARIANT_TO_OBJECT(func_var);
108 NPVariant func_arg;
109 OBJECT_TO_NPVARIANT(npobject_, func_arg);
110 NPVariant func_result;
111 HostFunctions()->invokeDefault(id(), func, &func_arg, 1,
112 &func_result);
113
114 // Release the object - the page's reference should keep it alive.
115 HostFunctions()->releaseobject(npobject_);
116
117 return NPERR_NO_ERROR;
118 }
119
120 NPError DeletePluginInDeallocateTest::Destroy() {
121 // Because of http://crbug.com/94829, we can't signal completion from within
122 // the NPP_Destroy of the plugin that is being destroyed. We work-around
123 // that by testing using a second instance, and signalling though the main
124 // test instance.
125
126 // There should always be a signalling instance by the time we reach here.
127 if (!g_signalling_instance_)
128 return NPERR_NO_ERROR;
129
130 // If we're the signalling instance, do nothing.
131 if (g_signalling_instance_ == this)
132 return NPERR_NO_ERROR;
133
134 if (!npobject_) {
135 g_signalling_instance_->SetError("SetWindow was not invoked.");
136 } else {
137 // Verify that our object was deallocated exactly once.
138 DeletePluginInDeallocateTestNPObject* test_object =
139 reinterpret_cast<DeletePluginInDeallocateTestNPObject*>(npobject_);
140 if (test_object->deallocate_count_ != 1)
141 g_signalling_instance_->SetError(
142 "Object was not deallocated exactly once.");
143 delete test_object;
144 }
145
146 g_signalling_instance_->SignalTestCompleted();
147
148 return NPERR_NO_ERROR;
149 }
150
151 } // namespace NPAPIClient
OLDNEW
« no previous file with comments | « webkit/plugins/npapi/test/plugin_delete_plugin_in_deallocate_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