0

Remove NPAPI test plugin

Naga... Naga... Naga... Not gonna work here anymore, anyway.

BUG=474535,493212

Review URL: https://codereview.chromium.org/1852523003

Cr-Commit-Position: refs/heads/master@{#384728}
This commit is contained in:
piman
2016-04-01 16:54:04 -07:00
committed by Commit bot
parent 5a009bd874
commit ad12e38032
38 changed files with 1 additions and 5029 deletions

@ -388,7 +388,6 @@
# ../chrome/test/mini_installer requires mini_installer.
'../chrome/installer/mini_installer.gyp:mini_installer',
'../chrome_elf/chrome_elf.gyp:chrome_elf_unittests',
'../content/content_shell_and_tests.gyp:copy_test_netscape_plugin',
'../courgette/courgette.gyp:courgette_unittests',
'../sandbox/sandbox.gyp:sbox_integration_tests',
'../sandbox/sandbox.gyp:sbox_unittests',
@ -1040,7 +1039,6 @@
'../components/components_tests.gyp:components_unittests',
'../content/content_shell_and_tests.gyp:content_browsertests',
'../content/content_shell_and_tests.gyp:content_unittests',
'../content/content_shell_and_tests.gyp:copy_test_netscape_plugin',
# ../chrome/test/mini_installer requires mini_installer.
'../chrome/installer/mini_installer.gyp:mini_installer',
'../courgette/courgette.gyp:courgette_unittests',

@ -185,7 +185,6 @@
'<(PRODUCT_DIR)/content_shell.pak',
'<(PRODUCT_DIR)/libclearkeycdm.dylib',
'<(PRODUCT_DIR)/osmesa.so',
'<(PRODUCT_DIR)/plugins/test_netscape_plugin.plugin/',
'<(PRODUCT_DIR)/power_saver_test_plugin.plugin/Contents/MacOS/power_saver_test_plugin',
'<(PRODUCT_DIR)/ppapi_tests.plugin/Contents/MacOS/ppapi_tests',
],
@ -207,7 +206,6 @@
'<(PRODUCT_DIR)/clearkeycdm.dll',
'<(PRODUCT_DIR)/clearkeycdmadapter.dll',
'<(PRODUCT_DIR)/crashpad_handler.exe',
'<(PRODUCT_DIR)/plugins/',
'<(PRODUCT_DIR)/power_saver_test_plugin.dll',
'<(PRODUCT_DIR)/ppapi_tests.dll',
'tools/build/repack_locales.py',

@ -3301,7 +3301,6 @@
'target_name': 'browser_tests_run',
'type': 'none',
'dependencies': [
'../content/content_shell_and_tests.gyp:copy_test_netscape_plugin',
'browser_tests',
'chrome',
],

@ -111,8 +111,6 @@ component("test_runner") {
"//ui/gfx/geometry",
"//url",
"//v8",
#'copy_test_netscape_plugin', TODO(GYP)
]
}

@ -92,7 +92,6 @@
'variables': {
'files': [
'<(PRODUCT_DIR)/Content Shell.app/',
'<(PRODUCT_DIR)/plugins/test_netscape_plugin.plugin/',
'<(PRODUCT_DIR)/ppapi_tests.plugin/Contents/MacOS/ppapi_tests',
],
},
@ -105,7 +104,6 @@
'<(PRODUCT_DIR)/Content Shell.app.dSYM/',
'<(PRODUCT_DIR)/content_browsertests.dSYM/',
'<(PRODUCT_DIR)/ppapi_tests.plugin.dSYM/',
'<(PRODUCT_DIR)/test_netscape_plugin.plugin.dSYM/',
],
},
}],
@ -113,7 +111,6 @@
'variables': {
'files': [
'<(PRODUCT_DIR)/osmesa.dll',
'<(PRODUCT_DIR)/plugins/np_test_netscape_plugin.dll',
'<(PRODUCT_DIR)/ppapi_tests.dll',
],
},

