2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 #include "PluginTest.h"
32 class NPRuntimeRemoveProperty : public PluginTest {
34 NPRuntimeRemoveProperty(NPP npp, const string& identifier)
35 : PluginTest(npp, identifier)
40 struct TestObject : Object<TestObject> {
43 : m_lastRemovedProperty(0)
47 bool hasProperty(NPIdentifier propertyName)
49 if (identifierIs(propertyName, "lastRemovedProperty"))
55 bool getProperty(NPIdentifier propertyName, NPVariant* result)
57 assert(identifierIs(propertyName, "lastRemovedProperty"));
59 if (!m_lastRemovedProperty)
62 if (pluginTest()->NPN_IdentifierIsString(m_lastRemovedProperty)) {
63 char* lastRemovedPropertyName = pluginTest()->NPN_UTF8FromIdentifier(m_lastRemovedProperty);
65 STRINGZ_TO_NPVARIANT(lastRemovedPropertyName, *result);
69 int intIdentifier = pluginTest()->NPN_IntFromIdentifier(m_lastRemovedProperty);
70 DOUBLE_TO_NPVARIANT(intIdentifier, *result);
74 bool removeProperty(NPIdentifier propertyName)
76 m_lastRemovedProperty = propertyName;
81 NPIdentifier m_lastRemovedProperty;
84 struct PluginObject : Object<PluginObject> {
94 pluginTest()->NPN_ReleaseObject(m_testObject);
97 bool hasMethod(NPIdentifier methodName)
99 if (identifierIs(methodName, "testRemoveProperty"))
105 bool invoke(NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result)
107 assert(identifierIs(methodName, "testRemoveProperty"));
109 if (argumentCount != 2)
112 if (!NPVARIANT_IS_OBJECT(arguments[0]))
115 if (!NPVARIANT_IS_STRING(arguments[1]) && !NPVARIANT_IS_DOUBLE(arguments[1]))
118 NPIdentifier propertyName;
119 if (NPVARIANT_IS_STRING(arguments[1])) {
120 string propertyNameString(arguments[1].value.stringValue.UTF8Characters,
121 arguments[1].value.stringValue.UTF8Length);
123 propertyName = pluginTest()->NPN_GetStringIdentifier(propertyNameString.c_str());
125 int32_t number = static_cast<int32_t>(arguments[1].value.doubleValue);
126 propertyName = pluginTest()->NPN_GetIntIdentifier(number);
129 pluginTest()->NPN_RemoveProperty(NPVARIANT_TO_OBJECT(arguments[0]), propertyName);
131 VOID_TO_NPVARIANT(*result);
135 bool hasProperty(NPIdentifier propertyName)
137 if (identifierIs(propertyName, "testObject"))
143 bool getProperty(NPIdentifier propertyName, NPVariant* result)
145 assert(identifierIs(propertyName, "testObject"));
148 m_testObject = TestObject::create(pluginTest());
150 OBJECT_TO_NPVARIANT(pluginTest()->NPN_RetainObject(m_testObject), *result);
155 NPObject* m_testObject;
158 virtual NPError NPP_GetValue(NPPVariable variable, void *value)
160 if (variable != NPPVpluginScriptableNPObject)
161 return NPERR_GENERIC_ERROR;
163 *(NPObject**)value = PluginObject::create(this);
165 return NPERR_NO_ERROR;
170 static PluginTest::Register<NPRuntimeRemoveProperty> npRuntimeRemoveProperty("npruntime-remove-property");