2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 #include "PluginTest.h"
28 #include "PluginObject.h"
33 extern NPNetscapeFuncs *browser;
35 static void (*shutdownFunction)();
37 PluginTest* PluginTest::create(NPP npp, const string& identifier)
39 if (identifier.empty())
40 return new PluginTest(npp, identifier);
42 CreateTestFunction createTestFunction = createTestFunctions()[identifier];
43 if (createTestFunction)
44 return createTestFunction(npp, identifier);
49 PluginTest::PluginTest(NPP npp, const string& identifier)
51 , m_identifier(identifier)
53 // Reset the shutdown function.
57 PluginTest::~PluginTest()
61 void PluginTest::NP_Shutdown()
67 void PluginTest::registerNPShutdownFunction(void (*func)())
69 assert(!shutdownFunction);
70 shutdownFunction = func;
73 void PluginTest::indicateTestFailure()
75 // This should really be an assert, but there's no way for the test framework
76 // to know that the plug-in process crashed, so we'll just sleep for a while
77 // to ensure that the test times out.
85 NPError PluginTest::NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char *argn[], char *argv[], NPSavedData *saved)
87 return NPERR_NO_ERROR;
90 NPError PluginTest::NPP_Destroy(NPSavedData**)
92 return NPERR_NO_ERROR;
95 NPError PluginTest::NPP_SetWindow(NPP, NPWindow*)
97 return NPERR_NO_ERROR;
100 NPError PluginTest::NPP_NewStream(NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype)
102 return NPERR_NO_ERROR;
105 NPError PluginTest::NPP_DestroyStream(NPStream *stream, NPReason reason)
107 return NPERR_NO_ERROR;
110 int32_t PluginTest::NPP_WriteReady(NPStream*)
115 int32_t PluginTest::NPP_Write(NPStream*, int32_t offset, int32_t len, void* buffer)
120 int16_t PluginTest::NPP_HandleEvent(void*)
125 bool PluginTest::NPP_URLNotify(const char* url, NPReason, void* notifyData)
127 // FIXME: Port the code from NPP_URLNotify in main.cpp over to always using
128 // PluginTest, so we don't have to use a return value to indicate whether the "default" NPP_URLNotify implementation should be invoked.
132 NPError PluginTest::NPP_GetValue(NPPVariable variable, void *value)
134 // We don't know anything about plug-in values so just return NPERR_GENERIC_ERROR.
135 return NPERR_GENERIC_ERROR;
138 NPError PluginTest::NPP_SetValue(NPNVariable, void *value)
140 return NPERR_GENERIC_ERROR;
145 NPError PluginTest::NPN_GetURL(const char* url, const char* target)
147 return browser->geturl(m_npp, url, target);
150 NPError PluginTest::NPN_GetURLNotify(const char *url, const char *target, void *notifyData)
152 return browser->geturlnotify(m_npp, url, target, notifyData);
155 NPError PluginTest::NPN_GetValue(NPNVariable variable, void* value)
157 return browser->getvalue(m_npp, variable, value);
160 void PluginTest::NPN_InvalidateRect(NPRect* invalidRect)
162 browser->invalidaterect(m_npp, invalidRect);
165 // NPRuntime NPN functions.
167 NPIdentifier PluginTest::NPN_GetStringIdentifier(const NPUTF8 *name)
169 return browser->getstringidentifier(name);
172 NPIdentifier PluginTest::NPN_GetIntIdentifier(int32_t intid)
174 return browser->getintidentifier(intid);
177 bool PluginTest::NPN_IdentifierIsString(NPIdentifier npIdentifier)
179 return browser->identifierisstring(npIdentifier);
182 NPUTF8* PluginTest::NPN_UTF8FromIdentifier(NPIdentifier npIdentifier)
184 return browser->utf8fromidentifier(npIdentifier);
187 int32_t PluginTest::NPN_IntFromIdentifier(NPIdentifier npIdentifier)
189 return browser->intfromidentifier(npIdentifier);
192 NPObject* PluginTest::NPN_CreateObject(NPClass* npClass)
194 return browser->createobject(m_npp, npClass);
197 NPObject* PluginTest::NPN_RetainObject(NPObject* npObject)
199 return browser->retainobject(npObject);
202 void PluginTest::NPN_ReleaseObject(NPObject* npObject)
204 browser->releaseobject(npObject);
207 bool PluginTest::NPN_RemoveProperty(NPObject* npObject, NPIdentifier propertyName)
209 return browser->removeproperty(m_npp, npObject, propertyName);
213 bool PluginTest::NPN_ConvertPoint(double sourceX, double sourceY, NPCoordinateSpace sourceSpace, double *destX, double *destY, NPCoordinateSpace destSpace)
215 return browser->convertpoint(m_npp, sourceX, sourceY, sourceSpace, destX, destY, destSpace);
219 void PluginTest::executeScript(const char* script)
221 NPObject* windowScriptObject;
222 browser->getvalue(m_npp, NPNVWindowNPObject, &windowScriptObject);
225 npScript.UTF8Characters = script;
226 npScript.UTF8Length = strlen(script);
228 NPVariant browserResult;
229 browser->evaluate(m_npp, windowScriptObject, &npScript, &browserResult);
230 browser->releasevariantvalue(&browserResult);
233 void PluginTest::log(const char* format, ...)
236 va_start(args, format);
237 pluginLogWithArguments(m_npp, format, args);
241 void PluginTest::waitUntilDone()
243 executeScript("layoutTestController.waitUntilDone()");
246 void PluginTest::notifyDone()
248 executeScript("layoutTestController.notifyDone()");
251 void PluginTest::registerCreateTestFunction(const string& identifier, CreateTestFunction createTestFunction)
253 assert(!createTestFunctions().count(identifier));
255 createTestFunctions()[identifier] = createTestFunction;
258 std::map<std::string, PluginTest::CreateTestFunction>& PluginTest::createTestFunctions()
260 static std::map<std::string, CreateTestFunction> testFunctions;
262 return testFunctions;