@ -33,7 +33,6 @@
'content_shell_resources',
'content_shell_mojo_bindings',
'content_test_mojo_bindings',
'copy_test_netscape_plugin',
'layouttest_support_content',
'../base/base.gyp:base',
'../base/base.gyp:base_static',
@ -548,104 +547,6 @@
'content_shell',
],
},
{
'target_name': 'test_netscape_plugin',
'conditions': [
['OS != "win" and OS != "mac"', {
'type': 'none',
}, { # OS=="win" or OS=="mac"
'type': 'loadable_module',
'sources': [
'shell/tools/plugin/PluginObject.cpp',
'shell/tools/plugin/PluginObject.h',
'shell/tools/plugin/PluginTest.cpp',
'shell/tools/plugin/PluginTest.h',
'shell/tools/plugin/TestObject.cpp',
'shell/tools/plugin/Tests/EvaluateJSAfterRemovingPluginElement.cpp',
'shell/tools/plugin/Tests/FormValue.cpp',
'shell/tools/plugin/Tests/GetUserAgentWithNullNPPFromNPPNew.cpp',
'shell/tools/plugin/Tests/LeakWindowScriptableObject.cpp',
'shell/tools/plugin/Tests/LogNPPSetWindow.cpp',
'shell/tools/plugin/Tests/NPDeallocateCalledBeforeNPShutdown.cpp',
'shell/tools/plugin/Tests/NPPNewFails.cpp',
'shell/tools/plugin/Tests/NPRuntimeCallsWithNullNPP.cpp',
'shell/tools/plugin/Tests/NPRuntimeObjectFromDestroyedPlugin.cpp',
'shell/tools/plugin/Tests/NPRuntimeRemoveProperty.cpp',
'shell/tools/plugin/Tests/NullNPPGetValuePointer.cpp',
'shell/tools/plugin/Tests/PassDifferentNPPStruct.cpp',
'shell/tools/plugin/Tests/PluginScriptableNPObjectInvokeDefault.cpp',
'shell/tools/plugin/Tests/PluginScriptableObjectOverridesAllProperties.cpp',
'shell/tools/plugin/main.cpp',
'shell/tools/plugin/test_object.h',
],
'include_dirs': [
'<(DEPTH)',
'<(DEPTH)/content/shell/tools/plugin/',
],
'dependencies': [
'../base/base.gyp:base',
'../third_party/npapi/npapi.gyp:npapi',
],
'conditions': [
['OS=="mac"', {
'mac_bundle': 1,
'product_extension': 'plugin',
'link_settings': {
'libraries': [
'$(SDKROOT)/System/Library/Frameworks/Carbon.framework',
'$(SDKROOT)/System/Library/Frameworks/Cocoa.framework',
'$(SDKROOT)/System/Library/Frameworks/QuartzCore.framework',
]
},
'xcode_settings': {
'GCC_SYMBOLS_PRIVATE_EXTERN': 'NO',
'INFOPLIST_FILE': 'shell/tools/plugin/mac/Info.plist',
},
}],
['OS=="win"', {
'conditions': [
['MSVS_VERSION < "2015"', {
'defines': [
# This seems like a hack, but this is what Safari Win does.
# Luckily it is no longer needed/allowed with VS 2015.
'snprintf=_snprintf',
],
}],
],
'sources': [
'shell/tools/plugin/win/TestNetscapePlugin.def',
'shell/tools/plugin/win/TestNetscapePlugin.rc',
],
# The .rc file requires that the name of the dll is np_test_netscape_plugin.dll.
'product_name': 'np_test_netscape_plugin',
# Disable c4267 warnings until we fix size_t to int truncations.
'msvs_disabled_warnings': [ 4267, ],
}],
],
}],
],
},
{
'target_name': 'copy_test_netscape_plugin',
'type': 'none',
'dependencies': [
'test_netscape_plugin',
],
'conditions': [
['OS=="win"', {
'copies': [{
'destination': '<(PRODUCT_DIR)/plugins',
'files': ['<(PRODUCT_DIR)/np_test_netscape_plugin.dll'],
}],
}],
['OS=="mac"', {
'copies': [{
'destination': '<(PRODUCT_DIR)/plugins/',
'files': ['<(PRODUCT_DIR)/test_netscape_plugin.plugin/'],
}],
}],
],
},
{
'target_name': 'content_shell_mojo_bindings_mojom',
'type': 'none',

@ -252,8 +252,6 @@ static_library("content_shell_lib") {
"//ui/gl",
"//url",
"//v8",
#'copy_test_netscape_plugin', TODO(GYP)
]
if (enable_plugins) {
deps += [
@ -294,7 +292,6 @@ static_library("content_shell_lib") {
if (is_android) {
deps += [ "//content/shell/android:content_shell_jni_headers" ]
#deps -= [ "copy_test_netscape_plugin" ] TODO(GYP)
}
if (is_posix && !is_mac) {
@ -332,11 +329,6 @@ static_library("content_shell_lib") {
]
}
# The test plugin relies on X11.
if (is_linux && !use_x11) {
#deps -= [ 'copy_test_netscape_plugin' ] TODO(GYP)
}
if (is_chromeos) {
deps += [
"//chromeos",

File diff suppressed because it is too large Load Diff

@ -1,94 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PluginObject_h
#define PluginObject_h
#include <bindings/npfunctions.h>
#include <stdarg.h>
class PluginTest;
extern NPNetscapeFuncs *browser;
extern NPPluginFuncs* pluginFunctions;
typedef struct {
NPObject header;
PluginTest* pluginTest;
NPP npp;
NPBool eventLogging;
NPBool logSetWindow;
NPBool logDestroy;
NPBool returnNegativeOneFromWrite;
NPBool returnErrorFromNewStream;
NPObject* testObject;
NPObject* rememberedObject;
NPStream* stream;
NPBool testGetURLOnDestroy;
NPBool testWindowOpen;
NPBool testKeyboardFocusForPlugins;
NPBool mouseDownForEvaluateScript;
char* onStreamLoad;
char* onStreamDestroy;
char* onDestroy;
char* onURLNotify;
char* onSetWindow;
char* onPaintEvent;
char* firstUrl;
char* firstHeaders;
char* lastUrl;
char* lastHeaders;
char* evaluateScriptOnMouseDownOrKeyDown;
#ifdef XP_MACOSX
NPEventModel eventModel;
#endif
NPWindow lastWindow;
NPBool alwaysFilterEvents;
} PluginObject;
extern NPClass* createPluginClass(void);
extern void handleCallback(PluginObject* object,
const char* url,
NPReason reason,
void* notifyData);
extern void notifyStream(PluginObject* object,
const char* url,
const char* headers);
extern void testNPRuntime(NPP npp);
extern void pluginLog(NPP instance, const char* format, ...);
extern void pluginLogWithArguments(NPP instance,
const char* format,
va_list args);
extern bool testDocumentOpen(NPP npp);
extern bool testWindowOpen(NPP npp);
#endif // PluginObject_h

@ -1,265 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#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) {
// Reset the shutdown function.
shutdownFunction = 0;
}
PluginTest::~PluginTest() {}
void PluginTest::NP_Shutdown() {
if (shutdownFunction)
shutdownFunction();
}
void PluginTest::registerNPShutdownFunction(void (*func)()) {
assert(!shutdownFunction);
shutdownFunction = func;
}
void PluginTest::indicateTestFailure() {
// This should really be an assert, but there's no way for the test framework
// to know that the plugin process crashed, so we'll just sleep for a while
// to ensure that the test times out.
#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) {
// FIXME: Port the code from NPP_URLNotify in main.cpp over to always using
// PluginTest, so we don't have to use a return value to indicate whether the
// "default" NPP_URLNotify implementation should be invoked.
return false;
}
NPError PluginTest::NPP_GetValue(NPPVariable variable, void* value) {
// We don't know anything about plugin values so just return
// NPERR_GENERIC_ERROR.
return NPERR_GENERIC_ERROR;
}
NPError PluginTest::NPP_SetValue(NPNVariable, void* value) {
return NPERR_GENERIC_ERROR;
}
// NPN functions.
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);
}
// NPRuntime NPN functions.
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;
}

@ -1,302 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PluginTest_h
#define PluginTest_h
#include <assert.h>
#include <bindings/npfunctions.h>
#include <stdint.h>
#include <map>
#include <string>
// Helper classes for implementing has_member
typedef char (&no_tag)[1];
typedef char (&yes_tag)[2];
#define DEFINE_HAS_MEMBER_CHECK(member, returnType, argumentTypes) \
template <typename T, returnType(T::*member) argumentTypes> \
struct pmf_##member##_helper {}; \
template <typename T> \
no_tag has_member_##member##_helper(...); \
template <typename T> \
yes_tag has_member_##member##_helper(pmf_##member##_helper<T, &T::member>*); \
template <typename T> \
struct has_member_##member { \
static const bool value = \
sizeof(has_member_##member##_helper<T>(0)) == sizeof(yes_tag); \
};
DEFINE_HAS_MEMBER_CHECK(hasMethod, bool, (NPIdentifier methodName));
DEFINE_HAS_MEMBER_CHECK(
invoke,
bool,
(NPIdentifier methodName, const NPVariant*, uint32_t, NPVariant* result));
DEFINE_HAS_MEMBER_CHECK(invokeDefault,
bool,
(const NPVariant*, uint32_t, NPVariant* result));
DEFINE_HAS_MEMBER_CHECK(hasProperty, bool, (NPIdentifier propertyName));
DEFINE_HAS_MEMBER_CHECK(getProperty,
bool,
(NPIdentifier propertyName, NPVariant* result));
DEFINE_HAS_MEMBER_CHECK(removeProperty, bool, (NPIdentifier propertyName));
class PluginTest {
public:
static PluginTest* create(NPP, const std::string& identifier);
virtual ~PluginTest();
static void NP_Shutdown();
// NPP functions.
virtual NPError NPP_New(NPMIMEType pluginType,
uint16_t mode,
int16_t argc,
char* argn[],
char* argv[],
NPSavedData* saved);
virtual NPError NPP_Destroy(NPSavedData**);
virtual NPError NPP_SetWindow(NPWindow*);
virtual NPError NPP_NewStream(NPMIMEType,
NPStream*,
NPBool seekable,
uint16_t* stype);
virtual NPError NPP_DestroyStream(NPStream*, NPReason);
virtual int32_t NPP_WriteReady(NPStream*);
virtual int32_t NPP_Write(NPStream*,
int32_t offset,
int32_t len,
void* buffer);
virtual int16_t NPP_HandleEvent(void* event);
virtual bool NPP_URLNotify(const char* url, NPReason, void* notifyData);
virtual NPError NPP_GetValue(NPPVariable, void* value);
virtual NPError NPP_SetValue(NPNVariable, void* value);
// NPN functions.
NPError NPN_GetValue(NPNVariable, void* value);
void NPN_InvalidateRect(NPRect* invalidRect);
bool NPN_Invoke(NPObject*,
NPIdentifier methodName,
const NPVariant* args,
uint32_t argCount,
NPVariant* result);
void* NPN_MemAlloc(uint32_t size);
// NPRuntime NPN functions.
NPIdentifier NPN_GetStringIdentifier(const NPUTF8* name);
NPIdentifier NPN_GetIntIdentifier(int32_t intid);
bool NPN_IdentifierIsString(NPIdentifier);
NPUTF8* NPN_UTF8FromIdentifier(NPIdentifier);
int32_t NPN_IntFromIdentifier(NPIdentifier);
NPObject* NPN_CreateObject(NPClass*);
NPObject* NPN_RetainObject(NPObject*);
void NPN_ReleaseObject(NPObject*);
bool NPN_GetProperty(NPObject*, NPIdentifier propertyName, NPVariant* value);
bool NPN_RemoveProperty(NPObject*, NPIdentifier propertyName);
void NPN_ReleaseVariantValue(NPVariant*);
#ifdef XP_MACOSX
bool NPN_ConvertPoint(double sourceX,
double sourceY,
NPCoordinateSpace sourceSpace,
double* destX,
double* destY,
NPCoordinateSpace destSpace);
#endif
bool executeScript(const NPString*, NPVariant* result);
void executeScript(const char*);
void log(const char* format, ...);
void registerNPShutdownFunction(void (*)());
static void indicateTestFailure();
template <typename TestClassTy>
class Register {
public:
Register(const std::string& identifier) {
registerCreateTestFunction(identifier, Register::create);
}
private:
static PluginTest* create(NPP npp, const std::string& identifier) {
return new TestClassTy(npp, identifier);
}
};
protected:
PluginTest(NPP npp, const std::string& identifier);
// FIXME: A plugin test shouldn't need to know about it's NPP. Make this
// private.
NPP m_npp;
const std::string& identifier() const { return m_identifier; }
static NPNetscapeFuncs* netscapeFuncs();
void waitUntilDone();
void notifyDone();
// NPObject helper template.
template <typename T>
struct Object : NPObject {
public:
static NPObject* create(PluginTest* pluginTest) {
Object* object =
static_cast<Object*>(pluginTest->NPN_CreateObject(npClass()));
object->m_pluginTest = pluginTest;
return object;
}
// These should never be called.
bool hasMethod(NPIdentifier methodName) {
assert(false);
return false;
}
bool invoke(NPIdentifier methodName,
const NPVariant*,
uint32_t,
NPVariant* result) {
assert(false);
return false;
}
bool invokeDefault(const NPVariant*, uint32_t, NPVariant* result) {
assert(false);
return false;
}
bool hasProperty(NPIdentifier propertyName) {
assert(false);
return false;
}
bool getProperty(NPIdentifier propertyName, NPVariant* result) {
assert(false);
return false;
}
bool removeProperty(NPIdentifier propertyName) {
assert(false);
return false;
}
// Helper functions.
bool identifierIs(NPIdentifier identifier, const char* value) {
return pluginTest()->NPN_GetStringIdentifier(value) == identifier;
}
protected:
Object() : m_pluginTest(0) {}
virtual ~Object() {}
PluginTest* pluginTest() const { return m_pluginTest; }
private:
static NPObject* NP_Allocate(NPP npp, NPClass* aClass) { return new T; }
static void NP_Deallocate(NPObject* npObject) {
delete static_cast<T*>(npObject);
}
static bool NP_HasMethod(NPObject* npObject, NPIdentifier methodName) {
return static_cast<T*>(npObject)->hasMethod(methodName);
}
static bool NP_Invoke(NPObject* npObject,
NPIdentifier methodName,
const NPVariant* arguments,
uint32_t argumentCount,
NPVariant* result) {
return static_cast<T*>(npObject)
->invoke(methodName, arguments, argumentCount, result);
}
static bool NP_InvokeDefault(NPObject* npObject,
const NPVariant* arguments,
uint32_t argumentCount,
NPVariant* result) {
return static_cast<T*>(npObject)
->invokeDefault(arguments, argumentCount, result);
}
static bool NP_HasProperty(NPObject* npObject, NPIdentifier propertyName) {
return static_cast<T*>(npObject)->hasProperty(propertyName);
}
static bool NP_GetProperty(NPObject* npObject,
NPIdentifier propertyName,
NPVariant* result) {
return static_cast<T*>(npObject)->getProperty(propertyName, result);
}
static bool NP_RemoveProperty(NPObject* npObject,
NPIdentifier propertyName) {
return static_cast<T*>(npObject)->removeProperty(propertyName);
}
static NPClass* npClass() {
static NPClass npClass = {
NP_CLASS_STRUCT_VERSION, NP_Allocate, NP_Deallocate,
0, // NPClass::invalidate
has_member_hasMethod<T>::value ? NP_HasMethod : 0,
has_member_invoke<T>::value ? NP_Invoke : 0,
has_member_invokeDefault<T>::value ? NP_InvokeDefault : 0,
has_member_hasProperty<T>::value ? NP_HasProperty : 0,
has_member_getProperty<T>::value ? NP_GetProperty : 0,
0, // NPClass::setProperty
has_member_removeProperty<T>::value ? NP_RemoveProperty : 0,
0, // NPClass::enumerate
0 // NPClass::construct
};
return &npClass;
};
PluginTest* m_pluginTest;
};
private:
typedef PluginTest* (*CreateTestFunction)(NPP, const std::string&);
static void registerCreateTestFunction(const std::string&,
CreateTestFunction);
static std::map<std::string, CreateTestFunction>& createTestFunctions();
std::string m_identifier;
};
#endif // PluginTest_h

@ -1,222 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2007 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "content/shell/tools/plugin/test_object.h"
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "PluginObject.h"
static bool testEnumerate(NPObject* npobj,
NPIdentifier** value,
uint32_t* count);
static bool testHasMethod(NPObject*, NPIdentifier name);
static bool testInvoke(NPObject*,
NPIdentifier name,
const NPVariant* args,
uint32_t argCount,
NPVariant* result);
static bool testHasProperty(NPObject*, NPIdentifier name);
static bool testGetProperty(NPObject*, NPIdentifier name, NPVariant*);
static NPObject* testAllocate(NPP npp, NPClass* theClass);
static void testDeallocate(NPObject* obj);
static bool testConstruct(NPObject* obj,
const NPVariant* args,
uint32_t argCount,
NPVariant* result);
static NPClass g_test_class = {
NP_CLASS_STRUCT_VERSION, testAllocate, testDeallocate, 0,
testHasMethod, testInvoke, 0, testHasProperty,
testGetProperty, 0, 0, testEnumerate,
testConstruct};
static int g_test_object_count = 0;
typedef struct {
NPObject header;
NPObject* testObject;
} TestObject;
static bool identifiersInitialized = false;
#define NUM_ENUMERATABLE_TEST_IDENTIFIERS 2
enum {
ID_PROPERTY_FOO = 0,
ID_PROPERTY_BAR,
ID_PROPERTY_OBJECT_POINTER,
ID_PROPERTY_TEST_OBJECT,
ID_PROPERTY_REF_COUNT,
NUM_TEST_IDENTIFIERS,
};
static NPIdentifier testIdentifiers[NUM_TEST_IDENTIFIERS];
static const NPUTF8* testIdentifierNames[NUM_TEST_IDENTIFIERS] = {
"foo", "bar", "objectPointer", "testObject", "refCount", };
#define ID_THROW_EXCEPTION_METHOD 0
#define NUM_METHOD_IDENTIFIERS 1
static NPIdentifier testMethodIdentifiers[NUM_METHOD_IDENTIFIERS];
static const NPUTF8* testMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
"throwException", };
static void initializeIdentifiers(void) {
browser->getstringidentifiers(
testIdentifierNames, NUM_TEST_IDENTIFIERS, testIdentifiers);
browser->getstringidentifiers(
testMethodIdentifierNames, NUM_METHOD_IDENTIFIERS, testMethodIdentifiers);
}
static NPObject* testAllocate(NPP npp, NPClass* /*theClass*/) {
TestObject* newInstance =
static_cast<TestObject*>(malloc(sizeof(TestObject)));
newInstance->testObject = 0;
++g_test_object_count;
if (!identifiersInitialized) {
identifiersInitialized = true;
initializeIdentifiers();
}
return reinterpret_cast<NPObject*>(newInstance);
}
static void testDeallocate(NPObject* obj) {
TestObject* testObject = reinterpret_cast<TestObject*>(obj);
if (testObject->testObject)
browser->releaseobject(testObject->testObject);
--g_test_object_count;
free(obj);
}
static bool testHasMethod(NPObject*, NPIdentifier name) {
for (unsigned i = 0; i < NUM_METHOD_IDENTIFIERS; i++) {
if (testMethodIdentifiers[i] == name)
return true;
}
return false;
}
static bool testInvoke(NPObject* header,
NPIdentifier name,
const NPVariant* /*args*/,
uint32_t /*argCount*/,
NPVariant* /*result*/) {
if (name == testMethodIdentifiers[ID_THROW_EXCEPTION_METHOD]) {
browser->setexception(header, "test object throwException SUCCESS");
return true;
}
return false;
}
static bool testHasProperty(NPObject*, NPIdentifier name) {
for (unsigned i = 0; i < NUM_TEST_IDENTIFIERS; i++) {
if (testIdentifiers[i] == name)
return true;
}
return false;
}
static bool testGetProperty(NPObject* npobj,
NPIdentifier name,
NPVariant* result) {
if (name == testIdentifiers[ID_PROPERTY_FOO]) {
char* mem = static_cast<char*>(browser->memalloc(4));
strcpy(mem, "foo");
STRINGZ_TO_NPVARIANT(mem, *result);
return true;
}
if (name == testIdentifiers[ID_PROPERTY_BAR]) {
char* mem = static_cast<char*>(browser->memalloc(4));
strcpy(mem, "bar");
STRINGZ_TO_NPVARIANT(mem, *result);
return true;
}
if (name == testIdentifiers[ID_PROPERTY_OBJECT_POINTER]) {
int32_t objectPointer =
static_cast<int32_t>(reinterpret_cast<long long>(npobj));
INT32_TO_NPVARIANT(objectPointer, *result);
return true;
}
if (name == testIdentifiers[ID_PROPERTY_TEST_OBJECT]) {
TestObject* testObject = reinterpret_cast<TestObject*>(npobj);
if (!testObject->testObject)
testObject->testObject = browser->createobject(0, &g_test_class);
browser->retainobject(testObject->testObject);
OBJECT_TO_NPVARIANT(testObject->testObject, *result);
return true;
}
if (name == testIdentifiers[ID_PROPERTY_REF_COUNT]) {
INT32_TO_NPVARIANT(npobj->referenceCount, *result);
return true;
}
return false;
}
static bool testEnumerate(NPObject* /*npobj*/,
NPIdentifier** value,
uint32_t* count) {
*count = NUM_ENUMERATABLE_TEST_IDENTIFIERS;
*value = (NPIdentifier*)browser->memalloc(NUM_ENUMERATABLE_TEST_IDENTIFIERS *
sizeof(NPIdentifier));
memcpy(*value,
testIdentifiers,
sizeof(NPIdentifier) * NUM_ENUMERATABLE_TEST_IDENTIFIERS);
return true;
}
static bool testConstruct(NPObject* npobj,
const NPVariant* /*args*/,
uint32_t /*argCount*/,
NPVariant* result) {
browser->retainobject(npobj);
// Just return the same object.
OBJECT_TO_NPVARIANT(npobj, *result);
return true;
}
namespace content {
NPClass* GetTestClass() { return &g_test_class; }
int GetTestObjectCount() { return g_test_object_count; }
} // namespace content

@ -1,68 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "PluginTest.h"
#include "PluginObject.h"
using namespace std;
// Executing JS after removing the plugin element from the document should not crash.
class EvaluateJSAfterRemovingPluginElement : public PluginTest {
public:
EvaluateJSAfterRemovingPluginElement(NPP, const string& identifier);
private:
NPError NPP_DestroyStream(NPStream*, NPReason) override;
bool m_didExecuteScript;
};
static PluginTest::Register<EvaluateJSAfterRemovingPluginElement> registrar("evaluate-js-after-removing-plugin-element");
EvaluateJSAfterRemovingPluginElement::EvaluateJSAfterRemovingPluginElement(NPP npp, const string& identifier)
: PluginTest(npp, identifier)
, m_didExecuteScript(false)
{
waitUntilDone();
}
NPError EvaluateJSAfterRemovingPluginElement::NPP_DestroyStream(NPStream*, NPReason)
{
if (m_didExecuteScript)
return NPERR_NO_ERROR;
m_didExecuteScript = true;
executeScript("var plugin = document.getElementsByTagName('embed')[0]; plugin.parentElement.removeChild(plugin);");
executeScript("document.body.appendChild(document.createTextNode('Executing script after removing the plugin element from the document succeeded.'));");
notifyDone();
return NPERR_NO_ERROR;
}

@ -1,62 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "PluginTest.h"
#include <stdint.h>
#include "PluginObject.h"
using namespace std;
// Executing JS within NPP_New when initializing asynchronously should not be able to deadlock with the WebProcess
class EvaluteJSWithinNPP_New : public PluginTest {
public:
EvaluteJSWithinNPP_New(NPP, const string& identifier);
private:
virtual NPError NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData *);
};
EvaluteJSWithinNPP_New::EvaluteJSWithinNPP_New(NPP npp, const string& identifier)
: PluginTest(npp, identifier)
{
}
NPError EvaluteJSWithinNPP_New::NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData *saved)
{
// Give the WebProcess enough time to be deadlocked waiting for the PluginProcess.
usleep(15000);
executeScript("var theLocation = window.location;");
return NPERR_NO_ERROR;
}
static PluginTest::Register<EvaluteJSWithinNPP_New> registrar("evalute-js-within-npp-new");

