Backed out changeset e22b5d4e8ce9 (bug 518940) on suspicion of causing Linux orange.

--HG--
extra : rebase_source : 431d4f6349808163322ff48cfb32d85cc8beefe5
This commit is contained in:
Boris Zbarsky 2009-09-30 23:17:36 -04:00
parent ba7930b505
commit 9e1027ce01
4 changed files with 1 additions and 336 deletions

View File

@ -46,7 +46,6 @@ include $(topsrcdir)/config/rules.mk
_MOCHITEST_FILES = \
test_npobject_getters.html \
test_npruntime_npninvoke.html \
loremipsum.txt \
loremipsum_file.txt \
post.sjs \

View File

@ -1,161 +0,0 @@
<html>
<head>
<title>NPN_Invoke Tests</title>
<script type="text/javascript"
src="/MochiKit/packed.js"></script>
<script type="text/javascript"
src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css"
href="/tests/SimpleTest/test.css" />
</head>
<body onload="runTests()">
<p id="display"></p>
<embed id="plugin1" type="application/x-test" width="400" height="100">
</embed>
<script class="testbody" type="application/javascript">
////
// This test exercises NPN_Invoke by calling the plugin's npnInvokeTest
// method, which in turn invokes a script method with 1 or more parameters,
// and then compares the return vale with an expected value. This is good
// for verifying various NPVariant values and types moving between
// the browser and the plugin.
//
SimpleTest.waitForExplicitFinish();
// This function returns all the arguments passed to it, either as a
// single variable (in the caes of 1 argument), or as an array.
function returnArgs() {
if (arguments.length == 1)
return arguments[0];
var arr = new Array();
for (i = 0; i < arguments.length; i++) {
arr.push(arguments[i]);
}
return arr;
}
// Same as above but explicitly expects two arguments.
function returnTwoArgs(arg1, arg2) {
return [arg1, arg2];
}
// some objects and arrays used in the tests...
var obj = {"key1": "string", "key2": 0, "key3": true, "key4": undefined,
"key5": null, "key6": -551235.12552, "key7": false};
var arr = ["string", 0, true, false, undefined, null, -1, 55512.1252];
var obj2 = {"key1": "string", "key2": 0, "key3": true, "key4": undefined,
"key5": null, "key6": -551235.12552, "key7": false, "array": arr};
var arr2 = ["string", false, undefined, null, -1, 55512.1252,
{"a": "apple", "b": true, "c": undefined}];
////
// A list of tests to run. Each member of the main array contains
// two members: the first contains the arguments passed to npnInvokeTest,
// and the second is the expected result.
//
var tests = [
// numeric values
[["returnArgs", 0, 0], true],
[["returnArgs", 1, 1], true],
[["returnArgs", 32768, 32768], true],
[["returnArgs", -32768, -32768], true],
[["returnArgs", 2147483648, 2147483648], true],
[["returnArgs", -2147483648, -2147483648], true],
[["returnArgs", 1.0, 1.0], true],
[["returnArgs", 1.592786, 1.592786], true],
[["returnArgs", 1.592786837, 1.592786837], true],
[["returnArgs", -1.592786, -1.592786], true],
[["returnArgs", -1.592786837, -1.592786837], true],
[["returnArgs", 15235.592786, 15235.592786], true],
// null, void, bool
[["returnArgs", null, null], true],
[["returnArgs", undefined, undefined], true],
[["returnArgs", undefined, null], false],
[["returnArgs", null, undefined], false],
[["returnArgs", 0, undefined], false],
[["returnArgs", 0, null], false],
[["returnArgs", 0, false], false],
[["returnArgs", 1, true], false],
[["returnArgs", true, true], true],
[["returnArgs", false, false], true],
// strings
[["returnArgs", "", ""], true],
[["returnArgs", "test", "test"], true],
[["returnArgs", "test", "testing"], false],
[["returnArgs", "test\n", "test\n"], true],
[["returnArgs", "test\nline2", "test\nline2"], true],
[["returnArgs", "test\nline2", "testline2"], false],
[["returnArgs", "test\u000aline2", "test\u000aline2"], true],
[["returnArgs", "test\u0020line2", "test line2"], true],
[["returnArgs", "test line2", "test\u0020line2"], true],
// objects and arrays
[["returnArgs", obj, obj], true],
[["returnArgs", arr, arr], true],
[["returnArgs", obj2, obj2], true],
[["returnArgs", arr2, arr2], true],
// multiple arguments
[["returnArgs", [0, 1, 2], 0, 1, 2], true],
[["returnArgs", [5, "a", true, false, null],
5, "a", true, false, null], true],
[["returnArgs", [-1500.583, "test string\n",
[5, 10, 15, 20], {"a": 1, "b": 2}],
-1500.583, "test string\n", [5, 10, 15, 20], {"a": 1, "b": 2}], true],
[["returnArgs", [undefined, 0, null, "yes"],
undefined, 0, null, "yes"], true],
[["returnArgs", [0, undefined, null, "yes"],
0, undefined, null, "yes"], true],
// too many/too few args
[["returnTwoArgs", ["a", "b"], "a", "b", "c"], true],
[["returnTwoArgs", ["a", undefined], "a"], true],
[["returnTwoArgs", [undefined, undefined]], true],
];
function runTests() {
var plugin = document.getElementById("plugin1");
var result;
for each (var test in tests) {
switch (test[0].length) {
case 2:
result = plugin.npnInvokeTest(test[0][0], test[0][1]);
break;
case 3:
result = plugin.npnInvokeTest(test[0][0], test[0][1], test[0][2]);
break;
case 4:
result = plugin.npnInvokeTest(test[0][0], test[0][1], test[0][2],
test[0][3]);
break;
case 5:
result = plugin.npnInvokeTest(test[0][0], test[0][1], test[0][2],
test[0][3], test[0][4]);
case 6:
result = plugin.npnInvokeTest(test[0][0], test[0][1], test[0][2],
test[0][3], test[0][4], test[0][5]);
break;
case 7:
result = plugin.npnInvokeTest(test[0][0], test[0][1], test[0][2],
test[0][3], test[0][4], test[0][5], test[0][6]);
break;
default:
is(false, "bad number of test arguments");
}
is(result, test[1], "npnInvokeTestFailed: " + plugin.getError());
appendChildNodes($("verbose"),
SPAN((result == test[1] ? "pass" : "fail") + ": " + test[0]));
if (result != test[1])
appendChildNodes($("verbose"), SPAN(" " + plugin.getError()));
appendChildNodes($("verbose"), BR());
}
SimpleTest.finish();
}
</script>
<div id="verbose">
</div>
</body>
</html>

