2009-10-12 10:38:11 -07:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>NPN_Invoke_Default 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">
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
// global test function
|
|
|
|
function testMe(arg) {
|
2009-10-16 15:29:15 -07:00
|
|
|
var result = arg+arg;
|
|
|
|
for (var i = 1; i < arguments.length; i++) {
|
|
|
|
result += arguments[i] + arguments[i];
|
|
|
|
}
|
|
|
|
return result;
|
2009-10-12 10:38:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
// This test exercises NPN_InvokeDefault using the test plugin's
|
|
|
|
// npnInvokeDefaultTest method. This method invokes an object
|
|
|
|
// with a single parameter, and returns the result of the invocation.
|
|
|
|
// The test list below is used to drive the tests. Each member of the
|
|
|
|
// array contains three members: the object to invoke, an argument to
|
|
|
|
// invoke it with, and the expected result of the invocation.
|
|
|
|
//
|
|
|
|
var tests = [
|
|
|
|
// Number object
|
|
|
|
["Number", 3, 3],
|
|
|
|
["Number", "3", 3],
|
|
|
|
["Number", "0x20", 32],
|
|
|
|
["Number", "three", Number.NaN],
|
|
|
|
["Number", "1e+3", 1000],
|
|
|
|
["Number", 5.6612, 5.6612],
|
|
|
|
// Array object
|
|
|
|
["Array", 3, Array(3)],
|
|
|
|
// Boolean object
|
|
|
|
["Boolean", 0, false],
|
|
|
|
["Boolean", null, false],
|
|
|
|
["Boolean", "", false],
|
|
|
|
["Boolean", false, false],
|
|
|
|
["Boolean", true, true],
|
|
|
|
["Boolean", "true", true],
|
|
|
|
["Boolean", "false", true],
|
|
|
|
["Boolean", new Boolean(false), true],
|
|
|
|
["Boolean", { "value": false }, true],
|
|
|
|
// Function object
|
|
|
|
["Function", "return 3", Function("return 3")],
|
|
|
|
["Function", "window.alert('test')", Function("window.alert('test')")],
|
|
|
|
// Object object
|
|
|
|
["Object", undefined, Object()],
|
|
|
|
["Object", null, Object()],
|
|
|
|
["Object", true, new Boolean(true)],
|
|
|
|
["Object", Boolean(), new Boolean(false)],
|
|
|
|
["Object", "a string", new String("a string")],
|
|
|
|
["Object", 3.14, new Number(3.14)],
|
|
|
|
["Object", { "key1": "test", "key2": 15 }, { "key1": "test", "key2": 15 }],
|
|
|
|
["Object", [1, 3, 5, 7, 9, 11, 13, 17], [1, 3, 5, 7, 9, 11, 13, 17]],
|
|
|
|
// RegExp object
|
|
|
|
["RegExp", "...", RegExp("...")],
|
|
|
|
// String object
|
|
|
|
["String", "testing", "testing"],
|
|
|
|
["String", "test\u0020me", "test me"],
|
|
|
|
["String", "314", "314"],
|
|
|
|
["String", "true", "true"],
|
|
|
|
["String", "null", "null"],
|
|
|
|
["String", "2 + 2", String("2 + 2")],
|
2009-10-16 15:29:15 -07:00
|
|
|
["String", ""],
|
2009-10-12 10:38:11 -07:00
|
|
|
// global functions
|
|
|
|
["testMe", 3, 6],
|
2009-10-16 15:29:15 -07:00
|
|
|
["testMe", "string", [1,2], "stringstring1,21,2"],
|
2009-10-12 10:38:11 -07:00
|
|
|
["testMe", "me", "meme"],
|
|
|
|
["testMe", undefined, Number.NaN],
|
|
|
|
["testMe", [1, 2], "1,21,2"],
|
2009-10-16 15:29:15 -07:00
|
|
|
["testMe", 3, 4, 14],
|
2009-10-12 10:38:11 -07:00
|
|
|
["isNaN", "junk", true],
|
|
|
|
["parseInt", "156", 156],
|
|
|
|
["encodeURI", "a = b", "a%20=%20b"],
|
|
|
|
];
|
|
|
|
|
|
|
|
function runTests() {
|
|
|
|
var plugin = document.getElementById("plugin1");
|
|
|
|
|
2009-10-16 10:27:33 -07:00
|
|
|
// Test calling NPN_InvokeDefault from within plugin code.
|
2009-10-12 10:38:11 -07:00
|
|
|
for each (var test in tests) {
|
2009-10-16 15:29:15 -07:00
|
|
|
var result;
|
|
|
|
var expected = test[test.length - 1];
|
|
|
|
switch (test.length) {
|
|
|
|
case 2:
|
|
|
|
result = plugin.npnInvokeDefaultTest(test[0]);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
result = plugin.npnInvokeDefaultTest(test[0], test[1]);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
result = plugin.npnInvokeDefaultTest(test[0], test[1], test[2]);
|
|
|
|
break;
|
|
|
|
}
|
2009-10-12 10:38:11 -07:00
|
|
|
// serialize the two values for easy
|
2009-10-16 15:29:15 -07:00
|
|
|
var json_expected = JSON.stringify(expected);
|
2009-10-12 10:38:11 -07:00
|
|
|
var json_result = JSON.stringify(result);
|
|
|
|
if (typeof(result) == "function")
|
|
|
|
json_result = result.toString();
|
|
|
|
if (typeof(test[2]) == "function")
|
2009-10-16 15:29:15 -07:00
|
|
|
json_expected = expected.toString();
|
2009-10-12 10:38:11 -07:00
|
|
|
is(json_result, json_expected,
|
|
|
|
"npnInvokeDefault returned an unexpected value");
|
2009-10-16 15:29:15 -07:00
|
|
|
is(typeof(result), typeof(expected),
|
2009-10-12 10:38:11 -07:00
|
|
|
"npnInvokeDefaultTest return value was of unexpected type");
|
|
|
|
var success = (json_result == json_expected &&
|
2009-10-16 15:29:15 -07:00
|
|
|
typeof(result) == typeof(expected));
|
|
|
|
appendChildNodes($("verbose"),
|
|
|
|
SPAN((success ? "pass" : "fail") + ": " + test[0] + "("));
|
|
|
|
for (var i = 1; i < test.length - 1; i++) {
|
|
|
|
appendChildNodes($("verbose"),
|
|
|
|
SPAN(JSON.stringify(test[i]) + (i < test.length - 2 ? "," : "")));
|
|
|
|
}
|
2009-10-12 10:38:11 -07:00
|
|
|
appendChildNodes($("verbose"),
|
2009-10-16 15:29:15 -07:00
|
|
|
SPAN(") == " + json_result + "(" +
|
2009-10-12 10:38:11 -07:00
|
|
|
typeof(result) + "), expected " + json_expected + "(" +
|
2009-10-16 15:29:15 -07:00
|
|
|
typeof(expected) + ")"),
|
2009-10-12 10:38:11 -07:00
|
|
|
BR()
|
|
|
|
);
|
|
|
|
}
|
2009-10-16 10:27:33 -07:00
|
|
|
|
|
|
|
// Test calling the invokedefault method of plugin-defined object
|
|
|
|
is(plugin(), "Test Plug-in",
|
|
|
|
"calling NPN_InvokeDefault on plugin-defined Object doesn't work");
|
|
|
|
is(plugin(1), "Test Plug-in;1",
|
|
|
|
"calling NPN_InvokeDefault on plugin-defined Object doesn't work");
|
|
|
|
is(plugin("test"), "Test Plug-in;test",
|
|
|
|
"calling NPN_InvokeDefault on plugin-defined Object doesn't work");
|
|
|
|
is(plugin(undefined, -1, null), "Test Plug-in;undefined;-1;null",
|
|
|
|
"calling NPN_InvokeDefault on plugin-defined Object doesn't work");
|
|
|
|
|
2009-10-12 10:38:11 -07:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div id="verbose">
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|