@ -1,32 +0,0 @@
// Copyright 2014 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 "PluginTest.h"
#include <string.h>
extern NPNetscapeFuncs *browser;
class FormValue : public PluginTest {
public:
FormValue(NPP npp, const std::string& identifier)
: PluginTest(npp, identifier)
{
}
NPError NPP_GetValue(NPPVariable, void*) override;
};
NPError FormValue::NPP_GetValue(NPPVariable variable, void *value)
{
if (variable == NPPVformValue) {
static const char formValueText[] = "Plugin form value";
*((void**)value) = browser->memalloc(sizeof(formValueText));
if (!*((void**)value))
return NPERR_OUT_OF_MEMORY_ERROR;
strncpy(*((char**)value), formValueText, sizeof(formValueText));
return NPERR_NO_ERROR;
}
return NPERR_GENERIC_ERROR;
}
static PluginTest::Register<FormValue> formValue("form-value");

@ -1,64 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "PluginTest.h"
#include <stdint.h>
#include "PluginObject.h"
using namespace std;
// Trying to get the user agent with a null instance from NPP_New.
class GetUserAgentWithNullNPPFromNPPNew : public PluginTest {
public:
GetUserAgentWithNullNPPFromNPPNew(NPP npp, const string& identifier)
: PluginTest(npp, identifier)
{
}
private:
NPError NPP_New(NPMIMEType pluginType,
uint16_t mode,
int16_t argc,
char* argn[],
char* argv[],
NPSavedData* saved) override {
if (!browser->uagent(0))
pluginLog(m_npp, "FAILURE: Null user agent returned.");
else
pluginLog(m_npp, "SUCCESS!");
return NPERR_NO_ERROR;
}
};
static PluginTest::Register<GetUserAgentWithNullNPPFromNPPNew> getUserAgentWithNullNPPFromNPPNew("get-user-agent-with-null-npp-from-npp-new");

@ -1,73 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "PluginTest.h"
#include <stdint.h>
#include "PluginObject.h"
using namespace std;
// Executing JS within NPP_New when initializing asynchronously should not be able to deadlock with the WebProcess
class InvokeDestroysPluginWithinNPP_New : public PluginTest {
public:
InvokeDestroysPluginWithinNPP_New(NPP, const string& identifier);
private:
virtual NPError NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData *);
};
InvokeDestroysPluginWithinNPP_New::InvokeDestroysPluginWithinNPP_New(NPP npp, const string& identifier)
: PluginTest(npp, identifier)
{
}
NPError InvokeDestroysPluginWithinNPP_New::NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData *saved)
{
// Give the WebProcess enough time to be deadlocked waiting for the PluginProcess if things aren't working correctly.
usleep(15000);
NPObject* windowObject = 0;
if (NPN_GetValue(NPNVWindowNPObject, &windowObject) != NPERR_NO_ERROR)
return NPERR_GENERIC_ERROR;
if (!windowObject)
return NPERR_GENERIC_ERROR;
NPVariant result;
if (!NPN_Invoke(windowObject, NPN_GetStringIdentifier("removePluginElement"), 0, 0, &result))
return NPERR_GENERIC_ERROR;
return NPERR_NO_ERROR;
}
static PluginTest::Register<InvokeDestroysPluginWithinNPP_New> registrar("invoke-destroys-plugin-within-npp-new");