View File

@ -27,22 +27,12 @@ returns true if it succeeds and false if it doesn't. It should never succeed.
== NPRuntime testing ==
The test plugin object supports the following scriptable methods:
The test plugin object supports the following scriptable method:
* identifierToStringTest(ident)
Converts a string, int32 or double parameter 'ident' to an NPIdentifier and
then to a string, which is returned.
* npnInvokeTest(method, expected, args...)
Causes the plugin to call the specified script method using NPN_Invoke,
passing it 1 or more arguments specified in args. The return value of this
call is compared against 'expected', and if they match, npnInvokeTest will
return true. Otherwise, it will return false.
* getError()
If an error has occurred during the last stream or npruntime function,
this will return a string error message, otherwise it returns "pass".
== Private browsing ==
The test plugin object supports the following scriptable methods:

View File

@ -63,7 +63,6 @@ static NPClass sNPClass;
typedef bool (* ScriptableFunction)
(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool npnInvokeTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool setUndefinedValueTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool identifierToStringTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool timerTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
@ -82,7 +81,6 @@ static bool getLastMouseY(NPObject* npobj, const NPVariant* args, uint32_t argCo
static bool getError(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static const NPUTF8* sPluginMethodIdentifierNames[] = {
"npnInvokeTest",
"setUndefinedValueTest",
"identifierToStringTest",
"timerTest",
@ -102,7 +100,6 @@ static const NPUTF8* sPluginMethodIdentifierNames[] = {
};
static NPIdentifier sPluginMethodIdentifiers[ARRAY_LENGTH(sPluginMethodIdentifierNames)];
static const ScriptableFunction sPluginMethodFunctions[ARRAY_LENGTH(sPluginMethodIdentifierNames)] = {
npnInvokeTest,
setUndefinedValueTest,
identifierToStringTest,
timerTest,
@ -1007,25 +1004,6 @@ NPN_Write(NPP instance,
return sBrowserFuncs->write(instance, stream, len, buf);
}
bool
NPN_Enumerate(NPP instance,
NPObject *npobj,
NPIdentifier **identifiers,
uint32_t *identifierCount)
{
return sBrowserFuncs->enumerate(instance, npobj, identifiers,
identifierCount);
}
bool
NPN_GetProperty(NPP instance,
NPObject *npobj,
NPIdentifier propertyName,
NPVariant *result)
{
return sBrowserFuncs->getproperty(instance, npobj, propertyName, result);
}
//
// npruntime object functions
//
@ -1117,147 +1095,6 @@ scriptableConstruct(NPObject* npobj, const NPVariant* args, uint32_t argCount, N
// test functions
//
static bool
compareVariants(NPP instance, const NPVariant* var1, const NPVariant* var2, ostringstream* err)
{
bool success = true;
if (var1->type != var2->type) {
*err << "Variant types don't match; got " << var1->type <<
" expected " << var2->type;
return false;
}
switch (var1->type) {
case NPVariantType_Int32: {
int32_t result = NPVARIANT_TO_INT32(*var1);
int32_t expected = NPVARIANT_TO_INT32(*var2);
if (result != expected) {
*err << "Variant values don't match; got " << result <<
" expected " << expected;
success = false;
}
break;
}
case NPVariantType_Double: {
double result = NPVARIANT_TO_DOUBLE(*var1);
double expected = NPVARIANT_TO_DOUBLE(*var2);
if (result != expected) {
*err << "Variant values don't match; got " << result <<
" expected " << expected;
success = false;
}
break;
}
case NPVariantType_Void: {
// void values are always equivalent
break;
}
case NPVariantType_Null: {
// null values are always equivalent
break;
}
case NPVariantType_Bool: {
bool result = NPVARIANT_TO_BOOLEAN(*var1);
bool expected = NPVARIANT_TO_BOOLEAN(*var2);
if (result != expected) {
*err << "Variant values don't match; got " << result <<
" expected " << expected;
success = false;
}
break;
}
case NPVariantType_String: {
const NPString* result = &NPVARIANT_TO_STRING(*var1);
const NPString* expected = &NPVARIANT_TO_STRING(*var2);
if (strcmp(result->UTF8Characters, expected->UTF8Characters) ||
strlen(result->UTF8Characters) != strlen(expected->UTF8Characters)) {
*err << "Variant values don't match; got " <<
result->UTF8Characters << " expected " <<
expected->UTF8Characters;
success = false;
}
break;
}
case NPVariantType_Object: {
uint32_t i, identifierCount = 0;
NPIdentifier* identifiers;
NPObject* result = NPVARIANT_TO_OBJECT(*var1);
NPObject* expected = NPVARIANT_TO_OBJECT(*var2);
bool enumerate_result = NPN_Enumerate(instance, expected,
&identifiers, &identifierCount);
if (!enumerate_result) {
*err << "NPN_Enumerate failed";
success = false;
}
for (i = 0; i < identifierCount; i++) {
NPUTF8* utf8String = NPN_UTF8FromIdentifier(identifiers[i]);
NPVariant resultVariant, expectedVariant;
if (!NPN_GetProperty(instance, expected, identifiers[i],
&expectedVariant)) {
*err << "NPN_GetProperty returned false";
success = false;
}
else {
if (!NPN_HasProperty(instance, result, identifiers[i])) {
*err << "NPN_HasProperty returned false";
success = false;
}
else {
if (!NPN_GetProperty(instance, result, identifiers[i],
&resultVariant)) {
*err << "NPN_GetProperty 2 returned false";
success = false;
}
else {
success = compareVariants(instance, &resultVariant,
&expectedVariant, err);
NPN_ReleaseVariantValue(&expectedVariant);
}
}
NPN_ReleaseVariantValue(&resultVariant);
}
}
break;
}
default:
*err << "Unknown variant type";
success = false;
}
return success;
}
static bool
npnInvokeTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
NPP npp = static_cast<TestNPObject*>(npobj)->npp;
InstanceData* id = static_cast<InstanceData*>(npp->pdata);
id->err.str("");
if (argCount < 2)
return false;
NPIdentifier function = variantToIdentifier(args[0]);
if (!function)
return false;
NPObject* windowObject;
NPN_GetValue(npp, NPNVWindowNPObject, &windowObject);
if (!windowObject)
return false;
NPVariant invokeResult;
bool invokeReturn = NPN_Invoke(npp, windowObject, function,
argCount > 2 ? &args[2] : NULL, argCount - 2, &invokeResult);
bool compareResult = compareVariants(npp, &invokeResult, &args[1],
&id->err);
NPN_ReleaseObject(windowObject);
NPN_ReleaseVariantValue(&invokeResult);
BOOLEAN_TO_NPVARIANT(invokeReturn && compareResult, *result);
return true;
}
static bool
setUndefinedValueTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{