This source file includes following definitions.
- create
- m_identifier
- NP_Shutdown
- registerNPShutdownFunction
- indicateTestFailure
- NPP_New
- NPP_Destroy
- NPP_SetWindow
- NPP_NewStream
- NPP_DestroyStream
- NPP_WriteReady
- NPP_Write
- NPP_HandleEvent
- NPP_URLNotify
- NPP_GetValue
- NPP_SetValue
- NPN_GetURL
- NPN_GetURLNotify
- NPN_GetValue
- NPN_InvalidateRect
- NPN_Invoke
- NPN_MemAlloc
- NPN_GetStringIdentifier
- NPN_GetIntIdentifier
- NPN_IdentifierIsString
- NPN_UTF8FromIdentifier
- NPN_IntFromIdentifier
- NPN_CreateObject
- NPN_RetainObject
- NPN_ReleaseObject
- NPN_GetProperty
- NPN_RemoveProperty
- NPN_ReleaseVariantValue
- NPN_ConvertPoint
- executeScript
- executeScript
- log
- netscapeFuncs
- waitUntilDone
- notifyDone
- registerCreateTestFunction
- createTestFunctions
#include "PluginTest.h"
#include "PluginObject.h"
#include <string.h>
#if defined(XP_UNIX) || defined(ANDROID)
#include <unistd.h>
#endif
using namespace std;
extern NPNetscapeFuncs *browser;
static void (*shutdownFunction)();
PluginTest* PluginTest::create(NPP npp, const string& identifier) {
if (identifier.empty())
return new PluginTest(npp, identifier);
CreateTestFunction createTestFunction = createTestFunctions()[identifier];
if (createTestFunction)
return createTestFunction(npp, identifier);
return 0;
}
PluginTest::PluginTest(NPP npp, const string& identifier)
: m_npp(npp), m_identifier(identifier) {
shutdownFunction = 0;
}
PluginTest::~PluginTest() {}
void PluginTest::NP_Shutdown() {
if (shutdownFunction)
shutdownFunction();
}
void PluginTest::registerNPShutdownFunction(void (*func)()) {
assert(!shutdownFunction);
shutdownFunction = func;
}
void PluginTest::indicateTestFailure() {
#if defined(XP_WIN)
::Sleep(100000);
#else
sleep(1000);
#endif
}
NPError PluginTest::NPP_New(NPMIMEType pluginType,
uint16_t mode,
int16_t argc,
char* argn[],
char* argv[],
NPSavedData* saved) {
return NPERR_NO_ERROR;
}
NPError PluginTest::NPP_Destroy(NPSavedData**) { return NPERR_NO_ERROR; }
NPError PluginTest::NPP_SetWindow(NPWindow*) { return NPERR_NO_ERROR; }
NPError PluginTest::NPP_NewStream(NPMIMEType type,
NPStream* stream,
NPBool seekable,
uint16_t* stype) {
return NPERR_NO_ERROR;
}
NPError PluginTest::NPP_DestroyStream(NPStream* stream, NPReason reason) {
return NPERR_NO_ERROR;
}
int32_t PluginTest::NPP_WriteReady(NPStream*) { return 4096; }
int32_t PluginTest::NPP_Write(NPStream*,
int32_t offset,
int32_t len,
void* buffer) {
return len;
}
int16_t PluginTest::NPP_HandleEvent(void*) { return 0; }
bool PluginTest::NPP_URLNotify(const char* url, NPReason, void* notifyData) {
return false;
}
NPError PluginTest::NPP_GetValue(NPPVariable variable, void* value) {
return NPERR_GENERIC_ERROR;
}
NPError PluginTest::NPP_SetValue(NPNVariable, void* value) {
return NPERR_GENERIC_ERROR;
}
NPError PluginTest::NPN_GetURL(const char* url, const char* target) {
return browser->geturl(m_npp, url, target);
}
NPError PluginTest::NPN_GetURLNotify(const char* url,
const char* target,
void* notifyData) {
return browser->geturlnotify(m_npp, url, target, notifyData);
}
NPError PluginTest::NPN_GetValue(NPNVariable variable, void* value) {
return browser->getvalue(m_npp, variable, value);
}
void PluginTest::NPN_InvalidateRect(NPRect* invalidRect) {
browser->invalidaterect(m_npp, invalidRect);
}
bool PluginTest::NPN_Invoke(NPObject* npobj,
NPIdentifier methodName,
const NPVariant* args,
uint32_t argCount,
NPVariant* result) {
return browser->invoke(m_npp, npobj, methodName, args, argCount, result);
}
void* PluginTest::NPN_MemAlloc(uint32_t size) {
return browser->memalloc(size);
}
NPIdentifier PluginTest::NPN_GetStringIdentifier(const NPUTF8* name) {
return browser->getstringidentifier(name);
}
NPIdentifier PluginTest::NPN_GetIntIdentifier(int32_t intid) {
return browser->getintidentifier(intid);
}
bool PluginTest::NPN_IdentifierIsString(NPIdentifier npIdentifier) {
return browser->identifierisstring(npIdentifier);
}
NPUTF8* PluginTest::NPN_UTF8FromIdentifier(NPIdentifier npIdentifier) {
return browser->utf8fromidentifier(npIdentifier);
}
int32_t PluginTest::NPN_IntFromIdentifier(NPIdentifier npIdentifier) {
return browser->intfromidentifier(npIdentifier);
}
NPObject* PluginTest::NPN_CreateObject(NPClass* npClass) {
return browser->createobject(m_npp, npClass);
}
NPObject* PluginTest::NPN_RetainObject(NPObject* npObject) {
return browser->retainobject(npObject);
}
void PluginTest::NPN_ReleaseObject(NPObject* npObject) {
browser->releaseobject(npObject);
}
bool PluginTest::NPN_GetProperty(NPObject* npObject,
NPIdentifier propertyName,
NPVariant* value) {
return browser->getproperty(m_npp, npObject, propertyName, value);
}
bool PluginTest::NPN_RemoveProperty(NPObject* npObject,
NPIdentifier propertyName) {
return browser->removeproperty(m_npp, npObject, propertyName);
}
void PluginTest::NPN_ReleaseVariantValue(NPVariant* variant) {
browser->releasevariantvalue(variant);
}
#ifdef XP_MACOSX
bool PluginTest::NPN_ConvertPoint(double sourceX,
double sourceY,
NPCoordinateSpace sourceSpace,
double* destX,
double* destY,
NPCoordinateSpace destSpace) {
return browser->convertpoint(
m_npp, sourceX, sourceY, sourceSpace, destX, destY, destSpace);
}
#endif
bool PluginTest::executeScript(const NPString* script, NPVariant* result) {
NPObject* windowScriptObject;
browser->getvalue(m_npp, NPNVWindowNPObject, &windowScriptObject);
return browser->evaluate(
m_npp, windowScriptObject, const_cast<NPString*>(script), result);
}
void PluginTest::executeScript(const char* script) {
NPString npScript;
npScript.UTF8Characters = script;
npScript.UTF8Length = strlen(script);
NPVariant browserResult;
executeScript(&npScript, &browserResult);
browser->releasevariantvalue(&browserResult);
}
void PluginTest::log(const char* format, ...) {
va_list args;
va_start(args, format);
pluginLogWithArguments(m_npp, format, args);
va_end(args);
}
NPNetscapeFuncs* PluginTest::netscapeFuncs() { return browser; }
void PluginTest::waitUntilDone() {
executeScript("testRunner.waitUntilDone()");
}
void PluginTest::notifyDone() { executeScript("testRunner.notifyDone()"); }
void PluginTest::registerCreateTestFunction(
const string& identifier,
CreateTestFunction createTestFunction) {
assert(!createTestFunctions().count(identifier));
createTestFunctions()[identifier] = createTestFunction;
}
std::map<std::string, PluginTest::CreateTestFunction>&
PluginTest::createTestFunctions() {
static std::map<std::string, CreateTestFunction> testFunctions;
return testFunctions;
}