@ -1,49 +0,0 @@
// Copyright 2014 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 <stdint.h>
#include "PluginTest.h"
using namespace std;
class LeakWindowScriptableObject : public PluginTest {
public:
LeakWindowScriptableObject(NPP npp, const string& identifier)
: PluginTest(npp, identifier)
{
}
private:
NPError NPP_New(NPMIMEType pluginType,
uint16_t mode,
int16_t argc,
char* argn[],
char* argv[],
NPSavedData* saved) override {
// Get a new reference to the window script object.
NPObject* window;
if (NPN_GetValue(NPNVWindowNPObject, &window) != NPERR_NO_ERROR) {
log("Fail: Cannot fetch window script object");
return NPERR_NO_ERROR;
}
// Get another reference to the same object via window.self.
NPIdentifier self_name = NPN_GetStringIdentifier("self");
NPVariant window_self_variant;
if (!NPN_GetProperty(window, self_name, &window_self_variant)) {
log("Fail: Cannot query window.self");
return NPERR_NO_ERROR;
}
if (!NPVARIANT_IS_OBJECT(window_self_variant)) {
log("Fail: window.self is not an object");
return NPERR_NO_ERROR;
}
// Leak both references to the window script object.
return NPERR_NO_ERROR;
}
};
static PluginTest::Register<LeakWindowScriptableObject> leakWindowScriptableObject("leak-window-scriptable-object");

@ -1,65 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "PluginTest.h"
#include <stdio.h>
using namespace std;
class LogNPPSetWindow : public PluginTest {
public:
LogNPPSetWindow(NPP, const string& identifier);
private:
NPError NPP_SetWindow(NPWindow*) override;
};
LogNPPSetWindow::LogNPPSetWindow(NPP npp, const string& identifier)
: PluginTest(npp, identifier)
{
}
NPError LogNPPSetWindow::NPP_SetWindow(NPWindow* window)
{
char message[1024];
snprintf(message, 1024, "NPP_SetWindow: %s window, Rect {%i, %i, %i, %i}, Clip Rect {%i, %i, %i, %i}, Type %i",
window->window ? "non-NULL" : "NULL", window->x, window->y, window->width, window->height,
window->clipRect.left, window->clipRect.top, window->clipRect.right, window->clipRect.bottom,
window->type);
char script[1536];
snprintf(script, 1536, "window.setTimeout('windowWasSet(\"%s\");', 0);", message);
executeScript(script);
return NPERR_NO_ERROR;
}
static PluginTest::Register<LogNPPSetWindow> registrar("log-npp-set-window");

@ -1,102 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include "PluginTest.h"
using namespace std;
static bool wasShutdownCalled = false;
class NPDeallocateCalledBeforeNPShutdown : public PluginTest {
public:
NPDeallocateCalledBeforeNPShutdown(NPP npp, const string& identifier)
: PluginTest(npp, identifier)
{
}
private:
// This is the test object.
class TestObject : public Object<TestObject> {
public:
~TestObject() override {
if (wasShutdownCalled)
indicateTestFailure();
}
};
// This is the scriptable object. It has a single "testObject" property.
class ScriptableObject : public Object<ScriptableObject> {
public:
bool hasProperty(NPIdentifier propertyName)
{
return propertyName == pluginTest()->NPN_GetStringIdentifier("testObject");
}
bool getProperty(NPIdentifier propertyName, NPVariant* result)
{
if (propertyName != pluginTest()->NPN_GetStringIdentifier("testObject"))
return false;
NPObject* testObject = TestObject::create(pluginTest());
OBJECT_TO_NPVARIANT(testObject, *result);
return true;
}
};
NPError NPP_New(NPMIMEType pluginType,
uint16_t mode,
int16_t argc,
char* argn[],
char* argv[],
NPSavedData* saved) override {
registerNPShutdownFunction(shutdown);
return NPERR_NO_ERROR;
}
NPError NPP_GetValue(NPPVariable variable, void* value) override {
if (variable != NPPVpluginScriptableNPObject)
return NPERR_GENERIC_ERROR;
*(NPObject**)value = ScriptableObject::create(this);
return NPERR_NO_ERROR;
}
static void shutdown()
{
wasShutdownCalled = true;
}
};
static PluginTest::Register<NPDeallocateCalledBeforeNPShutdown> npRuntimeObjectFromDestroyedPlugin("np-deallocate-called-before-np-shutdown");

@ -1,56 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include "PluginTest.h"
#include <string.h>
using namespace std;
class NPPNewFails : public PluginTest {
public:
NPPNewFails(NPP npp, const string& identifier)
: PluginTest(npp, identifier)
{
}
private:
NPError NPP_New(NPMIMEType pluginType,
uint16_t mode,
int16_t argc,
char* argn[],
char* argv[],
NPSavedData* saved) override {
return NPERR_GENERIC_ERROR;
}
};
static PluginTest::Register<NPPNewFails> nppNewFails("npp-new-fails");

@ -1,131 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "PluginTest.h"
#include <stdint.h>
#include "PluginObject.h"
using namespace std;
// NPP_SetWindow should be called with a null window handle as destruction begins on non-Mac platforms.
class NPPSetWindowCalledDuringDestruction : public PluginTest {
public:
NPPSetWindowCalledDuringDestruction(NPP, const string& identifier);
void setWillBeDestroyed() { m_willBeDestroyed = true; }
private:
struct ScriptObject : Object<ScriptObject> {
bool hasMethod(NPIdentifier);
bool invoke(NPIdentifier, const NPVariant*, uint32_t, NPVariant*);
};
virtual NPError NPP_GetValue(NPPVariable, void*);
virtual NPError NPP_SetWindow(NPWindow*);
virtual NPError NPP_Destroy(NPSavedData**);
bool m_willBeDestroyed;
bool m_setWindowCalledBeforeDestruction;
bool m_setWindowCalledDuringDestruction;
};
static PluginTest::Register<NPPSetWindowCalledDuringDestruction> registrar("npp-set-window-called-during-destruction");
NPPSetWindowCalledDuringDestruction::NPPSetWindowCalledDuringDestruction(NPP npp, const string& identifier)
: PluginTest(npp, identifier)
, m_willBeDestroyed(false)
, m_setWindowCalledBeforeDestruction(false)
, m_setWindowCalledDuringDestruction(false)
{
}
NPError NPPSetWindowCalledDuringDestruction::NPP_GetValue(NPPVariable variable, void* value)
{
if (variable != NPPVpluginScriptableNPObject)
return NPERR_GENERIC_ERROR;
*static_cast<NPObject**>(value) = ScriptObject::create(this);
return NPERR_NO_ERROR;
}
NPError NPPSetWindowCalledDuringDestruction::NPP_SetWindow(NPWindow* window)
{
if (m_willBeDestroyed) {
m_setWindowCalledDuringDestruction = true;
if (!m_setWindowCalledBeforeDestruction) {
log("Fail: setWillBeDestroyed() was called before the initial NPP_SetWindow call");
return NPERR_NO_ERROR;
}
#ifndef XP_MACOSX
if (window->window)
log("Fail: NPP_SetWindow passed a non-null window during plugin destruction");
#endif
return NPERR_NO_ERROR;
}
if (m_setWindowCalledBeforeDestruction) {
log("Fail: NPP_SetWindow called more than once before plugin destruction");
return NPERR_NO_ERROR;
}
m_setWindowCalledBeforeDestruction = true;
return NPERR_NO_ERROR;
}
NPError NPPSetWindowCalledDuringDestruction::NPP_Destroy(NPSavedData**)
{
#ifdef XP_MACOSX
bool shouldHaveBeenCalledDuringDestruction = false;
#else
bool shouldHaveBeenCalledDuringDestruction = true;
#endif
if (m_setWindowCalledDuringDestruction == shouldHaveBeenCalledDuringDestruction)
log("Success: NPP_SetWindow %s called during plugin destruction", shouldHaveBeenCalledDuringDestruction ? "was" : "was not");
else
log("Fail: NPP_SetWindow %s called during plugin destruction", shouldHaveBeenCalledDuringDestruction ? "was not" : "was");
return NPERR_NO_ERROR;
}
bool NPPSetWindowCalledDuringDestruction::ScriptObject::hasMethod(NPIdentifier methodName)
{
return methodName == pluginTest()->NPN_GetStringIdentifier("setWillBeDestroyed");
}
bool NPPSetWindowCalledDuringDestruction::ScriptObject::invoke(NPIdentifier identifier, const NPVariant*, uint32_t, NPVariant*)
{
assert(identifier == pluginTest()->NPN_GetStringIdentifier("setWillBeDestroyed"));
static_cast<NPPSetWindowCalledDuringDestruction*>(pluginTest())->setWillBeDestroyed();
return true;
}

@ -1,76 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include "PluginTest.h"
class NPRuntimeCallsWithNullNPP : public PluginTest {
public:
NPRuntimeCallsWithNullNPP(NPP npp, const std::string& identifier)
: PluginTest(npp, identifier)
{
}
private:
NPError NPP_New(NPMIMEType pluginType,
uint16_t mode,
int16_t argc,
char* argn[],
char* argv[],
NPSavedData* saved) override {
NPObject* windowObject = 0;
if (NPN_GetValue(NPNVWindowNPObject, &windowObject) != NPERR_NO_ERROR || !windowObject)
return NPERR_GENERIC_ERROR;
NPIdentifier alertIdentifier = NPN_GetStringIdentifier("alert");
if (!PluginTest::netscapeFuncs()->hasmethod(0, windowObject, alertIdentifier)) {
NPN_ReleaseObject(windowObject);
return NPERR_GENERIC_ERROR;
}
NPIdentifier documentIdentifier = NPN_GetStringIdentifier("document");
NPVariant variant;
if (!PluginTest::netscapeFuncs()->getproperty(0, windowObject, documentIdentifier, &variant)) {
NPN_ReleaseObject(windowObject);
return NPERR_GENERIC_ERROR;
}
NPN_ReleaseVariantValue(&variant);
NPN_ReleaseObject(windowObject);
executeScript("document.getElementById('result').innerHTML = 'SUCCESS!'");
notifyDone();
return NPERR_NO_ERROR;
}
};
static PluginTest::Register<NPRuntimeCallsWithNullNPP> npRuntimeCallsWithNullNPP("npruntime-calls-with-null-npp");

@ -1,93 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include "PluginTest.h"
using namespace std;
class NPRuntimeObjectFromDestroyedPlugin : public PluginTest {
public:
NPRuntimeObjectFromDestroyedPlugin(NPP npp, const string& identifier)
: PluginTest(npp, identifier)
{
}
private:
// This is the test object.
class TestObject : public Object<TestObject> { };
// This is the scriptable object. It has a single "testObject" property and an "evaluate" function.
class ScriptableObject : public Object<ScriptableObject> {
public:
bool hasMethod(NPIdentifier methodName)
{
return identifierIs(methodName, "evaluate");
}
bool invoke(NPIdentifier methodName, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
if (!identifierIs(methodName, "evaluate"))
return false;
if (argCount != 1 || !NPVARIANT_IS_STRING(args[0]))
return false;
return pluginTest()->executeScript(&NPVARIANT_TO_STRING(args[0]), result);
}
bool hasProperty(NPIdentifier propertyName)
{
return identifierIs(propertyName, "testObject");
}
bool getProperty(NPIdentifier propertyName, NPVariant* result)
{
if (propertyName != pluginTest()->NPN_GetStringIdentifier("testObject"))
return false;
NPObject* testObject = TestObject::create(pluginTest());
OBJECT_TO_NPVARIANT(testObject, *result);
return true;
}
};
NPError NPP_GetValue(NPPVariable variable, void* value) override {
if (variable != NPPVpluginScriptableNPObject)
return NPERR_GENERIC_ERROR;
*(NPObject**)value = ScriptableObject::create(this);
return NPERR_NO_ERROR;
}
};
static PluginTest::Register<NPRuntimeObjectFromDestroyedPlugin> npRuntimeObjectFromDestroyedPlugin("npruntime-object-from-destroyed-plugin");

@ -1,173 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include <string.h>
#include "PluginTest.h"
using namespace std;
class NPRuntimeRemoveProperty : public PluginTest {
public:
NPRuntimeRemoveProperty(NPP npp, const string& identifier)
: PluginTest(npp, identifier)
{
}
private:
struct TestObject : Object<TestObject> {
public:
TestObject()
: m_lastRemovedProperty(0)
{
}
bool hasProperty(NPIdentifier propertyName)
{
if (identifierIs(propertyName, "lastRemovedProperty"))
return true;
return false;
}
bool getProperty(NPIdentifier propertyName, NPVariant* result)
{
assert(identifierIs(propertyName, "lastRemovedProperty"));
if (!m_lastRemovedProperty)
return false;
if (pluginTest()->NPN_IdentifierIsString(m_lastRemovedProperty)) {
char* lastRemovedPropertyName = pluginTest()->NPN_UTF8FromIdentifier(m_lastRemovedProperty);
STRINGZ_TO_NPVARIANT(lastRemovedPropertyName, *result);
return true;
}
int intIdentifier = pluginTest()->NPN_IntFromIdentifier(m_lastRemovedProperty);
DOUBLE_TO_NPVARIANT(intIdentifier, *result);
return true;
}
bool removeProperty(NPIdentifier propertyName)
{
m_lastRemovedProperty = propertyName;
return true;
}
private:
NPIdentifier m_lastRemovedProperty;
};
struct PluginObject : Object<PluginObject> {
public:
PluginObject()
: m_testObject(0)
{
}
~PluginObject() override {
if (m_testObject)
pluginTest()->NPN_ReleaseObject(m_testObject);
}
bool hasMethod(NPIdentifier methodName)
{
if (identifierIs(methodName, "testRemoveProperty"))
return true;
return false;
}
bool invoke(NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result)
{
assert(identifierIs(methodName, "testRemoveProperty"));
if (argumentCount != 2)
return false;
if (!NPVARIANT_IS_OBJECT(arguments[0]))
return false;
if (!NPVARIANT_IS_STRING(arguments[1]) && !NPVARIANT_IS_DOUBLE(arguments[1]))
return false;
NPIdentifier propertyName;
if (NPVARIANT_IS_STRING(arguments[1])) {
string propertyNameString(arguments[1].value.stringValue.UTF8Characters,
arguments[1].value.stringValue.UTF8Length);
propertyName = pluginTest()->NPN_GetStringIdentifier(propertyNameString.c_str());
} else {
int32_t number = static_cast<int32_t>(arguments[1].value.doubleValue);
propertyName = pluginTest()->NPN_GetIntIdentifier(number);
}
pluginTest()->NPN_RemoveProperty(NPVARIANT_TO_OBJECT(arguments[0]), propertyName);
VOID_TO_NPVARIANT(*result);
return true;
}
bool hasProperty(NPIdentifier propertyName)
{
if (identifierIs(propertyName, "testObject"))
return true;
return false;
}
bool getProperty(NPIdentifier propertyName, NPVariant* result)
{
assert(identifierIs(propertyName, "testObject"));
if (!m_testObject)
m_testObject = TestObject::create(pluginTest());
OBJECT_TO_NPVARIANT(pluginTest()->NPN_RetainObject(m_testObject), *result);
return true;
}
private:
NPObject* m_testObject;
};
NPError NPP_GetValue(NPPVariable variable, void* value) override {
if (variable != NPPVpluginScriptableNPObject)
return NPERR_GENERIC_ERROR;
*(NPObject**)value = PluginObject::create(this);
return NPERR_NO_ERROR;
}
};
static PluginTest::Register<NPRuntimeRemoveProperty> npRuntimeRemoveProperty("npruntime-remove-property");

@ -1,74 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "PluginTest.h"
#include "PluginObject.h"
using namespace std;
// Passing null for our NPP_GetValue function pointer should not crash.
class NullNPPGetValuePointer : public PluginTest {
public:
NullNPPGetValuePointer(NPP, const string& identifier);
private:
NPError NPP_Destroy(NPSavedData**) override;
NPError NPP_GetValue(NPPVariable, void* value) override;
NPP_GetValueProcPtr m_originalNPPGetValuePointer;
};
static PluginTest::Register<NullNPPGetValuePointer> registrar("null-npp-getvalue-pointer");
NullNPPGetValuePointer::NullNPPGetValuePointer(NPP npp, const string& identifier)
: PluginTest(npp, identifier)
, m_originalNPPGetValuePointer(pluginFunctions->getvalue)
{
// Be sneaky and null out the getvalue pointer the browser is holding. This simulates a plugin
// that doesn't implement NPP_GetValue (like Shockwave Director 10.3 on Windows). Note that if
// WebKit copies the NPPluginFuncs struct this technique will have no effect and WebKit will
// call into our NPP_GetValue implementation.
pluginFunctions->getvalue = 0;
}
NPError NullNPPGetValuePointer::NPP_Destroy(NPSavedData**)
{
// Set the NPP_GetValue pointer back the way it was before we mucked with it so we don't mess
// up future uses of the plugin module.
pluginFunctions->getvalue = m_originalNPPGetValuePointer;
return NPERR_NO_ERROR;
}
NPError NullNPPGetValuePointer::NPP_GetValue(NPPVariable, void*)
{
pluginLog(m_npp, "NPP_GetValue was called but should not have been. Maybe WebKit copied the NPPluginFuncs struct, which would invalidate this test.");
return NPERR_GENERIC_ERROR;
}

@ -1,75 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "PluginTest.h"
#include "PluginObject.h"
using namespace std;
// Passing a different NPP struct that has the same ndata value as the one passed to NPP_New should
// not trigger an assertion failure.
class PassDifferentNPPStruct : public PluginTest {
public:
PassDifferentNPPStruct(NPP npp, const string& identifier)
: PluginTest(npp, identifier)
, m_didReceiveInitialSetWindowCall(false)
{
}
private:
NPError NPP_SetWindow(NPWindow* window) override {
if (m_didReceiveInitialSetWindowCall)
return NPERR_NO_ERROR;
m_didReceiveInitialSetWindowCall = true;
NPP oldNPP = m_npp;
NPP_t differentNPP = *m_npp;
m_npp = &differentNPP;
NPBool privateMode;
NPError error = NPN_GetValue(NPNVprivateModeBool, &privateMode);
m_npp = oldNPP;
if (error != NPERR_NO_ERROR) {
log("NPN_GetValue(NPNVprivateModeBool) with a different NPP struct failed with error %d", error);
notifyDone();
return NPERR_GENERIC_ERROR;
}
log("NPN_GetValue(NPNVprivateModeBool) with a different NPP struct succeeded");
notifyDone();
return NPERR_NO_ERROR;
}
bool m_didReceiveInitialSetWindowCall;
};
static PluginTest::Register<PassDifferentNPPStruct> getValueNetscapeWindow("pass-different-npp-struct");

@ -1,73 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include "PluginTest.h"
using namespace std;
// A test where the plugins scriptable object either has or doesn't have an invokeDefault function.
class PluginScriptableNPObjectInvokeDefault : public PluginTest {
public:
PluginScriptableNPObjectInvokeDefault(NPP npp, const string& identifier)
: PluginTest(npp, identifier)
{
}
private:
struct NPObjectWithoutInvokeDefault : Object<NPObjectWithoutInvokeDefault> { };
struct NPObjectWithInvokeDefault : Object<NPObjectWithInvokeDefault> {
public:
bool invokeDefault(const NPVariant*, uint32_t, NPVariant* result)
{
INT32_TO_NPVARIANT(1, *result);
return true;
}
};
NPError NPP_GetValue(NPPVariable variable, void* value) override {
if (variable != NPPVpluginScriptableNPObject)
return NPERR_GENERIC_ERROR;
NPObject* object;
if (identifier() == "plugin-scriptable-npobject-invoke-default")
object = NPObjectWithInvokeDefault::create(this);
else
object = NPObjectWithoutInvokeDefault::create(this);
*(NPObject**)value = object;
return NPERR_NO_ERROR;
}
};
static PluginTest::Register<PluginScriptableNPObjectInvokeDefault> pluginScriptableNPObjectInvokeDefault("plugin-scriptable-npobject-invoke-default");
static PluginTest::Register<PluginScriptableNPObjectInvokeDefault> pluginScriptableNPObjectNoInvokeDefault("plugin-scriptable-npobject-no-invoke-default");

@ -1,84 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "PluginTest.h"
#include <stdio.h>
#include <string.h>
using namespace std;
class PluginScriptableObjectOverridesAllProperties : public PluginTest {
public:
PluginScriptableObjectOverridesAllProperties(NPP npp, const string& identifier)
: PluginTest(npp, identifier)
{
}
private:
class PluginObject : public Object<PluginObject> {
public:
PluginObject()
{
}
~PluginObject() override {}
bool hasProperty(NPIdentifier propertyName)
{
return true;
}
bool getProperty(NPIdentifier propertyName, NPVariant* result)
{
static const char* message = "My name is ";
char* propertyString = pluginTest()->NPN_UTF8FromIdentifier(propertyName);
int bufferLength = strlen(propertyString) + strlen(message) + 1;
char* resultBuffer = static_cast<char*>(pluginTest()->NPN_MemAlloc(bufferLength));
snprintf(resultBuffer, bufferLength, "%s%s", message, propertyString);
STRINGZ_TO_NPVARIANT(resultBuffer, *result);
return true;
}
};
NPError NPP_GetValue(NPPVariable variable, void* value) override {
if (variable != NPPVpluginScriptableNPObject)
return NPERR_GENERIC_ERROR;
*(NPObject**)value = PluginObject::create(this);
return NPERR_NO_ERROR;
}
};
static PluginTest::Register<PluginScriptableObjectOverridesAllProperties> pluginScriptableObjectOverridesAllProperties("plugin-scriptable-object-overrides-all-properties");

@ -1,93 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include "PluginTest.h"
#include <string.h>
using namespace std;
class SlowNPPNew : public PluginTest {
public:
SlowNPPNew(NPP npp, const string& identifier)
: PluginTest(npp, identifier)
{
}
private:
class PluginObject : public Object<PluginObject> {
public:
PluginObject()
{
}
~PluginObject()
{
}
bool hasProperty(NPIdentifier propertyName)
{
return true;
}
bool getProperty(NPIdentifier propertyName, NPVariant* result)
{
static const char* message = "My name is ";
char* propertyString = pluginTest()->NPN_UTF8FromIdentifier(propertyName);
int bufferLength = strlen(propertyString) + strlen(message) + 1;
char* resultBuffer = static_cast<char*>(pluginTest()->NPN_MemAlloc(bufferLength));
snprintf(resultBuffer, bufferLength, "%s%s", message, propertyString);
STRINGZ_TO_NPVARIANT(resultBuffer, *result);
return true;
}
};
virtual NPError NPP_GetValue(NPPVariable variable, void *value)
{
if (variable != NPPVpluginScriptableNPObject)
return NPERR_GENERIC_ERROR;
*(NPObject**)value = PluginObject::create(this);
return NPERR_NO_ERROR;
}
virtual NPError NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData *saved)
{
usleep(550000);
return NPERR_NO_ERROR;
}
};
static PluginTest::Register<SlowNPPNew> slowNPPNew("slow-npp-new");

@ -1,60 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>test_netscape_plugin</string>
<key>CFBundleGetInfoString</key>
<string>420+, Copyright 2006-2009 Apple Inc.</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.apple.testnetscapeplugin</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BRPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFPlugInDynamicRegisterFunction</key>
<string></string>
<key>CFPlugInDynamicRegistration</key>
<string>NO</string>
<key>CFPlugInFactories</key>
<dict>
<key>00000000-0000-0000-0000-000000000000</key>
<string>MyFactoryFunction</string>
</dict>
<key>CFPlugInTypes</key>
<dict>
<key>00000000-0000-0000-0000-000000000000</key>
<array>
<string>00000000-0000-0000-0000-000000000000</string>
</array>
</dict>
<key>CFPlugInUnloadFunction</key>
<string></string>
<key>WebPluginDescription</key>
<string>Simple Netscape plug-in that handles test content for WebKit</string>
<key>WebPluginMIMETypes</key>
<dict>
<key>application/x-webkit-test-netscape</key>
<dict>
<key>WebPluginExtensions</key>
<array>
<string>testnetscape</string>
</array>
<key>WebPluginTypeDescription</key>
<string>test netscape content</string>
</dict>
</dict>
<key>WebPluginName</key>
<string>WebKit Test PlugIn</string>
</dict>
</plist>

@ -1,853 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include <stdint.h>
#include <cstdlib>
#include <cstring>
#include <string>
#include "PluginObject.h"
#include "PluginTest.h"
#include "base/strings/string_util.h"
#ifdef XP_UNIX
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#endif
#if !defined(NP_NO_CARBON) && defined(QD_HEADERS_ARE_PRIVATE) && QD_HEADERS_ARE_PRIVATE
extern "C" void GlobalToLocal(Point*);
#endif
using namespace std;
#define CRASH() do { \
*(int *)(uintptr_t)0xbbadbeef = 0; \
((void(*)())0)(); /* More reliable, but doesn't say BBADBEEF */ \
} while(false)
static bool getEntryPointsWasCalled = false;
static bool initializeWasCalled = false;
static NPClass* pluginObjectClass = 0;
#if defined(XP_WIN)
#define STDCALL __stdcall
static inline int strcasecmp(const char* s1, const char* s2)
{
return _stricmp(s1, s2);
}
#else
#define STDCALL
#endif
extern "C" {
NPError STDCALL NP_GetEntryPoints(NPPluginFuncs *pluginFuncs);
}
// Entry points
extern "C"
NPError STDCALL NP_Initialize(NPNetscapeFuncs *browserFuncs
#ifdef XP_UNIX
, NPPluginFuncs *pluginFuncs
#endif
)
{
// Create a copy of the PluginObject NPClass that we can trash on shutdown.
pluginObjectClass = createPluginClass();
initializeWasCalled = true;
#if defined(XP_WIN)
// Simulate Flash and QuickTime's behavior of crashing when NP_Initialize is called before NP_GetEntryPoints.
if (!getEntryPointsWasCalled)
CRASH();
#endif
browser = browserFuncs;
#ifdef XP_UNIX
return NP_GetEntryPoints(pluginFuncs);
#else
return NPERR_NO_ERROR;
#endif
}
extern "C"
NPError STDCALL NP_GetEntryPoints(NPPluginFuncs *pluginFuncs)
{
getEntryPointsWasCalled = true;
#ifdef XP_MACOSX
// Simulate Silverlight's behavior of crashing when NP_GetEntryPoints is called before NP_Initialize.
if (!initializeWasCalled)
CRASH();
#endif
pluginFunctions = pluginFuncs;
pluginFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
pluginFuncs->size = sizeof(pluginFuncs);
pluginFuncs->newp = NPP_New;
pluginFuncs->destroy = NPP_Destroy;
pluginFuncs->setwindow = NPP_SetWindow;
pluginFuncs->newstream = NPP_NewStream;
pluginFuncs->destroystream = NPP_DestroyStream;
pluginFuncs->asfile = NPP_StreamAsFile;
pluginFuncs->writeready = NPP_WriteReady;
pluginFuncs->write = (NPP_WriteProcPtr)NPP_Write;
pluginFuncs->print = NPP_Print;
pluginFuncs->event = NPP_HandleEvent;
pluginFuncs->urlnotify = NPP_URLNotify;
pluginFuncs->getvalue = NPP_GetValue;
pluginFuncs->setvalue = NPP_SetValue;
return NPERR_NO_ERROR;
}
extern "C"
void STDCALL NP_Shutdown(void)
{
// Trash the PluginObject NPClass so that the process will deterministically
// crash if Blink tries to call into the plugin's NPObjects after unloading
// it, rather than relying on OS-specific DLL unload behaviour.
// Note that we leak the NPClass copy, to act as a guard for the lifetime of
// the process.
memset(pluginObjectClass, 0xf00dbeef, sizeof(NPClass));
PluginTest::NP_Shutdown();
}
static void executeScript(const PluginObject* obj, const char* script);
NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char *argn[], char *argv[], NPSavedData *saved)
{
#ifdef XP_MACOSX
NPEventModel eventModel;
// Always turn on the CG model
NPBool supportsCoreGraphics;
if (browser->getvalue(instance, NPNVsupportsCoreGraphicsBool, &supportsCoreGraphics) != NPERR_NO_ERROR)
supportsCoreGraphics = false;
if (!supportsCoreGraphics)
return NPERR_INCOMPATIBLE_VERSION_ERROR;
#ifndef NP_NO_CARBON
NPBool supportsCarbon = false;
#endif
NPBool supportsCocoa = false;
#ifndef NP_NO_CARBON
// A browser that doesn't know about NPNVsupportsCarbonBool is one that only supports Carbon event model.
if (browser->getvalue(instance, NPNVsupportsCarbonBool, &supportsCarbon) != NPERR_NO_ERROR)
supportsCarbon = true;
#endif
if (browser->getvalue(instance, NPNVsupportsCocoaBool, &supportsCocoa) != NPERR_NO_ERROR)
supportsCocoa = false;
if (supportsCocoa) {
eventModel = NPEventModelCocoa;
#ifndef NP_NO_CARBON
} else if (supportsCarbon) {
eventModel = NPEventModelCarbon;
#endif
} else {
return NPERR_INCOMPATIBLE_VERSION_ERROR;
}
browser->setvalue(instance, NPPVpluginEventModel, (void *)eventModel);
#endif // XP_MACOSX
PluginObject* obj = (PluginObject*)browser->createobject(instance, pluginObjectClass);
instance->pdata = obj;
#ifdef XP_MACOSX
obj->eventModel = eventModel;
#endif // XP_MACOSX
obj->alwaysFilterEvents = false;
string testIdentifier;
const char* onNewScript = 0;
for (int i = 0; i < argc; i++) {
if (strcasecmp(argn[i], "test") == 0)
testIdentifier = argv[i];
if (strcasecmp(argn[i], "onstreamload") == 0 && !obj->onStreamLoad)
obj->onStreamLoad = base::strdup(argv[i]);
else if (strcasecmp(argn[i], "onStreamDestroy") == 0 && !obj->onStreamDestroy)
obj->onStreamDestroy = base::strdup(argv[i]);
else if (strcasecmp(argn[i], "onURLNotify") == 0 && !obj->onURLNotify)
obj->onURLNotify = base::strdup(argv[i]);
else if (strcasecmp(argn[i], "src") == 0 &&
strcasecmp(argv[i], "data:application/x-webkit-test-netscape,returnerrorfromnewstream") == 0)
obj->returnErrorFromNewStream = true;
else if (strcasecmp(argn[i], "src") == 0 &&
strcasecmp(argv[i], "data:application/x-webkit-test-netscape,alertwhenloaded") == 0)
executeScript(obj, "alert('Plugin Loaded!')");
else if (strcasecmp(argn[i], "src") == 0 &&
strcasecmp(argv[i], "data:application/x-webkit-test-netscape,logifloaded") == 0) {
for (int j = 0; j < argc; j++) {
if (strcasecmp(argn[j], "log") == 0) {
int length = 26 + strlen(argv[j]) + 1;
char* buffer = (char*) malloc(length);
snprintf(buffer, length, "xWebkitTestNetscapeLog('%s')", argv[j]);
executeScript(obj, buffer);
free(buffer);
}
}
} else if (strcasecmp(argn[i], "onSetWindow") == 0 && !obj->onSetWindow)
obj->onSetWindow = base::strdup(argv[i]);
else if (strcasecmp(argn[i], "onNew") == 0 && !onNewScript)
onNewScript = argv[i];
else if (strcasecmp(argn[i], "onPaintEvent") == 0 && !obj->onPaintEvent)
obj->onPaintEvent = base::strdup(argv[i]);
else if (strcasecmp(argn[i], "logfirstsetwindow") == 0)
obj->logSetWindow = true;
else if (strcasecmp(argn[i], "testnpruntime") == 0)
testNPRuntime(instance);
else if (strcasecmp(argn[i], "logSrc") == 0) {
for (int i = 0; i < argc; i++)
if (strcasecmp(argn[i], "src") == 0)
pluginLog(instance, "src: %s", argv[i]);
} else if (strcasecmp(argn[i], "cleardocumentduringnew") == 0)
executeScript(obj, "document.body.innerHTML = ''");
else if (!strcasecmp(argn[i], "ondestroy"))
obj->onDestroy = base::strdup(argv[i]);
else if (strcasecmp(argn[i], "testwindowopen") == 0)
obj->testWindowOpen = true;
else if (strcasecmp(argn[i], "testGetURLOnDestroy") == 0) {
#if defined(XP_WIN)
// FIXME: When https://bugs.webkit.org/show_bug.cgi?id=41831 is fixed, this #ifdef can be removed.
obj->testGetURLOnDestroy = TRUE;
#endif
} else if (!strcasecmp(argn[i], "src") && strstr(argv[i], "plugin-document-has-focus.pl"))
obj->testKeyboardFocusForPlugins = true;
else if (!strcasecmp(argn[i], "evaluatescript")) {
char* script = argv[i];
if (script == strstr(script, "mouse::")) {
obj->mouseDownForEvaluateScript = true;
obj->evaluateScriptOnMouseDownOrKeyDown = base::strdup(script + sizeof("mouse::") - 1);
} else if (script == strstr(script, "key::")) {
obj->evaluateScriptOnMouseDownOrKeyDown = base::strdup(script + sizeof("key::") - 1);
}
// When testing evaluate script on mouse-down or key-down, allow event logging to handle events.
if (obj->evaluateScriptOnMouseDownOrKeyDown)
obj->eventLogging = true;
} else if (!strcasecmp(argn[i], "alwaysFilterEvents")) {
obj->alwaysFilterEvents = true;
}
}
#ifdef XP_MACOSX
browser->setvalue(instance, NPPVpluginDrawingModel, (void *)NPDrawingModelCoreGraphics);
#endif
obj->pluginTest = PluginTest::create(instance, testIdentifier);
if (!obj->pluginTest) {
pluginLog(instance, "NPP_New: Could not find a test named \"%s\", maybe its .cpp file wasn't added to the build system?", testIdentifier.c_str());
return NPERR_GENERIC_ERROR;
}
if (onNewScript)
executeScript(obj, onNewScript);
return obj->pluginTest->NPP_New(pluginType, mode, argc, argn, argv, saved);
}
NPError NPP_Destroy(NPP instance, NPSavedData **save)
{
PluginObject* obj = static_cast<PluginObject*>(instance->pdata);
if (obj) {
if (obj->testGetURLOnDestroy)
browser->geturlnotify(obj->npp, "about:blank", "", 0);
if (obj->onDestroy) {
executeScript(obj, obj->onDestroy);
free(obj->onDestroy);
}
if (obj->onStreamLoad)
free(obj->onStreamLoad);
if (obj->onStreamDestroy)
free(obj->onStreamDestroy);
if (obj->onURLNotify)
free(obj->onURLNotify);
if (obj->onSetWindow)
free(obj->onSetWindow);
if (obj->onPaintEvent)
free(obj->onPaintEvent);
if (obj->evaluateScriptOnMouseDownOrKeyDown)
free(obj->evaluateScriptOnMouseDownOrKeyDown);
if (obj->logDestroy) {
// Note: this intentionally avoids using pluginLog(), because that
// requires running JS during document detach, which is forbidden.
puts("PLUGIN: NPP_Destroy");
fflush(stdout);
}
if (obj->pluginTest)
obj->pluginTest->NPP_Destroy(save);
browser->releaseobject(&obj->header);
}
return NPERR_NO_ERROR;
}
NPError NPP_SetWindow(NPP instance, NPWindow *window)
{
PluginObject* obj = static_cast<PluginObject*>(instance->pdata);
if (obj) {
obj->lastWindow = *window;
if (obj->logSetWindow) {
pluginLog(instance, "NPP_SetWindow: %d %d", (int)window->width, (int)window->height);
obj->logSetWindow = false;
executeScript(obj, "testRunner.notifyDone();");
}
if (obj->onSetWindow)
executeScript(obj, obj->onSetWindow);
if (obj->testWindowOpen) {
testWindowOpen(instance);
obj->testWindowOpen = false;
}
if (obj->testKeyboardFocusForPlugins) {
obj->eventLogging = true;
executeScript(obj, "eventSender.keyDown('A');");
}
}
return obj->pluginTest->NPP_SetWindow(window);
}
static void executeScript(const PluginObject* obj, const char* script)
{
NPObject *windowScriptObject;
browser->getvalue(obj->npp, NPNVWindowNPObject, &windowScriptObject);
NPString npScript;
npScript.UTF8Characters = script;
npScript.UTF8Length = strlen(script);
NPVariant browserResult;
browser->evaluate(obj->npp, windowScriptObject, &npScript, &browserResult);
browser->releasevariantvalue(&browserResult);
}
NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, uint16_t *stype)
{
PluginObject* obj = static_cast<PluginObject*>(instance->pdata);
obj->stream = stream;
*stype = NP_NORMAL;
if (obj->returnErrorFromNewStream)
return NPERR_GENERIC_ERROR;
if (browser->version >= NPVERS_HAS_RESPONSE_HEADERS)
notifyStream(obj, stream->url, stream->headers);
if (obj->onStreamLoad)
executeScript(obj, obj->onStreamLoad);
return obj->pluginTest->NPP_NewStream(type, stream, seekable, stype);
}
NPError NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason)
{
PluginObject* obj = (PluginObject*)instance->pdata;
if (obj->onStreamDestroy) {
NPObject* windowObject = 0;
NPError error = browser->getvalue(instance, NPNVWindowNPObject, &windowObject);
if (error == NPERR_NO_ERROR) {
NPVariant onStreamDestroyVariant;
if (browser->getproperty(instance, windowObject, browser->getstringidentifier(obj->onStreamDestroy), &onStreamDestroyVariant)) {
if (NPVARIANT_IS_OBJECT(onStreamDestroyVariant)) {
NPObject* onStreamDestroyFunction = NPVARIANT_TO_OBJECT(onStreamDestroyVariant);
NPVariant reasonVariant;
INT32_TO_NPVARIANT(reason, reasonVariant);
NPVariant result;
browser->invokeDefault(instance, onStreamDestroyFunction, &reasonVariant, 1, &result);
browser->releasevariantvalue(&result);
}
browser->releasevariantvalue(&onStreamDestroyVariant);
}
browser->releaseobject(windowObject);
}
}
return obj->pluginTest->NPP_DestroyStream(stream, reason);
}
int32_t NPP_WriteReady(NPP instance, NPStream *stream)
{
PluginObject* obj = (PluginObject*)instance->pdata;
return obj->pluginTest->NPP_WriteReady(stream);
}
int32_t NPP_Write(NPP instance, NPStream *stream, int32_t offset, int32_t len, void *buffer)
{
PluginObject* obj = (PluginObject*)instance->pdata;
if (obj->returnNegativeOneFromWrite)
return -1;
return obj->pluginTest->NPP_Write(stream, offset, len, buffer);
}
void NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname)
{
}
void NPP_Print(NPP instance, NPPrint *platformPrint)
{
}
#ifdef XP_MACOSX
#ifndef NP_NO_CARBON
static int16_t handleEventCarbon(NPP instance, PluginObject* obj, EventRecord* event)
{
Point pt = { event->where.v, event->where.h };
switch (event->what) {
case nullEvent:
// these are delivered non-deterministically, don't log.
break;
case mouseDown:
if (obj->eventLogging) {
#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
GlobalToLocal(&pt);
#if __clang__
#pragma clang diagnostic pop
#endif
pluginLog(instance, "mouseDown at (%d, %d)", pt.h, pt.v);
}
if (obj->evaluateScriptOnMouseDownOrKeyDown && obj->mouseDownForEvaluateScript)
executeScript(obj, obj->evaluateScriptOnMouseDownOrKeyDown);
break;
case mouseUp:
if (obj->eventLogging) {
#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
GlobalToLocal(&pt);
#if __clang__
#pragma clang diagnostic pop
#endif
pluginLog(instance, "mouseUp at (%d, %d)", pt.h, pt.v);
}
break;
case keyDown:
if (obj->eventLogging)
pluginLog(instance, "keyDown '%c'", (char)(event->message & 0xFF));
if (obj->evaluateScriptOnMouseDownOrKeyDown && !obj->mouseDownForEvaluateScript)
executeScript(obj, obj->evaluateScriptOnMouseDownOrKeyDown);
break;
case keyUp:
if (obj->eventLogging)
pluginLog(instance, "keyUp '%c'", (char)(event->message & 0xFF));
if (obj->testKeyboardFocusForPlugins) {
obj->eventLogging = false;
obj->testKeyboardFocusForPlugins = FALSE;
executeScript(obj, "testRunner.notifyDone();");
}
break;
case autoKey:
if (obj->eventLogging)
pluginLog(instance, "autoKey '%c'", (char)(event->message & 0xFF));
break;
case updateEvt:
if (obj->eventLogging)
pluginLog(instance, "updateEvt");
break;
case diskEvt:
if (obj->eventLogging)
pluginLog(instance, "diskEvt");
break;
case activateEvt:
if (obj->eventLogging)
pluginLog(instance, "activateEvt");
break;
case osEvt:
if (!obj->eventLogging)
break;
printf("PLUGIN: osEvt - ");
switch ((event->message & 0xFF000000) >> 24) {
case suspendResumeMessage:
printf("%s\n", (event->message & 0x1) ? "resume" : "suspend");
break;
case mouseMovedMessage:
printf("mouseMoved\n");
break;
default:
printf("%08lX\n", event->message);
}
break;
case kHighLevelEvent:
if (obj->eventLogging)
pluginLog(instance, "kHighLevelEvent");
break;
// NPAPI events
case NPEventType_GetFocusEvent:
if (obj->eventLogging)
pluginLog(instance, "getFocusEvent");
break;
case NPEventType_LoseFocusEvent:
if (obj->eventLogging)
pluginLog(instance, "loseFocusEvent");
break;
case NPEventType_AdjustCursorEvent:
if (obj->eventLogging)
pluginLog(instance, "adjustCursorEvent");
break;
default:
if (obj->eventLogging)
pluginLog(instance, "event %d", event->what);
}
return 0;
}
#endif
static int16_t handleEventCocoa(NPP instance, PluginObject* obj, NPCocoaEvent* event)
{
switch (event->type) {
case NPCocoaEventWindowFocusChanged:
case NPCocoaEventFocusChanged:
if (obj->eventLogging) {
if (event->data.focus.hasFocus)
pluginLog(instance, "getFocusEvent");
else
pluginLog(instance, "loseFocusEvent");
}
return 1;
case NPCocoaEventDrawRect: {
if (obj->onPaintEvent)
executeScript(obj, obj->onPaintEvent);
return 1;
}
case NPCocoaEventKeyDown:
if (obj->eventLogging && event->data.key.characters)
pluginLog(instance, "keyDown '%c'", CFStringGetCharacterAtIndex(reinterpret_cast<CFStringRef>(event->data.key.characters), 0));
if (obj->evaluateScriptOnMouseDownOrKeyDown && !obj->mouseDownForEvaluateScript)
executeScript(obj, obj->evaluateScriptOnMouseDownOrKeyDown);
return 1;
case NPCocoaEventKeyUp:
if (obj->eventLogging && event->data.key.characters) {
pluginLog(instance, "keyUp '%c'", CFStringGetCharacterAtIndex(reinterpret_cast<CFStringRef>(event->data.key.characters), 0));
if (obj->testKeyboardFocusForPlugins) {
obj->eventLogging = false;
obj->testKeyboardFocusForPlugins = FALSE;
executeScript(obj, "testRunner.notifyDone();");
}
}
return 1;
case NPCocoaEventFlagsChanged:
return 1;
case NPCocoaEventMouseDown:
if (obj->eventLogging) {
pluginLog(instance, "mouseDown at (%d, %d)",
(int)event->data.mouse.pluginX,
(int)event->data.mouse.pluginY);
}
if (obj->evaluateScriptOnMouseDownOrKeyDown && obj->mouseDownForEvaluateScript)
executeScript(obj, obj->evaluateScriptOnMouseDownOrKeyDown);
return 1;
case NPCocoaEventMouseUp:
if (obj->eventLogging) {
pluginLog(instance, "mouseUp at (%d, %d)",
(int)event->data.mouse.pluginX,
(int)event->data.mouse.pluginY);
}
return 1;
case NPCocoaEventMouseMoved:
case NPCocoaEventMouseEntered:
case NPCocoaEventMouseExited:
case NPCocoaEventMouseDragged:
case NPCocoaEventScrollWheel:
case NPCocoaEventTextInput:
return 1;
}
return 0;
}
#endif // XP_MACOSX
#ifdef XP_UNIX
static char keyEventToChar(XKeyEvent* event)
{
char c = ' ';
XLookupString(event, &c, sizeof(c), 0, 0);
return c;
}
static int16_t handleEventX11(NPP instance, PluginObject* obj, XEvent* event)
{
switch (event->type) {
case ButtonPress:
if (obj->eventLogging)
pluginLog(instance, "mouseDown at (%d, %d)", event->xbutton.x, event->xbutton.y);
if (obj->evaluateScriptOnMouseDownOrKeyDown && obj->mouseDownForEvaluateScript)
executeScript(obj, obj->evaluateScriptOnMouseDownOrKeyDown);
break;
case ButtonRelease:
if (obj->eventLogging)
pluginLog(instance, "mouseUp at (%d, %d)", event->xbutton.x, event->xbutton.y);
break;
case KeyPress:
// FIXME: extract key code
if (obj->eventLogging)
pluginLog(instance, "keyDown '%c'", keyEventToChar(&event->xkey));
if (obj->evaluateScriptOnMouseDownOrKeyDown && !obj->mouseDownForEvaluateScript)
executeScript(obj, obj->evaluateScriptOnMouseDownOrKeyDown);
break;
case KeyRelease:
// FIXME: extract key code
if (obj->eventLogging)
pluginLog(instance, "keyUp '%c'", keyEventToChar(&event->xkey));
if (obj->testKeyboardFocusForPlugins) {
obj->eventLogging = false;
obj->testKeyboardFocusForPlugins = false;
executeScript(obj, "testRunner.notifyDone();");
}
break;
case GraphicsExpose:
if (obj->eventLogging)
pluginLog(instance, "updateEvt");
if (obj->onPaintEvent)
executeScript(obj, obj->onPaintEvent);
break;
// NPAPI events
case FocusIn:
if (obj->eventLogging)
pluginLog(instance, "getFocusEvent");
break;
case FocusOut:
if (obj->eventLogging)
pluginLog(instance, "loseFocusEvent");
break;
case EnterNotify:
case LeaveNotify:
case MotionNotify:
break;
default:
if (obj->eventLogging)
pluginLog(instance, "event %d", event->type);
}
fflush(stdout);
return 0;
}
#endif // XP_UNIX
#ifdef XP_WIN
static int16_t handleEventWin(NPP instance, PluginObject* obj, NPEvent* event)
{
switch (event->event) {
case WM_PAINT:
if (obj->onPaintEvent)
executeScript(obj, obj->onPaintEvent);
break;
case WM_KEYDOWN:
if (obj->eventLogging)
pluginLog(instance, "keyDown '%c'", event->wParam);
if (obj->evaluateScriptOnMouseDownOrKeyDown && !obj->mouseDownForEvaluateScript)
executeScript(obj, obj->evaluateScriptOnMouseDownOrKeyDown);
break;
case WM_CHAR:
break;
case WM_KEYUP:
if (obj->eventLogging)
pluginLog(instance, "keyUp '%c'", event->wParam);
if (obj->testKeyboardFocusForPlugins) {
obj->eventLogging = false;
obj->testKeyboardFocusForPlugins = FALSE;
executeScript(obj, "testRunner.notifyDone();");
}
break;
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
if (obj->eventLogging)
pluginLog(instance, "mouseDown at (%d, %d)", LOWORD(event->lParam), HIWORD(event->lParam));
if (obj->evaluateScriptOnMouseDownOrKeyDown && obj->mouseDownForEvaluateScript)
executeScript(obj, obj->evaluateScriptOnMouseDownOrKeyDown);
break;
case WM_LBUTTONUP:
case WM_MBUTTONUP:
case WM_RBUTTONUP:
if (obj->eventLogging)
pluginLog(instance, "mouseUp at (%d, %d)", LOWORD(event->lParam), HIWORD(event->lParam));
break;
case WM_SETFOCUS:
if (obj->eventLogging)
pluginLog(instance, "getFocusEvent");
break;
case WM_KILLFOCUS:
if (obj->eventLogging)
pluginLog(instance, "loseFocusEvent");
break;
}
return 0;
}
#endif // XP_WIN
int16_t NPP_HandleEvent(NPP instance, void *event)
{
PluginObject* obj = static_cast<PluginObject*>(instance->pdata);
if (obj->pluginTest->NPP_HandleEvent(event) == 1)
return 1;
int16_t ret = 0;
#ifdef XP_MACOSX
#ifndef NP_NO_CARBON
assert(obj->eventModel == NPEventModelCarbon ||
obj->eventModel == NPEventModelCocoa);
if (obj->eventModel == NPEventModelCocoa)
ret = handleEventCocoa(instance, obj, static_cast<NPCocoaEvent*>(event));
else if (obj->eventModel == NPEventModelCarbon)
ret = handleEventCarbon(instance, obj, static_cast<EventRecord*>(event));
#else
assert(obj->eventModel == NPEventModelCocoa);
ret = handleEventCocoa(instance, obj, static_cast<NPCocoaEvent*>(event));
#endif
#elif defined(XP_UNIX)
ret = handleEventX11(instance, obj, static_cast<XEvent*>(event));
#elif defined(XP_WIN)
ret = handleEventWin(instance, obj, static_cast<NPEvent*>(event));
#else
// FIXME: Implement for other platforms.
return obj->alwaysFilterEvents;
#endif // XP_MACOSX
if (ret == 0 && obj->alwaysFilterEvents)
return 1;
return ret;
}
void NPP_URLNotify(NPP instance, const char *url, NPReason reason, void *notifyData)
{
PluginObject* obj = static_cast<PluginObject*>(instance->pdata);
if (obj->pluginTest->NPP_URLNotify(url, reason, notifyData))
return;
if (obj->onURLNotify)
executeScript(obj, obj->onURLNotify);
handleCallback(obj, url, reason, notifyData);
}
NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
{
#ifdef XP_UNIX
if (variable == NPPVpluginNameString) {
*((char **)value) = const_cast<char*>("WebKit Test PlugIn");
return NPERR_NO_ERROR;
}
if (variable == NPPVpluginDescriptionString) {
*((char **)value) = const_cast<char*>("Simple Netscape® plugin that handles test content for WebKit");
return NPERR_NO_ERROR;
}
if (variable == NPPVpluginNeedsXEmbed) {
*((NPBool *)value) = true;
return NPERR_NO_ERROR;
}
#endif
if (!instance)
return NPERR_GENERIC_ERROR;
PluginObject* obj = static_cast<PluginObject*>(instance->pdata);
// First, check if the PluginTest object supports getting this value.
if (obj->pluginTest->NPP_GetValue(variable, value) == NPERR_NO_ERROR)
return NPERR_NO_ERROR;
if (variable == NPPVpluginScriptableNPObject) {
void **v = (void **)value;
// Return value is expected to be retained
browser->retainobject((NPObject *)obj);
*v = obj;
return NPERR_NO_ERROR;
}
return NPERR_GENERIC_ERROR;
}
NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value)
{
PluginObject* obj = static_cast<PluginObject*>(instance->pdata);
return obj->pluginTest->NPP_SetValue(variable, value);
}
#ifdef XP_UNIX
extern "C"
const char* NP_GetMIMEDescription(void)
{
return "application/x-webkit-test-netscape:testnetscape:test netscape content";
}
extern "C"
NPError NP_GetValue(NPP instance, NPPVariable variable, void* value)
{
return NPP_GetValue(instance, variable, value);
}
#endif

@ -1,43 +0,0 @@
// Copyright 2014 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.
/*
* Copyright (C) 2007 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CONTENT_SHELL_TOOLS_PLUGIN_TEST_OBJECT_H_
#define CONTENT_SHELL_TOOLS_PLUGIN_TEST_OBJECT_H_
#include <bindings/npapi.h>
#include <bindings/npruntime.h>
namespace content {
NPClass* GetTestClass();
int GetTestObjectCount();
} // namespace content
#endif // CONTENT_SHELL_TOOLS_PLUGIN_TEST_OBJECT_H_

@ -1,6 +0,0 @@
LIBRARY "np_test_netscape_plugin"
EXPORTS
NP_GetEntryPoints @1
NP_Initialize @2
NP_Shutdown @3

@ -1,102 +0,0 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "windows.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""windows.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904e4"
BEGIN
VALUE "CompanyName", "Apple Inc."
VALUE "FileDescription", "Simple Netscape plug-in that handles test content for WebKit"
VALUE "FileExtents", "testnetscape"
VALUE "FileOpenName", "test netscape content"
VALUE "LegalCopyright", "Copyright Apple Inc. 2007-2009"
VALUE "MIMEType", "application/x-webkit-test-netscape"
VALUE "OriginalFilename", "np_test_netscape_plugin.dll"
VALUE "ProductName", "WebKit Test PlugIn"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1252
END
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

@ -1,6 +0,0 @@
LIBRARY "np_test_netscape_plugin_debug"
EXPORTS
NP_GetEntryPoints @1
NP_Initialize @2
NP_Shutdown @3

@ -1,18 +0,0 @@
// Copyright 2014 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.
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by TestNetscapePlugin.rc
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

@ -415,16 +415,9 @@ test("content_browsertests") {
]
if (is_mac) {
data += [
"$root_out_dir/Content Shell.app/",
"$root_out_dir/plugins/test_netscape_plugin.plugin/",
]
data += [ "$root_out_dir/Content Shell.app/" ]
}
if (is_win) {
# TODO(GYP): Add this once //content/shell:copy_test_netscape_plugin
# exists.
#data += [ "$root_out_dir/plugins/np_test_netscape_plugin.dll" ]
if (symbol_level != 0) {
data += [ "$root_out_dir/content_browsertests.exe.pdb" ]
}